1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2018 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>
89 #include "rust-lang.h"
90 #include "common/pathstuff.h"
92 /* When == 1, print basic high level tracing messages.
93 When > 1, be more verbose.
94 This is in contrast to the low level DIE reading of dwarf_die_debug. */
95 static unsigned int dwarf_read_debug
= 0;
97 /* When non-zero, dump DIEs after they are read in. */
98 static unsigned int dwarf_die_debug
= 0;
100 /* When non-zero, dump line number entries as they are read in. */
101 static unsigned int dwarf_line_debug
= 0;
103 /* When non-zero, cross-check physname against demangler. */
104 static int check_physname
= 0;
106 /* When non-zero, do not reject deprecated .gdb_index sections. */
107 static int use_deprecated_index_sections
= 0;
109 static const struct objfile_data
*dwarf2_objfile_data_key
;
111 /* The "aclass" indices for various kinds of computed DWARF symbols. */
113 static int dwarf2_locexpr_index
;
114 static int dwarf2_loclist_index
;
115 static int dwarf2_locexpr_block_index
;
116 static int dwarf2_loclist_block_index
;
118 /* A descriptor for dwarf sections.
120 S.ASECTION, SIZE are typically initialized when the objfile is first
121 scanned. BUFFER, READIN are filled in later when the section is read.
122 If the section contained compressed data then SIZE is updated to record
123 the uncompressed size of the section.
125 DWP file format V2 introduces a wrinkle that is easiest to handle by
126 creating the concept of virtual sections contained within a real section.
127 In DWP V2 the sections of the input DWO files are concatenated together
128 into one section, but section offsets are kept relative to the original
130 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
131 the real section this "virtual" section is contained in, and BUFFER,SIZE
132 describe the virtual section. */
134 struct dwarf2_section_info
138 /* If this is a real section, the bfd section. */
140 /* If this is a virtual section, pointer to the containing ("real")
142 struct dwarf2_section_info
*containing_section
;
144 /* Pointer to section data, only valid if readin. */
145 const gdb_byte
*buffer
;
146 /* The size of the section, real or virtual. */
148 /* If this is a virtual section, the offset in the real section.
149 Only valid if is_virtual. */
150 bfd_size_type virtual_offset
;
151 /* True if we have tried to read this section. */
153 /* True if this is a virtual section, False otherwise.
154 This specifies which of s.section and s.containing_section to use. */
158 typedef struct dwarf2_section_info dwarf2_section_info_def
;
159 DEF_VEC_O (dwarf2_section_info_def
);
161 /* All offsets in the index are of this type. It must be
162 architecture-independent. */
163 typedef uint32_t offset_type
;
165 /* Ensure only legit values are used. */
166 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
168 gdb_assert ((unsigned int) (value) <= 1); \
169 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
172 /* Ensure only legit values are used. */
173 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
175 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
176 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
177 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
180 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
181 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
183 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
184 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
189 /* Convert VALUE between big- and little-endian. */
192 byte_swap (offset_type value
)
196 result
= (value
& 0xff) << 24;
197 result
|= (value
& 0xff00) << 8;
198 result
|= (value
& 0xff0000) >> 8;
199 result
|= (value
& 0xff000000) >> 24;
203 #define MAYBE_SWAP(V) byte_swap (V)
206 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
207 #endif /* WORDS_BIGENDIAN */
209 /* An index into a (C++) symbol name component in a symbol name as
210 recorded in the mapped_index's symbol table. For each C++ symbol
211 in the symbol table, we record one entry for the start of each
212 component in the symbol in a table of name components, and then
213 sort the table, in order to be able to binary search symbol names,
214 ignoring leading namespaces, both completion and regular look up.
215 For example, for symbol "A::B::C", we'll have an entry that points
216 to "A::B::C", another that points to "B::C", and another for "C".
217 Note that function symbols in GDB index have no parameter
218 information, just the function/method names. You can convert a
219 name_component to a "const char *" using the
220 'mapped_index::symbol_name_at(offset_type)' method. */
222 struct name_component
224 /* Offset in the symbol name where the component starts. Stored as
225 a (32-bit) offset instead of a pointer to save memory and improve
226 locality on 64-bit architectures. */
227 offset_type name_offset
;
229 /* The symbol's index in the symbol and constant pool tables of a
234 /* Base class containing bits shared by both .gdb_index and
235 .debug_name indexes. */
237 struct mapped_index_base
239 /* The name_component table (a sorted vector). See name_component's
240 description above. */
241 std::vector
<name_component
> name_components
;
243 /* How NAME_COMPONENTS is sorted. */
244 enum case_sensitivity name_components_casing
;
246 /* Return the number of names in the symbol table. */
247 virtual size_t symbol_name_count () const = 0;
249 /* Get the name of the symbol at IDX in the symbol table. */
250 virtual const char *symbol_name_at (offset_type idx
) const = 0;
252 /* Return whether the name at IDX in the symbol table should be
254 virtual bool symbol_name_slot_invalid (offset_type idx
) const
259 /* Build the symbol name component sorted vector, if we haven't
261 void build_name_components ();
263 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
264 possible matches for LN_NO_PARAMS in the name component
266 std::pair
<std::vector
<name_component
>::const_iterator
,
267 std::vector
<name_component
>::const_iterator
>
268 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
270 /* Prevent deleting/destroying via a base class pointer. */
272 ~mapped_index_base() = default;
275 /* A description of the mapped index. The file format is described in
276 a comment by the code that writes the index. */
277 struct mapped_index final
: public mapped_index_base
279 /* A slot/bucket in the symbol table hash. */
280 struct symbol_table_slot
282 const offset_type name
;
283 const offset_type vec
;
286 /* Index data format version. */
289 /* The total length of the buffer. */
292 /* The address table data. */
293 gdb::array_view
<const gdb_byte
> address_table
;
295 /* The symbol table, implemented as a hash table. */
296 gdb::array_view
<symbol_table_slot
> symbol_table
;
298 /* A pointer to the constant pool. */
299 const char *constant_pool
;
301 bool symbol_name_slot_invalid (offset_type idx
) const override
303 const auto &bucket
= this->symbol_table
[idx
];
304 return bucket
.name
== 0 && bucket
.vec
;
307 /* Convenience method to get at the name of the symbol at IDX in the
309 const char *symbol_name_at (offset_type idx
) const override
310 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
312 size_t symbol_name_count () const override
313 { return this->symbol_table
.size (); }
316 /* A description of the mapped .debug_names.
317 Uninitialized map has CU_COUNT 0. */
318 struct mapped_debug_names final
: public mapped_index_base
320 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
321 : dwarf2_per_objfile (dwarf2_per_objfile_
)
324 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
325 bfd_endian dwarf5_byte_order
;
326 bool dwarf5_is_dwarf64
;
327 bool augmentation_is_gdb
;
329 uint32_t cu_count
= 0;
330 uint32_t tu_count
, bucket_count
, name_count
;
331 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
332 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
333 const gdb_byte
*name_table_string_offs_reordered
;
334 const gdb_byte
*name_table_entry_offs_reordered
;
335 const gdb_byte
*entry_pool
;
342 /* Attribute name DW_IDX_*. */
345 /* Attribute form DW_FORM_*. */
348 /* Value if FORM is DW_FORM_implicit_const. */
349 LONGEST implicit_const
;
351 std::vector
<attr
> attr_vec
;
354 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
356 const char *namei_to_name (uint32_t namei
) const;
358 /* Implementation of the mapped_index_base virtual interface, for
359 the name_components cache. */
361 const char *symbol_name_at (offset_type idx
) const override
362 { return namei_to_name (idx
); }
364 size_t symbol_name_count () const override
365 { return this->name_count
; }
368 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
369 DEF_VEC_P (dwarf2_per_cu_ptr
);
373 int nr_uniq_abbrev_tables
;
375 int nr_symtab_sharers
;
376 int nr_stmt_less_type_units
;
377 int nr_all_type_units_reallocs
;
380 /* Collection of data recorded per objfile.
381 This hangs off of dwarf2_objfile_data_key. */
383 struct dwarf2_per_objfile
: public allocate_on_obstack
385 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
386 dwarf2 section names, or is NULL if the standard ELF names are
388 dwarf2_per_objfile (struct objfile
*objfile
,
389 const dwarf2_debug_sections
*names
);
391 ~dwarf2_per_objfile ();
393 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
395 /* Free all cached compilation units. */
396 void free_cached_comp_units ();
398 /* This function is mapped across the sections and remembers the
399 offset and size of each of the debugging sections we are
401 void locate_sections (bfd
*abfd
, asection
*sectp
,
402 const dwarf2_debug_sections
&names
);
405 dwarf2_section_info info
{};
406 dwarf2_section_info abbrev
{};
407 dwarf2_section_info line
{};
408 dwarf2_section_info loc
{};
409 dwarf2_section_info loclists
{};
410 dwarf2_section_info macinfo
{};
411 dwarf2_section_info macro
{};
412 dwarf2_section_info str
{};
413 dwarf2_section_info line_str
{};
414 dwarf2_section_info ranges
{};
415 dwarf2_section_info rnglists
{};
416 dwarf2_section_info addr
{};
417 dwarf2_section_info frame
{};
418 dwarf2_section_info eh_frame
{};
419 dwarf2_section_info gdb_index
{};
420 dwarf2_section_info debug_names
{};
421 dwarf2_section_info debug_aranges
{};
423 VEC (dwarf2_section_info_def
) *types
= NULL
;
426 struct objfile
*objfile
= NULL
;
428 /* Table of all the compilation units. This is used to locate
429 the target compilation unit of a particular reference. */
430 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
432 /* The number of compilation units in ALL_COMP_UNITS. */
433 int n_comp_units
= 0;
435 /* The number of .debug_types-related CUs. */
436 int n_type_units
= 0;
438 /* The number of elements allocated in all_type_units.
439 If there are skeleton-less TUs, we add them to all_type_units lazily. */
440 int n_allocated_type_units
= 0;
442 /* The .debug_types-related CUs (TUs).
443 This is stored in malloc space because we may realloc it. */
444 struct signatured_type
**all_type_units
= NULL
;
446 /* Table of struct type_unit_group objects.
447 The hash key is the DW_AT_stmt_list value. */
448 htab_t type_unit_groups
{};
450 /* A table mapping .debug_types signatures to its signatured_type entry.
451 This is NULL if the .debug_types section hasn't been read in yet. */
452 htab_t signatured_types
{};
454 /* Type unit statistics, to see how well the scaling improvements
456 struct tu_stats tu_stats
{};
458 /* A chain of compilation units that are currently read in, so that
459 they can be freed later. */
460 dwarf2_per_cu_data
*read_in_chain
= NULL
;
462 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
463 This is NULL if the table hasn't been allocated yet. */
466 /* True if we've checked for whether there is a DWP file. */
467 bool dwp_checked
= false;
469 /* The DWP file if there is one, or NULL. */
470 struct dwp_file
*dwp_file
= NULL
;
472 /* The shared '.dwz' file, if one exists. This is used when the
473 original data was compressed using 'dwz -m'. */
474 struct dwz_file
*dwz_file
= NULL
;
476 /* A flag indicating whether this objfile has a section loaded at a
478 bool has_section_at_zero
= false;
480 /* True if we are using the mapped index,
481 or we are faking it for OBJF_READNOW's sake. */
482 bool using_index
= false;
484 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
485 mapped_index
*index_table
= NULL
;
487 /* The mapped index, or NULL if .debug_names is missing or not being used. */
488 std::unique_ptr
<mapped_debug_names
> debug_names_table
;
490 /* When using index_table, this keeps track of all quick_file_names entries.
491 TUs typically share line table entries with a CU, so we maintain a
492 separate table of all line table entries to support the sharing.
493 Note that while there can be way more TUs than CUs, we've already
494 sorted all the TUs into "type unit groups", grouped by their
495 DW_AT_stmt_list value. Therefore the only sharing done here is with a
496 CU and its associated TU group if there is one. */
497 htab_t quick_file_names_table
{};
499 /* Set during partial symbol reading, to prevent queueing of full
501 bool reading_partial_symbols
= false;
503 /* Table mapping type DIEs to their struct type *.
504 This is NULL if not allocated yet.
505 The mapping is done via (CU/TU + DIE offset) -> type. */
506 htab_t die_type_hash
{};
508 /* The CUs we recently read. */
509 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
511 /* Table containing line_header indexed by offset and offset_in_dwz. */
512 htab_t line_header_hash
{};
514 /* Table containing all filenames. This is an optional because the
515 table is lazily constructed on first access. */
516 gdb::optional
<filename_seen_cache
> filenames_cache
;
519 /* Get the dwarf2_per_objfile associated to OBJFILE. */
521 struct dwarf2_per_objfile
*
522 get_dwarf2_per_objfile (struct objfile
*objfile
)
524 return ((struct dwarf2_per_objfile
*)
525 objfile_data (objfile
, dwarf2_objfile_data_key
));
528 /* Set the dwarf2_per_objfile associated to OBJFILE. */
531 set_dwarf2_per_objfile (struct objfile
*objfile
,
532 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
534 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
535 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
538 /* Default names of the debugging sections. */
540 /* Note that if the debugging section has been compressed, it might
541 have a name like .zdebug_info. */
543 static const struct dwarf2_debug_sections dwarf2_elf_names
=
545 { ".debug_info", ".zdebug_info" },
546 { ".debug_abbrev", ".zdebug_abbrev" },
547 { ".debug_line", ".zdebug_line" },
548 { ".debug_loc", ".zdebug_loc" },
549 { ".debug_loclists", ".zdebug_loclists" },
550 { ".debug_macinfo", ".zdebug_macinfo" },
551 { ".debug_macro", ".zdebug_macro" },
552 { ".debug_str", ".zdebug_str" },
553 { ".debug_line_str", ".zdebug_line_str" },
554 { ".debug_ranges", ".zdebug_ranges" },
555 { ".debug_rnglists", ".zdebug_rnglists" },
556 { ".debug_types", ".zdebug_types" },
557 { ".debug_addr", ".zdebug_addr" },
558 { ".debug_frame", ".zdebug_frame" },
559 { ".eh_frame", NULL
},
560 { ".gdb_index", ".zgdb_index" },
561 { ".debug_names", ".zdebug_names" },
562 { ".debug_aranges", ".zdebug_aranges" },
566 /* List of DWO/DWP sections. */
568 static const struct dwop_section_names
570 struct dwarf2_section_names abbrev_dwo
;
571 struct dwarf2_section_names info_dwo
;
572 struct dwarf2_section_names line_dwo
;
573 struct dwarf2_section_names loc_dwo
;
574 struct dwarf2_section_names loclists_dwo
;
575 struct dwarf2_section_names macinfo_dwo
;
576 struct dwarf2_section_names macro_dwo
;
577 struct dwarf2_section_names str_dwo
;
578 struct dwarf2_section_names str_offsets_dwo
;
579 struct dwarf2_section_names types_dwo
;
580 struct dwarf2_section_names cu_index
;
581 struct dwarf2_section_names tu_index
;
585 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
586 { ".debug_info.dwo", ".zdebug_info.dwo" },
587 { ".debug_line.dwo", ".zdebug_line.dwo" },
588 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
589 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
590 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
591 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
592 { ".debug_str.dwo", ".zdebug_str.dwo" },
593 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
594 { ".debug_types.dwo", ".zdebug_types.dwo" },
595 { ".debug_cu_index", ".zdebug_cu_index" },
596 { ".debug_tu_index", ".zdebug_tu_index" },
599 /* local data types */
601 /* The data in a compilation unit header, after target2host
602 translation, looks like this. */
603 struct comp_unit_head
607 unsigned char addr_size
;
608 unsigned char signed_addr_p
;
609 sect_offset abbrev_sect_off
;
611 /* Size of file offsets; either 4 or 8. */
612 unsigned int offset_size
;
614 /* Size of the length field; either 4 or 12. */
615 unsigned int initial_length_size
;
617 enum dwarf_unit_type unit_type
;
619 /* Offset to the first byte of this compilation unit header in the
620 .debug_info section, for resolving relative reference dies. */
621 sect_offset sect_off
;
623 /* Offset to first die in this cu from the start of the cu.
624 This will be the first byte following the compilation unit header. */
625 cu_offset first_die_cu_offset
;
627 /* 64-bit signature of this type unit - it is valid only for
628 UNIT_TYPE DW_UT_type. */
631 /* For types, offset in the type's DIE of the type defined by this TU. */
632 cu_offset type_cu_offset_in_tu
;
635 /* Type used for delaying computation of method physnames.
636 See comments for compute_delayed_physnames. */
637 struct delayed_method_info
639 /* The type to which the method is attached, i.e., its parent class. */
642 /* The index of the method in the type's function fieldlists. */
645 /* The index of the method in the fieldlist. */
648 /* The name of the DIE. */
651 /* The DIE associated with this method. */
652 struct die_info
*die
;
655 /* Internal state when decoding a particular compilation unit. */
658 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
661 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
663 /* The header of the compilation unit. */
664 struct comp_unit_head header
{};
666 /* Base address of this compilation unit. */
667 CORE_ADDR base_address
= 0;
669 /* Non-zero if base_address has been set. */
672 /* The language we are debugging. */
673 enum language language
= language_unknown
;
674 const struct language_defn
*language_defn
= nullptr;
676 const char *producer
= nullptr;
678 /* The generic symbol table building routines have separate lists for
679 file scope symbols and all all other scopes (local scopes). So
680 we need to select the right one to pass to add_symbol_to_list().
681 We do it by keeping a pointer to the correct list in list_in_scope.
683 FIXME: The original dwarf code just treated the file scope as the
684 first local scope, and all other local scopes as nested local
685 scopes, and worked fine. Check to see if we really need to
686 distinguish these in buildsym.c. */
687 struct pending
**list_in_scope
= nullptr;
689 /* Hash table holding all the loaded partial DIEs
690 with partial_die->offset.SECT_OFF as hash. */
691 htab_t partial_dies
= nullptr;
693 /* Storage for things with the same lifetime as this read-in compilation
694 unit, including partial DIEs. */
695 auto_obstack comp_unit_obstack
;
697 /* When multiple dwarf2_cu structures are living in memory, this field
698 chains them all together, so that they can be released efficiently.
699 We will probably also want a generation counter so that most-recently-used
700 compilation units are cached... */
701 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
703 /* Backlink to our per_cu entry. */
704 struct dwarf2_per_cu_data
*per_cu
;
706 /* How many compilation units ago was this CU last referenced? */
709 /* A hash table of DIE cu_offset for following references with
710 die_info->offset.sect_off as hash. */
711 htab_t die_hash
= nullptr;
713 /* Full DIEs if read in. */
714 struct die_info
*dies
= nullptr;
716 /* A set of pointers to dwarf2_per_cu_data objects for compilation
717 units referenced by this one. Only set during full symbol processing;
718 partial symbol tables do not have dependencies. */
719 htab_t dependencies
= nullptr;
721 /* Header data from the line table, during full symbol processing. */
722 struct line_header
*line_header
= nullptr;
723 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
724 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
725 this is the DW_TAG_compile_unit die for this CU. We'll hold on
726 to the line header as long as this DIE is being processed. See
727 process_die_scope. */
728 die_info
*line_header_die_owner
= nullptr;
730 /* A list of methods which need to have physnames computed
731 after all type information has been read. */
732 std::vector
<delayed_method_info
> method_list
;
734 /* To be copied to symtab->call_site_htab. */
735 htab_t call_site_htab
= nullptr;
737 /* Non-NULL if this CU came from a DWO file.
738 There is an invariant here that is important to remember:
739 Except for attributes copied from the top level DIE in the "main"
740 (or "stub") file in preparation for reading the DWO file
741 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
742 Either there isn't a DWO file (in which case this is NULL and the point
743 is moot), or there is and either we're not going to read it (in which
744 case this is NULL) or there is and we are reading it (in which case this
746 struct dwo_unit
*dwo_unit
= nullptr;
748 /* The DW_AT_addr_base attribute if present, zero otherwise
749 (zero is a valid value though).
750 Note this value comes from the Fission stub CU/TU's DIE. */
751 ULONGEST addr_base
= 0;
753 /* The DW_AT_ranges_base attribute if present, zero otherwise
754 (zero is a valid value though).
755 Note this value comes from the Fission stub CU/TU's DIE.
756 Also note that the value is zero in the non-DWO case so this value can
757 be used without needing to know whether DWO files are in use or not.
758 N.B. This does not apply to DW_AT_ranges appearing in
759 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
760 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
761 DW_AT_ranges_base *would* have to be applied, and we'd have to care
762 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
763 ULONGEST ranges_base
= 0;
765 /* When reading debug info generated by older versions of rustc, we
766 have to rewrite some union types to be struct types with a
767 variant part. This rewriting must be done after the CU is fully
768 read in, because otherwise at the point of rewriting some struct
769 type might not have been fully processed. So, we keep a list of
770 all such types here and process them after expansion. */
771 std::vector
<struct type
*> rust_unions
;
773 /* Mark used when releasing cached dies. */
774 unsigned int mark
: 1;
776 /* This CU references .debug_loc. See the symtab->locations_valid field.
777 This test is imperfect as there may exist optimized debug code not using
778 any location list and still facing inlining issues if handled as
779 unoptimized code. For a future better test see GCC PR other/32998. */
780 unsigned int has_loclist
: 1;
782 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
783 if all the producer_is_* fields are valid. This information is cached
784 because profiling CU expansion showed excessive time spent in
785 producer_is_gxx_lt_4_6. */
786 unsigned int checked_producer
: 1;
787 unsigned int producer_is_gxx_lt_4_6
: 1;
788 unsigned int producer_is_gcc_lt_4_3
: 1;
789 unsigned int producer_is_icc_lt_14
: 1;
791 /* When set, the file that we're processing is known to have
792 debugging info for C++ namespaces. GCC 3.3.x did not produce
793 this information, but later versions do. */
795 unsigned int processing_has_namespace_info
: 1;
797 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
800 /* Persistent data held for a compilation unit, even when not
801 processing it. We put a pointer to this structure in the
802 read_symtab_private field of the psymtab. */
804 struct dwarf2_per_cu_data
806 /* The start offset and length of this compilation unit.
807 NOTE: Unlike comp_unit_head.length, this length includes
809 If the DIE refers to a DWO file, this is always of the original die,
811 sect_offset sect_off
;
814 /* DWARF standard version this data has been read from (such as 4 or 5). */
817 /* Flag indicating this compilation unit will be read in before
818 any of the current compilation units are processed. */
819 unsigned int queued
: 1;
821 /* This flag will be set when reading partial DIEs if we need to load
822 absolutely all DIEs for this compilation unit, instead of just the ones
823 we think are interesting. It gets set if we look for a DIE in the
824 hash table and don't find it. */
825 unsigned int load_all_dies
: 1;
827 /* Non-zero if this CU is from .debug_types.
828 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
830 unsigned int is_debug_types
: 1;
832 /* Non-zero if this CU is from the .dwz file. */
833 unsigned int is_dwz
: 1;
835 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
836 This flag is only valid if is_debug_types is true.
837 We can't read a CU directly from a DWO file: There are required
838 attributes in the stub. */
839 unsigned int reading_dwo_directly
: 1;
841 /* Non-zero if the TU has been read.
842 This is used to assist the "Stay in DWO Optimization" for Fission:
843 When reading a DWO, it's faster to read TUs from the DWO instead of
844 fetching them from random other DWOs (due to comdat folding).
845 If the TU has already been read, the optimization is unnecessary
846 (and unwise - we don't want to change where gdb thinks the TU lives
848 This flag is only valid if is_debug_types is true. */
849 unsigned int tu_read
: 1;
851 /* The section this CU/TU lives in.
852 If the DIE refers to a DWO file, this is always the original die,
854 struct dwarf2_section_info
*section
;
856 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
857 of the CU cache it gets reset to NULL again. This is left as NULL for
858 dummy CUs (a CU header, but nothing else). */
859 struct dwarf2_cu
*cu
;
861 /* The corresponding dwarf2_per_objfile. */
862 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
864 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
865 is active. Otherwise, the 'psymtab' field is active. */
868 /* The partial symbol table associated with this compilation unit,
869 or NULL for unread partial units. */
870 struct partial_symtab
*psymtab
;
872 /* Data needed by the "quick" functions. */
873 struct dwarf2_per_cu_quick_data
*quick
;
876 /* The CUs we import using DW_TAG_imported_unit. This is filled in
877 while reading psymtabs, used to compute the psymtab dependencies,
878 and then cleared. Then it is filled in again while reading full
879 symbols, and only deleted when the objfile is destroyed.
881 This is also used to work around a difference between the way gold
882 generates .gdb_index version <=7 and the way gdb does. Arguably this
883 is a gold bug. For symbols coming from TUs, gold records in the index
884 the CU that includes the TU instead of the TU itself. This breaks
885 dw2_lookup_symbol: It assumes that if the index says symbol X lives
886 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
887 will find X. Alas TUs live in their own symtab, so after expanding CU Y
888 we need to look in TU Z to find X. Fortunately, this is akin to
889 DW_TAG_imported_unit, so we just use the same mechanism: For
890 .gdb_index version <=7 this also records the TUs that the CU referred
891 to. Concurrently with this change gdb was modified to emit version 8
892 indices so we only pay a price for gold generated indices.
893 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
894 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
897 /* Entry in the signatured_types hash table. */
899 struct signatured_type
901 /* The "per_cu" object of this type.
902 This struct is used iff per_cu.is_debug_types.
903 N.B.: This is the first member so that it's easy to convert pointers
905 struct dwarf2_per_cu_data per_cu
;
907 /* The type's signature. */
910 /* Offset in the TU of the type's DIE, as read from the TU header.
911 If this TU is a DWO stub and the definition lives in a DWO file
912 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
913 cu_offset type_offset_in_tu
;
915 /* Offset in the section of the type's DIE.
916 If the definition lives in a DWO file, this is the offset in the
917 .debug_types.dwo section.
918 The value is zero until the actual value is known.
919 Zero is otherwise not a valid section offset. */
920 sect_offset type_offset_in_section
;
922 /* Type units are grouped by their DW_AT_stmt_list entry so that they
923 can share them. This points to the containing symtab. */
924 struct type_unit_group
*type_unit_group
;
927 The first time we encounter this type we fully read it in and install it
928 in the symbol tables. Subsequent times we only need the type. */
931 /* Containing DWO unit.
932 This field is valid iff per_cu.reading_dwo_directly. */
933 struct dwo_unit
*dwo_unit
;
936 typedef struct signatured_type
*sig_type_ptr
;
937 DEF_VEC_P (sig_type_ptr
);
939 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
940 This includes type_unit_group and quick_file_names. */
942 struct stmt_list_hash
944 /* The DWO unit this table is from or NULL if there is none. */
945 struct dwo_unit
*dwo_unit
;
947 /* Offset in .debug_line or .debug_line.dwo. */
948 sect_offset line_sect_off
;
951 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
952 an object of this type. */
954 struct type_unit_group
956 /* dwarf2read.c's main "handle" on a TU symtab.
957 To simplify things we create an artificial CU that "includes" all the
958 type units using this stmt_list so that the rest of the code still has
959 a "per_cu" handle on the symtab.
960 This PER_CU is recognized by having no section. */
961 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
962 struct dwarf2_per_cu_data per_cu
;
964 /* The TUs that share this DW_AT_stmt_list entry.
965 This is added to while parsing type units to build partial symtabs,
966 and is deleted afterwards and not used again. */
967 VEC (sig_type_ptr
) *tus
;
969 /* The compunit symtab.
970 Type units in a group needn't all be defined in the same source file,
971 so we create an essentially anonymous symtab as the compunit symtab. */
972 struct compunit_symtab
*compunit_symtab
;
974 /* The data used to construct the hash key. */
975 struct stmt_list_hash hash
;
977 /* The number of symtabs from the line header.
978 The value here must match line_header.num_file_names. */
979 unsigned int num_symtabs
;
981 /* The symbol tables for this TU (obtained from the files listed in
983 WARNING: The order of entries here must match the order of entries
984 in the line header. After the first TU using this type_unit_group, the
985 line header for the subsequent TUs is recreated from this. This is done
986 because we need to use the same symtabs for each TU using the same
987 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
988 there's no guarantee the line header doesn't have duplicate entries. */
989 struct symtab
**symtabs
;
992 /* These sections are what may appear in a (real or virtual) DWO file. */
996 struct dwarf2_section_info abbrev
;
997 struct dwarf2_section_info line
;
998 struct dwarf2_section_info loc
;
999 struct dwarf2_section_info loclists
;
1000 struct dwarf2_section_info macinfo
;
1001 struct dwarf2_section_info macro
;
1002 struct dwarf2_section_info str
;
1003 struct dwarf2_section_info str_offsets
;
1004 /* In the case of a virtual DWO file, these two are unused. */
1005 struct dwarf2_section_info info
;
1006 VEC (dwarf2_section_info_def
) *types
;
1009 /* CUs/TUs in DWP/DWO files. */
1013 /* Backlink to the containing struct dwo_file. */
1014 struct dwo_file
*dwo_file
;
1016 /* The "id" that distinguishes this CU/TU.
1017 .debug_info calls this "dwo_id", .debug_types calls this "signature".
1018 Since signatures came first, we stick with it for consistency. */
1021 /* The section this CU/TU lives in, in the DWO file. */
1022 struct dwarf2_section_info
*section
;
1024 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
1025 sect_offset sect_off
;
1026 unsigned int length
;
1028 /* For types, offset in the type's DIE of the type defined by this TU. */
1029 cu_offset type_offset_in_tu
;
1032 /* include/dwarf2.h defines the DWP section codes.
1033 It defines a max value but it doesn't define a min value, which we
1034 use for error checking, so provide one. */
1036 enum dwp_v2_section_ids
1041 /* Data for one DWO file.
1043 This includes virtual DWO files (a virtual DWO file is a DWO file as it
1044 appears in a DWP file). DWP files don't really have DWO files per se -
1045 comdat folding of types "loses" the DWO file they came from, and from
1046 a high level view DWP files appear to contain a mass of random types.
1047 However, to maintain consistency with the non-DWP case we pretend DWP
1048 files contain virtual DWO files, and we assign each TU with one virtual
1049 DWO file (generally based on the line and abbrev section offsets -
1050 a heuristic that seems to work in practice). */
1054 /* The DW_AT_GNU_dwo_name attribute.
1055 For virtual DWO files the name is constructed from the section offsets
1056 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
1057 from related CU+TUs. */
1058 const char *dwo_name
;
1060 /* The DW_AT_comp_dir attribute. */
1061 const char *comp_dir
;
1063 /* The bfd, when the file is open. Otherwise this is NULL.
1064 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
1067 /* The sections that make up this DWO file.
1068 Remember that for virtual DWO files in DWP V2, these are virtual
1069 sections (for lack of a better name). */
1070 struct dwo_sections sections
;
1072 /* The CUs in the file.
1073 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
1074 an extension to handle LLVM's Link Time Optimization output (where
1075 multiple source files may be compiled into a single object/dwo pair). */
1078 /* Table of TUs in the file.
1079 Each element is a struct dwo_unit. */
1083 /* These sections are what may appear in a DWP file. */
1087 /* These are used by both DWP version 1 and 2. */
1088 struct dwarf2_section_info str
;
1089 struct dwarf2_section_info cu_index
;
1090 struct dwarf2_section_info tu_index
;
1092 /* These are only used by DWP version 2 files.
1093 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
1094 sections are referenced by section number, and are not recorded here.
1095 In DWP version 2 there is at most one copy of all these sections, each
1096 section being (effectively) comprised of the concatenation of all of the
1097 individual sections that exist in the version 1 format.
1098 To keep the code simple we treat each of these concatenated pieces as a
1099 section itself (a virtual section?). */
1100 struct dwarf2_section_info abbrev
;
1101 struct dwarf2_section_info info
;
1102 struct dwarf2_section_info line
;
1103 struct dwarf2_section_info loc
;
1104 struct dwarf2_section_info macinfo
;
1105 struct dwarf2_section_info macro
;
1106 struct dwarf2_section_info str_offsets
;
1107 struct dwarf2_section_info types
;
1110 /* These sections are what may appear in a virtual DWO file in DWP version 1.
1111 A virtual DWO file is a DWO file as it appears in a DWP file. */
1113 struct virtual_v1_dwo_sections
1115 struct dwarf2_section_info abbrev
;
1116 struct dwarf2_section_info line
;
1117 struct dwarf2_section_info loc
;
1118 struct dwarf2_section_info macinfo
;
1119 struct dwarf2_section_info macro
;
1120 struct dwarf2_section_info str_offsets
;
1121 /* Each DWP hash table entry records one CU or one TU.
1122 That is recorded here, and copied to dwo_unit.section. */
1123 struct dwarf2_section_info info_or_types
;
1126 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
1127 In version 2, the sections of the DWO files are concatenated together
1128 and stored in one section of that name. Thus each ELF section contains
1129 several "virtual" sections. */
1131 struct virtual_v2_dwo_sections
1133 bfd_size_type abbrev_offset
;
1134 bfd_size_type abbrev_size
;
1136 bfd_size_type line_offset
;
1137 bfd_size_type line_size
;
1139 bfd_size_type loc_offset
;
1140 bfd_size_type loc_size
;
1142 bfd_size_type macinfo_offset
;
1143 bfd_size_type macinfo_size
;
1145 bfd_size_type macro_offset
;
1146 bfd_size_type macro_size
;
1148 bfd_size_type str_offsets_offset
;
1149 bfd_size_type str_offsets_size
;
1151 /* Each DWP hash table entry records one CU or one TU.
1152 That is recorded here, and copied to dwo_unit.section. */
1153 bfd_size_type info_or_types_offset
;
1154 bfd_size_type info_or_types_size
;
1157 /* Contents of DWP hash tables. */
1159 struct dwp_hash_table
1161 uint32_t version
, nr_columns
;
1162 uint32_t nr_units
, nr_slots
;
1163 const gdb_byte
*hash_table
, *unit_table
;
1168 const gdb_byte
*indices
;
1172 /* This is indexed by column number and gives the id of the section
1174 #define MAX_NR_V2_DWO_SECTIONS \
1175 (1 /* .debug_info or .debug_types */ \
1176 + 1 /* .debug_abbrev */ \
1177 + 1 /* .debug_line */ \
1178 + 1 /* .debug_loc */ \
1179 + 1 /* .debug_str_offsets */ \
1180 + 1 /* .debug_macro or .debug_macinfo */)
1181 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1182 const gdb_byte
*offsets
;
1183 const gdb_byte
*sizes
;
1188 /* Data for one DWP file. */
1192 /* Name of the file. */
1195 /* File format version. */
1201 /* Section info for this file. */
1202 struct dwp_sections sections
;
1204 /* Table of CUs in the file. */
1205 const struct dwp_hash_table
*cus
;
1207 /* Table of TUs in the file. */
1208 const struct dwp_hash_table
*tus
;
1210 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1214 /* Table to map ELF section numbers to their sections.
1215 This is only needed for the DWP V1 file format. */
1216 unsigned int num_sections
;
1217 asection
**elf_sections
;
1220 /* This represents a '.dwz' file. */
1224 /* A dwz file can only contain a few sections. */
1225 struct dwarf2_section_info abbrev
;
1226 struct dwarf2_section_info info
;
1227 struct dwarf2_section_info str
;
1228 struct dwarf2_section_info line
;
1229 struct dwarf2_section_info macro
;
1230 struct dwarf2_section_info gdb_index
;
1231 struct dwarf2_section_info debug_names
;
1233 /* The dwz's BFD. */
1237 /* Struct used to pass misc. parameters to read_die_and_children, et
1238 al. which are used for both .debug_info and .debug_types dies.
1239 All parameters here are unchanging for the life of the call. This
1240 struct exists to abstract away the constant parameters of die reading. */
1242 struct die_reader_specs
1244 /* The bfd of die_section. */
1247 /* The CU of the DIE we are parsing. */
1248 struct dwarf2_cu
*cu
;
1250 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1251 struct dwo_file
*dwo_file
;
1253 /* The section the die comes from.
1254 This is either .debug_info or .debug_types, or the .dwo variants. */
1255 struct dwarf2_section_info
*die_section
;
1257 /* die_section->buffer. */
1258 const gdb_byte
*buffer
;
1260 /* The end of the buffer. */
1261 const gdb_byte
*buffer_end
;
1263 /* The value of the DW_AT_comp_dir attribute. */
1264 const char *comp_dir
;
1266 /* The abbreviation table to use when reading the DIEs. */
1267 struct abbrev_table
*abbrev_table
;
1270 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1271 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1272 const gdb_byte
*info_ptr
,
1273 struct die_info
*comp_unit_die
,
1277 /* A 1-based directory index. This is a strong typedef to prevent
1278 accidentally using a directory index as a 0-based index into an
1280 enum class dir_index
: unsigned int {};
1282 /* Likewise, a 1-based file name index. */
1283 enum class file_name_index
: unsigned int {};
1287 file_entry () = default;
1289 file_entry (const char *name_
, dir_index d_index_
,
1290 unsigned int mod_time_
, unsigned int length_
)
1293 mod_time (mod_time_
),
1297 /* Return the include directory at D_INDEX stored in LH. Returns
1298 NULL if D_INDEX is out of bounds. */
1299 const char *include_dir (const line_header
*lh
) const;
1301 /* The file name. Note this is an observing pointer. The memory is
1302 owned by debug_line_buffer. */
1303 const char *name
{};
1305 /* The directory index (1-based). */
1306 dir_index d_index
{};
1308 unsigned int mod_time
{};
1310 unsigned int length
{};
1312 /* True if referenced by the Line Number Program. */
1315 /* The associated symbol table, if any. */
1316 struct symtab
*symtab
{};
1319 /* The line number information for a compilation unit (found in the
1320 .debug_line section) begins with a "statement program header",
1321 which contains the following information. */
1328 /* Add an entry to the include directory table. */
1329 void add_include_dir (const char *include_dir
);
1331 /* Add an entry to the file name table. */
1332 void add_file_name (const char *name
, dir_index d_index
,
1333 unsigned int mod_time
, unsigned int length
);
1335 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1336 is out of bounds. */
1337 const char *include_dir_at (dir_index index
) const
1339 /* Convert directory index number (1-based) to vector index
1341 size_t vec_index
= to_underlying (index
) - 1;
1343 if (vec_index
>= include_dirs
.size ())
1345 return include_dirs
[vec_index
];
1348 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1349 is out of bounds. */
1350 file_entry
*file_name_at (file_name_index index
)
1352 /* Convert file name index number (1-based) to vector index
1354 size_t vec_index
= to_underlying (index
) - 1;
1356 if (vec_index
>= file_names
.size ())
1358 return &file_names
[vec_index
];
1361 /* Const version of the above. */
1362 const file_entry
*file_name_at (unsigned int index
) const
1364 if (index
>= file_names
.size ())
1366 return &file_names
[index
];
1369 /* Offset of line number information in .debug_line section. */
1370 sect_offset sect_off
{};
1372 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1373 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1375 unsigned int total_length
{};
1376 unsigned short version
{};
1377 unsigned int header_length
{};
1378 unsigned char minimum_instruction_length
{};
1379 unsigned char maximum_ops_per_instruction
{};
1380 unsigned char default_is_stmt
{};
1382 unsigned char line_range
{};
1383 unsigned char opcode_base
{};
1385 /* standard_opcode_lengths[i] is the number of operands for the
1386 standard opcode whose value is i. This means that
1387 standard_opcode_lengths[0] is unused, and the last meaningful
1388 element is standard_opcode_lengths[opcode_base - 1]. */
1389 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1391 /* The include_directories table. Note these are observing
1392 pointers. The memory is owned by debug_line_buffer. */
1393 std::vector
<const char *> include_dirs
;
1395 /* The file_names table. */
1396 std::vector
<file_entry
> file_names
;
1398 /* The start and end of the statement program following this
1399 header. These point into dwarf2_per_objfile->line_buffer. */
1400 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1403 typedef std::unique_ptr
<line_header
> line_header_up
;
1406 file_entry::include_dir (const line_header
*lh
) const
1408 return lh
->include_dir_at (d_index
);
1411 /* When we construct a partial symbol table entry we only
1412 need this much information. */
1413 struct partial_die_info
: public allocate_on_obstack
1415 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1417 /* Disable assign but still keep copy ctor, which is needed
1418 load_partial_dies. */
1419 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1421 /* Adjust the partial die before generating a symbol for it. This
1422 function may set the is_external flag or change the DIE's
1424 void fixup (struct dwarf2_cu
*cu
);
1426 /* Read a minimal amount of information into the minimal die
1428 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1429 const struct abbrev_info
&abbrev
,
1430 const gdb_byte
*info_ptr
);
1432 /* Offset of this DIE. */
1433 const sect_offset sect_off
;
1435 /* DWARF-2 tag for this DIE. */
1436 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1438 /* Assorted flags describing the data found in this DIE. */
1439 const unsigned int has_children
: 1;
1441 unsigned int is_external
: 1;
1442 unsigned int is_declaration
: 1;
1443 unsigned int has_type
: 1;
1444 unsigned int has_specification
: 1;
1445 unsigned int has_pc_info
: 1;
1446 unsigned int may_be_inlined
: 1;
1448 /* This DIE has been marked DW_AT_main_subprogram. */
1449 unsigned int main_subprogram
: 1;
1451 /* Flag set if the SCOPE field of this structure has been
1453 unsigned int scope_set
: 1;
1455 /* Flag set if the DIE has a byte_size attribute. */
1456 unsigned int has_byte_size
: 1;
1458 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1459 unsigned int has_const_value
: 1;
1461 /* Flag set if any of the DIE's children are template arguments. */
1462 unsigned int has_template_arguments
: 1;
1464 /* Flag set if fixup has been called on this die. */
1465 unsigned int fixup_called
: 1;
1467 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1468 unsigned int is_dwz
: 1;
1470 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1471 unsigned int spec_is_dwz
: 1;
1473 /* The name of this DIE. Normally the value of DW_AT_name, but
1474 sometimes a default name for unnamed DIEs. */
1475 const char *name
= nullptr;
1477 /* The linkage name, if present. */
1478 const char *linkage_name
= nullptr;
1480 /* The scope to prepend to our children. This is generally
1481 allocated on the comp_unit_obstack, so will disappear
1482 when this compilation unit leaves the cache. */
1483 const char *scope
= nullptr;
1485 /* Some data associated with the partial DIE. The tag determines
1486 which field is live. */
1489 /* The location description associated with this DIE, if any. */
1490 struct dwarf_block
*locdesc
;
1491 /* The offset of an import, for DW_TAG_imported_unit. */
1492 sect_offset sect_off
;
1495 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1496 CORE_ADDR lowpc
= 0;
1497 CORE_ADDR highpc
= 0;
1499 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1500 DW_AT_sibling, if any. */
1501 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1502 could return DW_AT_sibling values to its caller load_partial_dies. */
1503 const gdb_byte
*sibling
= nullptr;
1505 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1506 DW_AT_specification (or DW_AT_abstract_origin or
1507 DW_AT_extension). */
1508 sect_offset spec_offset
{};
1510 /* Pointers to this DIE's parent, first child, and next sibling,
1512 struct partial_die_info
*die_parent
= nullptr;
1513 struct partial_die_info
*die_child
= nullptr;
1514 struct partial_die_info
*die_sibling
= nullptr;
1516 friend struct partial_die_info
*
1517 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1520 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1521 partial_die_info (sect_offset sect_off
)
1522 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1526 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1528 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1533 has_specification
= 0;
1536 main_subprogram
= 0;
1539 has_const_value
= 0;
1540 has_template_arguments
= 0;
1547 /* This data structure holds the information of an abbrev. */
1550 unsigned int number
; /* number identifying abbrev */
1551 enum dwarf_tag tag
; /* dwarf tag */
1552 unsigned short has_children
; /* boolean */
1553 unsigned short num_attrs
; /* number of attributes */
1554 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1555 struct abbrev_info
*next
; /* next in chain */
1560 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1561 ENUM_BITFIELD(dwarf_form
) form
: 16;
1563 /* It is valid only if FORM is DW_FORM_implicit_const. */
1564 LONGEST implicit_const
;
1567 /* Size of abbrev_table.abbrev_hash_table. */
1568 #define ABBREV_HASH_SIZE 121
1570 /* Top level data structure to contain an abbreviation table. */
1574 explicit abbrev_table (sect_offset off
)
1578 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1579 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1582 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1584 /* Allocate space for a struct abbrev_info object in
1586 struct abbrev_info
*alloc_abbrev ();
1588 /* Add an abbreviation to the table. */
1589 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1591 /* Look up an abbrev in the table.
1592 Returns NULL if the abbrev is not found. */
1594 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1597 /* Where the abbrev table came from.
1598 This is used as a sanity check when the table is used. */
1599 const sect_offset sect_off
;
1601 /* Storage for the abbrev table. */
1602 auto_obstack abbrev_obstack
;
1606 /* Hash table of abbrevs.
1607 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1608 It could be statically allocated, but the previous code didn't so we
1610 struct abbrev_info
**m_abbrevs
;
1613 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1615 /* Attributes have a name and a value. */
1618 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1619 ENUM_BITFIELD(dwarf_form
) form
: 15;
1621 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1622 field should be in u.str (existing only for DW_STRING) but it is kept
1623 here for better struct attribute alignment. */
1624 unsigned int string_is_canonical
: 1;
1629 struct dwarf_block
*blk
;
1638 /* This data structure holds a complete die structure. */
1641 /* DWARF-2 tag for this DIE. */
1642 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1644 /* Number of attributes */
1645 unsigned char num_attrs
;
1647 /* True if we're presently building the full type name for the
1648 type derived from this DIE. */
1649 unsigned char building_fullname
: 1;
1651 /* True if this die is in process. PR 16581. */
1652 unsigned char in_process
: 1;
1655 unsigned int abbrev
;
1657 /* Offset in .debug_info or .debug_types section. */
1658 sect_offset sect_off
;
1660 /* The dies in a compilation unit form an n-ary tree. PARENT
1661 points to this die's parent; CHILD points to the first child of
1662 this node; and all the children of a given node are chained
1663 together via their SIBLING fields. */
1664 struct die_info
*child
; /* Its first child, if any. */
1665 struct die_info
*sibling
; /* Its next sibling, if any. */
1666 struct die_info
*parent
; /* Its parent, if any. */
1668 /* An array of attributes, with NUM_ATTRS elements. There may be
1669 zero, but it's not common and zero-sized arrays are not
1670 sufficiently portable C. */
1671 struct attribute attrs
[1];
1674 /* Get at parts of an attribute structure. */
1676 #define DW_STRING(attr) ((attr)->u.str)
1677 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1678 #define DW_UNSND(attr) ((attr)->u.unsnd)
1679 #define DW_BLOCK(attr) ((attr)->u.blk)
1680 #define DW_SND(attr) ((attr)->u.snd)
1681 #define DW_ADDR(attr) ((attr)->u.addr)
1682 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1684 /* Blocks are a bunch of untyped bytes. */
1689 /* Valid only if SIZE is not zero. */
1690 const gdb_byte
*data
;
1693 #ifndef ATTR_ALLOC_CHUNK
1694 #define ATTR_ALLOC_CHUNK 4
1697 /* Allocate fields for structs, unions and enums in this size. */
1698 #ifndef DW_FIELD_ALLOC_CHUNK
1699 #define DW_FIELD_ALLOC_CHUNK 4
1702 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1703 but this would require a corresponding change in unpack_field_as_long
1705 static int bits_per_byte
= 8;
1707 /* When reading a variant or variant part, we track a bit more
1708 information about the field, and store it in an object of this
1711 struct variant_field
1713 /* If we see a DW_TAG_variant, then this will be the discriminant
1715 ULONGEST discriminant_value
;
1716 /* If we see a DW_TAG_variant, then this will be set if this is the
1718 bool default_branch
;
1719 /* While reading a DW_TAG_variant_part, this will be set if this
1720 field is the discriminant. */
1721 bool is_discriminant
;
1726 int accessibility
= 0;
1728 /* Extra information to describe a variant or variant part. */
1729 struct variant_field variant
{};
1730 struct field field
{};
1735 const char *name
= nullptr;
1736 std::vector
<struct fn_field
> fnfields
;
1739 /* The routines that read and process dies for a C struct or C++ class
1740 pass lists of data member fields and lists of member function fields
1741 in an instance of a field_info structure, as defined below. */
1744 /* List of data member and baseclasses fields. */
1745 std::vector
<struct nextfield
> fields
;
1746 std::vector
<struct nextfield
> baseclasses
;
1748 /* Number of fields (including baseclasses). */
1751 /* Set if the accesibility of one of the fields is not public. */
1752 int non_public_fields
= 0;
1754 /* Member function fieldlist array, contains name of possibly overloaded
1755 member function, number of overloaded member functions and a pointer
1756 to the head of the member function field chain. */
1757 std::vector
<struct fnfieldlist
> fnfieldlists
;
1759 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1760 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1761 std::vector
<struct decl_field
> typedef_field_list
;
1763 /* Nested types defined by this class and the number of elements in this
1765 std::vector
<struct decl_field
> nested_types_list
;
1768 /* One item on the queue of compilation units to read in full symbols
1770 struct dwarf2_queue_item
1772 struct dwarf2_per_cu_data
*per_cu
;
1773 enum language pretend_language
;
1774 struct dwarf2_queue_item
*next
;
1777 /* The current queue. */
1778 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1780 /* Loaded secondary compilation units are kept in memory until they
1781 have not been referenced for the processing of this many
1782 compilation units. Set this to zero to disable caching. Cache
1783 sizes of up to at least twenty will improve startup time for
1784 typical inter-CU-reference binaries, at an obvious memory cost. */
1785 static int dwarf_max_cache_age
= 5;
1787 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1788 struct cmd_list_element
*c
, const char *value
)
1790 fprintf_filtered (file
, _("The upper bound on the age of cached "
1791 "DWARF compilation units is %s.\n"),
1795 /* local function prototypes */
1797 static const char *get_section_name (const struct dwarf2_section_info
*);
1799 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1801 static void dwarf2_find_base_address (struct die_info
*die
,
1802 struct dwarf2_cu
*cu
);
1804 static struct partial_symtab
*create_partial_symtab
1805 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1807 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1808 const gdb_byte
*info_ptr
,
1809 struct die_info
*type_unit_die
,
1810 int has_children
, void *data
);
1812 static void dwarf2_build_psymtabs_hard
1813 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1815 static void scan_partial_symbols (struct partial_die_info
*,
1816 CORE_ADDR
*, CORE_ADDR
*,
1817 int, struct dwarf2_cu
*);
1819 static void add_partial_symbol (struct partial_die_info
*,
1820 struct dwarf2_cu
*);
1822 static void add_partial_namespace (struct partial_die_info
*pdi
,
1823 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1824 int set_addrmap
, struct dwarf2_cu
*cu
);
1826 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1827 CORE_ADDR
*highpc
, int set_addrmap
,
1828 struct dwarf2_cu
*cu
);
1830 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1831 struct dwarf2_cu
*cu
);
1833 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1834 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1835 int need_pc
, struct dwarf2_cu
*cu
);
1837 static void dwarf2_read_symtab (struct partial_symtab
*,
1840 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1842 static abbrev_table_up abbrev_table_read_table
1843 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1846 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1848 static struct partial_die_info
*load_partial_dies
1849 (const struct die_reader_specs
*, const gdb_byte
*, int);
1851 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1852 struct dwarf2_cu
*);
1854 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1855 struct attribute
*, struct attr_abbrev
*,
1858 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1860 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1862 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1864 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1866 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1868 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1871 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1873 static LONGEST read_checked_initial_length_and_offset
1874 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1875 unsigned int *, unsigned int *);
1877 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1878 const struct comp_unit_head
*,
1881 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1883 static sect_offset read_abbrev_offset
1884 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1885 struct dwarf2_section_info
*, sect_offset
);
1887 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1889 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1891 static const char *read_indirect_string
1892 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1893 const struct comp_unit_head
*, unsigned int *);
1895 static const char *read_indirect_line_string
1896 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1897 const struct comp_unit_head
*, unsigned int *);
1899 static const char *read_indirect_string_at_offset
1900 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1901 LONGEST str_offset
);
1903 static const char *read_indirect_string_from_dwz
1904 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1906 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1908 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1912 static const char *read_str_index (const struct die_reader_specs
*reader
,
1913 ULONGEST str_index
);
1915 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1917 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1918 struct dwarf2_cu
*);
1920 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1923 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1924 struct dwarf2_cu
*cu
);
1926 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1927 struct dwarf2_cu
*cu
);
1929 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1931 static struct die_info
*die_specification (struct die_info
*die
,
1932 struct dwarf2_cu
**);
1934 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1935 struct dwarf2_cu
*cu
);
1937 static void dwarf_decode_lines (struct line_header
*, const char *,
1938 struct dwarf2_cu
*, struct partial_symtab
*,
1939 CORE_ADDR
, int decode_mapping
);
1941 static void dwarf2_start_subfile (const char *, const char *);
1943 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1944 const char *, const char *,
1947 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1948 struct dwarf2_cu
*, struct symbol
* = NULL
);
1950 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1951 struct dwarf2_cu
*);
1953 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1956 struct obstack
*obstack
,
1957 struct dwarf2_cu
*cu
, LONGEST
*value
,
1958 const gdb_byte
**bytes
,
1959 struct dwarf2_locexpr_baton
**baton
);
1961 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1963 static int need_gnat_info (struct dwarf2_cu
*);
1965 static struct type
*die_descriptive_type (struct die_info
*,
1966 struct dwarf2_cu
*);
1968 static void set_descriptive_type (struct type
*, struct die_info
*,
1969 struct dwarf2_cu
*);
1971 static struct type
*die_containing_type (struct die_info
*,
1972 struct dwarf2_cu
*);
1974 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1975 struct dwarf2_cu
*);
1977 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1979 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1981 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1983 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1984 const char *suffix
, int physname
,
1985 struct dwarf2_cu
*cu
);
1987 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1989 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1991 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1993 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1995 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1997 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1999 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
2000 struct dwarf2_cu
*, struct partial_symtab
*);
2002 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
2003 values. Keep the items ordered with increasing constraints compliance. */
2006 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
2007 PC_BOUNDS_NOT_PRESENT
,
2009 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
2010 were present but they do not form a valid range of PC addresses. */
2013 /* Discontiguous range was found - that is DW_AT_ranges was found. */
2016 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
2020 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
2021 CORE_ADDR
*, CORE_ADDR
*,
2023 struct partial_symtab
*);
2025 static void get_scope_pc_bounds (struct die_info
*,
2026 CORE_ADDR
*, CORE_ADDR
*,
2027 struct dwarf2_cu
*);
2029 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
2030 CORE_ADDR
, struct dwarf2_cu
*);
2032 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
2033 struct dwarf2_cu
*);
2035 static void dwarf2_attach_fields_to_type (struct field_info
*,
2036 struct type
*, struct dwarf2_cu
*);
2038 static void dwarf2_add_member_fn (struct field_info
*,
2039 struct die_info
*, struct type
*,
2040 struct dwarf2_cu
*);
2042 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
2044 struct dwarf2_cu
*);
2046 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
2048 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
2050 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
2052 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
2054 static struct using_direct
**using_directives (enum language
);
2056 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
2058 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
2060 static struct type
*read_module_type (struct die_info
*die
,
2061 struct dwarf2_cu
*cu
);
2063 static const char *namespace_name (struct die_info
*die
,
2064 int *is_anonymous
, struct dwarf2_cu
*);
2066 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
2068 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
2070 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
2071 struct dwarf2_cu
*);
2073 static struct die_info
*read_die_and_siblings_1
2074 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
2077 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
2078 const gdb_byte
*info_ptr
,
2079 const gdb_byte
**new_info_ptr
,
2080 struct die_info
*parent
);
2082 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
2083 struct die_info
**, const gdb_byte
*,
2086 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
2087 struct die_info
**, const gdb_byte
*,
2090 static void process_die (struct die_info
*, struct dwarf2_cu
*);
2092 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
2095 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
2097 static const char *dwarf2_full_name (const char *name
,
2098 struct die_info
*die
,
2099 struct dwarf2_cu
*cu
);
2101 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
2102 struct dwarf2_cu
*cu
);
2104 static struct die_info
*dwarf2_extension (struct die_info
*die
,
2105 struct dwarf2_cu
**);
2107 static const char *dwarf_tag_name (unsigned int);
2109 static const char *dwarf_attr_name (unsigned int);
2111 static const char *dwarf_form_name (unsigned int);
2113 static const char *dwarf_bool_name (unsigned int);
2115 static const char *dwarf_type_encoding_name (unsigned int);
2117 static struct die_info
*sibling_die (struct die_info
*);
2119 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
2121 static void dump_die_for_error (struct die_info
*);
2123 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
2126 /*static*/ void dump_die (struct die_info
*, int max_level
);
2128 static void store_in_ref_table (struct die_info
*,
2129 struct dwarf2_cu
*);
2131 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
2133 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
2135 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
2136 const struct attribute
*,
2137 struct dwarf2_cu
**);
2139 static struct die_info
*follow_die_ref (struct die_info
*,
2140 const struct attribute
*,
2141 struct dwarf2_cu
**);
2143 static struct die_info
*follow_die_sig (struct die_info
*,
2144 const struct attribute
*,
2145 struct dwarf2_cu
**);
2147 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
2148 struct dwarf2_cu
*);
2150 static struct type
*get_DW_AT_signature_type (struct die_info
*,
2151 const struct attribute
*,
2152 struct dwarf2_cu
*);
2154 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
2156 static void read_signatured_type (struct signatured_type
*);
2158 static int attr_to_dynamic_prop (const struct attribute
*attr
,
2159 struct die_info
*die
, struct dwarf2_cu
*cu
,
2160 struct dynamic_prop
*prop
);
2162 /* memory allocation interface */
2164 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
2166 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
2168 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
2170 static int attr_form_is_block (const struct attribute
*);
2172 static int attr_form_is_section_offset (const struct attribute
*);
2174 static int attr_form_is_constant (const struct attribute
*);
2176 static int attr_form_is_ref (const struct attribute
*);
2178 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
2179 struct dwarf2_loclist_baton
*baton
,
2180 const struct attribute
*attr
);
2182 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
2184 struct dwarf2_cu
*cu
,
2187 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
2188 const gdb_byte
*info_ptr
,
2189 struct abbrev_info
*abbrev
);
2191 static hashval_t
partial_die_hash (const void *item
);
2193 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
2195 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
2196 (sect_offset sect_off
, unsigned int offset_in_dwz
,
2197 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2199 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2200 struct die_info
*comp_unit_die
,
2201 enum language pretend_language
);
2203 static void free_cached_comp_units (void *);
2205 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2207 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2209 static struct type
*set_die_type (struct die_info
*, struct type
*,
2210 struct dwarf2_cu
*);
2212 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2214 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2216 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2219 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2222 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2225 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2226 struct dwarf2_per_cu_data
*);
2228 static void dwarf2_mark (struct dwarf2_cu
*);
2230 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2232 static struct type
*get_die_type_at_offset (sect_offset
,
2233 struct dwarf2_per_cu_data
*);
2235 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2237 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2238 enum language pretend_language
);
2240 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2242 /* Class, the destructor of which frees all allocated queue entries. This
2243 will only have work to do if an error was thrown while processing the
2244 dwarf. If no error was thrown then the queue entries should have all
2245 been processed, and freed, as we went along. */
2247 class dwarf2_queue_guard
2250 dwarf2_queue_guard () = default;
2252 /* Free any entries remaining on the queue. There should only be
2253 entries left if we hit an error while processing the dwarf. */
2254 ~dwarf2_queue_guard ()
2256 struct dwarf2_queue_item
*item
, *last
;
2258 item
= dwarf2_queue
;
2261 /* Anything still marked queued is likely to be in an
2262 inconsistent state, so discard it. */
2263 if (item
->per_cu
->queued
)
2265 if (item
->per_cu
->cu
!= NULL
)
2266 free_one_cached_comp_unit (item
->per_cu
);
2267 item
->per_cu
->queued
= 0;
2275 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2279 /* The return type of find_file_and_directory. Note, the enclosed
2280 string pointers are only valid while this object is valid. */
2282 struct file_and_directory
2284 /* The filename. This is never NULL. */
2287 /* The compilation directory. NULL if not known. If we needed to
2288 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2289 points directly to the DW_AT_comp_dir string attribute owned by
2290 the obstack that owns the DIE. */
2291 const char *comp_dir
;
2293 /* If we needed to build a new string for comp_dir, this is what
2294 owns the storage. */
2295 std::string comp_dir_storage
;
2298 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2299 struct dwarf2_cu
*cu
);
2301 static char *file_full_name (int file
, struct line_header
*lh
,
2302 const char *comp_dir
);
2304 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2305 enum class rcuh_kind
{ COMPILE
, TYPE
};
2307 static const gdb_byte
*read_and_check_comp_unit_head
2308 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2309 struct comp_unit_head
*header
,
2310 struct dwarf2_section_info
*section
,
2311 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2312 rcuh_kind section_kind
);
2314 static void init_cutu_and_read_dies
2315 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2316 int use_existing_cu
, int keep
,
2317 die_reader_func_ftype
*die_reader_func
, void *data
);
2319 static void init_cutu_and_read_dies_simple
2320 (struct dwarf2_per_cu_data
*this_cu
,
2321 die_reader_func_ftype
*die_reader_func
, void *data
);
2323 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2325 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2327 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2328 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2329 struct dwp_file
*dwp_file
, const char *comp_dir
,
2330 ULONGEST signature
, int is_debug_types
);
2332 static struct dwp_file
*get_dwp_file
2333 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2335 static struct dwo_unit
*lookup_dwo_comp_unit
2336 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2338 static struct dwo_unit
*lookup_dwo_type_unit
2339 (struct signatured_type
*, const char *, const char *);
2341 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2343 static void free_dwo_file_cleanup (void *);
2345 struct free_dwo_file_cleanup_data
2347 struct dwo_file
*dwo_file
;
2348 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
2351 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2353 static void check_producer (struct dwarf2_cu
*cu
);
2355 static void free_line_header_voidp (void *arg
);
2357 /* Various complaints about symbol reading that don't abort the process. */
2360 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2362 complaint (&symfile_complaints
,
2363 _("statement list doesn't fit in .debug_line section"));
2367 dwarf2_debug_line_missing_file_complaint (void)
2369 complaint (&symfile_complaints
,
2370 _(".debug_line section has line data without a file"));
2374 dwarf2_debug_line_missing_end_sequence_complaint (void)
2376 complaint (&symfile_complaints
,
2377 _(".debug_line section has line "
2378 "program sequence without an end"));
2382 dwarf2_complex_location_expr_complaint (void)
2384 complaint (&symfile_complaints
, _("location expression too complex"));
2388 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2391 complaint (&symfile_complaints
,
2392 _("const value length mismatch for '%s', got %d, expected %d"),
2397 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2399 complaint (&symfile_complaints
,
2400 _("debug info runs off end of %s section"
2402 get_section_name (section
),
2403 get_section_file_name (section
));
2407 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2409 complaint (&symfile_complaints
,
2410 _("macro debug info contains a "
2411 "malformed macro definition:\n`%s'"),
2416 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2418 complaint (&symfile_complaints
,
2419 _("invalid attribute class or form for '%s' in '%s'"),
2423 /* Hash function for line_header_hash. */
2426 line_header_hash (const struct line_header
*ofs
)
2428 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2431 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2434 line_header_hash_voidp (const void *item
)
2436 const struct line_header
*ofs
= (const struct line_header
*) item
;
2438 return line_header_hash (ofs
);
2441 /* Equality function for line_header_hash. */
2444 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2446 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2447 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2449 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2450 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2455 /* Read the given attribute value as an address, taking the attribute's
2456 form into account. */
2459 attr_value_as_address (struct attribute
*attr
)
2463 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2465 /* Aside from a few clearly defined exceptions, attributes that
2466 contain an address must always be in DW_FORM_addr form.
2467 Unfortunately, some compilers happen to be violating this
2468 requirement by encoding addresses using other forms, such
2469 as DW_FORM_data4 for example. For those broken compilers,
2470 we try to do our best, without any guarantee of success,
2471 to interpret the address correctly. It would also be nice
2472 to generate a complaint, but that would require us to maintain
2473 a list of legitimate cases where a non-address form is allowed,
2474 as well as update callers to pass in at least the CU's DWARF
2475 version. This is more overhead than what we're willing to
2476 expand for a pretty rare case. */
2477 addr
= DW_UNSND (attr
);
2480 addr
= DW_ADDR (attr
);
2485 /* The suffix for an index file. */
2486 #define INDEX4_SUFFIX ".gdb-index"
2487 #define INDEX5_SUFFIX ".debug_names"
2488 #define DEBUG_STR_SUFFIX ".debug_str"
2490 /* See declaration. */
2492 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2493 const dwarf2_debug_sections
*names
)
2494 : objfile (objfile_
)
2497 names
= &dwarf2_elf_names
;
2499 bfd
*obfd
= objfile
->obfd
;
2501 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2502 locate_sections (obfd
, sec
, *names
);
2505 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2507 dwarf2_per_objfile::~dwarf2_per_objfile ()
2509 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2510 free_cached_comp_units ();
2512 if (quick_file_names_table
)
2513 htab_delete (quick_file_names_table
);
2515 if (line_header_hash
)
2516 htab_delete (line_header_hash
);
2518 for (int ix
= 0; ix
< n_comp_units
; ++ix
)
2519 VEC_free (dwarf2_per_cu_ptr
, all_comp_units
[ix
]->imported_symtabs
);
2521 for (int ix
= 0; ix
< n_type_units
; ++ix
)
2522 VEC_free (dwarf2_per_cu_ptr
,
2523 all_type_units
[ix
]->per_cu
.imported_symtabs
);
2524 xfree (all_type_units
);
2526 VEC_free (dwarf2_section_info_def
, types
);
2528 if (dwo_files
!= NULL
)
2529 free_dwo_files (dwo_files
, objfile
);
2530 if (dwp_file
!= NULL
)
2531 gdb_bfd_unref (dwp_file
->dbfd
);
2533 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2534 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2536 if (index_table
!= NULL
)
2537 index_table
->~mapped_index ();
2539 /* Everything else should be on the objfile obstack. */
2542 /* See declaration. */
2545 dwarf2_per_objfile::free_cached_comp_units ()
2547 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2548 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2549 while (per_cu
!= NULL
)
2551 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2554 *last_chain
= next_cu
;
2559 /* Try to locate the sections we need for DWARF 2 debugging
2560 information and return true if we have enough to do something.
2561 NAMES points to the dwarf2 section names, or is NULL if the standard
2562 ELF names are used. */
2565 dwarf2_has_info (struct objfile
*objfile
,
2566 const struct dwarf2_debug_sections
*names
)
2568 if (objfile
->flags
& OBJF_READNEVER
)
2571 struct dwarf2_per_objfile
*dwarf2_per_objfile
2572 = get_dwarf2_per_objfile (objfile
);
2574 if (dwarf2_per_objfile
== NULL
)
2576 /* Initialize per-objfile state. */
2578 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2580 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2582 return (!dwarf2_per_objfile
->info
.is_virtual
2583 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2584 && !dwarf2_per_objfile
->abbrev
.is_virtual
2585 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2588 /* Return the containing section of virtual section SECTION. */
2590 static struct dwarf2_section_info
*
2591 get_containing_section (const struct dwarf2_section_info
*section
)
2593 gdb_assert (section
->is_virtual
);
2594 return section
->s
.containing_section
;
2597 /* Return the bfd owner of SECTION. */
2600 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2602 if (section
->is_virtual
)
2604 section
= get_containing_section (section
);
2605 gdb_assert (!section
->is_virtual
);
2607 return section
->s
.section
->owner
;
2610 /* Return the bfd section of SECTION.
2611 Returns NULL if the section is not present. */
2614 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2616 if (section
->is_virtual
)
2618 section
= get_containing_section (section
);
2619 gdb_assert (!section
->is_virtual
);
2621 return section
->s
.section
;
2624 /* Return the name of SECTION. */
2627 get_section_name (const struct dwarf2_section_info
*section
)
2629 asection
*sectp
= get_section_bfd_section (section
);
2631 gdb_assert (sectp
!= NULL
);
2632 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2635 /* Return the name of the file SECTION is in. */
2638 get_section_file_name (const struct dwarf2_section_info
*section
)
2640 bfd
*abfd
= get_section_bfd_owner (section
);
2642 return bfd_get_filename (abfd
);
2645 /* Return the id of SECTION.
2646 Returns 0 if SECTION doesn't exist. */
2649 get_section_id (const struct dwarf2_section_info
*section
)
2651 asection
*sectp
= get_section_bfd_section (section
);
2658 /* Return the flags of SECTION.
2659 SECTION (or containing section if this is a virtual section) must exist. */
2662 get_section_flags (const struct dwarf2_section_info
*section
)
2664 asection
*sectp
= get_section_bfd_section (section
);
2666 gdb_assert (sectp
!= NULL
);
2667 return bfd_get_section_flags (sectp
->owner
, sectp
);
2670 /* When loading sections, we look either for uncompressed section or for
2671 compressed section names. */
2674 section_is_p (const char *section_name
,
2675 const struct dwarf2_section_names
*names
)
2677 if (names
->normal
!= NULL
2678 && strcmp (section_name
, names
->normal
) == 0)
2680 if (names
->compressed
!= NULL
2681 && strcmp (section_name
, names
->compressed
) == 0)
2686 /* See declaration. */
2689 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2690 const dwarf2_debug_sections
&names
)
2692 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2694 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2697 else if (section_is_p (sectp
->name
, &names
.info
))
2699 this->info
.s
.section
= sectp
;
2700 this->info
.size
= bfd_get_section_size (sectp
);
2702 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2704 this->abbrev
.s
.section
= sectp
;
2705 this->abbrev
.size
= bfd_get_section_size (sectp
);
2707 else if (section_is_p (sectp
->name
, &names
.line
))
2709 this->line
.s
.section
= sectp
;
2710 this->line
.size
= bfd_get_section_size (sectp
);
2712 else if (section_is_p (sectp
->name
, &names
.loc
))
2714 this->loc
.s
.section
= sectp
;
2715 this->loc
.size
= bfd_get_section_size (sectp
);
2717 else if (section_is_p (sectp
->name
, &names
.loclists
))
2719 this->loclists
.s
.section
= sectp
;
2720 this->loclists
.size
= bfd_get_section_size (sectp
);
2722 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2724 this->macinfo
.s
.section
= sectp
;
2725 this->macinfo
.size
= bfd_get_section_size (sectp
);
2727 else if (section_is_p (sectp
->name
, &names
.macro
))
2729 this->macro
.s
.section
= sectp
;
2730 this->macro
.size
= bfd_get_section_size (sectp
);
2732 else if (section_is_p (sectp
->name
, &names
.str
))
2734 this->str
.s
.section
= sectp
;
2735 this->str
.size
= bfd_get_section_size (sectp
);
2737 else if (section_is_p (sectp
->name
, &names
.line_str
))
2739 this->line_str
.s
.section
= sectp
;
2740 this->line_str
.size
= bfd_get_section_size (sectp
);
2742 else if (section_is_p (sectp
->name
, &names
.addr
))
2744 this->addr
.s
.section
= sectp
;
2745 this->addr
.size
= bfd_get_section_size (sectp
);
2747 else if (section_is_p (sectp
->name
, &names
.frame
))
2749 this->frame
.s
.section
= sectp
;
2750 this->frame
.size
= bfd_get_section_size (sectp
);
2752 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2754 this->eh_frame
.s
.section
= sectp
;
2755 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2757 else if (section_is_p (sectp
->name
, &names
.ranges
))
2759 this->ranges
.s
.section
= sectp
;
2760 this->ranges
.size
= bfd_get_section_size (sectp
);
2762 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2764 this->rnglists
.s
.section
= sectp
;
2765 this->rnglists
.size
= bfd_get_section_size (sectp
);
2767 else if (section_is_p (sectp
->name
, &names
.types
))
2769 struct dwarf2_section_info type_section
;
2771 memset (&type_section
, 0, sizeof (type_section
));
2772 type_section
.s
.section
= sectp
;
2773 type_section
.size
= bfd_get_section_size (sectp
);
2775 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2778 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2780 this->gdb_index
.s
.section
= sectp
;
2781 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2783 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2785 this->debug_names
.s
.section
= sectp
;
2786 this->debug_names
.size
= bfd_get_section_size (sectp
);
2788 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2790 this->debug_aranges
.s
.section
= sectp
;
2791 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2794 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2795 && bfd_section_vma (abfd
, sectp
) == 0)
2796 this->has_section_at_zero
= true;
2799 /* A helper function that decides whether a section is empty,
2803 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2805 if (section
->is_virtual
)
2806 return section
->size
== 0;
2807 return section
->s
.section
== NULL
|| section
->size
== 0;
2810 /* Read the contents of the section INFO.
2811 OBJFILE is the main object file, but not necessarily the file where
2812 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2814 If the section is compressed, uncompress it before returning. */
2817 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2821 gdb_byte
*buf
, *retbuf
;
2825 info
->buffer
= NULL
;
2828 if (dwarf2_section_empty_p (info
))
2831 sectp
= get_section_bfd_section (info
);
2833 /* If this is a virtual section we need to read in the real one first. */
2834 if (info
->is_virtual
)
2836 struct dwarf2_section_info
*containing_section
=
2837 get_containing_section (info
);
2839 gdb_assert (sectp
!= NULL
);
2840 if ((sectp
->flags
& SEC_RELOC
) != 0)
2842 error (_("Dwarf Error: DWP format V2 with relocations is not"
2843 " supported in section %s [in module %s]"),
2844 get_section_name (info
), get_section_file_name (info
));
2846 dwarf2_read_section (objfile
, containing_section
);
2847 /* Other code should have already caught virtual sections that don't
2849 gdb_assert (info
->virtual_offset
+ info
->size
2850 <= containing_section
->size
);
2851 /* If the real section is empty or there was a problem reading the
2852 section we shouldn't get here. */
2853 gdb_assert (containing_section
->buffer
!= NULL
);
2854 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2858 /* If the section has relocations, we must read it ourselves.
2859 Otherwise we attach it to the BFD. */
2860 if ((sectp
->flags
& SEC_RELOC
) == 0)
2862 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2866 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2869 /* When debugging .o files, we may need to apply relocations; see
2870 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2871 We never compress sections in .o files, so we only need to
2872 try this when the section is not compressed. */
2873 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2876 info
->buffer
= retbuf
;
2880 abfd
= get_section_bfd_owner (info
);
2881 gdb_assert (abfd
!= NULL
);
2883 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2884 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2886 error (_("Dwarf Error: Can't read DWARF data"
2887 " in section %s [in module %s]"),
2888 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2892 /* A helper function that returns the size of a section in a safe way.
2893 If you are positive that the section has been read before using the
2894 size, then it is safe to refer to the dwarf2_section_info object's
2895 "size" field directly. In other cases, you must call this
2896 function, because for compressed sections the size field is not set
2897 correctly until the section has been read. */
2899 static bfd_size_type
2900 dwarf2_section_size (struct objfile
*objfile
,
2901 struct dwarf2_section_info
*info
)
2904 dwarf2_read_section (objfile
, info
);
2908 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2912 dwarf2_get_section_info (struct objfile
*objfile
,
2913 enum dwarf2_section_enum sect
,
2914 asection
**sectp
, const gdb_byte
**bufp
,
2915 bfd_size_type
*sizep
)
2917 struct dwarf2_per_objfile
*data
2918 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2919 dwarf2_objfile_data_key
);
2920 struct dwarf2_section_info
*info
;
2922 /* We may see an objfile without any DWARF, in which case we just
2933 case DWARF2_DEBUG_FRAME
:
2934 info
= &data
->frame
;
2936 case DWARF2_EH_FRAME
:
2937 info
= &data
->eh_frame
;
2940 gdb_assert_not_reached ("unexpected section");
2943 dwarf2_read_section (objfile
, info
);
2945 *sectp
= get_section_bfd_section (info
);
2946 *bufp
= info
->buffer
;
2947 *sizep
= info
->size
;
2950 /* A helper function to find the sections for a .dwz file. */
2953 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2955 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2957 /* Note that we only support the standard ELF names, because .dwz
2958 is ELF-only (at the time of writing). */
2959 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2961 dwz_file
->abbrev
.s
.section
= sectp
;
2962 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2964 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2966 dwz_file
->info
.s
.section
= sectp
;
2967 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2969 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2971 dwz_file
->str
.s
.section
= sectp
;
2972 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2974 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2976 dwz_file
->line
.s
.section
= sectp
;
2977 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2979 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2981 dwz_file
->macro
.s
.section
= sectp
;
2982 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2984 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2986 dwz_file
->gdb_index
.s
.section
= sectp
;
2987 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2989 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2991 dwz_file
->debug_names
.s
.section
= sectp
;
2992 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2996 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2997 there is no .gnu_debugaltlink section in the file. Error if there
2998 is such a section but the file cannot be found. */
3000 static struct dwz_file
*
3001 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
3003 const char *filename
;
3004 struct dwz_file
*result
;
3005 bfd_size_type buildid_len_arg
;
3009 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
3010 return dwarf2_per_objfile
->dwz_file
;
3012 bfd_set_error (bfd_error_no_error
);
3013 gdb::unique_xmalloc_ptr
<char> data
3014 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
3015 &buildid_len_arg
, &buildid
));
3018 if (bfd_get_error () == bfd_error_no_error
)
3020 error (_("could not read '.gnu_debugaltlink' section: %s"),
3021 bfd_errmsg (bfd_get_error ()));
3024 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
3026 buildid_len
= (size_t) buildid_len_arg
;
3028 filename
= data
.get ();
3030 std::string abs_storage
;
3031 if (!IS_ABSOLUTE_PATH (filename
))
3033 gdb::unique_xmalloc_ptr
<char> abs
3034 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
3036 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
3037 filename
= abs_storage
.c_str ();
3040 /* First try the file name given in the section. If that doesn't
3041 work, try to use the build-id instead. */
3042 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
3043 if (dwz_bfd
!= NULL
)
3045 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
3049 if (dwz_bfd
== NULL
)
3050 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
3052 if (dwz_bfd
== NULL
)
3053 error (_("could not find '.gnu_debugaltlink' file for %s"),
3054 objfile_name (dwarf2_per_objfile
->objfile
));
3056 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
3058 result
->dwz_bfd
= dwz_bfd
.release ();
3060 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
3062 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
3063 dwarf2_per_objfile
->dwz_file
= result
;
3067 /* DWARF quick_symbols_functions support. */
3069 /* TUs can share .debug_line entries, and there can be a lot more TUs than
3070 unique line tables, so we maintain a separate table of all .debug_line
3071 derived entries to support the sharing.
3072 All the quick functions need is the list of file names. We discard the
3073 line_header when we're done and don't need to record it here. */
3074 struct quick_file_names
3076 /* The data used to construct the hash key. */
3077 struct stmt_list_hash hash
;
3079 /* The number of entries in file_names, real_names. */
3080 unsigned int num_file_names
;
3082 /* The file names from the line table, after being run through
3084 const char **file_names
;
3086 /* The file names from the line table after being run through
3087 gdb_realpath. These are computed lazily. */
3088 const char **real_names
;
3091 /* When using the index (and thus not using psymtabs), each CU has an
3092 object of this type. This is used to hold information needed by
3093 the various "quick" methods. */
3094 struct dwarf2_per_cu_quick_data
3096 /* The file table. This can be NULL if there was no file table
3097 or it's currently not read in.
3098 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
3099 struct quick_file_names
*file_names
;
3101 /* The corresponding symbol table. This is NULL if symbols for this
3102 CU have not yet been read. */
3103 struct compunit_symtab
*compunit_symtab
;
3105 /* A temporary mark bit used when iterating over all CUs in
3106 expand_symtabs_matching. */
3107 unsigned int mark
: 1;
3109 /* True if we've tried to read the file table and found there isn't one.
3110 There will be no point in trying to read it again next time. */
3111 unsigned int no_file_data
: 1;
3114 /* Utility hash function for a stmt_list_hash. */
3117 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
3121 if (stmt_list_hash
->dwo_unit
!= NULL
)
3122 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
3123 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
3127 /* Utility equality function for a stmt_list_hash. */
3130 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
3131 const struct stmt_list_hash
*rhs
)
3133 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
3135 if (lhs
->dwo_unit
!= NULL
3136 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
3139 return lhs
->line_sect_off
== rhs
->line_sect_off
;
3142 /* Hash function for a quick_file_names. */
3145 hash_file_name_entry (const void *e
)
3147 const struct quick_file_names
*file_data
3148 = (const struct quick_file_names
*) e
;
3150 return hash_stmt_list_entry (&file_data
->hash
);
3153 /* Equality function for a quick_file_names. */
3156 eq_file_name_entry (const void *a
, const void *b
)
3158 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
3159 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
3161 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
3164 /* Delete function for a quick_file_names. */
3167 delete_file_name_entry (void *e
)
3169 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
3172 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3174 xfree ((void*) file_data
->file_names
[i
]);
3175 if (file_data
->real_names
)
3176 xfree ((void*) file_data
->real_names
[i
]);
3179 /* The space for the struct itself lives on objfile_obstack,
3180 so we don't free it here. */
3183 /* Create a quick_file_names hash table. */
3186 create_quick_file_names_table (unsigned int nr_initial_entries
)
3188 return htab_create_alloc (nr_initial_entries
,
3189 hash_file_name_entry
, eq_file_name_entry
,
3190 delete_file_name_entry
, xcalloc
, xfree
);
3193 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
3194 have to be created afterwards. You should call age_cached_comp_units after
3195 processing PER_CU->CU. dw2_setup must have been already called. */
3198 load_cu (struct dwarf2_per_cu_data
*per_cu
)
3200 if (per_cu
->is_debug_types
)
3201 load_full_type_unit (per_cu
);
3203 load_full_comp_unit (per_cu
, language_minimal
);
3205 if (per_cu
->cu
== NULL
)
3206 return; /* Dummy CU. */
3208 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
3211 /* Read in the symbols for PER_CU. */
3214 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3216 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3218 /* Skip type_unit_groups, reading the type units they contain
3219 is handled elsewhere. */
3220 if (IS_TYPE_UNIT_GROUP (per_cu
))
3223 /* The destructor of dwarf2_queue_guard frees any entries left on
3224 the queue. After this point we're guaranteed to leave this function
3225 with the dwarf queue empty. */
3226 dwarf2_queue_guard q_guard
;
3228 if (dwarf2_per_objfile
->using_index
3229 ? per_cu
->v
.quick
->compunit_symtab
== NULL
3230 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
3232 queue_comp_unit (per_cu
, language_minimal
);
3235 /* If we just loaded a CU from a DWO, and we're working with an index
3236 that may badly handle TUs, load all the TUs in that DWO as well.
3237 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
3238 if (!per_cu
->is_debug_types
3239 && per_cu
->cu
!= NULL
3240 && per_cu
->cu
->dwo_unit
!= NULL
3241 && dwarf2_per_objfile
->index_table
!= NULL
3242 && dwarf2_per_objfile
->index_table
->version
<= 7
3243 /* DWP files aren't supported yet. */
3244 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
3245 queue_and_load_all_dwo_tus (per_cu
);
3248 process_queue (dwarf2_per_objfile
);
3250 /* Age the cache, releasing compilation units that have not
3251 been used recently. */
3252 age_cached_comp_units (dwarf2_per_objfile
);
3255 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
3256 the objfile from which this CU came. Returns the resulting symbol
3259 static struct compunit_symtab
*
3260 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3262 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3264 gdb_assert (dwarf2_per_objfile
->using_index
);
3265 if (!per_cu
->v
.quick
->compunit_symtab
)
3267 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
,
3268 dwarf2_per_objfile
);
3269 scoped_restore decrementer
= increment_reading_symtab ();
3270 dw2_do_instantiate_symtab (per_cu
);
3271 process_cu_includes (dwarf2_per_objfile
);
3272 do_cleanups (back_to
);
3275 return per_cu
->v
.quick
->compunit_symtab
;
3278 /* Return the CU/TU given its index.
3280 This is intended for loops like:
3282 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3283 + dwarf2_per_objfile->n_type_units); ++i)
3285 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3291 static struct dwarf2_per_cu_data
*
3292 dw2_get_cutu (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3295 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3297 index
-= dwarf2_per_objfile
->n_comp_units
;
3298 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3299 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3302 return dwarf2_per_objfile
->all_comp_units
[index
];
3305 /* Return the CU given its index.
3306 This differs from dw2_get_cutu in that it's for when you know INDEX
3309 static struct dwarf2_per_cu_data
*
3310 dw2_get_cu (struct dwarf2_per_objfile
*dwarf2_per_objfile
, int index
)
3312 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3314 return dwarf2_per_objfile
->all_comp_units
[index
];
3317 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3318 objfile_obstack, and constructed with the specified field
3321 static dwarf2_per_cu_data
*
3322 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3323 struct dwarf2_section_info
*section
,
3325 sect_offset sect_off
, ULONGEST length
)
3327 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3328 dwarf2_per_cu_data
*the_cu
3329 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3330 struct dwarf2_per_cu_data
);
3331 the_cu
->sect_off
= sect_off
;
3332 the_cu
->length
= length
;
3333 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3334 the_cu
->section
= section
;
3335 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3336 struct dwarf2_per_cu_quick_data
);
3337 the_cu
->is_dwz
= is_dwz
;
3341 /* A helper for create_cus_from_index that handles a given list of
3345 create_cus_from_index_list (struct objfile
*objfile
,
3346 const gdb_byte
*cu_list
, offset_type n_elements
,
3347 struct dwarf2_section_info
*section
,
3352 struct dwarf2_per_objfile
*dwarf2_per_objfile
3353 = get_dwarf2_per_objfile (objfile
);
3355 for (i
= 0; i
< n_elements
; i
+= 2)
3357 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3359 sect_offset sect_off
3360 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3361 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3364 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
3365 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3370 /* Read the CU list from the mapped index, and use it to create all
3371 the CU objects for this objfile. */
3374 create_cus_from_index (struct objfile
*objfile
,
3375 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3376 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3378 struct dwz_file
*dwz
;
3379 struct dwarf2_per_objfile
*dwarf2_per_objfile
3380 = get_dwarf2_per_objfile (objfile
);
3382 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3383 dwarf2_per_objfile
->all_comp_units
=
3384 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3385 dwarf2_per_objfile
->n_comp_units
);
3387 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3388 &dwarf2_per_objfile
->info
, 0, 0);
3390 if (dwz_elements
== 0)
3393 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3394 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3395 cu_list_elements
/ 2);
3398 /* Create the signatured type hash table from the index. */
3401 create_signatured_type_table_from_index (struct objfile
*objfile
,
3402 struct dwarf2_section_info
*section
,
3403 const gdb_byte
*bytes
,
3404 offset_type elements
)
3407 htab_t sig_types_hash
;
3408 struct dwarf2_per_objfile
*dwarf2_per_objfile
3409 = get_dwarf2_per_objfile (objfile
);
3411 dwarf2_per_objfile
->n_type_units
3412 = dwarf2_per_objfile
->n_allocated_type_units
3414 dwarf2_per_objfile
->all_type_units
=
3415 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3417 sig_types_hash
= allocate_signatured_type_table (objfile
);
3419 for (i
= 0; i
< elements
; i
+= 3)
3421 struct signatured_type
*sig_type
;
3424 cu_offset type_offset_in_tu
;
3426 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3427 sect_offset sect_off
3428 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3430 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3432 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3435 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3436 struct signatured_type
);
3437 sig_type
->signature
= signature
;
3438 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3439 sig_type
->per_cu
.is_debug_types
= 1;
3440 sig_type
->per_cu
.section
= section
;
3441 sig_type
->per_cu
.sect_off
= sect_off
;
3442 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3443 sig_type
->per_cu
.v
.quick
3444 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3445 struct dwarf2_per_cu_quick_data
);
3447 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3450 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3453 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3456 /* Create the signatured type hash table from .debug_names. */
3459 create_signatured_type_table_from_debug_names
3460 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3461 const mapped_debug_names
&map
,
3462 struct dwarf2_section_info
*section
,
3463 struct dwarf2_section_info
*abbrev_section
)
3465 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3467 dwarf2_read_section (objfile
, section
);
3468 dwarf2_read_section (objfile
, abbrev_section
);
3470 dwarf2_per_objfile
->n_type_units
3471 = dwarf2_per_objfile
->n_allocated_type_units
3473 dwarf2_per_objfile
->all_type_units
3474 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3476 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3478 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3480 struct signatured_type
*sig_type
;
3483 cu_offset type_offset_in_tu
;
3485 sect_offset sect_off
3486 = (sect_offset
) (extract_unsigned_integer
3487 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3489 map
.dwarf5_byte_order
));
3491 comp_unit_head cu_header
;
3492 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3494 section
->buffer
+ to_underlying (sect_off
),
3497 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3498 struct signatured_type
);
3499 sig_type
->signature
= cu_header
.signature
;
3500 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3501 sig_type
->per_cu
.is_debug_types
= 1;
3502 sig_type
->per_cu
.section
= section
;
3503 sig_type
->per_cu
.sect_off
= sect_off
;
3504 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3505 sig_type
->per_cu
.v
.quick
3506 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3507 struct dwarf2_per_cu_quick_data
);
3509 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3512 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3515 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3518 /* Read the address map data from the mapped index, and use it to
3519 populate the objfile's psymtabs_addrmap. */
3522 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3523 struct mapped_index
*index
)
3525 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3526 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3527 const gdb_byte
*iter
, *end
;
3528 struct addrmap
*mutable_map
;
3531 auto_obstack temp_obstack
;
3533 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3535 iter
= index
->address_table
.data ();
3536 end
= iter
+ index
->address_table
.size ();
3538 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3542 ULONGEST hi
, lo
, cu_index
;
3543 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3545 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3547 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3552 complaint (&symfile_complaints
,
3553 _(".gdb_index address table has invalid range (%s - %s)"),
3554 hex_string (lo
), hex_string (hi
));
3558 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3560 complaint (&symfile_complaints
,
3561 _(".gdb_index address table has invalid CU number %u"),
3562 (unsigned) cu_index
);
3566 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3567 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3568 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3569 dw2_get_cutu (dwarf2_per_objfile
, cu_index
));
3572 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3573 &objfile
->objfile_obstack
);
3576 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3577 populate the objfile's psymtabs_addrmap. */
3580 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3581 struct dwarf2_section_info
*section
)
3583 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3584 bfd
*abfd
= objfile
->obfd
;
3585 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3586 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3587 SECT_OFF_TEXT (objfile
));
3589 auto_obstack temp_obstack
;
3590 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3592 std::unordered_map
<sect_offset
,
3593 dwarf2_per_cu_data
*,
3594 gdb::hash_enum
<sect_offset
>>
3595 debug_info_offset_to_per_cu
;
3596 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3598 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cui
);
3599 const auto insertpair
3600 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3601 if (!insertpair
.second
)
3603 warning (_("Section .debug_aranges in %s has duplicate "
3604 "debug_info_offset %s, ignoring .debug_aranges."),
3605 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3610 dwarf2_read_section (objfile
, section
);
3612 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3614 const gdb_byte
*addr
= section
->buffer
;
3616 while (addr
< section
->buffer
+ section
->size
)
3618 const gdb_byte
*const entry_addr
= addr
;
3619 unsigned int bytes_read
;
3621 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3625 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3626 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3627 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3628 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3630 warning (_("Section .debug_aranges in %s entry at offset %zu "
3631 "length %s exceeds section length %s, "
3632 "ignoring .debug_aranges."),
3633 objfile_name (objfile
), entry_addr
- section
->buffer
,
3634 plongest (bytes_read
+ entry_length
),
3635 pulongest (section
->size
));
3639 /* The version number. */
3640 const uint16_t version
= read_2_bytes (abfd
, addr
);
3644 warning (_("Section .debug_aranges in %s entry at offset %zu "
3645 "has unsupported version %d, ignoring .debug_aranges."),
3646 objfile_name (objfile
), entry_addr
- section
->buffer
,
3651 const uint64_t debug_info_offset
3652 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3653 addr
+= offset_size
;
3654 const auto per_cu_it
3655 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3656 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3658 warning (_("Section .debug_aranges in %s entry at offset %zu "
3659 "debug_info_offset %s does not exists, "
3660 "ignoring .debug_aranges."),
3661 objfile_name (objfile
), entry_addr
- section
->buffer
,
3662 pulongest (debug_info_offset
));
3665 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3667 const uint8_t address_size
= *addr
++;
3668 if (address_size
< 1 || address_size
> 8)
3670 warning (_("Section .debug_aranges in %s entry at offset %zu "
3671 "address_size %u is invalid, ignoring .debug_aranges."),
3672 objfile_name (objfile
), entry_addr
- section
->buffer
,
3677 const uint8_t segment_selector_size
= *addr
++;
3678 if (segment_selector_size
!= 0)
3680 warning (_("Section .debug_aranges in %s entry at offset %zu "
3681 "segment_selector_size %u is not supported, "
3682 "ignoring .debug_aranges."),
3683 objfile_name (objfile
), entry_addr
- section
->buffer
,
3684 segment_selector_size
);
3688 /* Must pad to an alignment boundary that is twice the address
3689 size. It is undocumented by the DWARF standard but GCC does
3691 for (size_t padding
= ((-(addr
- section
->buffer
))
3692 & (2 * address_size
- 1));
3693 padding
> 0; padding
--)
3696 warning (_("Section .debug_aranges in %s entry at offset %zu "
3697 "padding is not zero, ignoring .debug_aranges."),
3698 objfile_name (objfile
), entry_addr
- section
->buffer
);
3704 if (addr
+ 2 * address_size
> entry_end
)
3706 warning (_("Section .debug_aranges in %s entry at offset %zu "
3707 "address list is not properly terminated, "
3708 "ignoring .debug_aranges."),
3709 objfile_name (objfile
), entry_addr
- section
->buffer
);
3712 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3714 addr
+= address_size
;
3715 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3717 addr
+= address_size
;
3718 if (start
== 0 && length
== 0)
3720 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3722 /* Symbol was eliminated due to a COMDAT group. */
3725 ULONGEST end
= start
+ length
;
3726 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3727 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3728 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3732 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3733 &objfile
->objfile_obstack
);
3736 /* The hash function for strings in the mapped index. This is the same as
3737 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3738 implementation. This is necessary because the hash function is tied to the
3739 format of the mapped index file. The hash values do not have to match with
3742 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3745 mapped_index_string_hash (int index_version
, const void *p
)
3747 const unsigned char *str
= (const unsigned char *) p
;
3751 while ((c
= *str
++) != 0)
3753 if (index_version
>= 5)
3755 r
= r
* 67 + c
- 113;
3761 /* Find a slot in the mapped index INDEX for the object named NAME.
3762 If NAME is found, set *VEC_OUT to point to the CU vector in the
3763 constant pool and return true. If NAME cannot be found, return
3767 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3768 offset_type
**vec_out
)
3771 offset_type slot
, step
;
3772 int (*cmp
) (const char *, const char *);
3774 gdb::unique_xmalloc_ptr
<char> without_params
;
3775 if (current_language
->la_language
== language_cplus
3776 || current_language
->la_language
== language_fortran
3777 || current_language
->la_language
== language_d
)
3779 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3782 if (strchr (name
, '(') != NULL
)
3784 without_params
= cp_remove_params (name
);
3786 if (without_params
!= NULL
)
3787 name
= without_params
.get ();
3791 /* Index version 4 did not support case insensitive searches. But the
3792 indices for case insensitive languages are built in lowercase, therefore
3793 simulate our NAME being searched is also lowercased. */
3794 hash
= mapped_index_string_hash ((index
->version
== 4
3795 && case_sensitivity
== case_sensitive_off
3796 ? 5 : index
->version
),
3799 slot
= hash
& (index
->symbol_table
.size () - 1);
3800 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3801 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3807 const auto &bucket
= index
->symbol_table
[slot
];
3808 if (bucket
.name
== 0 && bucket
.vec
== 0)
3811 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3812 if (!cmp (name
, str
))
3814 *vec_out
= (offset_type
*) (index
->constant_pool
3815 + MAYBE_SWAP (bucket
.vec
));
3819 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3823 /* A helper function that reads the .gdb_index from SECTION and fills
3824 in MAP. FILENAME is the name of the file containing the section;
3825 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3826 ok to use deprecated sections.
3828 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3829 out parameters that are filled in with information about the CU and
3830 TU lists in the section.
3832 Returns 1 if all went well, 0 otherwise. */
3835 read_index_from_section (struct objfile
*objfile
,
3836 const char *filename
,
3838 struct dwarf2_section_info
*section
,
3839 struct mapped_index
*map
,
3840 const gdb_byte
**cu_list
,
3841 offset_type
*cu_list_elements
,
3842 const gdb_byte
**types_list
,
3843 offset_type
*types_list_elements
)
3845 const gdb_byte
*addr
;
3846 offset_type version
;
3847 offset_type
*metadata
;
3850 if (dwarf2_section_empty_p (section
))
3853 /* Older elfutils strip versions could keep the section in the main
3854 executable while splitting it for the separate debug info file. */
3855 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3858 dwarf2_read_section (objfile
, section
);
3860 addr
= section
->buffer
;
3861 /* Version check. */
3862 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3863 /* Versions earlier than 3 emitted every copy of a psymbol. This
3864 causes the index to behave very poorly for certain requests. Version 3
3865 contained incomplete addrmap. So, it seems better to just ignore such
3869 static int warning_printed
= 0;
3870 if (!warning_printed
)
3872 warning (_("Skipping obsolete .gdb_index section in %s."),
3874 warning_printed
= 1;
3878 /* Index version 4 uses a different hash function than index version
3881 Versions earlier than 6 did not emit psymbols for inlined
3882 functions. Using these files will cause GDB not to be able to
3883 set breakpoints on inlined functions by name, so we ignore these
3884 indices unless the user has done
3885 "set use-deprecated-index-sections on". */
3886 if (version
< 6 && !deprecated_ok
)
3888 static int warning_printed
= 0;
3889 if (!warning_printed
)
3892 Skipping deprecated .gdb_index section in %s.\n\
3893 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3894 to use the section anyway."),
3896 warning_printed
= 1;
3900 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3901 of the TU (for symbols coming from TUs),
3902 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3903 Plus gold-generated indices can have duplicate entries for global symbols,
3904 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3905 These are just performance bugs, and we can't distinguish gdb-generated
3906 indices from gold-generated ones, so issue no warning here. */
3908 /* Indexes with higher version than the one supported by GDB may be no
3909 longer backward compatible. */
3913 map
->version
= version
;
3914 map
->total_size
= section
->size
;
3916 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3919 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3920 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3924 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3925 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3926 - MAYBE_SWAP (metadata
[i
]))
3930 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3931 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3933 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3936 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3937 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3939 = gdb::array_view
<mapped_index::symbol_table_slot
>
3940 ((mapped_index::symbol_table_slot
*) symbol_table
,
3941 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3944 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3949 /* Read .gdb_index. If everything went ok, initialize the "quick"
3950 elements of all the CUs and return 1. Otherwise, return 0. */
3953 dwarf2_read_index (struct objfile
*objfile
)
3955 struct mapped_index local_map
, *map
;
3956 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3957 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3958 struct dwz_file
*dwz
;
3959 struct dwarf2_per_objfile
*dwarf2_per_objfile
3960 = get_dwarf2_per_objfile (objfile
);
3962 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3963 use_deprecated_index_sections
,
3964 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3965 &cu_list
, &cu_list_elements
,
3966 &types_list
, &types_list_elements
))
3969 /* Don't use the index if it's empty. */
3970 if (local_map
.symbol_table
.empty ())
3973 /* If there is a .dwz file, read it so we can get its CU list as
3975 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3978 struct mapped_index dwz_map
;
3979 const gdb_byte
*dwz_types_ignore
;
3980 offset_type dwz_types_elements_ignore
;
3982 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3984 &dwz
->gdb_index
, &dwz_map
,
3985 &dwz_list
, &dwz_list_elements
,
3987 &dwz_types_elements_ignore
))
3989 warning (_("could not read '.gdb_index' section from %s; skipping"),
3990 bfd_get_filename (dwz
->dwz_bfd
));
3995 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3998 if (types_list_elements
)
4000 struct dwarf2_section_info
*section
;
4002 /* We can only handle a single .debug_types when we have an
4004 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
4007 section
= VEC_index (dwarf2_section_info_def
,
4008 dwarf2_per_objfile
->types
, 0);
4010 create_signatured_type_table_from_index (objfile
, section
, types_list
,
4011 types_list_elements
);
4014 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
4016 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
4017 map
= new (map
) mapped_index ();
4020 dwarf2_per_objfile
->index_table
= map
;
4021 dwarf2_per_objfile
->using_index
= 1;
4022 dwarf2_per_objfile
->quick_file_names_table
=
4023 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4028 /* die_reader_func for dw2_get_file_names. */
4031 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
4032 const gdb_byte
*info_ptr
,
4033 struct die_info
*comp_unit_die
,
4037 struct dwarf2_cu
*cu
= reader
->cu
;
4038 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
4039 struct dwarf2_per_objfile
*dwarf2_per_objfile
4040 = cu
->per_cu
->dwarf2_per_objfile
;
4041 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4042 struct dwarf2_per_cu_data
*lh_cu
;
4043 struct attribute
*attr
;
4046 struct quick_file_names
*qfn
;
4048 gdb_assert (! this_cu
->is_debug_types
);
4050 /* Our callers never want to match partial units -- instead they
4051 will match the enclosing full CU. */
4052 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
4054 this_cu
->v
.quick
->no_file_data
= 1;
4062 sect_offset line_offset
{};
4064 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4067 struct quick_file_names find_entry
;
4069 line_offset
= (sect_offset
) DW_UNSND (attr
);
4071 /* We may have already read in this line header (TU line header sharing).
4072 If we have we're done. */
4073 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
4074 find_entry
.hash
.line_sect_off
= line_offset
;
4075 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
4076 &find_entry
, INSERT
);
4079 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
4083 lh
= dwarf_decode_line_header (line_offset
, cu
);
4087 lh_cu
->v
.quick
->no_file_data
= 1;
4091 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
4092 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
4093 qfn
->hash
.line_sect_off
= line_offset
;
4094 gdb_assert (slot
!= NULL
);
4097 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
4099 qfn
->num_file_names
= lh
->file_names
.size ();
4101 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
4102 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
4103 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
4104 qfn
->real_names
= NULL
;
4106 lh_cu
->v
.quick
->file_names
= qfn
;
4109 /* A helper for the "quick" functions which attempts to read the line
4110 table for THIS_CU. */
4112 static struct quick_file_names
*
4113 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
4115 /* This should never be called for TUs. */
4116 gdb_assert (! this_cu
->is_debug_types
);
4117 /* Nor type unit groups. */
4118 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
4120 if (this_cu
->v
.quick
->file_names
!= NULL
)
4121 return this_cu
->v
.quick
->file_names
;
4122 /* If we know there is no line data, no point in looking again. */
4123 if (this_cu
->v
.quick
->no_file_data
)
4126 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
4128 if (this_cu
->v
.quick
->no_file_data
)
4130 return this_cu
->v
.quick
->file_names
;
4133 /* A helper for the "quick" functions which computes and caches the
4134 real path for a given file name from the line table. */
4137 dw2_get_real_path (struct objfile
*objfile
,
4138 struct quick_file_names
*qfn
, int index
)
4140 if (qfn
->real_names
== NULL
)
4141 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
4142 qfn
->num_file_names
, const char *);
4144 if (qfn
->real_names
[index
] == NULL
)
4145 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
4147 return qfn
->real_names
[index
];
4150 static struct symtab
*
4151 dw2_find_last_source_symtab (struct objfile
*objfile
)
4153 struct dwarf2_per_objfile
*dwarf2_per_objfile
4154 = get_dwarf2_per_objfile (objfile
);
4155 int index
= dwarf2_per_objfile
->n_comp_units
- 1;
4156 dwarf2_per_cu_data
*dwarf_cu
= dw2_get_cutu (dwarf2_per_objfile
, index
);
4157 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
4162 return compunit_primary_filetab (cust
);
4165 /* Traversal function for dw2_forget_cached_source_info. */
4168 dw2_free_cached_file_names (void **slot
, void *info
)
4170 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
4172 if (file_data
->real_names
)
4176 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
4178 xfree ((void*) file_data
->real_names
[i
]);
4179 file_data
->real_names
[i
] = NULL
;
4187 dw2_forget_cached_source_info (struct objfile
*objfile
)
4189 struct dwarf2_per_objfile
*dwarf2_per_objfile
4190 = get_dwarf2_per_objfile (objfile
);
4192 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
4193 dw2_free_cached_file_names
, NULL
);
4196 /* Helper function for dw2_map_symtabs_matching_filename that expands
4197 the symtabs and calls the iterator. */
4200 dw2_map_expand_apply (struct objfile
*objfile
,
4201 struct dwarf2_per_cu_data
*per_cu
,
4202 const char *name
, const char *real_path
,
4203 gdb::function_view
<bool (symtab
*)> callback
)
4205 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
4207 /* Don't visit already-expanded CUs. */
4208 if (per_cu
->v
.quick
->compunit_symtab
)
4211 /* This may expand more than one symtab, and we want to iterate over
4213 dw2_instantiate_symtab (per_cu
);
4215 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
4216 last_made
, callback
);
4219 /* Implementation of the map_symtabs_matching_filename method. */
4222 dw2_map_symtabs_matching_filename
4223 (struct objfile
*objfile
, const char *name
, const char *real_path
,
4224 gdb::function_view
<bool (symtab
*)> callback
)
4227 const char *name_basename
= lbasename (name
);
4228 struct dwarf2_per_objfile
*dwarf2_per_objfile
4229 = get_dwarf2_per_objfile (objfile
);
4231 /* The rule is CUs specify all the files, including those used by
4232 any TU, so there's no need to scan TUs here. */
4234 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4237 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
4238 struct quick_file_names
*file_data
;
4240 /* We only need to look at symtabs not already expanded. */
4241 if (per_cu
->v
.quick
->compunit_symtab
)
4244 file_data
= dw2_get_file_names (per_cu
);
4245 if (file_data
== NULL
)
4248 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4250 const char *this_name
= file_data
->file_names
[j
];
4251 const char *this_real_name
;
4253 if (compare_filenames_for_search (this_name
, name
))
4255 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4261 /* Before we invoke realpath, which can get expensive when many
4262 files are involved, do a quick comparison of the basenames. */
4263 if (! basenames_may_differ
4264 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
4267 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4268 if (compare_filenames_for_search (this_real_name
, name
))
4270 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4276 if (real_path
!= NULL
)
4278 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
4279 gdb_assert (IS_ABSOLUTE_PATH (name
));
4280 if (this_real_name
!= NULL
4281 && FILENAME_CMP (real_path
, this_real_name
) == 0)
4283 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4295 /* Struct used to manage iterating over all CUs looking for a symbol. */
4297 struct dw2_symtab_iterator
4299 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
4300 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
4301 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
4302 int want_specific_block
;
4303 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
4304 Unused if !WANT_SPECIFIC_BLOCK. */
4306 /* The kind of symbol we're looking for. */
4308 /* The list of CUs from the index entry of the symbol,
4309 or NULL if not found. */
4311 /* The next element in VEC to look at. */
4313 /* The number of elements in VEC, or zero if there is no match. */
4315 /* Have we seen a global version of the symbol?
4316 If so we can ignore all further global instances.
4317 This is to work around gold/15646, inefficient gold-generated
4322 /* Initialize the index symtab iterator ITER.
4323 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
4324 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
4327 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
4328 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4329 int want_specific_block
,
4334 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
4335 iter
->want_specific_block
= want_specific_block
;
4336 iter
->block_index
= block_index
;
4337 iter
->domain
= domain
;
4339 iter
->global_seen
= 0;
4341 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
4343 /* index is NULL if OBJF_READNOW. */
4344 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
4345 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4353 /* Return the next matching CU or NULL if there are no more. */
4355 static struct dwarf2_per_cu_data
*
4356 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4358 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4360 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4362 offset_type cu_index_and_attrs
=
4363 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4364 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4365 struct dwarf2_per_cu_data
*per_cu
;
4366 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
4367 /* This value is only valid for index versions >= 7. */
4368 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4369 gdb_index_symbol_kind symbol_kind
=
4370 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4371 /* Only check the symbol attributes if they're present.
4372 Indices prior to version 7 don't record them,
4373 and indices >= 7 may elide them for certain symbols
4374 (gold does this). */
4376 (dwarf2_per_objfile
->index_table
->version
>= 7
4377 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4379 /* Don't crash on bad data. */
4380 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4381 + dwarf2_per_objfile
->n_type_units
))
4383 complaint (&symfile_complaints
,
4384 _(".gdb_index entry has bad CU index"
4386 objfile_name (dwarf2_per_objfile
->objfile
));
4390 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
4392 /* Skip if already read in. */
4393 if (per_cu
->v
.quick
->compunit_symtab
)
4396 /* Check static vs global. */
4399 if (iter
->want_specific_block
4400 && want_static
!= is_static
)
4402 /* Work around gold/15646. */
4403 if (!is_static
&& iter
->global_seen
)
4406 iter
->global_seen
= 1;
4409 /* Only check the symbol's kind if it has one. */
4412 switch (iter
->domain
)
4415 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4416 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4417 /* Some types are also in VAR_DOMAIN. */
4418 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4422 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4426 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4441 static struct compunit_symtab
*
4442 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4443 const char *name
, domain_enum domain
)
4445 struct compunit_symtab
*stab_best
= NULL
;
4446 struct dwarf2_per_objfile
*dwarf2_per_objfile
4447 = get_dwarf2_per_objfile (objfile
);
4449 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4451 struct dw2_symtab_iterator iter
;
4452 struct dwarf2_per_cu_data
*per_cu
;
4454 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4456 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4458 struct symbol
*sym
, *with_opaque
= NULL
;
4459 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4460 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4461 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4463 sym
= block_find_symbol (block
, name
, domain
,
4464 block_find_non_opaque_type_preferred
,
4467 /* Some caution must be observed with overloaded functions
4468 and methods, since the index will not contain any overload
4469 information (but NAME might contain it). */
4472 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4474 if (with_opaque
!= NULL
4475 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4478 /* Keep looking through other CUs. */
4485 dw2_print_stats (struct objfile
*objfile
)
4487 struct dwarf2_per_objfile
*dwarf2_per_objfile
4488 = get_dwarf2_per_objfile (objfile
);
4489 int total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4492 for (int i
= 0; i
< total
; ++i
)
4494 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4496 if (!per_cu
->v
.quick
->compunit_symtab
)
4499 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4500 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4503 /* This dumps minimal information about the index.
4504 It is called via "mt print objfiles".
4505 One use is to verify .gdb_index has been loaded by the
4506 gdb.dwarf2/gdb-index.exp testcase. */
4509 dw2_dump (struct objfile
*objfile
)
4511 struct dwarf2_per_objfile
*dwarf2_per_objfile
4512 = get_dwarf2_per_objfile (objfile
);
4514 gdb_assert (dwarf2_per_objfile
->using_index
);
4515 printf_filtered (".gdb_index:");
4516 if (dwarf2_per_objfile
->index_table
!= NULL
)
4518 printf_filtered (" version %d\n",
4519 dwarf2_per_objfile
->index_table
->version
);
4522 printf_filtered (" faked for \"readnow\"\n");
4523 printf_filtered ("\n");
4527 dw2_relocate (struct objfile
*objfile
,
4528 const struct section_offsets
*new_offsets
,
4529 const struct section_offsets
*delta
)
4531 /* There's nothing to relocate here. */
4535 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4536 const char *func_name
)
4538 struct dwarf2_per_objfile
*dwarf2_per_objfile
4539 = get_dwarf2_per_objfile (objfile
);
4541 struct dw2_symtab_iterator iter
;
4542 struct dwarf2_per_cu_data
*per_cu
;
4544 /* Note: It doesn't matter what we pass for block_index here. */
4545 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4548 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4549 dw2_instantiate_symtab (per_cu
);
4554 dw2_expand_all_symtabs (struct objfile
*objfile
)
4556 struct dwarf2_per_objfile
*dwarf2_per_objfile
4557 = get_dwarf2_per_objfile (objfile
);
4558 int total_units
= (dwarf2_per_objfile
->n_comp_units
4559 + dwarf2_per_objfile
->n_type_units
);
4561 for (int i
= 0; i
< total_units
; ++i
)
4563 struct dwarf2_per_cu_data
*per_cu
4564 = dw2_get_cutu (dwarf2_per_objfile
, i
);
4566 dw2_instantiate_symtab (per_cu
);
4571 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4572 const char *fullname
)
4574 struct dwarf2_per_objfile
*dwarf2_per_objfile
4575 = get_dwarf2_per_objfile (objfile
);
4577 /* We don't need to consider type units here.
4578 This is only called for examining code, e.g. expand_line_sal.
4579 There can be an order of magnitude (or more) more type units
4580 than comp units, and we avoid them if we can. */
4582 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4585 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4586 struct quick_file_names
*file_data
;
4588 /* We only need to look at symtabs not already expanded. */
4589 if (per_cu
->v
.quick
->compunit_symtab
)
4592 file_data
= dw2_get_file_names (per_cu
);
4593 if (file_data
== NULL
)
4596 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4598 const char *this_fullname
= file_data
->file_names
[j
];
4600 if (filename_cmp (this_fullname
, fullname
) == 0)
4602 dw2_instantiate_symtab (per_cu
);
4610 dw2_map_matching_symbols (struct objfile
*objfile
,
4611 const char * name
, domain_enum domain
,
4613 int (*callback
) (struct block
*,
4614 struct symbol
*, void *),
4615 void *data
, symbol_name_match_type match
,
4616 symbol_compare_ftype
*ordered_compare
)
4618 /* Currently unimplemented; used for Ada. The function can be called if the
4619 current language is Ada for a non-Ada objfile using GNU index. As Ada
4620 does not look for non-Ada symbols this function should just return. */
4623 /* Symbol name matcher for .gdb_index names.
4625 Symbol names in .gdb_index have a few particularities:
4627 - There's no indication of which is the language of each symbol.
4629 Since each language has its own symbol name matching algorithm,
4630 and we don't know which language is the right one, we must match
4631 each symbol against all languages. This would be a potential
4632 performance problem if it were not mitigated by the
4633 mapped_index::name_components lookup table, which significantly
4634 reduces the number of times we need to call into this matcher,
4635 making it a non-issue.
4637 - Symbol names in the index have no overload (parameter)
4638 information. I.e., in C++, "foo(int)" and "foo(long)" both
4639 appear as "foo" in the index, for example.
4641 This means that the lookup names passed to the symbol name
4642 matcher functions must have no parameter information either
4643 because (e.g.) symbol search name "foo" does not match
4644 lookup-name "foo(int)" [while swapping search name for lookup
4647 class gdb_index_symbol_name_matcher
4650 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4651 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4653 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4654 Returns true if any matcher matches. */
4655 bool matches (const char *symbol_name
);
4658 /* A reference to the lookup name we're matching against. */
4659 const lookup_name_info
&m_lookup_name
;
4661 /* A vector holding all the different symbol name matchers, for all
4663 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4666 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4667 (const lookup_name_info
&lookup_name
)
4668 : m_lookup_name (lookup_name
)
4670 /* Prepare the vector of comparison functions upfront, to avoid
4671 doing the same work for each symbol. Care is taken to avoid
4672 matching with the same matcher more than once if/when multiple
4673 languages use the same matcher function. */
4674 auto &matchers
= m_symbol_name_matcher_funcs
;
4675 matchers
.reserve (nr_languages
);
4677 matchers
.push_back (default_symbol_name_matcher
);
4679 for (int i
= 0; i
< nr_languages
; i
++)
4681 const language_defn
*lang
= language_def ((enum language
) i
);
4682 symbol_name_matcher_ftype
*name_matcher
4683 = get_symbol_name_matcher (lang
, m_lookup_name
);
4685 /* Don't insert the same comparison routine more than once.
4686 Note that we do this linear walk instead of a seemingly
4687 cheaper sorted insert, or use a std::set or something like
4688 that, because relative order of function addresses is not
4689 stable. This is not a problem in practice because the number
4690 of supported languages is low, and the cost here is tiny
4691 compared to the number of searches we'll do afterwards using
4693 if (name_matcher
!= default_symbol_name_matcher
4694 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4695 == matchers
.end ()))
4696 matchers
.push_back (name_matcher
);
4701 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4703 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4704 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4710 /* Starting from a search name, return the string that finds the upper
4711 bound of all strings that start with SEARCH_NAME in a sorted name
4712 list. Returns the empty string to indicate that the upper bound is
4713 the end of the list. */
4716 make_sort_after_prefix_name (const char *search_name
)
4718 /* When looking to complete "func", we find the upper bound of all
4719 symbols that start with "func" by looking for where we'd insert
4720 the closest string that would follow "func" in lexicographical
4721 order. Usually, that's "func"-with-last-character-incremented,
4722 i.e. "fund". Mind non-ASCII characters, though. Usually those
4723 will be UTF-8 multi-byte sequences, but we can't be certain.
4724 Especially mind the 0xff character, which is a valid character in
4725 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4726 rule out compilers allowing it in identifiers. Note that
4727 conveniently, strcmp/strcasecmp are specified to compare
4728 characters interpreted as unsigned char. So what we do is treat
4729 the whole string as a base 256 number composed of a sequence of
4730 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4731 to 0, and carries 1 to the following more-significant position.
4732 If the very first character in SEARCH_NAME ends up incremented
4733 and carries/overflows, then the upper bound is the end of the
4734 list. The string after the empty string is also the empty
4737 Some examples of this operation:
4739 SEARCH_NAME => "+1" RESULT
4743 "\xff" "a" "\xff" => "\xff" "b"
4748 Then, with these symbols for example:
4754 completing "func" looks for symbols between "func" and
4755 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4756 which finds "func" and "func1", but not "fund".
4760 funcÿ (Latin1 'ÿ' [0xff])
4764 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4765 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4769 ÿÿ (Latin1 'ÿ' [0xff])
4772 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4773 the end of the list.
4775 std::string after
= search_name
;
4776 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4778 if (!after
.empty ())
4779 after
.back () = (unsigned char) after
.back () + 1;
4783 /* See declaration. */
4785 std::pair
<std::vector
<name_component
>::const_iterator
,
4786 std::vector
<name_component
>::const_iterator
>
4787 mapped_index_base::find_name_components_bounds
4788 (const lookup_name_info
&lookup_name_without_params
) const
4791 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4794 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4796 /* Comparison function object for lower_bound that matches against a
4797 given symbol name. */
4798 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4801 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4802 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4803 return name_cmp (elem_name
, name
) < 0;
4806 /* Comparison function object for upper_bound that matches against a
4807 given symbol name. */
4808 auto lookup_compare_upper
= [&] (const char *name
,
4809 const name_component
&elem
)
4811 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4812 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4813 return name_cmp (name
, elem_name
) < 0;
4816 auto begin
= this->name_components
.begin ();
4817 auto end
= this->name_components
.end ();
4819 /* Find the lower bound. */
4822 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4825 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4828 /* Find the upper bound. */
4831 if (lookup_name_without_params
.completion_mode ())
4833 /* In completion mode, we want UPPER to point past all
4834 symbols names that have the same prefix. I.e., with
4835 these symbols, and completing "func":
4837 function << lower bound
4839 other_function << upper bound
4841 We find the upper bound by looking for the insertion
4842 point of "func"-with-last-character-incremented,
4844 std::string after
= make_sort_after_prefix_name (cplus
);
4847 return std::lower_bound (lower
, end
, after
.c_str (),
4848 lookup_compare_lower
);
4851 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4854 return {lower
, upper
};
4857 /* See declaration. */
4860 mapped_index_base::build_name_components ()
4862 if (!this->name_components
.empty ())
4865 this->name_components_casing
= case_sensitivity
;
4867 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4869 /* The code below only knows how to break apart components of C++
4870 symbol names (and other languages that use '::' as
4871 namespace/module separator). If we add support for wild matching
4872 to some language that uses some other operator (E.g., Ada, Go and
4873 D use '.'), then we'll need to try splitting the symbol name
4874 according to that language too. Note that Ada does support wild
4875 matching, but doesn't currently support .gdb_index. */
4876 auto count
= this->symbol_name_count ();
4877 for (offset_type idx
= 0; idx
< count
; idx
++)
4879 if (this->symbol_name_slot_invalid (idx
))
4882 const char *name
= this->symbol_name_at (idx
);
4884 /* Add each name component to the name component table. */
4885 unsigned int previous_len
= 0;
4886 for (unsigned int current_len
= cp_find_first_component (name
);
4887 name
[current_len
] != '\0';
4888 current_len
+= cp_find_first_component (name
+ current_len
))
4890 gdb_assert (name
[current_len
] == ':');
4891 this->name_components
.push_back ({previous_len
, idx
});
4892 /* Skip the '::'. */
4894 previous_len
= current_len
;
4896 this->name_components
.push_back ({previous_len
, idx
});
4899 /* Sort name_components elements by name. */
4900 auto name_comp_compare
= [&] (const name_component
&left
,
4901 const name_component
&right
)
4903 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4904 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4906 const char *left_name
= left_qualified
+ left
.name_offset
;
4907 const char *right_name
= right_qualified
+ right
.name_offset
;
4909 return name_cmp (left_name
, right_name
) < 0;
4912 std::sort (this->name_components
.begin (),
4913 this->name_components
.end (),
4917 /* Helper for dw2_expand_symtabs_matching that works with a
4918 mapped_index_base instead of the containing objfile. This is split
4919 to a separate function in order to be able to unit test the
4920 name_components matching using a mock mapped_index_base. For each
4921 symbol name that matches, calls MATCH_CALLBACK, passing it the
4922 symbol's index in the mapped_index_base symbol table. */
4925 dw2_expand_symtabs_matching_symbol
4926 (mapped_index_base
&index
,
4927 const lookup_name_info
&lookup_name_in
,
4928 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4929 enum search_domain kind
,
4930 gdb::function_view
<void (offset_type
)> match_callback
)
4932 lookup_name_info lookup_name_without_params
4933 = lookup_name_in
.make_ignore_params ();
4934 gdb_index_symbol_name_matcher lookup_name_matcher
4935 (lookup_name_without_params
);
4937 /* Build the symbol name component sorted vector, if we haven't
4939 index
.build_name_components ();
4941 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4943 /* Now for each symbol name in range, check to see if we have a name
4944 match, and if so, call the MATCH_CALLBACK callback. */
4946 /* The same symbol may appear more than once in the range though.
4947 E.g., if we're looking for symbols that complete "w", and we have
4948 a symbol named "w1::w2", we'll find the two name components for
4949 that same symbol in the range. To be sure we only call the
4950 callback once per symbol, we first collect the symbol name
4951 indexes that matched in a temporary vector and ignore
4953 std::vector
<offset_type
> matches
;
4954 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4956 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4958 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4960 if (!lookup_name_matcher
.matches (qualified
)
4961 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4964 matches
.push_back (bounds
.first
->idx
);
4967 std::sort (matches
.begin (), matches
.end ());
4969 /* Finally call the callback, once per match. */
4971 for (offset_type idx
: matches
)
4975 match_callback (idx
);
4980 /* Above we use a type wider than idx's for 'prev', since 0 and
4981 (offset_type)-1 are both possible values. */
4982 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4987 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4989 /* A mock .gdb_index/.debug_names-like name index table, enough to
4990 exercise dw2_expand_symtabs_matching_symbol, which works with the
4991 mapped_index_base interface. Builds an index from the symbol list
4992 passed as parameter to the constructor. */
4993 class mock_mapped_index
: public mapped_index_base
4996 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4997 : m_symbol_table (symbols
)
5000 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
5002 /* Return the number of names in the symbol table. */
5003 virtual size_t symbol_name_count () const
5005 return m_symbol_table
.size ();
5008 /* Get the name of the symbol at IDX in the symbol table. */
5009 virtual const char *symbol_name_at (offset_type idx
) const
5011 return m_symbol_table
[idx
];
5015 gdb::array_view
<const char *> m_symbol_table
;
5018 /* Convenience function that converts a NULL pointer to a "<null>"
5019 string, to pass to print routines. */
5022 string_or_null (const char *str
)
5024 return str
!= NULL
? str
: "<null>";
5027 /* Check if a lookup_name_info built from
5028 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
5029 index. EXPECTED_LIST is the list of expected matches, in expected
5030 matching order. If no match expected, then an empty list is
5031 specified. Returns true on success. On failure prints a warning
5032 indicating the file:line that failed, and returns false. */
5035 check_match (const char *file
, int line
,
5036 mock_mapped_index
&mock_index
,
5037 const char *name
, symbol_name_match_type match_type
,
5038 bool completion_mode
,
5039 std::initializer_list
<const char *> expected_list
)
5041 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
5043 bool matched
= true;
5045 auto mismatch
= [&] (const char *expected_str
,
5048 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
5049 "expected=\"%s\", got=\"%s\"\n"),
5051 (match_type
== symbol_name_match_type::FULL
5053 name
, string_or_null (expected_str
), string_or_null (got
));
5057 auto expected_it
= expected_list
.begin ();
5058 auto expected_end
= expected_list
.end ();
5060 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
5062 [&] (offset_type idx
)
5064 const char *matched_name
= mock_index
.symbol_name_at (idx
);
5065 const char *expected_str
5066 = expected_it
== expected_end
? NULL
: *expected_it
++;
5068 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
5069 mismatch (expected_str
, matched_name
);
5072 const char *expected_str
5073 = expected_it
== expected_end
? NULL
: *expected_it
++;
5074 if (expected_str
!= NULL
)
5075 mismatch (expected_str
, NULL
);
5080 /* The symbols added to the mock mapped_index for testing (in
5082 static const char *test_symbols
[] = {
5091 "ns2::tmpl<int>::foo2",
5092 "(anonymous namespace)::A::B::C",
5094 /* These are used to check that the increment-last-char in the
5095 matching algorithm for completion doesn't match "t1_fund" when
5096 completing "t1_func". */
5102 /* A UTF-8 name with multi-byte sequences to make sure that
5103 cp-name-parser understands this as a single identifier ("função"
5104 is "function" in PT). */
5107 /* \377 (0xff) is Latin1 'ÿ'. */
5110 /* \377 (0xff) is Latin1 'ÿ'. */
5114 /* A name with all sorts of complications. Starts with "z" to make
5115 it easier for the completion tests below. */
5116 #define Z_SYM_NAME \
5117 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
5118 "::tuple<(anonymous namespace)::ui*, " \
5119 "std::default_delete<(anonymous namespace)::ui>, void>"
5124 /* Returns true if the mapped_index_base::find_name_component_bounds
5125 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
5126 in completion mode. */
5129 check_find_bounds_finds (mapped_index_base
&index
,
5130 const char *search_name
,
5131 gdb::array_view
<const char *> expected_syms
)
5133 lookup_name_info
lookup_name (search_name
,
5134 symbol_name_match_type::FULL
, true);
5136 auto bounds
= index
.find_name_components_bounds (lookup_name
);
5138 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
5139 if (distance
!= expected_syms
.size ())
5142 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
5144 auto nc_elem
= bounds
.first
+ exp_elem
;
5145 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
5146 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
5153 /* Test the lower-level mapped_index::find_name_component_bounds
5157 test_mapped_index_find_name_component_bounds ()
5159 mock_mapped_index
mock_index (test_symbols
);
5161 mock_index
.build_name_components ();
5163 /* Test the lower-level mapped_index::find_name_component_bounds
5164 method in completion mode. */
5166 static const char *expected_syms
[] = {
5171 SELF_CHECK (check_find_bounds_finds (mock_index
,
5172 "t1_func", expected_syms
));
5175 /* Check that the increment-last-char in the name matching algorithm
5176 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
5178 static const char *expected_syms1
[] = {
5182 SELF_CHECK (check_find_bounds_finds (mock_index
,
5183 "\377", expected_syms1
));
5185 static const char *expected_syms2
[] = {
5188 SELF_CHECK (check_find_bounds_finds (mock_index
,
5189 "\377\377", expected_syms2
));
5193 /* Test dw2_expand_symtabs_matching_symbol. */
5196 test_dw2_expand_symtabs_matching_symbol ()
5198 mock_mapped_index
mock_index (test_symbols
);
5200 /* We let all tests run until the end even if some fails, for debug
5202 bool any_mismatch
= false;
5204 /* Create the expected symbols list (an initializer_list). Needed
5205 because lists have commas, and we need to pass them to CHECK,
5206 which is a macro. */
5207 #define EXPECT(...) { __VA_ARGS__ }
5209 /* Wrapper for check_match that passes down the current
5210 __FILE__/__LINE__. */
5211 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
5212 any_mismatch |= !check_match (__FILE__, __LINE__, \
5214 NAME, MATCH_TYPE, COMPLETION_MODE, \
5217 /* Identity checks. */
5218 for (const char *sym
: test_symbols
)
5220 /* Should be able to match all existing symbols. */
5221 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
5224 /* Should be able to match all existing symbols with
5226 std::string with_params
= std::string (sym
) + "(int)";
5227 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5230 /* Should be able to match all existing symbols with
5231 parameters and qualifiers. */
5232 with_params
= std::string (sym
) + " ( int ) const";
5233 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5236 /* This should really find sym, but cp-name-parser.y doesn't
5237 know about lvalue/rvalue qualifiers yet. */
5238 with_params
= std::string (sym
) + " ( int ) &&";
5239 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5243 /* Check that the name matching algorithm for completion doesn't get
5244 confused with Latin1 'ÿ' / 0xff. */
5246 static const char str
[] = "\377";
5247 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5248 EXPECT ("\377", "\377\377123"));
5251 /* Check that the increment-last-char in the matching algorithm for
5252 completion doesn't match "t1_fund" when completing "t1_func". */
5254 static const char str
[] = "t1_func";
5255 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5256 EXPECT ("t1_func", "t1_func1"));
5259 /* Check that completion mode works at each prefix of the expected
5262 static const char str
[] = "function(int)";
5263 size_t len
= strlen (str
);
5266 for (size_t i
= 1; i
< len
; i
++)
5268 lookup
.assign (str
, i
);
5269 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5270 EXPECT ("function"));
5274 /* While "w" is a prefix of both components, the match function
5275 should still only be called once. */
5277 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
5279 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
5283 /* Same, with a "complicated" symbol. */
5285 static const char str
[] = Z_SYM_NAME
;
5286 size_t len
= strlen (str
);
5289 for (size_t i
= 1; i
< len
; i
++)
5291 lookup
.assign (str
, i
);
5292 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5293 EXPECT (Z_SYM_NAME
));
5297 /* In FULL mode, an incomplete symbol doesn't match. */
5299 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
5303 /* A complete symbol with parameters matches any overload, since the
5304 index has no overload info. */
5306 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
5307 EXPECT ("std::zfunction", "std::zfunction2"));
5308 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
5309 EXPECT ("std::zfunction", "std::zfunction2"));
5310 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
5311 EXPECT ("std::zfunction", "std::zfunction2"));
5314 /* Check that whitespace is ignored appropriately. A symbol with a
5315 template argument list. */
5317 static const char expected
[] = "ns::foo<int>";
5318 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
5320 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
5324 /* Check that whitespace is ignored appropriately. A symbol with a
5325 template argument list that includes a pointer. */
5327 static const char expected
[] = "ns::foo<char*>";
5328 /* Try both completion and non-completion modes. */
5329 static const bool completion_mode
[2] = {false, true};
5330 for (size_t i
= 0; i
< 2; i
++)
5332 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
5333 completion_mode
[i
], EXPECT (expected
));
5334 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
5335 completion_mode
[i
], EXPECT (expected
));
5337 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
5338 completion_mode
[i
], EXPECT (expected
));
5339 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
5340 completion_mode
[i
], EXPECT (expected
));
5345 /* Check method qualifiers are ignored. */
5346 static const char expected
[] = "ns::foo<char*>";
5347 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
5348 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5349 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
5350 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5351 CHECK_MATCH ("foo < char * > ( int ) const",
5352 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5353 CHECK_MATCH ("foo < char * > ( int ) &&",
5354 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5357 /* Test lookup names that don't match anything. */
5359 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
5362 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
5366 /* Some wild matching tests, exercising "(anonymous namespace)",
5367 which should not be confused with a parameter list. */
5369 static const char *syms
[] = {
5373 "A :: B :: C ( int )",
5378 for (const char *s
: syms
)
5380 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
5381 EXPECT ("(anonymous namespace)::A::B::C"));
5386 static const char expected
[] = "ns2::tmpl<int>::foo2";
5387 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5389 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5393 SELF_CHECK (!any_mismatch
);
5402 test_mapped_index_find_name_component_bounds ();
5403 test_dw2_expand_symtabs_matching_symbol ();
5406 }} // namespace selftests::dw2_expand_symtabs_matching
5408 #endif /* GDB_SELF_TEST */
5410 /* If FILE_MATCHER is NULL or if PER_CU has
5411 dwarf2_per_cu_quick_data::MARK set (see
5412 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5413 EXPANSION_NOTIFY on it. */
5416 dw2_expand_symtabs_matching_one
5417 (struct dwarf2_per_cu_data
*per_cu
,
5418 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5419 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5421 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5423 bool symtab_was_null
5424 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5426 dw2_instantiate_symtab (per_cu
);
5428 if (expansion_notify
!= NULL
5430 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5431 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5435 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5436 matched, to expand corresponding CUs that were marked. IDX is the
5437 index of the symbol name that matched. */
5440 dw2_expand_marked_cus
5441 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5442 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5443 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5446 offset_type
*vec
, vec_len
, vec_idx
;
5447 bool global_seen
= false;
5448 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5450 vec
= (offset_type
*) (index
.constant_pool
5451 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5452 vec_len
= MAYBE_SWAP (vec
[0]);
5453 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5455 struct dwarf2_per_cu_data
*per_cu
;
5456 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5457 /* This value is only valid for index versions >= 7. */
5458 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5459 gdb_index_symbol_kind symbol_kind
=
5460 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5461 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5462 /* Only check the symbol attributes if they're present.
5463 Indices prior to version 7 don't record them,
5464 and indices >= 7 may elide them for certain symbols
5465 (gold does this). */
5468 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5470 /* Work around gold/15646. */
5473 if (!is_static
&& global_seen
)
5479 /* Only check the symbol's kind if it has one. */
5484 case VARIABLES_DOMAIN
:
5485 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5488 case FUNCTIONS_DOMAIN
:
5489 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5493 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5501 /* Don't crash on bad data. */
5502 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5503 + dwarf2_per_objfile
->n_type_units
))
5505 complaint (&symfile_complaints
,
5506 _(".gdb_index entry has bad CU index"
5508 objfile_name (dwarf2_per_objfile
->objfile
));
5512 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
5513 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5518 /* If FILE_MATCHER is non-NULL, set all the
5519 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5520 that match FILE_MATCHER. */
5523 dw_expand_symtabs_matching_file_matcher
5524 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5525 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5527 if (file_matcher
== NULL
)
5530 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5532 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5534 NULL
, xcalloc
, xfree
));
5535 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5537 NULL
, xcalloc
, xfree
));
5539 /* The rule is CUs specify all the files, including those used by
5540 any TU, so there's no need to scan TUs here. */
5542 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5545 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5546 struct quick_file_names
*file_data
;
5551 per_cu
->v
.quick
->mark
= 0;
5553 /* We only need to look at symtabs not already expanded. */
5554 if (per_cu
->v
.quick
->compunit_symtab
)
5557 file_data
= dw2_get_file_names (per_cu
);
5558 if (file_data
== NULL
)
5561 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5563 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5565 per_cu
->v
.quick
->mark
= 1;
5569 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5571 const char *this_real_name
;
5573 if (file_matcher (file_data
->file_names
[j
], false))
5575 per_cu
->v
.quick
->mark
= 1;
5579 /* Before we invoke realpath, which can get expensive when many
5580 files are involved, do a quick comparison of the basenames. */
5581 if (!basenames_may_differ
5582 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5586 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5587 if (file_matcher (this_real_name
, false))
5589 per_cu
->v
.quick
->mark
= 1;
5594 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5595 ? visited_found
.get ()
5596 : visited_not_found
.get (),
5603 dw2_expand_symtabs_matching
5604 (struct objfile
*objfile
,
5605 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5606 const lookup_name_info
&lookup_name
,
5607 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5608 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5609 enum search_domain kind
)
5611 struct dwarf2_per_objfile
*dwarf2_per_objfile
5612 = get_dwarf2_per_objfile (objfile
);
5614 /* index_table is NULL if OBJF_READNOW. */
5615 if (!dwarf2_per_objfile
->index_table
)
5618 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5620 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5622 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5624 kind
, [&] (offset_type idx
)
5626 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5627 expansion_notify
, kind
);
5631 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5634 static struct compunit_symtab
*
5635 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5640 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5641 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5644 if (cust
->includes
== NULL
)
5647 for (i
= 0; cust
->includes
[i
]; ++i
)
5649 struct compunit_symtab
*s
= cust
->includes
[i
];
5651 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5659 static struct compunit_symtab
*
5660 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5661 struct bound_minimal_symbol msymbol
,
5663 struct obj_section
*section
,
5666 struct dwarf2_per_cu_data
*data
;
5667 struct compunit_symtab
*result
;
5669 if (!objfile
->psymtabs_addrmap
)
5672 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5677 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5678 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5679 paddress (get_objfile_arch (objfile
), pc
));
5682 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5684 gdb_assert (result
!= NULL
);
5689 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5690 void *data
, int need_fullname
)
5692 struct dwarf2_per_objfile
*dwarf2_per_objfile
5693 = get_dwarf2_per_objfile (objfile
);
5695 if (!dwarf2_per_objfile
->filenames_cache
)
5697 dwarf2_per_objfile
->filenames_cache
.emplace ();
5699 htab_up
visited (htab_create_alloc (10,
5700 htab_hash_pointer
, htab_eq_pointer
,
5701 NULL
, xcalloc
, xfree
));
5703 /* The rule is CUs specify all the files, including those used
5704 by any TU, so there's no need to scan TUs here. We can
5705 ignore file names coming from already-expanded CUs. */
5707 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5709 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
5711 if (per_cu
->v
.quick
->compunit_symtab
)
5713 void **slot
= htab_find_slot (visited
.get (),
5714 per_cu
->v
.quick
->file_names
,
5717 *slot
= per_cu
->v
.quick
->file_names
;
5721 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5723 dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5724 struct quick_file_names
*file_data
;
5727 /* We only need to look at symtabs not already expanded. */
5728 if (per_cu
->v
.quick
->compunit_symtab
)
5731 file_data
= dw2_get_file_names (per_cu
);
5732 if (file_data
== NULL
)
5735 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5738 /* Already visited. */
5743 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5745 const char *filename
= file_data
->file_names
[j
];
5746 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5751 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5753 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5756 this_real_name
= gdb_realpath (filename
);
5757 (*fun
) (filename
, this_real_name
.get (), data
);
5762 dw2_has_symbols (struct objfile
*objfile
)
5767 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5770 dw2_find_last_source_symtab
,
5771 dw2_forget_cached_source_info
,
5772 dw2_map_symtabs_matching_filename
,
5777 dw2_expand_symtabs_for_function
,
5778 dw2_expand_all_symtabs
,
5779 dw2_expand_symtabs_with_fullname
,
5780 dw2_map_matching_symbols
,
5781 dw2_expand_symtabs_matching
,
5782 dw2_find_pc_sect_compunit_symtab
,
5784 dw2_map_symbol_filenames
5787 /* DWARF-5 debug_names reader. */
5789 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5790 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5792 /* A helper function that reads the .debug_names section in SECTION
5793 and fills in MAP. FILENAME is the name of the file containing the
5794 section; it is used for error reporting.
5796 Returns true if all went well, false otherwise. */
5799 read_debug_names_from_section (struct objfile
*objfile
,
5800 const char *filename
,
5801 struct dwarf2_section_info
*section
,
5802 mapped_debug_names
&map
)
5804 if (dwarf2_section_empty_p (section
))
5807 /* Older elfutils strip versions could keep the section in the main
5808 executable while splitting it for the separate debug info file. */
5809 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5812 dwarf2_read_section (objfile
, section
);
5814 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5816 const gdb_byte
*addr
= section
->buffer
;
5818 bfd
*const abfd
= get_section_bfd_owner (section
);
5820 unsigned int bytes_read
;
5821 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5824 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5825 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5826 if (bytes_read
+ length
!= section
->size
)
5828 /* There may be multiple per-CU indices. */
5829 warning (_("Section .debug_names in %s length %s does not match "
5830 "section length %s, ignoring .debug_names."),
5831 filename
, plongest (bytes_read
+ length
),
5832 pulongest (section
->size
));
5836 /* The version number. */
5837 uint16_t version
= read_2_bytes (abfd
, addr
);
5841 warning (_("Section .debug_names in %s has unsupported version %d, "
5842 "ignoring .debug_names."),
5848 uint16_t padding
= read_2_bytes (abfd
, addr
);
5852 warning (_("Section .debug_names in %s has unsupported padding %d, "
5853 "ignoring .debug_names."),
5858 /* comp_unit_count - The number of CUs in the CU list. */
5859 map
.cu_count
= read_4_bytes (abfd
, addr
);
5862 /* local_type_unit_count - The number of TUs in the local TU
5864 map
.tu_count
= read_4_bytes (abfd
, addr
);
5867 /* foreign_type_unit_count - The number of TUs in the foreign TU
5869 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5871 if (foreign_tu_count
!= 0)
5873 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5874 "ignoring .debug_names."),
5875 filename
, static_cast<unsigned long> (foreign_tu_count
));
5879 /* bucket_count - The number of hash buckets in the hash lookup
5881 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5884 /* name_count - The number of unique names in the index. */
5885 map
.name_count
= read_4_bytes (abfd
, addr
);
5888 /* abbrev_table_size - The size in bytes of the abbreviations
5890 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5893 /* augmentation_string_size - The size in bytes of the augmentation
5894 string. This value is rounded up to a multiple of 4. */
5895 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5897 map
.augmentation_is_gdb
= ((augmentation_string_size
5898 == sizeof (dwarf5_augmentation
))
5899 && memcmp (addr
, dwarf5_augmentation
,
5900 sizeof (dwarf5_augmentation
)) == 0);
5901 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5902 addr
+= augmentation_string_size
;
5905 map
.cu_table_reordered
= addr
;
5906 addr
+= map
.cu_count
* map
.offset_size
;
5908 /* List of Local TUs */
5909 map
.tu_table_reordered
= addr
;
5910 addr
+= map
.tu_count
* map
.offset_size
;
5912 /* Hash Lookup Table */
5913 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5914 addr
+= map
.bucket_count
* 4;
5915 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5916 addr
+= map
.name_count
* 4;
5919 map
.name_table_string_offs_reordered
= addr
;
5920 addr
+= map
.name_count
* map
.offset_size
;
5921 map
.name_table_entry_offs_reordered
= addr
;
5922 addr
+= map
.name_count
* map
.offset_size
;
5924 const gdb_byte
*abbrev_table_start
= addr
;
5927 unsigned int bytes_read
;
5928 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5933 const auto insertpair
5934 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5935 if (!insertpair
.second
)
5937 warning (_("Section .debug_names in %s has duplicate index %s, "
5938 "ignoring .debug_names."),
5939 filename
, pulongest (index_num
));
5942 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5943 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5948 mapped_debug_names::index_val::attr attr
;
5949 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5951 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5953 if (attr
.form
== DW_FORM_implicit_const
)
5955 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5959 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5961 indexval
.attr_vec
.push_back (std::move (attr
));
5964 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5966 warning (_("Section .debug_names in %s has abbreviation_table "
5967 "of size %zu vs. written as %u, ignoring .debug_names."),
5968 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5971 map
.entry_pool
= addr
;
5976 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5980 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5981 const mapped_debug_names
&map
,
5982 dwarf2_section_info
§ion
,
5983 bool is_dwz
, int base_offset
)
5985 sect_offset sect_off_prev
;
5986 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5988 sect_offset sect_off_next
;
5989 if (i
< map
.cu_count
)
5992 = (sect_offset
) (extract_unsigned_integer
5993 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5995 map
.dwarf5_byte_order
));
5998 sect_off_next
= (sect_offset
) section
.size
;
6001 const ULONGEST length
= sect_off_next
- sect_off_prev
;
6002 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
6003 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
6004 sect_off_prev
, length
);
6006 sect_off_prev
= sect_off_next
;
6010 /* Read the CU list from the mapped index, and use it to create all
6011 the CU objects for this dwarf2_per_objfile. */
6014 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6015 const mapped_debug_names
&map
,
6016 const mapped_debug_names
&dwz_map
)
6018 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6020 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
6021 dwarf2_per_objfile
->all_comp_units
6022 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
6023 dwarf2_per_objfile
->n_comp_units
);
6025 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
6026 dwarf2_per_objfile
->info
,
6028 0 /* base_offset */);
6030 if (dwz_map
.cu_count
== 0)
6033 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
6034 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
6036 map
.cu_count
/* base_offset */);
6039 /* Read .debug_names. If everything went ok, initialize the "quick"
6040 elements of all the CUs and return true. Otherwise, return false. */
6043 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6045 mapped_debug_names
local_map (dwarf2_per_objfile
);
6046 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
6047 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6049 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
6050 &dwarf2_per_objfile
->debug_names
,
6054 /* Don't use the index if it's empty. */
6055 if (local_map
.name_count
== 0)
6058 /* If there is a .dwz file, read it so we can get its CU list as
6060 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
6063 if (!read_debug_names_from_section (objfile
,
6064 bfd_get_filename (dwz
->dwz_bfd
),
6065 &dwz
->debug_names
, dwz_map
))
6067 warning (_("could not read '.debug_names' section from %s; skipping"),
6068 bfd_get_filename (dwz
->dwz_bfd
));
6073 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
6075 if (local_map
.tu_count
!= 0)
6077 /* We can only handle a single .debug_types when we have an
6079 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
6082 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
6083 dwarf2_per_objfile
->types
, 0);
6085 create_signatured_type_table_from_debug_names
6086 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
6089 create_addrmap_from_aranges (dwarf2_per_objfile
,
6090 &dwarf2_per_objfile
->debug_aranges
);
6092 dwarf2_per_objfile
->debug_names_table
.reset
6093 (new mapped_debug_names (dwarf2_per_objfile
));
6094 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
6095 dwarf2_per_objfile
->using_index
= 1;
6096 dwarf2_per_objfile
->quick_file_names_table
=
6097 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6102 /* Symbol name hashing function as specified by DWARF-5. */
6105 dwarf5_djb_hash (const char *str_
)
6107 const unsigned char *str
= (const unsigned char *) str_
;
6109 /* Note: tolower here ignores UTF-8, which isn't fully compliant.
6110 See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
6112 uint32_t hash
= 5381;
6113 while (int c
= *str
++)
6114 hash
= hash
* 33 + tolower (c
);
6118 /* Type used to manage iterating over all CUs looking for a symbol for
6121 class dw2_debug_names_iterator
6124 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
6125 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
6126 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6127 bool want_specific_block
,
6128 block_enum block_index
, domain_enum domain
,
6130 : m_map (map
), m_want_specific_block (want_specific_block
),
6131 m_block_index (block_index
), m_domain (domain
),
6132 m_addr (find_vec_in_debug_names (map
, name
))
6135 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6136 search_domain search
, uint32_t namei
)
6139 m_addr (find_vec_in_debug_names (map
, namei
))
6142 /* Return the next matching CU or NULL if there are no more. */
6143 dwarf2_per_cu_data
*next ();
6146 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6148 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6151 /* The internalized form of .debug_names. */
6152 const mapped_debug_names
&m_map
;
6154 /* If true, only look for symbols that match BLOCK_INDEX. */
6155 const bool m_want_specific_block
= false;
6157 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
6158 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
6160 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
6162 /* The kind of symbol we're looking for. */
6163 const domain_enum m_domain
= UNDEF_DOMAIN
;
6164 const search_domain m_search
= ALL_DOMAIN
;
6166 /* The list of CUs from the index entry of the symbol, or NULL if
6168 const gdb_byte
*m_addr
;
6172 mapped_debug_names::namei_to_name (uint32_t namei
) const
6174 const ULONGEST namei_string_offs
6175 = extract_unsigned_integer ((name_table_string_offs_reordered
6176 + namei
* offset_size
),
6179 return read_indirect_string_at_offset
6180 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
6183 /* Find a slot in .debug_names for the object named NAME. If NAME is
6184 found, return pointer to its pool data. If NAME cannot be found,
6188 dw2_debug_names_iterator::find_vec_in_debug_names
6189 (const mapped_debug_names
&map
, const char *name
)
6191 int (*cmp
) (const char *, const char *);
6193 if (current_language
->la_language
== language_cplus
6194 || current_language
->la_language
== language_fortran
6195 || current_language
->la_language
== language_d
)
6197 /* NAME is already canonical. Drop any qualifiers as
6198 .debug_names does not contain any. */
6200 if (strchr (name
, '(') != NULL
)
6202 gdb::unique_xmalloc_ptr
<char> without_params
6203 = cp_remove_params (name
);
6205 if (without_params
!= NULL
)
6207 name
= without_params
.get();
6212 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
6214 const uint32_t full_hash
= dwarf5_djb_hash (name
);
6216 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6217 (map
.bucket_table_reordered
6218 + (full_hash
% map
.bucket_count
)), 4,
6219 map
.dwarf5_byte_order
);
6223 if (namei
>= map
.name_count
)
6225 complaint (&symfile_complaints
,
6226 _("Wrong .debug_names with name index %u but name_count=%u "
6228 namei
, map
.name_count
,
6229 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6235 const uint32_t namei_full_hash
6236 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6237 (map
.hash_table_reordered
+ namei
), 4,
6238 map
.dwarf5_byte_order
);
6239 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
6242 if (full_hash
== namei_full_hash
)
6244 const char *const namei_string
= map
.namei_to_name (namei
);
6246 #if 0 /* An expensive sanity check. */
6247 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
6249 complaint (&symfile_complaints
,
6250 _("Wrong .debug_names hash for string at index %u "
6252 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
6257 if (cmp (namei_string
, name
) == 0)
6259 const ULONGEST namei_entry_offs
6260 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6261 + namei
* map
.offset_size
),
6262 map
.offset_size
, map
.dwarf5_byte_order
);
6263 return map
.entry_pool
+ namei_entry_offs
;
6268 if (namei
>= map
.name_count
)
6274 dw2_debug_names_iterator::find_vec_in_debug_names
6275 (const mapped_debug_names
&map
, uint32_t namei
)
6277 if (namei
>= map
.name_count
)
6279 complaint (&symfile_complaints
,
6280 _("Wrong .debug_names with name index %u but name_count=%u "
6282 namei
, map
.name_count
,
6283 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6287 const ULONGEST namei_entry_offs
6288 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6289 + namei
* map
.offset_size
),
6290 map
.offset_size
, map
.dwarf5_byte_order
);
6291 return map
.entry_pool
+ namei_entry_offs
;
6294 /* See dw2_debug_names_iterator. */
6296 dwarf2_per_cu_data
*
6297 dw2_debug_names_iterator::next ()
6302 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
6303 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6304 bfd
*const abfd
= objfile
->obfd
;
6308 unsigned int bytes_read
;
6309 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6310 m_addr
+= bytes_read
;
6314 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
6315 if (indexval_it
== m_map
.abbrev_map
.cend ())
6317 complaint (&symfile_complaints
,
6318 _("Wrong .debug_names undefined abbrev code %s "
6320 pulongest (abbrev
), objfile_name (objfile
));
6323 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
6324 bool have_is_static
= false;
6326 dwarf2_per_cu_data
*per_cu
= NULL
;
6327 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
6332 case DW_FORM_implicit_const
:
6333 ull
= attr
.implicit_const
;
6335 case DW_FORM_flag_present
:
6339 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6340 m_addr
+= bytes_read
;
6343 complaint (&symfile_complaints
,
6344 _("Unsupported .debug_names form %s [in module %s]"),
6345 dwarf_form_name (attr
.form
),
6346 objfile_name (objfile
));
6349 switch (attr
.dw_idx
)
6351 case DW_IDX_compile_unit
:
6352 /* Don't crash on bad data. */
6353 if (ull
>= dwarf2_per_objfile
->n_comp_units
)
6355 complaint (&symfile_complaints
,
6356 _(".debug_names entry has bad CU index %s"
6359 objfile_name (dwarf2_per_objfile
->objfile
));
6362 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, ull
);
6364 case DW_IDX_type_unit
:
6365 /* Don't crash on bad data. */
6366 if (ull
>= dwarf2_per_objfile
->n_type_units
)
6368 complaint (&symfile_complaints
,
6369 _(".debug_names entry has bad TU index %s"
6372 objfile_name (dwarf2_per_objfile
->objfile
));
6375 per_cu
= dw2_get_cutu (dwarf2_per_objfile
,
6376 dwarf2_per_objfile
->n_comp_units
+ ull
);
6378 case DW_IDX_GNU_internal
:
6379 if (!m_map
.augmentation_is_gdb
)
6381 have_is_static
= true;
6384 case DW_IDX_GNU_external
:
6385 if (!m_map
.augmentation_is_gdb
)
6387 have_is_static
= true;
6393 /* Skip if already read in. */
6394 if (per_cu
->v
.quick
->compunit_symtab
)
6397 /* Check static vs global. */
6400 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
6401 if (m_want_specific_block
&& want_static
!= is_static
)
6405 /* Match dw2_symtab_iter_next, symbol_kind
6406 and debug_names::psymbol_tag. */
6410 switch (indexval
.dwarf_tag
)
6412 case DW_TAG_variable
:
6413 case DW_TAG_subprogram
:
6414 /* Some types are also in VAR_DOMAIN. */
6415 case DW_TAG_typedef
:
6416 case DW_TAG_structure_type
:
6423 switch (indexval
.dwarf_tag
)
6425 case DW_TAG_typedef
:
6426 case DW_TAG_structure_type
:
6433 switch (indexval
.dwarf_tag
)
6436 case DW_TAG_variable
:
6446 /* Match dw2_expand_symtabs_matching, symbol_kind and
6447 debug_names::psymbol_tag. */
6450 case VARIABLES_DOMAIN
:
6451 switch (indexval
.dwarf_tag
)
6453 case DW_TAG_variable
:
6459 case FUNCTIONS_DOMAIN
:
6460 switch (indexval
.dwarf_tag
)
6462 case DW_TAG_subprogram
:
6469 switch (indexval
.dwarf_tag
)
6471 case DW_TAG_typedef
:
6472 case DW_TAG_structure_type
:
6485 static struct compunit_symtab
*
6486 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6487 const char *name
, domain_enum domain
)
6489 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6490 struct dwarf2_per_objfile
*dwarf2_per_objfile
6491 = get_dwarf2_per_objfile (objfile
);
6493 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6496 /* index is NULL if OBJF_READNOW. */
6499 const auto &map
= *mapp
;
6501 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6502 block_index
, domain
, name
);
6504 struct compunit_symtab
*stab_best
= NULL
;
6505 struct dwarf2_per_cu_data
*per_cu
;
6506 while ((per_cu
= iter
.next ()) != NULL
)
6508 struct symbol
*sym
, *with_opaque
= NULL
;
6509 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6510 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6511 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6513 sym
= block_find_symbol (block
, name
, domain
,
6514 block_find_non_opaque_type_preferred
,
6517 /* Some caution must be observed with overloaded functions and
6518 methods, since the index will not contain any overload
6519 information (but NAME might contain it). */
6522 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6524 if (with_opaque
!= NULL
6525 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6528 /* Keep looking through other CUs. */
6534 /* This dumps minimal information about .debug_names. It is called
6535 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6536 uses this to verify that .debug_names has been loaded. */
6539 dw2_debug_names_dump (struct objfile
*objfile
)
6541 struct dwarf2_per_objfile
*dwarf2_per_objfile
6542 = get_dwarf2_per_objfile (objfile
);
6544 gdb_assert (dwarf2_per_objfile
->using_index
);
6545 printf_filtered (".debug_names:");
6546 if (dwarf2_per_objfile
->debug_names_table
)
6547 printf_filtered (" exists\n");
6549 printf_filtered (" faked for \"readnow\"\n");
6550 printf_filtered ("\n");
6554 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6555 const char *func_name
)
6557 struct dwarf2_per_objfile
*dwarf2_per_objfile
6558 = get_dwarf2_per_objfile (objfile
);
6560 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6561 if (dwarf2_per_objfile
->debug_names_table
)
6563 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6565 /* Note: It doesn't matter what we pass for block_index here. */
6566 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6567 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6569 struct dwarf2_per_cu_data
*per_cu
;
6570 while ((per_cu
= iter
.next ()) != NULL
)
6571 dw2_instantiate_symtab (per_cu
);
6576 dw2_debug_names_expand_symtabs_matching
6577 (struct objfile
*objfile
,
6578 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6579 const lookup_name_info
&lookup_name
,
6580 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6581 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6582 enum search_domain kind
)
6584 struct dwarf2_per_objfile
*dwarf2_per_objfile
6585 = get_dwarf2_per_objfile (objfile
);
6587 /* debug_names_table is NULL if OBJF_READNOW. */
6588 if (!dwarf2_per_objfile
->debug_names_table
)
6591 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6593 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6595 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6597 kind
, [&] (offset_type namei
)
6599 /* The name was matched, now expand corresponding CUs that were
6601 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6603 struct dwarf2_per_cu_data
*per_cu
;
6604 while ((per_cu
= iter
.next ()) != NULL
)
6605 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6610 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6613 dw2_find_last_source_symtab
,
6614 dw2_forget_cached_source_info
,
6615 dw2_map_symtabs_matching_filename
,
6616 dw2_debug_names_lookup_symbol
,
6618 dw2_debug_names_dump
,
6620 dw2_debug_names_expand_symtabs_for_function
,
6621 dw2_expand_all_symtabs
,
6622 dw2_expand_symtabs_with_fullname
,
6623 dw2_map_matching_symbols
,
6624 dw2_debug_names_expand_symtabs_matching
,
6625 dw2_find_pc_sect_compunit_symtab
,
6627 dw2_map_symbol_filenames
6630 /* See symfile.h. */
6633 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6635 struct dwarf2_per_objfile
*dwarf2_per_objfile
6636 = get_dwarf2_per_objfile (objfile
);
6638 /* If we're about to read full symbols, don't bother with the
6639 indices. In this case we also don't care if some other debug
6640 format is making psymtabs, because they are all about to be
6642 if ((objfile
->flags
& OBJF_READNOW
))
6646 dwarf2_per_objfile
->using_index
= 1;
6647 create_all_comp_units (dwarf2_per_objfile
);
6648 create_all_type_units (dwarf2_per_objfile
);
6649 dwarf2_per_objfile
->quick_file_names_table
=
6650 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6652 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6653 + dwarf2_per_objfile
->n_type_units
); ++i
)
6655 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
6657 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6658 struct dwarf2_per_cu_quick_data
);
6661 /* Return 1 so that gdb sees the "quick" functions. However,
6662 these functions will be no-ops because we will have expanded
6664 *index_kind
= dw_index_kind::GDB_INDEX
;
6668 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6670 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6674 if (dwarf2_read_index (objfile
))
6676 *index_kind
= dw_index_kind::GDB_INDEX
;
6685 /* Build a partial symbol table. */
6688 dwarf2_build_psymtabs (struct objfile
*objfile
)
6690 struct dwarf2_per_objfile
*dwarf2_per_objfile
6691 = get_dwarf2_per_objfile (objfile
);
6693 if (objfile
->global_psymbols
.capacity () == 0
6694 && objfile
->static_psymbols
.capacity () == 0)
6695 init_psymbol_list (objfile
, 1024);
6699 /* This isn't really ideal: all the data we allocate on the
6700 objfile's obstack is still uselessly kept around. However,
6701 freeing it seems unsafe. */
6702 psymtab_discarder
psymtabs (objfile
);
6703 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6706 CATCH (except
, RETURN_MASK_ERROR
)
6708 exception_print (gdb_stderr
, except
);
6713 /* Return the total length of the CU described by HEADER. */
6716 get_cu_length (const struct comp_unit_head
*header
)
6718 return header
->initial_length_size
+ header
->length
;
6721 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6724 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6726 sect_offset bottom
= cu_header
->sect_off
;
6727 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6729 return sect_off
>= bottom
&& sect_off
< top
;
6732 /* Find the base address of the compilation unit for range lists and
6733 location lists. It will normally be specified by DW_AT_low_pc.
6734 In DWARF-3 draft 4, the base address could be overridden by
6735 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6736 compilation units with discontinuous ranges. */
6739 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6741 struct attribute
*attr
;
6744 cu
->base_address
= 0;
6746 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6749 cu
->base_address
= attr_value_as_address (attr
);
6754 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6757 cu
->base_address
= attr_value_as_address (attr
);
6763 /* Read in the comp unit header information from the debug_info at info_ptr.
6764 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6765 NOTE: This leaves members offset, first_die_offset to be filled in
6768 static const gdb_byte
*
6769 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6770 const gdb_byte
*info_ptr
,
6771 struct dwarf2_section_info
*section
,
6772 rcuh_kind section_kind
)
6775 unsigned int bytes_read
;
6776 const char *filename
= get_section_file_name (section
);
6777 bfd
*abfd
= get_section_bfd_owner (section
);
6779 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6780 cu_header
->initial_length_size
= bytes_read
;
6781 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6782 info_ptr
+= bytes_read
;
6783 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6785 if (cu_header
->version
< 5)
6786 switch (section_kind
)
6788 case rcuh_kind::COMPILE
:
6789 cu_header
->unit_type
= DW_UT_compile
;
6791 case rcuh_kind::TYPE
:
6792 cu_header
->unit_type
= DW_UT_type
;
6795 internal_error (__FILE__
, __LINE__
,
6796 _("read_comp_unit_head: invalid section_kind"));
6800 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6801 (read_1_byte (abfd
, info_ptr
));
6803 switch (cu_header
->unit_type
)
6806 if (section_kind
!= rcuh_kind::COMPILE
)
6807 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6808 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6812 section_kind
= rcuh_kind::TYPE
;
6815 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6816 "(is %d, should be %d or %d) [in module %s]"),
6817 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6820 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6823 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6826 info_ptr
+= bytes_read
;
6827 if (cu_header
->version
< 5)
6829 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6832 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6833 if (signed_addr
< 0)
6834 internal_error (__FILE__
, __LINE__
,
6835 _("read_comp_unit_head: dwarf from non elf file"));
6836 cu_header
->signed_addr_p
= signed_addr
;
6838 if (section_kind
== rcuh_kind::TYPE
)
6840 LONGEST type_offset
;
6842 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6845 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6846 info_ptr
+= bytes_read
;
6847 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6848 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6849 error (_("Dwarf Error: Too big type_offset in compilation unit "
6850 "header (is %s) [in module %s]"), plongest (type_offset
),
6857 /* Helper function that returns the proper abbrev section for
6860 static struct dwarf2_section_info
*
6861 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6863 struct dwarf2_section_info
*abbrev
;
6864 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6866 if (this_cu
->is_dwz
)
6867 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6869 abbrev
= &dwarf2_per_objfile
->abbrev
;
6874 /* Subroutine of read_and_check_comp_unit_head and
6875 read_and_check_type_unit_head to simplify them.
6876 Perform various error checking on the header. */
6879 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6880 struct comp_unit_head
*header
,
6881 struct dwarf2_section_info
*section
,
6882 struct dwarf2_section_info
*abbrev_section
)
6884 const char *filename
= get_section_file_name (section
);
6886 if (header
->version
< 2 || header
->version
> 5)
6887 error (_("Dwarf Error: wrong version in compilation unit header "
6888 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6891 if (to_underlying (header
->abbrev_sect_off
)
6892 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6893 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6894 "(offset %s + 6) [in module %s]"),
6895 sect_offset_str (header
->abbrev_sect_off
),
6896 sect_offset_str (header
->sect_off
),
6899 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6900 avoid potential 32-bit overflow. */
6901 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6903 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6904 "(offset %s + 0) [in module %s]"),
6905 header
->length
, sect_offset_str (header
->sect_off
),
6909 /* Read in a CU/TU header and perform some basic error checking.
6910 The contents of the header are stored in HEADER.
6911 The result is a pointer to the start of the first DIE. */
6913 static const gdb_byte
*
6914 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6915 struct comp_unit_head
*header
,
6916 struct dwarf2_section_info
*section
,
6917 struct dwarf2_section_info
*abbrev_section
,
6918 const gdb_byte
*info_ptr
,
6919 rcuh_kind section_kind
)
6921 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6923 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6925 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6927 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6929 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6935 /* Fetch the abbreviation table offset from a comp or type unit header. */
6938 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6939 struct dwarf2_section_info
*section
,
6940 sect_offset sect_off
)
6942 bfd
*abfd
= get_section_bfd_owner (section
);
6943 const gdb_byte
*info_ptr
;
6944 unsigned int initial_length_size
, offset_size
;
6947 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6948 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6949 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6950 offset_size
= initial_length_size
== 4 ? 4 : 8;
6951 info_ptr
+= initial_length_size
;
6953 version
= read_2_bytes (abfd
, info_ptr
);
6957 /* Skip unit type and address size. */
6961 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6964 /* Allocate a new partial symtab for file named NAME and mark this new
6965 partial symtab as being an include of PST. */
6968 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6969 struct objfile
*objfile
)
6971 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6973 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6975 /* It shares objfile->objfile_obstack. */
6976 subpst
->dirname
= pst
->dirname
;
6979 subpst
->textlow
= 0;
6980 subpst
->texthigh
= 0;
6982 subpst
->dependencies
6983 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6984 subpst
->dependencies
[0] = pst
;
6985 subpst
->number_of_dependencies
= 1;
6987 subpst
->globals_offset
= 0;
6988 subpst
->n_global_syms
= 0;
6989 subpst
->statics_offset
= 0;
6990 subpst
->n_static_syms
= 0;
6991 subpst
->compunit_symtab
= NULL
;
6992 subpst
->read_symtab
= pst
->read_symtab
;
6995 /* No private part is necessary for include psymtabs. This property
6996 can be used to differentiate between such include psymtabs and
6997 the regular ones. */
6998 subpst
->read_symtab_private
= NULL
;
7001 /* Read the Line Number Program data and extract the list of files
7002 included by the source file represented by PST. Build an include
7003 partial symtab for each of these included files. */
7006 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
7007 struct die_info
*die
,
7008 struct partial_symtab
*pst
)
7011 struct attribute
*attr
;
7013 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7015 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
7017 return; /* No linetable, so no includes. */
7019 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
7020 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
7024 hash_signatured_type (const void *item
)
7026 const struct signatured_type
*sig_type
7027 = (const struct signatured_type
*) item
;
7029 /* This drops the top 32 bits of the signature, but is ok for a hash. */
7030 return sig_type
->signature
;
7034 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
7036 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
7037 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
7039 return lhs
->signature
== rhs
->signature
;
7042 /* Allocate a hash table for signatured types. */
7045 allocate_signatured_type_table (struct objfile
*objfile
)
7047 return htab_create_alloc_ex (41,
7048 hash_signatured_type
,
7051 &objfile
->objfile_obstack
,
7052 hashtab_obstack_allocate
,
7053 dummy_obstack_deallocate
);
7056 /* A helper function to add a signatured type CU to a table. */
7059 add_signatured_type_cu_to_table (void **slot
, void *datum
)
7061 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
7062 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
7070 /* A helper for create_debug_types_hash_table. Read types from SECTION
7071 and fill them into TYPES_HTAB. It will process only type units,
7072 therefore DW_UT_type. */
7075 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7076 struct dwo_file
*dwo_file
,
7077 dwarf2_section_info
*section
, htab_t
&types_htab
,
7078 rcuh_kind section_kind
)
7080 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7081 struct dwarf2_section_info
*abbrev_section
;
7083 const gdb_byte
*info_ptr
, *end_ptr
;
7085 abbrev_section
= (dwo_file
!= NULL
7086 ? &dwo_file
->sections
.abbrev
7087 : &dwarf2_per_objfile
->abbrev
);
7089 if (dwarf_read_debug
)
7090 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
7091 get_section_name (section
),
7092 get_section_file_name (abbrev_section
));
7094 dwarf2_read_section (objfile
, section
);
7095 info_ptr
= section
->buffer
;
7097 if (info_ptr
== NULL
)
7100 /* We can't set abfd until now because the section may be empty or
7101 not present, in which case the bfd is unknown. */
7102 abfd
= get_section_bfd_owner (section
);
7104 /* We don't use init_cutu_and_read_dies_simple, or some such, here
7105 because we don't need to read any dies: the signature is in the
7108 end_ptr
= info_ptr
+ section
->size
;
7109 while (info_ptr
< end_ptr
)
7111 struct signatured_type
*sig_type
;
7112 struct dwo_unit
*dwo_tu
;
7114 const gdb_byte
*ptr
= info_ptr
;
7115 struct comp_unit_head header
;
7116 unsigned int length
;
7118 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
7120 /* Initialize it due to a false compiler warning. */
7121 header
.signature
= -1;
7122 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
7124 /* We need to read the type's signature in order to build the hash
7125 table, but we don't need anything else just yet. */
7127 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
7128 abbrev_section
, ptr
, section_kind
);
7130 length
= get_cu_length (&header
);
7132 /* Skip dummy type units. */
7133 if (ptr
>= info_ptr
+ length
7134 || peek_abbrev_code (abfd
, ptr
) == 0
7135 || header
.unit_type
!= DW_UT_type
)
7141 if (types_htab
== NULL
)
7144 types_htab
= allocate_dwo_unit_table (objfile
);
7146 types_htab
= allocate_signatured_type_table (objfile
);
7152 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7154 dwo_tu
->dwo_file
= dwo_file
;
7155 dwo_tu
->signature
= header
.signature
;
7156 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7157 dwo_tu
->section
= section
;
7158 dwo_tu
->sect_off
= sect_off
;
7159 dwo_tu
->length
= length
;
7163 /* N.B.: type_offset is not usable if this type uses a DWO file.
7164 The real type_offset is in the DWO file. */
7166 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7167 struct signatured_type
);
7168 sig_type
->signature
= header
.signature
;
7169 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7170 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7171 sig_type
->per_cu
.is_debug_types
= 1;
7172 sig_type
->per_cu
.section
= section
;
7173 sig_type
->per_cu
.sect_off
= sect_off
;
7174 sig_type
->per_cu
.length
= length
;
7177 slot
= htab_find_slot (types_htab
,
7178 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
7180 gdb_assert (slot
!= NULL
);
7183 sect_offset dup_sect_off
;
7187 const struct dwo_unit
*dup_tu
7188 = (const struct dwo_unit
*) *slot
;
7190 dup_sect_off
= dup_tu
->sect_off
;
7194 const struct signatured_type
*dup_tu
7195 = (const struct signatured_type
*) *slot
;
7197 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
7200 complaint (&symfile_complaints
,
7201 _("debug type entry at offset %s is duplicate to"
7202 " the entry at offset %s, signature %s"),
7203 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
7204 hex_string (header
.signature
));
7206 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
7208 if (dwarf_read_debug
> 1)
7209 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
7210 sect_offset_str (sect_off
),
7211 hex_string (header
.signature
));
7217 /* Create the hash table of all entries in the .debug_types
7218 (or .debug_types.dwo) section(s).
7219 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
7220 otherwise it is NULL.
7222 The result is a pointer to the hash table or NULL if there are no types.
7224 Note: This function processes DWO files only, not DWP files. */
7227 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7228 struct dwo_file
*dwo_file
,
7229 VEC (dwarf2_section_info_def
) *types
,
7233 struct dwarf2_section_info
*section
;
7235 if (VEC_empty (dwarf2_section_info_def
, types
))
7239 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
7241 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
7242 types_htab
, rcuh_kind::TYPE
);
7245 /* Create the hash table of all entries in the .debug_types section,
7246 and initialize all_type_units.
7247 The result is zero if there is an error (e.g. missing .debug_types section),
7248 otherwise non-zero. */
7251 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7253 htab_t types_htab
= NULL
;
7254 struct signatured_type
**iter
;
7256 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
7257 &dwarf2_per_objfile
->info
, types_htab
,
7258 rcuh_kind::COMPILE
);
7259 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
7260 dwarf2_per_objfile
->types
, types_htab
);
7261 if (types_htab
== NULL
)
7263 dwarf2_per_objfile
->signatured_types
= NULL
;
7267 dwarf2_per_objfile
->signatured_types
= types_htab
;
7269 dwarf2_per_objfile
->n_type_units
7270 = dwarf2_per_objfile
->n_allocated_type_units
7271 = htab_elements (types_htab
);
7272 dwarf2_per_objfile
->all_type_units
=
7273 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
7274 iter
= &dwarf2_per_objfile
->all_type_units
[0];
7275 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
7276 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
7277 == dwarf2_per_objfile
->n_type_units
);
7282 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
7283 If SLOT is non-NULL, it is the entry to use in the hash table.
7284 Otherwise we find one. */
7286 static struct signatured_type
*
7287 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
7290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7291 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
7292 struct signatured_type
*sig_type
;
7294 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
7296 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
7298 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
7299 dwarf2_per_objfile
->n_allocated_type_units
= 1;
7300 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
7301 dwarf2_per_objfile
->all_type_units
7302 = XRESIZEVEC (struct signatured_type
*,
7303 dwarf2_per_objfile
->all_type_units
,
7304 dwarf2_per_objfile
->n_allocated_type_units
);
7305 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
7307 dwarf2_per_objfile
->n_type_units
= n_type_units
;
7309 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7310 struct signatured_type
);
7311 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
7312 sig_type
->signature
= sig
;
7313 sig_type
->per_cu
.is_debug_types
= 1;
7314 if (dwarf2_per_objfile
->using_index
)
7316 sig_type
->per_cu
.v
.quick
=
7317 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7318 struct dwarf2_per_cu_quick_data
);
7323 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7326 gdb_assert (*slot
== NULL
);
7328 /* The rest of sig_type must be filled in by the caller. */
7332 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7333 Fill in SIG_ENTRY with DWO_ENTRY. */
7336 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7337 struct signatured_type
*sig_entry
,
7338 struct dwo_unit
*dwo_entry
)
7340 /* Make sure we're not clobbering something we don't expect to. */
7341 gdb_assert (! sig_entry
->per_cu
.queued
);
7342 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7343 if (dwarf2_per_objfile
->using_index
)
7345 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7346 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7349 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7350 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7351 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7352 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7353 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7355 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7356 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7357 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7358 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7359 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7360 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7361 sig_entry
->dwo_unit
= dwo_entry
;
7364 /* Subroutine of lookup_signatured_type.
7365 If we haven't read the TU yet, create the signatured_type data structure
7366 for a TU to be read in directly from a DWO file, bypassing the stub.
7367 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7368 using .gdb_index, then when reading a CU we want to stay in the DWO file
7369 containing that CU. Otherwise we could end up reading several other DWO
7370 files (due to comdat folding) to process the transitive closure of all the
7371 mentioned TUs, and that can be slow. The current DWO file will have every
7372 type signature that it needs.
7373 We only do this for .gdb_index because in the psymtab case we already have
7374 to read all the DWOs to build the type unit groups. */
7376 static struct signatured_type
*
7377 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7379 struct dwarf2_per_objfile
*dwarf2_per_objfile
7380 = cu
->per_cu
->dwarf2_per_objfile
;
7381 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7382 struct dwo_file
*dwo_file
;
7383 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7384 struct signatured_type find_sig_entry
, *sig_entry
;
7387 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7389 /* If TU skeletons have been removed then we may not have read in any
7391 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7393 dwarf2_per_objfile
->signatured_types
7394 = allocate_signatured_type_table (objfile
);
7397 /* We only ever need to read in one copy of a signatured type.
7398 Use the global signatured_types array to do our own comdat-folding
7399 of types. If this is the first time we're reading this TU, and
7400 the TU has an entry in .gdb_index, replace the recorded data from
7401 .gdb_index with this TU. */
7403 find_sig_entry
.signature
= sig
;
7404 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7405 &find_sig_entry
, INSERT
);
7406 sig_entry
= (struct signatured_type
*) *slot
;
7408 /* We can get here with the TU already read, *or* in the process of being
7409 read. Don't reassign the global entry to point to this DWO if that's
7410 the case. Also note that if the TU is already being read, it may not
7411 have come from a DWO, the program may be a mix of Fission-compiled
7412 code and non-Fission-compiled code. */
7414 /* Have we already tried to read this TU?
7415 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7416 needn't exist in the global table yet). */
7417 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7420 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7421 dwo_unit of the TU itself. */
7422 dwo_file
= cu
->dwo_unit
->dwo_file
;
7424 /* Ok, this is the first time we're reading this TU. */
7425 if (dwo_file
->tus
== NULL
)
7427 find_dwo_entry
.signature
= sig
;
7428 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7429 if (dwo_entry
== NULL
)
7432 /* If the global table doesn't have an entry for this TU, add one. */
7433 if (sig_entry
== NULL
)
7434 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7436 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7437 sig_entry
->per_cu
.tu_read
= 1;
7441 /* Subroutine of lookup_signatured_type.
7442 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7443 then try the DWP file. If the TU stub (skeleton) has been removed then
7444 it won't be in .gdb_index. */
7446 static struct signatured_type
*
7447 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7449 struct dwarf2_per_objfile
*dwarf2_per_objfile
7450 = cu
->per_cu
->dwarf2_per_objfile
;
7451 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7452 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7453 struct dwo_unit
*dwo_entry
;
7454 struct signatured_type find_sig_entry
, *sig_entry
;
7457 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7458 gdb_assert (dwp_file
!= NULL
);
7460 /* If TU skeletons have been removed then we may not have read in any
7462 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7464 dwarf2_per_objfile
->signatured_types
7465 = allocate_signatured_type_table (objfile
);
7468 find_sig_entry
.signature
= sig
;
7469 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7470 &find_sig_entry
, INSERT
);
7471 sig_entry
= (struct signatured_type
*) *slot
;
7473 /* Have we already tried to read this TU?
7474 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7475 needn't exist in the global table yet). */
7476 if (sig_entry
!= NULL
)
7479 if (dwp_file
->tus
== NULL
)
7481 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7482 sig
, 1 /* is_debug_types */);
7483 if (dwo_entry
== NULL
)
7486 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7487 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7492 /* Lookup a signature based type for DW_FORM_ref_sig8.
7493 Returns NULL if signature SIG is not present in the table.
7494 It is up to the caller to complain about this. */
7496 static struct signatured_type
*
7497 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7499 struct dwarf2_per_objfile
*dwarf2_per_objfile
7500 = cu
->per_cu
->dwarf2_per_objfile
;
7503 && dwarf2_per_objfile
->using_index
)
7505 /* We're in a DWO/DWP file, and we're using .gdb_index.
7506 These cases require special processing. */
7507 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7508 return lookup_dwo_signatured_type (cu
, sig
);
7510 return lookup_dwp_signatured_type (cu
, sig
);
7514 struct signatured_type find_entry
, *entry
;
7516 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7518 find_entry
.signature
= sig
;
7519 entry
= ((struct signatured_type
*)
7520 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7525 /* Low level DIE reading support. */
7527 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7530 init_cu_die_reader (struct die_reader_specs
*reader
,
7531 struct dwarf2_cu
*cu
,
7532 struct dwarf2_section_info
*section
,
7533 struct dwo_file
*dwo_file
,
7534 struct abbrev_table
*abbrev_table
)
7536 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7537 reader
->abfd
= get_section_bfd_owner (section
);
7539 reader
->dwo_file
= dwo_file
;
7540 reader
->die_section
= section
;
7541 reader
->buffer
= section
->buffer
;
7542 reader
->buffer_end
= section
->buffer
+ section
->size
;
7543 reader
->comp_dir
= NULL
;
7544 reader
->abbrev_table
= abbrev_table
;
7547 /* Subroutine of init_cutu_and_read_dies to simplify it.
7548 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7549 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7552 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7553 from it to the DIE in the DWO. If NULL we are skipping the stub.
7554 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7555 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7556 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7557 STUB_COMP_DIR may be non-NULL.
7558 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7559 are filled in with the info of the DIE from the DWO file.
7560 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7561 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7562 kept around for at least as long as *RESULT_READER.
7564 The result is non-zero if a valid (non-dummy) DIE was found. */
7567 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7568 struct dwo_unit
*dwo_unit
,
7569 struct die_info
*stub_comp_unit_die
,
7570 const char *stub_comp_dir
,
7571 struct die_reader_specs
*result_reader
,
7572 const gdb_byte
**result_info_ptr
,
7573 struct die_info
**result_comp_unit_die
,
7574 int *result_has_children
,
7575 abbrev_table_up
*result_dwo_abbrev_table
)
7577 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7578 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7579 struct dwarf2_cu
*cu
= this_cu
->cu
;
7581 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7582 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7583 int i
,num_extra_attrs
;
7584 struct dwarf2_section_info
*dwo_abbrev_section
;
7585 struct attribute
*attr
;
7586 struct die_info
*comp_unit_die
;
7588 /* At most one of these may be provided. */
7589 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7591 /* These attributes aren't processed until later:
7592 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7593 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7594 referenced later. However, these attributes are found in the stub
7595 which we won't have later. In order to not impose this complication
7596 on the rest of the code, we read them here and copy them to the
7605 if (stub_comp_unit_die
!= NULL
)
7607 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7609 if (! this_cu
->is_debug_types
)
7610 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7611 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7612 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7613 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7614 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7616 /* There should be a DW_AT_addr_base attribute here (if needed).
7617 We need the value before we can process DW_FORM_GNU_addr_index. */
7619 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7621 cu
->addr_base
= DW_UNSND (attr
);
7623 /* There should be a DW_AT_ranges_base attribute here (if needed).
7624 We need the value before we can process DW_AT_ranges. */
7625 cu
->ranges_base
= 0;
7626 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7628 cu
->ranges_base
= DW_UNSND (attr
);
7630 else if (stub_comp_dir
!= NULL
)
7632 /* Reconstruct the comp_dir attribute to simplify the code below. */
7633 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7634 comp_dir
->name
= DW_AT_comp_dir
;
7635 comp_dir
->form
= DW_FORM_string
;
7636 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7637 DW_STRING (comp_dir
) = stub_comp_dir
;
7640 /* Set up for reading the DWO CU/TU. */
7641 cu
->dwo_unit
= dwo_unit
;
7642 dwarf2_section_info
*section
= dwo_unit
->section
;
7643 dwarf2_read_section (objfile
, section
);
7644 abfd
= get_section_bfd_owner (section
);
7645 begin_info_ptr
= info_ptr
= (section
->buffer
7646 + to_underlying (dwo_unit
->sect_off
));
7647 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7649 if (this_cu
->is_debug_types
)
7651 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7653 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7654 &cu
->header
, section
,
7656 info_ptr
, rcuh_kind::TYPE
);
7657 /* This is not an assert because it can be caused by bad debug info. */
7658 if (sig_type
->signature
!= cu
->header
.signature
)
7660 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7661 " TU at offset %s [in module %s]"),
7662 hex_string (sig_type
->signature
),
7663 hex_string (cu
->header
.signature
),
7664 sect_offset_str (dwo_unit
->sect_off
),
7665 bfd_get_filename (abfd
));
7667 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7668 /* For DWOs coming from DWP files, we don't know the CU length
7669 nor the type's offset in the TU until now. */
7670 dwo_unit
->length
= get_cu_length (&cu
->header
);
7671 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7673 /* Establish the type offset that can be used to lookup the type.
7674 For DWO files, we don't know it until now. */
7675 sig_type
->type_offset_in_section
7676 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7680 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7681 &cu
->header
, section
,
7683 info_ptr
, rcuh_kind::COMPILE
);
7684 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7685 /* For DWOs coming from DWP files, we don't know the CU length
7687 dwo_unit
->length
= get_cu_length (&cu
->header
);
7690 *result_dwo_abbrev_table
7691 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7692 cu
->header
.abbrev_sect_off
);
7693 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7694 result_dwo_abbrev_table
->get ());
7696 /* Read in the die, but leave space to copy over the attributes
7697 from the stub. This has the benefit of simplifying the rest of
7698 the code - all the work to maintain the illusion of a single
7699 DW_TAG_{compile,type}_unit DIE is done here. */
7700 num_extra_attrs
= ((stmt_list
!= NULL
)
7704 + (comp_dir
!= NULL
));
7705 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7706 result_has_children
, num_extra_attrs
);
7708 /* Copy over the attributes from the stub to the DIE we just read in. */
7709 comp_unit_die
= *result_comp_unit_die
;
7710 i
= comp_unit_die
->num_attrs
;
7711 if (stmt_list
!= NULL
)
7712 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7714 comp_unit_die
->attrs
[i
++] = *low_pc
;
7715 if (high_pc
!= NULL
)
7716 comp_unit_die
->attrs
[i
++] = *high_pc
;
7718 comp_unit_die
->attrs
[i
++] = *ranges
;
7719 if (comp_dir
!= NULL
)
7720 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7721 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7723 if (dwarf_die_debug
)
7725 fprintf_unfiltered (gdb_stdlog
,
7726 "Read die from %s@0x%x of %s:\n",
7727 get_section_name (section
),
7728 (unsigned) (begin_info_ptr
- section
->buffer
),
7729 bfd_get_filename (abfd
));
7730 dump_die (comp_unit_die
, dwarf_die_debug
);
7733 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7734 TUs by skipping the stub and going directly to the entry in the DWO file.
7735 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7736 to get it via circuitous means. Blech. */
7737 if (comp_dir
!= NULL
)
7738 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7740 /* Skip dummy compilation units. */
7741 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7742 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7745 *result_info_ptr
= info_ptr
;
7749 /* Subroutine of init_cutu_and_read_dies to simplify it.
7750 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7751 Returns NULL if the specified DWO unit cannot be found. */
7753 static struct dwo_unit
*
7754 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7755 struct die_info
*comp_unit_die
)
7757 struct dwarf2_cu
*cu
= this_cu
->cu
;
7759 struct dwo_unit
*dwo_unit
;
7760 const char *comp_dir
, *dwo_name
;
7762 gdb_assert (cu
!= NULL
);
7764 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7765 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7766 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7768 if (this_cu
->is_debug_types
)
7770 struct signatured_type
*sig_type
;
7772 /* Since this_cu is the first member of struct signatured_type,
7773 we can go from a pointer to one to a pointer to the other. */
7774 sig_type
= (struct signatured_type
*) this_cu
;
7775 signature
= sig_type
->signature
;
7776 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7780 struct attribute
*attr
;
7782 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7784 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7786 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7787 signature
= DW_UNSND (attr
);
7788 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7795 /* Subroutine of init_cutu_and_read_dies to simplify it.
7796 See it for a description of the parameters.
7797 Read a TU directly from a DWO file, bypassing the stub. */
7800 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7801 int use_existing_cu
, int keep
,
7802 die_reader_func_ftype
*die_reader_func
,
7805 std::unique_ptr
<dwarf2_cu
> new_cu
;
7806 struct signatured_type
*sig_type
;
7807 struct die_reader_specs reader
;
7808 const gdb_byte
*info_ptr
;
7809 struct die_info
*comp_unit_die
;
7811 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7813 /* Verify we can do the following downcast, and that we have the
7815 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7816 sig_type
= (struct signatured_type
*) this_cu
;
7817 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7819 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7821 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7822 /* There's no need to do the rereading_dwo_cu handling that
7823 init_cutu_and_read_dies does since we don't read the stub. */
7827 /* If !use_existing_cu, this_cu->cu must be NULL. */
7828 gdb_assert (this_cu
->cu
== NULL
);
7829 new_cu
.reset (new dwarf2_cu (this_cu
));
7832 /* A future optimization, if needed, would be to use an existing
7833 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7834 could share abbrev tables. */
7836 /* The abbreviation table used by READER, this must live at least as long as
7838 abbrev_table_up dwo_abbrev_table
;
7840 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7841 NULL
/* stub_comp_unit_die */,
7842 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7844 &comp_unit_die
, &has_children
,
7845 &dwo_abbrev_table
) == 0)
7851 /* All the "real" work is done here. */
7852 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7854 /* This duplicates the code in init_cutu_and_read_dies,
7855 but the alternative is making the latter more complex.
7856 This function is only for the special case of using DWO files directly:
7857 no point in overly complicating the general case just to handle this. */
7858 if (new_cu
!= NULL
&& keep
)
7860 /* Link this CU into read_in_chain. */
7861 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7862 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7863 /* The chain owns it now. */
7868 /* Initialize a CU (or TU) and read its DIEs.
7869 If the CU defers to a DWO file, read the DWO file as well.
7871 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7872 Otherwise the table specified in the comp unit header is read in and used.
7873 This is an optimization for when we already have the abbrev table.
7875 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7876 Otherwise, a new CU is allocated with xmalloc.
7878 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7879 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7881 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7882 linker) then DIE_READER_FUNC will not get called. */
7885 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7886 struct abbrev_table
*abbrev_table
,
7887 int use_existing_cu
, int keep
,
7888 die_reader_func_ftype
*die_reader_func
,
7891 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7892 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7893 struct dwarf2_section_info
*section
= this_cu
->section
;
7894 bfd
*abfd
= get_section_bfd_owner (section
);
7895 struct dwarf2_cu
*cu
;
7896 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7897 struct die_reader_specs reader
;
7898 struct die_info
*comp_unit_die
;
7900 struct attribute
*attr
;
7901 struct signatured_type
*sig_type
= NULL
;
7902 struct dwarf2_section_info
*abbrev_section
;
7903 /* Non-zero if CU currently points to a DWO file and we need to
7904 reread it. When this happens we need to reread the skeleton die
7905 before we can reread the DWO file (this only applies to CUs, not TUs). */
7906 int rereading_dwo_cu
= 0;
7908 if (dwarf_die_debug
)
7909 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7910 this_cu
->is_debug_types
? "type" : "comp",
7911 sect_offset_str (this_cu
->sect_off
));
7913 if (use_existing_cu
)
7916 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7917 file (instead of going through the stub), short-circuit all of this. */
7918 if (this_cu
->reading_dwo_directly
)
7920 /* Narrow down the scope of possibilities to have to understand. */
7921 gdb_assert (this_cu
->is_debug_types
);
7922 gdb_assert (abbrev_table
== NULL
);
7923 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7924 die_reader_func
, data
);
7928 /* This is cheap if the section is already read in. */
7929 dwarf2_read_section (objfile
, section
);
7931 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7933 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7935 std::unique_ptr
<dwarf2_cu
> new_cu
;
7936 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7939 /* If this CU is from a DWO file we need to start over, we need to
7940 refetch the attributes from the skeleton CU.
7941 This could be optimized by retrieving those attributes from when we
7942 were here the first time: the previous comp_unit_die was stored in
7943 comp_unit_obstack. But there's no data yet that we need this
7945 if (cu
->dwo_unit
!= NULL
)
7946 rereading_dwo_cu
= 1;
7950 /* If !use_existing_cu, this_cu->cu must be NULL. */
7951 gdb_assert (this_cu
->cu
== NULL
);
7952 new_cu
.reset (new dwarf2_cu (this_cu
));
7956 /* Get the header. */
7957 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7959 /* We already have the header, there's no need to read it in again. */
7960 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7964 if (this_cu
->is_debug_types
)
7966 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7967 &cu
->header
, section
,
7968 abbrev_section
, info_ptr
,
7971 /* Since per_cu is the first member of struct signatured_type,
7972 we can go from a pointer to one to a pointer to the other. */
7973 sig_type
= (struct signatured_type
*) this_cu
;
7974 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7975 gdb_assert (sig_type
->type_offset_in_tu
7976 == cu
->header
.type_cu_offset_in_tu
);
7977 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7979 /* LENGTH has not been set yet for type units if we're
7980 using .gdb_index. */
7981 this_cu
->length
= get_cu_length (&cu
->header
);
7983 /* Establish the type offset that can be used to lookup the type. */
7984 sig_type
->type_offset_in_section
=
7985 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7987 this_cu
->dwarf_version
= cu
->header
.version
;
7991 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7992 &cu
->header
, section
,
7995 rcuh_kind::COMPILE
);
7997 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7998 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7999 this_cu
->dwarf_version
= cu
->header
.version
;
8003 /* Skip dummy compilation units. */
8004 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8005 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8008 /* If we don't have them yet, read the abbrevs for this compilation unit.
8009 And if we need to read them now, make sure they're freed when we're
8010 done (own the table through ABBREV_TABLE_HOLDER). */
8011 abbrev_table_up abbrev_table_holder
;
8012 if (abbrev_table
!= NULL
)
8013 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
8017 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8018 cu
->header
.abbrev_sect_off
);
8019 abbrev_table
= abbrev_table_holder
.get ();
8022 /* Read the top level CU/TU die. */
8023 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
8024 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8026 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
8027 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
8028 table from the DWO file and pass the ownership over to us. It will be
8029 referenced from READER, so we must make sure to free it after we're done
8032 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
8033 DWO CU, that this test will fail (the attribute will not be present). */
8034 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
8035 abbrev_table_up dwo_abbrev_table
;
8038 struct dwo_unit
*dwo_unit
;
8039 struct die_info
*dwo_comp_unit_die
;
8043 complaint (&symfile_complaints
,
8044 _("compilation unit with DW_AT_GNU_dwo_name"
8045 " has children (offset %s) [in module %s]"),
8046 sect_offset_str (this_cu
->sect_off
),
8047 bfd_get_filename (abfd
));
8049 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
8050 if (dwo_unit
!= NULL
)
8052 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
8053 comp_unit_die
, NULL
,
8055 &dwo_comp_unit_die
, &has_children
,
8056 &dwo_abbrev_table
) == 0)
8061 comp_unit_die
= dwo_comp_unit_die
;
8065 /* Yikes, we couldn't find the rest of the DIE, we only have
8066 the stub. A complaint has already been logged. There's
8067 not much more we can do except pass on the stub DIE to
8068 die_reader_func. We don't want to throw an error on bad
8073 /* All of the above is setup for this call. Yikes. */
8074 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8076 /* Done, clean up. */
8077 if (new_cu
!= NULL
&& keep
)
8079 /* Link this CU into read_in_chain. */
8080 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
8081 dwarf2_per_objfile
->read_in_chain
= this_cu
;
8082 /* The chain owns it now. */
8087 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
8088 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
8089 to have already done the lookup to find the DWO file).
8091 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
8092 THIS_CU->is_debug_types, but nothing else.
8094 We fill in THIS_CU->length.
8096 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
8097 linker) then DIE_READER_FUNC will not get called.
8099 THIS_CU->cu is always freed when done.
8100 This is done in order to not leave THIS_CU->cu in a state where we have
8101 to care whether it refers to the "main" CU or the DWO CU. */
8104 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
8105 struct dwo_file
*dwo_file
,
8106 die_reader_func_ftype
*die_reader_func
,
8109 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
8110 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8111 struct dwarf2_section_info
*section
= this_cu
->section
;
8112 bfd
*abfd
= get_section_bfd_owner (section
);
8113 struct dwarf2_section_info
*abbrev_section
;
8114 const gdb_byte
*begin_info_ptr
, *info_ptr
;
8115 struct die_reader_specs reader
;
8116 struct die_info
*comp_unit_die
;
8119 if (dwarf_die_debug
)
8120 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
8121 this_cu
->is_debug_types
? "type" : "comp",
8122 sect_offset_str (this_cu
->sect_off
));
8124 gdb_assert (this_cu
->cu
== NULL
);
8126 abbrev_section
= (dwo_file
!= NULL
8127 ? &dwo_file
->sections
.abbrev
8128 : get_abbrev_section_for_cu (this_cu
));
8130 /* This is cheap if the section is already read in. */
8131 dwarf2_read_section (objfile
, section
);
8133 struct dwarf2_cu
cu (this_cu
);
8135 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
8136 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
8137 &cu
.header
, section
,
8138 abbrev_section
, info_ptr
,
8139 (this_cu
->is_debug_types
8141 : rcuh_kind::COMPILE
));
8143 this_cu
->length
= get_cu_length (&cu
.header
);
8145 /* Skip dummy compilation units. */
8146 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8147 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8150 abbrev_table_up abbrev_table
8151 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8152 cu
.header
.abbrev_sect_off
);
8154 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
8155 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8157 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8160 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
8161 does not lookup the specified DWO file.
8162 This cannot be used to read DWO files.
8164 THIS_CU->cu is always freed when done.
8165 This is done in order to not leave THIS_CU->cu in a state where we have
8166 to care whether it refers to the "main" CU or the DWO CU.
8167 We can revisit this if the data shows there's a performance issue. */
8170 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
8171 die_reader_func_ftype
*die_reader_func
,
8174 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
8177 /* Type Unit Groups.
8179 Type Unit Groups are a way to collapse the set of all TUs (type units) into
8180 a more manageable set. The grouping is done by DW_AT_stmt_list entry
8181 so that all types coming from the same compilation (.o file) are grouped
8182 together. A future step could be to put the types in the same symtab as
8183 the CU the types ultimately came from. */
8186 hash_type_unit_group (const void *item
)
8188 const struct type_unit_group
*tu_group
8189 = (const struct type_unit_group
*) item
;
8191 return hash_stmt_list_entry (&tu_group
->hash
);
8195 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
8197 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
8198 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
8200 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
8203 /* Allocate a hash table for type unit groups. */
8206 allocate_type_unit_groups_table (struct objfile
*objfile
)
8208 return htab_create_alloc_ex (3,
8209 hash_type_unit_group
,
8212 &objfile
->objfile_obstack
,
8213 hashtab_obstack_allocate
,
8214 dummy_obstack_deallocate
);
8217 /* Type units that don't have DW_AT_stmt_list are grouped into their own
8218 partial symtabs. We combine several TUs per psymtab to not let the size
8219 of any one psymtab grow too big. */
8220 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
8221 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
8223 /* Helper routine for get_type_unit_group.
8224 Create the type_unit_group object used to hold one or more TUs. */
8226 static struct type_unit_group
*
8227 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
8229 struct dwarf2_per_objfile
*dwarf2_per_objfile
8230 = cu
->per_cu
->dwarf2_per_objfile
;
8231 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8232 struct dwarf2_per_cu_data
*per_cu
;
8233 struct type_unit_group
*tu_group
;
8235 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8236 struct type_unit_group
);
8237 per_cu
= &tu_group
->per_cu
;
8238 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8240 if (dwarf2_per_objfile
->using_index
)
8242 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8243 struct dwarf2_per_cu_quick_data
);
8247 unsigned int line_offset
= to_underlying (line_offset_struct
);
8248 struct partial_symtab
*pst
;
8251 /* Give the symtab a useful name for debug purposes. */
8252 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
8253 name
= xstrprintf ("<type_units_%d>",
8254 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
8256 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
8258 pst
= create_partial_symtab (per_cu
, name
);
8264 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
8265 tu_group
->hash
.line_sect_off
= line_offset_struct
;
8270 /* Look up the type_unit_group for type unit CU, and create it if necessary.
8271 STMT_LIST is a DW_AT_stmt_list attribute. */
8273 static struct type_unit_group
*
8274 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
8276 struct dwarf2_per_objfile
*dwarf2_per_objfile
8277 = cu
->per_cu
->dwarf2_per_objfile
;
8278 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8279 struct type_unit_group
*tu_group
;
8281 unsigned int line_offset
;
8282 struct type_unit_group type_unit_group_for_lookup
;
8284 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
8286 dwarf2_per_objfile
->type_unit_groups
=
8287 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
8290 /* Do we need to create a new group, or can we use an existing one? */
8294 line_offset
= DW_UNSND (stmt_list
);
8295 ++tu_stats
->nr_symtab_sharers
;
8299 /* Ugh, no stmt_list. Rare, but we have to handle it.
8300 We can do various things here like create one group per TU or
8301 spread them over multiple groups to split up the expansion work.
8302 To avoid worst case scenarios (too many groups or too large groups)
8303 we, umm, group them in bunches. */
8304 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
8305 | (tu_stats
->nr_stmt_less_type_units
8306 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
8307 ++tu_stats
->nr_stmt_less_type_units
;
8310 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
8311 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
8312 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8313 &type_unit_group_for_lookup
, INSERT
);
8316 tu_group
= (struct type_unit_group
*) *slot
;
8317 gdb_assert (tu_group
!= NULL
);
8321 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8322 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8324 ++tu_stats
->nr_symtabs
;
8330 /* Partial symbol tables. */
8332 /* Create a psymtab named NAME and assign it to PER_CU.
8334 The caller must fill in the following details:
8335 dirname, textlow, texthigh. */
8337 static struct partial_symtab
*
8338 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8340 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8341 struct partial_symtab
*pst
;
8343 pst
= start_psymtab_common (objfile
, name
, 0,
8344 objfile
->global_psymbols
,
8345 objfile
->static_psymbols
);
8347 pst
->psymtabs_addrmap_supported
= 1;
8349 /* This is the glue that links PST into GDB's symbol API. */
8350 pst
->read_symtab_private
= per_cu
;
8351 pst
->read_symtab
= dwarf2_read_symtab
;
8352 per_cu
->v
.psymtab
= pst
;
8357 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8360 struct process_psymtab_comp_unit_data
8362 /* True if we are reading a DW_TAG_partial_unit. */
8364 int want_partial_unit
;
8366 /* The "pretend" language that is used if the CU doesn't declare a
8369 enum language pretend_language
;
8372 /* die_reader_func for process_psymtab_comp_unit. */
8375 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8376 const gdb_byte
*info_ptr
,
8377 struct die_info
*comp_unit_die
,
8381 struct dwarf2_cu
*cu
= reader
->cu
;
8382 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8383 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8384 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8386 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8387 struct partial_symtab
*pst
;
8388 enum pc_bounds_kind cu_bounds_kind
;
8389 const char *filename
;
8390 struct process_psymtab_comp_unit_data
*info
8391 = (struct process_psymtab_comp_unit_data
*) data
;
8393 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8396 gdb_assert (! per_cu
->is_debug_types
);
8398 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8400 cu
->list_in_scope
= &file_symbols
;
8402 /* Allocate a new partial symbol table structure. */
8403 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8404 if (filename
== NULL
)
8407 pst
= create_partial_symtab (per_cu
, filename
);
8409 /* This must be done before calling dwarf2_build_include_psymtabs. */
8410 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8412 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8414 dwarf2_find_base_address (comp_unit_die
, cu
);
8416 /* Possibly set the default values of LOWPC and HIGHPC from
8418 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8419 &best_highpc
, cu
, pst
);
8420 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8421 /* Store the contiguous range if it is not empty; it can be empty for
8422 CUs with no code. */
8423 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8424 gdbarch_adjust_dwarf2_addr (gdbarch
,
8425 best_lowpc
+ baseaddr
),
8426 gdbarch_adjust_dwarf2_addr (gdbarch
,
8427 best_highpc
+ baseaddr
) - 1,
8430 /* Check if comp unit has_children.
8431 If so, read the rest of the partial symbols from this comp unit.
8432 If not, there's no more debug_info for this comp unit. */
8435 struct partial_die_info
*first_die
;
8436 CORE_ADDR lowpc
, highpc
;
8438 lowpc
= ((CORE_ADDR
) -1);
8439 highpc
= ((CORE_ADDR
) 0);
8441 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8443 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8444 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8446 /* If we didn't find a lowpc, set it to highpc to avoid
8447 complaints from `maint check'. */
8448 if (lowpc
== ((CORE_ADDR
) -1))
8451 /* If the compilation unit didn't have an explicit address range,
8452 then use the information extracted from its child dies. */
8453 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8456 best_highpc
= highpc
;
8459 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8460 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8462 end_psymtab_common (objfile
, pst
);
8464 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8467 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8468 struct dwarf2_per_cu_data
*iter
;
8470 /* Fill in 'dependencies' here; we fill in 'users' in a
8472 pst
->number_of_dependencies
= len
;
8474 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8476 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8479 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8481 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8484 /* Get the list of files included in the current compilation unit,
8485 and build a psymtab for each of them. */
8486 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8488 if (dwarf_read_debug
)
8490 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8492 fprintf_unfiltered (gdb_stdlog
,
8493 "Psymtab for %s unit @%s: %s - %s"
8494 ", %d global, %d static syms\n",
8495 per_cu
->is_debug_types
? "type" : "comp",
8496 sect_offset_str (per_cu
->sect_off
),
8497 paddress (gdbarch
, pst
->textlow
),
8498 paddress (gdbarch
, pst
->texthigh
),
8499 pst
->n_global_syms
, pst
->n_static_syms
);
8503 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8504 Process compilation unit THIS_CU for a psymtab. */
8507 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8508 int want_partial_unit
,
8509 enum language pretend_language
)
8511 /* If this compilation unit was already read in, free the
8512 cached copy in order to read it in again. This is
8513 necessary because we skipped some symbols when we first
8514 read in the compilation unit (see load_partial_dies).
8515 This problem could be avoided, but the benefit is unclear. */
8516 if (this_cu
->cu
!= NULL
)
8517 free_one_cached_comp_unit (this_cu
);
8519 if (this_cu
->is_debug_types
)
8520 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8524 process_psymtab_comp_unit_data info
;
8525 info
.want_partial_unit
= want_partial_unit
;
8526 info
.pretend_language
= pretend_language
;
8527 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8528 process_psymtab_comp_unit_reader
, &info
);
8531 /* Age out any secondary CUs. */
8532 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8535 /* Reader function for build_type_psymtabs. */
8538 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8539 const gdb_byte
*info_ptr
,
8540 struct die_info
*type_unit_die
,
8544 struct dwarf2_per_objfile
*dwarf2_per_objfile
8545 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8546 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8547 struct dwarf2_cu
*cu
= reader
->cu
;
8548 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8549 struct signatured_type
*sig_type
;
8550 struct type_unit_group
*tu_group
;
8551 struct attribute
*attr
;
8552 struct partial_die_info
*first_die
;
8553 CORE_ADDR lowpc
, highpc
;
8554 struct partial_symtab
*pst
;
8556 gdb_assert (data
== NULL
);
8557 gdb_assert (per_cu
->is_debug_types
);
8558 sig_type
= (struct signatured_type
*) per_cu
;
8563 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8564 tu_group
= get_type_unit_group (cu
, attr
);
8566 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8568 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8569 cu
->list_in_scope
= &file_symbols
;
8570 pst
= create_partial_symtab (per_cu
, "");
8573 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8575 lowpc
= (CORE_ADDR
) -1;
8576 highpc
= (CORE_ADDR
) 0;
8577 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8579 end_psymtab_common (objfile
, pst
);
8582 /* Struct used to sort TUs by their abbreviation table offset. */
8584 struct tu_abbrev_offset
8586 struct signatured_type
*sig_type
;
8587 sect_offset abbrev_offset
;
8590 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8593 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8594 const struct tu_abbrev_offset
&b
)
8596 return a
.abbrev_offset
< b
.abbrev_offset
;
8599 /* Efficiently read all the type units.
8600 This does the bulk of the work for build_type_psymtabs.
8602 The efficiency is because we sort TUs by the abbrev table they use and
8603 only read each abbrev table once. In one program there are 200K TUs
8604 sharing 8K abbrev tables.
8606 The main purpose of this function is to support building the
8607 dwarf2_per_objfile->type_unit_groups table.
8608 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8609 can collapse the search space by grouping them by stmt_list.
8610 The savings can be significant, in the same program from above the 200K TUs
8611 share 8K stmt_list tables.
8613 FUNC is expected to call get_type_unit_group, which will create the
8614 struct type_unit_group if necessary and add it to
8615 dwarf2_per_objfile->type_unit_groups. */
8618 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8620 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8621 abbrev_table_up abbrev_table
;
8622 sect_offset abbrev_offset
;
8625 /* It's up to the caller to not call us multiple times. */
8626 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8628 if (dwarf2_per_objfile
->n_type_units
== 0)
8631 /* TUs typically share abbrev tables, and there can be way more TUs than
8632 abbrev tables. Sort by abbrev table to reduce the number of times we
8633 read each abbrev table in.
8634 Alternatives are to punt or to maintain a cache of abbrev tables.
8635 This is simpler and efficient enough for now.
8637 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8638 symtab to use). Typically TUs with the same abbrev offset have the same
8639 stmt_list value too so in practice this should work well.
8641 The basic algorithm here is:
8643 sort TUs by abbrev table
8644 for each TU with same abbrev table:
8645 read abbrev table if first user
8646 read TU top level DIE
8647 [IWBN if DWO skeletons had DW_AT_stmt_list]
8650 if (dwarf_read_debug
)
8651 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8653 /* Sort in a separate table to maintain the order of all_type_units
8654 for .gdb_index: TU indices directly index all_type_units. */
8655 std::vector
<struct tu_abbrev_offset
> sorted_by_abbrev
8656 (dwarf2_per_objfile
->n_type_units
);
8657 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8659 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8661 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8662 sorted_by_abbrev
[i
].abbrev_offset
=
8663 read_abbrev_offset (dwarf2_per_objfile
,
8664 sig_type
->per_cu
.section
,
8665 sig_type
->per_cu
.sect_off
);
8667 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8668 sort_tu_by_abbrev_offset
);
8670 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8672 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8674 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8676 /* Switch to the next abbrev table if necessary. */
8677 if (abbrev_table
== NULL
8678 || tu
->abbrev_offset
!= abbrev_offset
)
8680 abbrev_offset
= tu
->abbrev_offset
;
8682 abbrev_table_read_table (dwarf2_per_objfile
,
8683 &dwarf2_per_objfile
->abbrev
,
8685 ++tu_stats
->nr_uniq_abbrev_tables
;
8688 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8689 0, 0, build_type_psymtabs_reader
, NULL
);
8693 /* Print collected type unit statistics. */
8696 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8698 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8700 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8701 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8702 dwarf2_per_objfile
->n_type_units
);
8703 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8704 tu_stats
->nr_uniq_abbrev_tables
);
8705 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8706 tu_stats
->nr_symtabs
);
8707 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8708 tu_stats
->nr_symtab_sharers
);
8709 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8710 tu_stats
->nr_stmt_less_type_units
);
8711 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8712 tu_stats
->nr_all_type_units_reallocs
);
8715 /* Traversal function for build_type_psymtabs. */
8718 build_type_psymtab_dependencies (void **slot
, void *info
)
8720 struct dwarf2_per_objfile
*dwarf2_per_objfile
8721 = (struct dwarf2_per_objfile
*) info
;
8722 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8723 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8724 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8725 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8726 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8727 struct signatured_type
*iter
;
8730 gdb_assert (len
> 0);
8731 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8733 pst
->number_of_dependencies
= len
;
8735 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8737 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8740 gdb_assert (iter
->per_cu
.is_debug_types
);
8741 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8742 iter
->type_unit_group
= tu_group
;
8745 VEC_free (sig_type_ptr
, tu_group
->tus
);
8750 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8751 Build partial symbol tables for the .debug_types comp-units. */
8754 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8756 if (! create_all_type_units (dwarf2_per_objfile
))
8759 build_type_psymtabs_1 (dwarf2_per_objfile
);
8762 /* Traversal function for process_skeletonless_type_unit.
8763 Read a TU in a DWO file and build partial symbols for it. */
8766 process_skeletonless_type_unit (void **slot
, void *info
)
8768 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8769 struct dwarf2_per_objfile
*dwarf2_per_objfile
8770 = (struct dwarf2_per_objfile
*) info
;
8771 struct signatured_type find_entry
, *entry
;
8773 /* If this TU doesn't exist in the global table, add it and read it in. */
8775 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8777 dwarf2_per_objfile
->signatured_types
8778 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8781 find_entry
.signature
= dwo_unit
->signature
;
8782 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8784 /* If we've already seen this type there's nothing to do. What's happening
8785 is we're doing our own version of comdat-folding here. */
8789 /* This does the job that create_all_type_units would have done for
8791 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8792 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8795 /* This does the job that build_type_psymtabs_1 would have done. */
8796 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8797 build_type_psymtabs_reader
, NULL
);
8802 /* Traversal function for process_skeletonless_type_units. */
8805 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8807 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8809 if (dwo_file
->tus
!= NULL
)
8811 htab_traverse_noresize (dwo_file
->tus
,
8812 process_skeletonless_type_unit
, info
);
8818 /* Scan all TUs of DWO files, verifying we've processed them.
8819 This is needed in case a TU was emitted without its skeleton.
8820 Note: This can't be done until we know what all the DWO files are. */
8823 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8825 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8826 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8827 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8829 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8830 process_dwo_file_for_skeletonless_type_units
,
8831 dwarf2_per_objfile
);
8835 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8838 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8842 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8844 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8845 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8851 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8853 /* Set the 'user' field only if it is not already set. */
8854 if (pst
->dependencies
[j
]->user
== NULL
)
8855 pst
->dependencies
[j
]->user
= pst
;
8860 /* Build the partial symbol table by doing a quick pass through the
8861 .debug_info and .debug_abbrev sections. */
8864 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8866 struct cleanup
*back_to
;
8868 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8870 if (dwarf_read_debug
)
8872 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8873 objfile_name (objfile
));
8876 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8878 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8880 /* Any cached compilation units will be linked by the per-objfile
8881 read_in_chain. Make sure to free them when we're done. */
8882 back_to
= make_cleanup (free_cached_comp_units
, dwarf2_per_objfile
);
8884 build_type_psymtabs (dwarf2_per_objfile
);
8886 create_all_comp_units (dwarf2_per_objfile
);
8888 /* Create a temporary address map on a temporary obstack. We later
8889 copy this to the final obstack. */
8890 auto_obstack temp_obstack
;
8892 scoped_restore save_psymtabs_addrmap
8893 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8894 addrmap_create_mutable (&temp_obstack
));
8896 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8898 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8900 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8903 /* This has to wait until we read the CUs, we need the list of DWOs. */
8904 process_skeletonless_type_units (dwarf2_per_objfile
);
8906 /* Now that all TUs have been processed we can fill in the dependencies. */
8907 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8909 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8910 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8913 if (dwarf_read_debug
)
8914 print_tu_stats (dwarf2_per_objfile
);
8916 set_partial_user (dwarf2_per_objfile
);
8918 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8919 &objfile
->objfile_obstack
);
8920 /* At this point we want to keep the address map. */
8921 save_psymtabs_addrmap
.release ();
8923 do_cleanups (back_to
);
8925 if (dwarf_read_debug
)
8926 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8927 objfile_name (objfile
));
8930 /* die_reader_func for load_partial_comp_unit. */
8933 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8934 const gdb_byte
*info_ptr
,
8935 struct die_info
*comp_unit_die
,
8939 struct dwarf2_cu
*cu
= reader
->cu
;
8941 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8943 /* Check if comp unit has_children.
8944 If so, read the rest of the partial symbols from this comp unit.
8945 If not, there's no more debug_info for this comp unit. */
8947 load_partial_dies (reader
, info_ptr
, 0);
8950 /* Load the partial DIEs for a secondary CU into memory.
8951 This is also used when rereading a primary CU with load_all_dies. */
8954 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8956 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8957 load_partial_comp_unit_reader
, NULL
);
8961 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8962 struct dwarf2_section_info
*section
,
8963 struct dwarf2_section_info
*abbrev_section
,
8964 unsigned int is_dwz
,
8967 struct dwarf2_per_cu_data
***all_comp_units
)
8969 const gdb_byte
*info_ptr
;
8970 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8972 if (dwarf_read_debug
)
8973 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8974 get_section_name (section
),
8975 get_section_file_name (section
));
8977 dwarf2_read_section (objfile
, section
);
8979 info_ptr
= section
->buffer
;
8981 while (info_ptr
< section
->buffer
+ section
->size
)
8983 struct dwarf2_per_cu_data
*this_cu
;
8985 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8987 comp_unit_head cu_header
;
8988 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8989 abbrev_section
, info_ptr
,
8990 rcuh_kind::COMPILE
);
8992 /* Save the compilation unit for later lookup. */
8993 if (cu_header
.unit_type
!= DW_UT_type
)
8995 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8996 struct dwarf2_per_cu_data
);
8997 memset (this_cu
, 0, sizeof (*this_cu
));
9001 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
9002 struct signatured_type
);
9003 memset (sig_type
, 0, sizeof (*sig_type
));
9004 sig_type
->signature
= cu_header
.signature
;
9005 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
9006 this_cu
= &sig_type
->per_cu
;
9008 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
9009 this_cu
->sect_off
= sect_off
;
9010 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
9011 this_cu
->is_dwz
= is_dwz
;
9012 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
9013 this_cu
->section
= section
;
9015 if (*n_comp_units
== *n_allocated
)
9018 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
9019 *all_comp_units
, *n_allocated
);
9021 (*all_comp_units
)[*n_comp_units
] = this_cu
;
9024 info_ptr
= info_ptr
+ this_cu
->length
;
9028 /* Create a list of all compilation units in OBJFILE.
9029 This is only done for -readnow and building partial symtabs. */
9032 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9036 struct dwarf2_per_cu_data
**all_comp_units
;
9037 struct dwz_file
*dwz
;
9038 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9042 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
9044 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
9045 &dwarf2_per_objfile
->abbrev
, 0,
9046 &n_allocated
, &n_comp_units
, &all_comp_units
);
9048 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
9050 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
9051 1, &n_allocated
, &n_comp_units
,
9054 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
9055 struct dwarf2_per_cu_data
*,
9057 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
9058 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
9059 xfree (all_comp_units
);
9060 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
9063 /* Process all loaded DIEs for compilation unit CU, starting at
9064 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
9065 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
9066 DW_AT_ranges). See the comments of add_partial_subprogram on how
9067 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
9070 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
9071 CORE_ADDR
*highpc
, int set_addrmap
,
9072 struct dwarf2_cu
*cu
)
9074 struct partial_die_info
*pdi
;
9076 /* Now, march along the PDI's, descending into ones which have
9077 interesting children but skipping the children of the other ones,
9078 until we reach the end of the compilation unit. */
9086 /* Anonymous namespaces or modules have no name but have interesting
9087 children, so we need to look at them. Ditto for anonymous
9090 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
9091 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
9092 || pdi
->tag
== DW_TAG_imported_unit
9093 || pdi
->tag
== DW_TAG_inlined_subroutine
)
9097 case DW_TAG_subprogram
:
9098 case DW_TAG_inlined_subroutine
:
9099 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9101 case DW_TAG_constant
:
9102 case DW_TAG_variable
:
9103 case DW_TAG_typedef
:
9104 case DW_TAG_union_type
:
9105 if (!pdi
->is_declaration
)
9107 add_partial_symbol (pdi
, cu
);
9110 case DW_TAG_class_type
:
9111 case DW_TAG_interface_type
:
9112 case DW_TAG_structure_type
:
9113 if (!pdi
->is_declaration
)
9115 add_partial_symbol (pdi
, cu
);
9117 if ((cu
->language
== language_rust
9118 || cu
->language
== language_cplus
) && pdi
->has_children
)
9119 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
9122 case DW_TAG_enumeration_type
:
9123 if (!pdi
->is_declaration
)
9124 add_partial_enumeration (pdi
, cu
);
9126 case DW_TAG_base_type
:
9127 case DW_TAG_subrange_type
:
9128 /* File scope base type definitions are added to the partial
9130 add_partial_symbol (pdi
, cu
);
9132 case DW_TAG_namespace
:
9133 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9136 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9138 case DW_TAG_imported_unit
:
9140 struct dwarf2_per_cu_data
*per_cu
;
9142 /* For now we don't handle imported units in type units. */
9143 if (cu
->per_cu
->is_debug_types
)
9145 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9146 " supported in type units [in module %s]"),
9147 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9150 per_cu
= dwarf2_find_containing_comp_unit
9151 (pdi
->d
.sect_off
, pdi
->is_dwz
,
9152 cu
->per_cu
->dwarf2_per_objfile
);
9154 /* Go read the partial unit, if needed. */
9155 if (per_cu
->v
.psymtab
== NULL
)
9156 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
9158 VEC_safe_push (dwarf2_per_cu_ptr
,
9159 cu
->per_cu
->imported_symtabs
, per_cu
);
9162 case DW_TAG_imported_declaration
:
9163 add_partial_symbol (pdi
, cu
);
9170 /* If the die has a sibling, skip to the sibling. */
9172 pdi
= pdi
->die_sibling
;
9176 /* Functions used to compute the fully scoped name of a partial DIE.
9178 Normally, this is simple. For C++, the parent DIE's fully scoped
9179 name is concatenated with "::" and the partial DIE's name.
9180 Enumerators are an exception; they use the scope of their parent
9181 enumeration type, i.e. the name of the enumeration type is not
9182 prepended to the enumerator.
9184 There are two complexities. One is DW_AT_specification; in this
9185 case "parent" means the parent of the target of the specification,
9186 instead of the direct parent of the DIE. The other is compilers
9187 which do not emit DW_TAG_namespace; in this case we try to guess
9188 the fully qualified name of structure types from their members'
9189 linkage names. This must be done using the DIE's children rather
9190 than the children of any DW_AT_specification target. We only need
9191 to do this for structures at the top level, i.e. if the target of
9192 any DW_AT_specification (if any; otherwise the DIE itself) does not
9195 /* Compute the scope prefix associated with PDI's parent, in
9196 compilation unit CU. The result will be allocated on CU's
9197 comp_unit_obstack, or a copy of the already allocated PDI->NAME
9198 field. NULL is returned if no prefix is necessary. */
9200 partial_die_parent_scope (struct partial_die_info
*pdi
,
9201 struct dwarf2_cu
*cu
)
9203 const char *grandparent_scope
;
9204 struct partial_die_info
*parent
, *real_pdi
;
9206 /* We need to look at our parent DIE; if we have a DW_AT_specification,
9207 then this means the parent of the specification DIE. */
9210 while (real_pdi
->has_specification
)
9211 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
9212 real_pdi
->spec_is_dwz
, cu
);
9214 parent
= real_pdi
->die_parent
;
9218 if (parent
->scope_set
)
9219 return parent
->scope
;
9223 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
9225 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9226 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9227 Work around this problem here. */
9228 if (cu
->language
== language_cplus
9229 && parent
->tag
== DW_TAG_namespace
9230 && strcmp (parent
->name
, "::") == 0
9231 && grandparent_scope
== NULL
)
9233 parent
->scope
= NULL
;
9234 parent
->scope_set
= 1;
9238 if (pdi
->tag
== DW_TAG_enumerator
)
9239 /* Enumerators should not get the name of the enumeration as a prefix. */
9240 parent
->scope
= grandparent_scope
;
9241 else if (parent
->tag
== DW_TAG_namespace
9242 || parent
->tag
== DW_TAG_module
9243 || parent
->tag
== DW_TAG_structure_type
9244 || parent
->tag
== DW_TAG_class_type
9245 || parent
->tag
== DW_TAG_interface_type
9246 || parent
->tag
== DW_TAG_union_type
9247 || parent
->tag
== DW_TAG_enumeration_type
)
9249 if (grandparent_scope
== NULL
)
9250 parent
->scope
= parent
->name
;
9252 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
9254 parent
->name
, 0, cu
);
9258 /* FIXME drow/2004-04-01: What should we be doing with
9259 function-local names? For partial symbols, we should probably be
9261 complaint (&symfile_complaints
,
9262 _("unhandled containing DIE tag %d for DIE at %s"),
9263 parent
->tag
, sect_offset_str (pdi
->sect_off
));
9264 parent
->scope
= grandparent_scope
;
9267 parent
->scope_set
= 1;
9268 return parent
->scope
;
9271 /* Return the fully scoped name associated with PDI, from compilation unit
9272 CU. The result will be allocated with malloc. */
9275 partial_die_full_name (struct partial_die_info
*pdi
,
9276 struct dwarf2_cu
*cu
)
9278 const char *parent_scope
;
9280 /* If this is a template instantiation, we can not work out the
9281 template arguments from partial DIEs. So, unfortunately, we have
9282 to go through the full DIEs. At least any work we do building
9283 types here will be reused if full symbols are loaded later. */
9284 if (pdi
->has_template_arguments
)
9288 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
9290 struct die_info
*die
;
9291 struct attribute attr
;
9292 struct dwarf2_cu
*ref_cu
= cu
;
9294 /* DW_FORM_ref_addr is using section offset. */
9295 attr
.name
= (enum dwarf_attribute
) 0;
9296 attr
.form
= DW_FORM_ref_addr
;
9297 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
9298 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
9300 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
9304 parent_scope
= partial_die_parent_scope (pdi
, cu
);
9305 if (parent_scope
== NULL
)
9308 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
9312 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
9314 struct dwarf2_per_objfile
*dwarf2_per_objfile
9315 = cu
->per_cu
->dwarf2_per_objfile
;
9316 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9317 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9319 const char *actual_name
= NULL
;
9321 char *built_actual_name
;
9323 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9325 built_actual_name
= partial_die_full_name (pdi
, cu
);
9326 if (built_actual_name
!= NULL
)
9327 actual_name
= built_actual_name
;
9329 if (actual_name
== NULL
)
9330 actual_name
= pdi
->name
;
9334 case DW_TAG_inlined_subroutine
:
9335 case DW_TAG_subprogram
:
9336 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
9337 if (pdi
->is_external
|| cu
->language
== language_ada
)
9339 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
9340 of the global scope. But in Ada, we want to be able to access
9341 nested procedures globally. So all Ada subprograms are stored
9342 in the global scope. */
9343 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9344 built_actual_name
!= NULL
,
9345 VAR_DOMAIN
, LOC_BLOCK
,
9346 &objfile
->global_psymbols
,
9347 addr
, cu
->language
, objfile
);
9351 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9352 built_actual_name
!= NULL
,
9353 VAR_DOMAIN
, LOC_BLOCK
,
9354 &objfile
->static_psymbols
,
9355 addr
, cu
->language
, objfile
);
9358 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9359 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9361 case DW_TAG_constant
:
9363 std::vector
<partial_symbol
*> *list
;
9365 if (pdi
->is_external
)
9366 list
= &objfile
->global_psymbols
;
9368 list
= &objfile
->static_psymbols
;
9369 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9370 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9371 list
, 0, cu
->language
, objfile
);
9374 case DW_TAG_variable
:
9376 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9380 && !dwarf2_per_objfile
->has_section_at_zero
)
9382 /* A global or static variable may also have been stripped
9383 out by the linker if unused, in which case its address
9384 will be nullified; do not add such variables into partial
9385 symbol table then. */
9387 else if (pdi
->is_external
)
9390 Don't enter into the minimal symbol tables as there is
9391 a minimal symbol table entry from the ELF symbols already.
9392 Enter into partial symbol table if it has a location
9393 descriptor or a type.
9394 If the location descriptor is missing, new_symbol will create
9395 a LOC_UNRESOLVED symbol, the address of the variable will then
9396 be determined from the minimal symbol table whenever the variable
9398 The address for the partial symbol table entry is not
9399 used by GDB, but it comes in handy for debugging partial symbol
9402 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9403 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9404 built_actual_name
!= NULL
,
9405 VAR_DOMAIN
, LOC_STATIC
,
9406 &objfile
->global_psymbols
,
9408 cu
->language
, objfile
);
9412 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9414 /* Static Variable. Skip symbols whose value we cannot know (those
9415 without location descriptors or constant values). */
9416 if (!has_loc
&& !pdi
->has_const_value
)
9418 xfree (built_actual_name
);
9422 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9423 built_actual_name
!= NULL
,
9424 VAR_DOMAIN
, LOC_STATIC
,
9425 &objfile
->static_psymbols
,
9426 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9427 cu
->language
, objfile
);
9430 case DW_TAG_typedef
:
9431 case DW_TAG_base_type
:
9432 case DW_TAG_subrange_type
:
9433 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9434 built_actual_name
!= NULL
,
9435 VAR_DOMAIN
, LOC_TYPEDEF
,
9436 &objfile
->static_psymbols
,
9437 0, cu
->language
, objfile
);
9439 case DW_TAG_imported_declaration
:
9440 case DW_TAG_namespace
:
9441 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9442 built_actual_name
!= NULL
,
9443 VAR_DOMAIN
, LOC_TYPEDEF
,
9444 &objfile
->global_psymbols
,
9445 0, cu
->language
, objfile
);
9448 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9449 built_actual_name
!= NULL
,
9450 MODULE_DOMAIN
, LOC_TYPEDEF
,
9451 &objfile
->global_psymbols
,
9452 0, cu
->language
, objfile
);
9454 case DW_TAG_class_type
:
9455 case DW_TAG_interface_type
:
9456 case DW_TAG_structure_type
:
9457 case DW_TAG_union_type
:
9458 case DW_TAG_enumeration_type
:
9459 /* Skip external references. The DWARF standard says in the section
9460 about "Structure, Union, and Class Type Entries": "An incomplete
9461 structure, union or class type is represented by a structure,
9462 union or class entry that does not have a byte size attribute
9463 and that has a DW_AT_declaration attribute." */
9464 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9466 xfree (built_actual_name
);
9470 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9471 static vs. global. */
9472 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9473 built_actual_name
!= NULL
,
9474 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9475 cu
->language
== language_cplus
9476 ? &objfile
->global_psymbols
9477 : &objfile
->static_psymbols
,
9478 0, cu
->language
, objfile
);
9481 case DW_TAG_enumerator
:
9482 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9483 built_actual_name
!= NULL
,
9484 VAR_DOMAIN
, LOC_CONST
,
9485 cu
->language
== language_cplus
9486 ? &objfile
->global_psymbols
9487 : &objfile
->static_psymbols
,
9488 0, cu
->language
, objfile
);
9494 xfree (built_actual_name
);
9497 /* Read a partial die corresponding to a namespace; also, add a symbol
9498 corresponding to that namespace to the symbol table. NAMESPACE is
9499 the name of the enclosing namespace. */
9502 add_partial_namespace (struct partial_die_info
*pdi
,
9503 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9504 int set_addrmap
, struct dwarf2_cu
*cu
)
9506 /* Add a symbol for the namespace. */
9508 add_partial_symbol (pdi
, cu
);
9510 /* Now scan partial symbols in that namespace. */
9512 if (pdi
->has_children
)
9513 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9516 /* Read a partial die corresponding to a Fortran module. */
9519 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9520 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9522 /* Add a symbol for the namespace. */
9524 add_partial_symbol (pdi
, cu
);
9526 /* Now scan partial symbols in that module. */
9528 if (pdi
->has_children
)
9529 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9532 /* Read a partial die corresponding to a subprogram or an inlined
9533 subprogram and create a partial symbol for that subprogram.
9534 When the CU language allows it, this routine also defines a partial
9535 symbol for each nested subprogram that this subprogram contains.
9536 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9537 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9539 PDI may also be a lexical block, in which case we simply search
9540 recursively for subprograms defined inside that lexical block.
9541 Again, this is only performed when the CU language allows this
9542 type of definitions. */
9545 add_partial_subprogram (struct partial_die_info
*pdi
,
9546 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9547 int set_addrmap
, struct dwarf2_cu
*cu
)
9549 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9551 if (pdi
->has_pc_info
)
9553 if (pdi
->lowpc
< *lowpc
)
9554 *lowpc
= pdi
->lowpc
;
9555 if (pdi
->highpc
> *highpc
)
9556 *highpc
= pdi
->highpc
;
9559 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9560 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9565 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9566 SECT_OFF_TEXT (objfile
));
9567 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9568 pdi
->lowpc
+ baseaddr
);
9569 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9570 pdi
->highpc
+ baseaddr
);
9571 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9572 cu
->per_cu
->v
.psymtab
);
9576 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9578 if (!pdi
->is_declaration
)
9579 /* Ignore subprogram DIEs that do not have a name, they are
9580 illegal. Do not emit a complaint at this point, we will
9581 do so when we convert this psymtab into a symtab. */
9583 add_partial_symbol (pdi
, cu
);
9587 if (! pdi
->has_children
)
9590 if (cu
->language
== language_ada
)
9592 pdi
= pdi
->die_child
;
9596 if (pdi
->tag
== DW_TAG_subprogram
9597 || pdi
->tag
== DW_TAG_inlined_subroutine
9598 || pdi
->tag
== DW_TAG_lexical_block
)
9599 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9600 pdi
= pdi
->die_sibling
;
9605 /* Read a partial die corresponding to an enumeration type. */
9608 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9609 struct dwarf2_cu
*cu
)
9611 struct partial_die_info
*pdi
;
9613 if (enum_pdi
->name
!= NULL
)
9614 add_partial_symbol (enum_pdi
, cu
);
9616 pdi
= enum_pdi
->die_child
;
9619 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9620 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9622 add_partial_symbol (pdi
, cu
);
9623 pdi
= pdi
->die_sibling
;
9627 /* Return the initial uleb128 in the die at INFO_PTR. */
9630 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9632 unsigned int bytes_read
;
9634 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9637 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9638 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9640 Return the corresponding abbrev, or NULL if the number is zero (indicating
9641 an empty DIE). In either case *BYTES_READ will be set to the length of
9642 the initial number. */
9644 static struct abbrev_info
*
9645 peek_die_abbrev (const die_reader_specs
&reader
,
9646 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9648 dwarf2_cu
*cu
= reader
.cu
;
9649 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9650 unsigned int abbrev_number
9651 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9653 if (abbrev_number
== 0)
9656 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9659 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9660 " at offset %s [in module %s]"),
9661 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9662 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9668 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9669 Returns a pointer to the end of a series of DIEs, terminated by an empty
9670 DIE. Any children of the skipped DIEs will also be skipped. */
9672 static const gdb_byte
*
9673 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9677 unsigned int bytes_read
;
9678 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9681 return info_ptr
+ bytes_read
;
9683 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9687 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9688 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9689 abbrev corresponding to that skipped uleb128 should be passed in
9690 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9693 static const gdb_byte
*
9694 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9695 struct abbrev_info
*abbrev
)
9697 unsigned int bytes_read
;
9698 struct attribute attr
;
9699 bfd
*abfd
= reader
->abfd
;
9700 struct dwarf2_cu
*cu
= reader
->cu
;
9701 const gdb_byte
*buffer
= reader
->buffer
;
9702 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9703 unsigned int form
, i
;
9705 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9707 /* The only abbrev we care about is DW_AT_sibling. */
9708 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9710 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9711 if (attr
.form
== DW_FORM_ref_addr
)
9712 complaint (&symfile_complaints
,
9713 _("ignoring absolute DW_AT_sibling"));
9716 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9717 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9719 if (sibling_ptr
< info_ptr
)
9720 complaint (&symfile_complaints
,
9721 _("DW_AT_sibling points backwards"));
9722 else if (sibling_ptr
> reader
->buffer_end
)
9723 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9729 /* If it isn't DW_AT_sibling, skip this attribute. */
9730 form
= abbrev
->attrs
[i
].form
;
9734 case DW_FORM_ref_addr
:
9735 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9736 and later it is offset sized. */
9737 if (cu
->header
.version
== 2)
9738 info_ptr
+= cu
->header
.addr_size
;
9740 info_ptr
+= cu
->header
.offset_size
;
9742 case DW_FORM_GNU_ref_alt
:
9743 info_ptr
+= cu
->header
.offset_size
;
9746 info_ptr
+= cu
->header
.addr_size
;
9753 case DW_FORM_flag_present
:
9754 case DW_FORM_implicit_const
:
9766 case DW_FORM_ref_sig8
:
9769 case DW_FORM_data16
:
9772 case DW_FORM_string
:
9773 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9774 info_ptr
+= bytes_read
;
9776 case DW_FORM_sec_offset
:
9778 case DW_FORM_GNU_strp_alt
:
9779 info_ptr
+= cu
->header
.offset_size
;
9781 case DW_FORM_exprloc
:
9783 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9784 info_ptr
+= bytes_read
;
9786 case DW_FORM_block1
:
9787 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9789 case DW_FORM_block2
:
9790 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9792 case DW_FORM_block4
:
9793 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9797 case DW_FORM_ref_udata
:
9798 case DW_FORM_GNU_addr_index
:
9799 case DW_FORM_GNU_str_index
:
9800 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9802 case DW_FORM_indirect
:
9803 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9804 info_ptr
+= bytes_read
;
9805 /* We need to continue parsing from here, so just go back to
9807 goto skip_attribute
;
9810 error (_("Dwarf Error: Cannot handle %s "
9811 "in DWARF reader [in module %s]"),
9812 dwarf_form_name (form
),
9813 bfd_get_filename (abfd
));
9817 if (abbrev
->has_children
)
9818 return skip_children (reader
, info_ptr
);
9823 /* Locate ORIG_PDI's sibling.
9824 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9826 static const gdb_byte
*
9827 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9828 struct partial_die_info
*orig_pdi
,
9829 const gdb_byte
*info_ptr
)
9831 /* Do we know the sibling already? */
9833 if (orig_pdi
->sibling
)
9834 return orig_pdi
->sibling
;
9836 /* Are there any children to deal with? */
9838 if (!orig_pdi
->has_children
)
9841 /* Skip the children the long way. */
9843 return skip_children (reader
, info_ptr
);
9846 /* Expand this partial symbol table into a full symbol table. SELF is
9850 dwarf2_read_symtab (struct partial_symtab
*self
,
9851 struct objfile
*objfile
)
9853 struct dwarf2_per_objfile
*dwarf2_per_objfile
9854 = get_dwarf2_per_objfile (objfile
);
9858 warning (_("bug: psymtab for %s is already read in."),
9865 printf_filtered (_("Reading in symbols for %s..."),
9867 gdb_flush (gdb_stdout
);
9870 /* If this psymtab is constructed from a debug-only objfile, the
9871 has_section_at_zero flag will not necessarily be correct. We
9872 can get the correct value for this flag by looking at the data
9873 associated with the (presumably stripped) associated objfile. */
9874 if (objfile
->separate_debug_objfile_backlink
)
9876 struct dwarf2_per_objfile
*dpo_backlink
9877 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9879 dwarf2_per_objfile
->has_section_at_zero
9880 = dpo_backlink
->has_section_at_zero
;
9883 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9885 psymtab_to_symtab_1 (self
);
9887 /* Finish up the debug error message. */
9889 printf_filtered (_("done.\n"));
9892 process_cu_includes (dwarf2_per_objfile
);
9895 /* Reading in full CUs. */
9897 /* Add PER_CU to the queue. */
9900 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9901 enum language pretend_language
)
9903 struct dwarf2_queue_item
*item
;
9906 item
= XNEW (struct dwarf2_queue_item
);
9907 item
->per_cu
= per_cu
;
9908 item
->pretend_language
= pretend_language
;
9911 if (dwarf2_queue
== NULL
)
9912 dwarf2_queue
= item
;
9914 dwarf2_queue_tail
->next
= item
;
9916 dwarf2_queue_tail
= item
;
9919 /* If PER_CU is not yet queued, add it to the queue.
9920 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9922 The result is non-zero if PER_CU was queued, otherwise the result is zero
9923 meaning either PER_CU is already queued or it is already loaded.
9925 N.B. There is an invariant here that if a CU is queued then it is loaded.
9926 The caller is required to load PER_CU if we return non-zero. */
9929 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9930 struct dwarf2_per_cu_data
*per_cu
,
9931 enum language pretend_language
)
9933 /* We may arrive here during partial symbol reading, if we need full
9934 DIEs to process an unusual case (e.g. template arguments). Do
9935 not queue PER_CU, just tell our caller to load its DIEs. */
9936 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9938 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9943 /* Mark the dependence relation so that we don't flush PER_CU
9945 if (dependent_cu
!= NULL
)
9946 dwarf2_add_dependence (dependent_cu
, per_cu
);
9948 /* If it's already on the queue, we have nothing to do. */
9952 /* If the compilation unit is already loaded, just mark it as
9954 if (per_cu
->cu
!= NULL
)
9956 per_cu
->cu
->last_used
= 0;
9960 /* Add it to the queue. */
9961 queue_comp_unit (per_cu
, pretend_language
);
9966 /* Process the queue. */
9969 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9971 struct dwarf2_queue_item
*item
, *next_item
;
9973 if (dwarf_read_debug
)
9975 fprintf_unfiltered (gdb_stdlog
,
9976 "Expanding one or more symtabs of objfile %s ...\n",
9977 objfile_name (dwarf2_per_objfile
->objfile
));
9980 /* The queue starts out with one item, but following a DIE reference
9981 may load a new CU, adding it to the end of the queue. */
9982 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9984 if ((dwarf2_per_objfile
->using_index
9985 ? !item
->per_cu
->v
.quick
->compunit_symtab
9986 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9987 /* Skip dummy CUs. */
9988 && item
->per_cu
->cu
!= NULL
)
9990 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9991 unsigned int debug_print_threshold
;
9994 if (per_cu
->is_debug_types
)
9996 struct signatured_type
*sig_type
=
9997 (struct signatured_type
*) per_cu
;
9999 sprintf (buf
, "TU %s at offset %s",
10000 hex_string (sig_type
->signature
),
10001 sect_offset_str (per_cu
->sect_off
));
10002 /* There can be 100s of TUs.
10003 Only print them in verbose mode. */
10004 debug_print_threshold
= 2;
10008 sprintf (buf
, "CU at offset %s",
10009 sect_offset_str (per_cu
->sect_off
));
10010 debug_print_threshold
= 1;
10013 if (dwarf_read_debug
>= debug_print_threshold
)
10014 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
10016 if (per_cu
->is_debug_types
)
10017 process_full_type_unit (per_cu
, item
->pretend_language
);
10019 process_full_comp_unit (per_cu
, item
->pretend_language
);
10021 if (dwarf_read_debug
>= debug_print_threshold
)
10022 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
10025 item
->per_cu
->queued
= 0;
10026 next_item
= item
->next
;
10030 dwarf2_queue_tail
= NULL
;
10032 if (dwarf_read_debug
)
10034 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
10035 objfile_name (dwarf2_per_objfile
->objfile
));
10039 /* Read in full symbols for PST, and anything it depends on. */
10042 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
10044 struct dwarf2_per_cu_data
*per_cu
;
10050 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
10051 if (!pst
->dependencies
[i
]->readin
10052 && pst
->dependencies
[i
]->user
== NULL
)
10054 /* Inform about additional files that need to be read in. */
10057 /* FIXME: i18n: Need to make this a single string. */
10058 fputs_filtered (" ", gdb_stdout
);
10060 fputs_filtered ("and ", gdb_stdout
);
10062 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
10063 wrap_here (""); /* Flush output. */
10064 gdb_flush (gdb_stdout
);
10066 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
10069 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
10071 if (per_cu
== NULL
)
10073 /* It's an include file, no symbols to read for it.
10074 Everything is in the parent symtab. */
10079 dw2_do_instantiate_symtab (per_cu
);
10082 /* Trivial hash function for die_info: the hash value of a DIE
10083 is its offset in .debug_info for this objfile. */
10086 die_hash (const void *item
)
10088 const struct die_info
*die
= (const struct die_info
*) item
;
10090 return to_underlying (die
->sect_off
);
10093 /* Trivial comparison function for die_info structures: two DIEs
10094 are equal if they have the same offset. */
10097 die_eq (const void *item_lhs
, const void *item_rhs
)
10099 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
10100 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
10102 return die_lhs
->sect_off
== die_rhs
->sect_off
;
10105 /* die_reader_func for load_full_comp_unit.
10106 This is identical to read_signatured_type_reader,
10107 but is kept separate for now. */
10110 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
10111 const gdb_byte
*info_ptr
,
10112 struct die_info
*comp_unit_die
,
10116 struct dwarf2_cu
*cu
= reader
->cu
;
10117 enum language
*language_ptr
= (enum language
*) data
;
10119 gdb_assert (cu
->die_hash
== NULL
);
10121 htab_create_alloc_ex (cu
->header
.length
/ 12,
10125 &cu
->comp_unit_obstack
,
10126 hashtab_obstack_allocate
,
10127 dummy_obstack_deallocate
);
10130 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
10131 &info_ptr
, comp_unit_die
);
10132 cu
->dies
= comp_unit_die
;
10133 /* comp_unit_die is not stored in die_hash, no need. */
10135 /* We try not to read any attributes in this function, because not
10136 all CUs needed for references have been loaded yet, and symbol
10137 table processing isn't initialized. But we have to set the CU language,
10138 or we won't be able to build types correctly.
10139 Similarly, if we do not read the producer, we can not apply
10140 producer-specific interpretation. */
10141 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
10144 /* Load the DIEs associated with PER_CU into memory. */
10147 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10148 enum language pretend_language
)
10150 gdb_assert (! this_cu
->is_debug_types
);
10152 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
10153 load_full_comp_unit_reader
, &pretend_language
);
10156 /* Add a DIE to the delayed physname list. */
10159 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
10160 const char *name
, struct die_info
*die
,
10161 struct dwarf2_cu
*cu
)
10163 struct delayed_method_info mi
;
10165 mi
.fnfield_index
= fnfield_index
;
10169 cu
->method_list
.push_back (mi
);
10172 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
10173 "const" / "volatile". If so, decrements LEN by the length of the
10174 modifier and return true. Otherwise return false. */
10178 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
10180 size_t mod_len
= sizeof (mod
) - 1;
10181 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
10189 /* Compute the physnames of any methods on the CU's method list.
10191 The computation of method physnames is delayed in order to avoid the
10192 (bad) condition that one of the method's formal parameters is of an as yet
10193 incomplete type. */
10196 compute_delayed_physnames (struct dwarf2_cu
*cu
)
10198 /* Only C++ delays computing physnames. */
10199 if (cu
->method_list
.empty ())
10201 gdb_assert (cu
->language
== language_cplus
);
10203 for (struct delayed_method_info
&mi
: cu
->method_list
)
10205 const char *physname
;
10206 struct fn_fieldlist
*fn_flp
10207 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
10208 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
10209 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
10210 = physname
? physname
: "";
10212 /* Since there's no tag to indicate whether a method is a
10213 const/volatile overload, extract that information out of the
10215 if (physname
!= NULL
)
10217 size_t len
= strlen (physname
);
10221 if (physname
[len
] == ')') /* shortcut */
10223 else if (check_modifier (physname
, len
, " const"))
10224 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
10225 else if (check_modifier (physname
, len
, " volatile"))
10226 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
10233 /* The list is no longer needed. */
10234 cu
->method_list
.clear ();
10237 /* Go objects should be embedded in a DW_TAG_module DIE,
10238 and it's not clear if/how imported objects will appear.
10239 To keep Go support simple until that's worked out,
10240 go back through what we've read and create something usable.
10241 We could do this while processing each DIE, and feels kinda cleaner,
10242 but that way is more invasive.
10243 This is to, for example, allow the user to type "p var" or "b main"
10244 without having to specify the package name, and allow lookups
10245 of module.object to work in contexts that use the expression
10249 fixup_go_packaging (struct dwarf2_cu
*cu
)
10251 char *package_name
= NULL
;
10252 struct pending
*list
;
10255 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
10257 for (i
= 0; i
< list
->nsyms
; ++i
)
10259 struct symbol
*sym
= list
->symbol
[i
];
10261 if (SYMBOL_LANGUAGE (sym
) == language_go
10262 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
10264 char *this_package_name
= go_symbol_package_name (sym
);
10266 if (this_package_name
== NULL
)
10268 if (package_name
== NULL
)
10269 package_name
= this_package_name
;
10272 struct objfile
*objfile
10273 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10274 if (strcmp (package_name
, this_package_name
) != 0)
10275 complaint (&symfile_complaints
,
10276 _("Symtab %s has objects from two different Go packages: %s and %s"),
10277 (symbol_symtab (sym
) != NULL
10278 ? symtab_to_filename_for_display
10279 (symbol_symtab (sym
))
10280 : objfile_name (objfile
)),
10281 this_package_name
, package_name
);
10282 xfree (this_package_name
);
10288 if (package_name
!= NULL
)
10290 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10291 const char *saved_package_name
10292 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10294 strlen (package_name
));
10295 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
10296 saved_package_name
);
10297 struct symbol
*sym
;
10299 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10301 sym
= allocate_symbol (objfile
);
10302 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
10303 SYMBOL_SET_NAMES (sym
, saved_package_name
,
10304 strlen (saved_package_name
), 0, objfile
);
10305 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
10306 e.g., "main" finds the "main" module and not C's main(). */
10307 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10308 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
10309 SYMBOL_TYPE (sym
) = type
;
10311 add_symbol_to_list (sym
, &global_symbols
);
10313 xfree (package_name
);
10317 /* Allocate a fully-qualified name consisting of the two parts on the
10320 static const char *
10321 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
10323 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
10326 /* A helper that allocates a struct discriminant_info to attach to a
10329 static struct discriminant_info
*
10330 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
10333 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10334 gdb_assert (discriminant_index
== -1
10335 || (discriminant_index
>= 0
10336 && discriminant_index
< TYPE_NFIELDS (type
)));
10337 gdb_assert (default_index
== -1
10338 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
10340 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
10342 struct discriminant_info
*disc
10343 = ((struct discriminant_info
*)
10345 offsetof (struct discriminant_info
, discriminants
)
10346 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
10347 disc
->default_index
= default_index
;
10348 disc
->discriminant_index
= discriminant_index
;
10350 struct dynamic_prop prop
;
10351 prop
.kind
= PROP_UNDEFINED
;
10352 prop
.data
.baton
= disc
;
10354 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
10359 /* Some versions of rustc emitted enums in an unusual way.
10361 Ordinary enums were emitted as unions. The first element of each
10362 structure in the union was named "RUST$ENUM$DISR". This element
10363 held the discriminant.
10365 These versions of Rust also implemented the "non-zero"
10366 optimization. When the enum had two values, and one is empty and
10367 the other holds a pointer that cannot be zero, the pointer is used
10368 as the discriminant, with a zero value meaning the empty variant.
10369 Here, the union's first member is of the form
10370 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10371 where the fieldnos are the indices of the fields that should be
10372 traversed in order to find the field (which may be several fields deep)
10373 and the variantname is the name of the variant of the case when the
10376 This function recognizes whether TYPE is of one of these forms,
10377 and, if so, smashes it to be a variant type. */
10380 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10382 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10384 /* We don't need to deal with empty enums. */
10385 if (TYPE_NFIELDS (type
) == 0)
10388 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10389 if (TYPE_NFIELDS (type
) == 1
10390 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10392 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10394 /* Decode the field name to find the offset of the
10396 ULONGEST bit_offset
= 0;
10397 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10398 while (name
[0] >= '0' && name
[0] <= '9')
10401 unsigned long index
= strtoul (name
, &tail
, 10);
10404 || index
>= TYPE_NFIELDS (field_type
)
10405 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10406 != FIELD_LOC_KIND_BITPOS
))
10408 complaint (&symfile_complaints
,
10409 _("Could not parse Rust enum encoding string \"%s\""
10411 TYPE_FIELD_NAME (type
, 0),
10412 objfile_name (objfile
));
10417 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10418 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10421 /* Make a union to hold the variants. */
10422 struct type
*union_type
= alloc_type (objfile
);
10423 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10424 TYPE_NFIELDS (union_type
) = 3;
10425 TYPE_FIELDS (union_type
)
10426 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10427 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10429 /* Put the discriminant must at index 0. */
10430 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10431 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10432 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10433 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10435 /* The order of fields doesn't really matter, so put the real
10436 field at index 1 and the data-less field at index 2. */
10437 struct discriminant_info
*disc
10438 = alloc_discriminant_info (union_type
, 0, 1);
10439 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10440 TYPE_FIELD_NAME (union_type
, 1)
10441 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10442 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10443 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10444 TYPE_FIELD_NAME (union_type
, 1));
10446 const char *dataless_name
10447 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10449 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10451 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10452 /* NAME points into the original discriminant name, which
10453 already has the correct lifetime. */
10454 TYPE_FIELD_NAME (union_type
, 2) = name
;
10455 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10456 disc
->discriminants
[2] = 0;
10458 /* Smash this type to be a structure type. We have to do this
10459 because the type has already been recorded. */
10460 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10461 TYPE_NFIELDS (type
) = 1;
10463 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10465 /* Install the variant part. */
10466 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10467 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10468 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10470 else if (TYPE_NFIELDS (type
) == 1)
10472 /* We assume that a union with a single field is a univariant
10474 /* Smash this type to be a structure type. We have to do this
10475 because the type has already been recorded. */
10476 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10478 /* Make a union to hold the variants. */
10479 struct type
*union_type
= alloc_type (objfile
);
10480 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10481 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10482 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10483 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10485 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10486 const char *variant_name
10487 = rust_last_path_segment (TYPE_NAME (field_type
));
10488 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10489 TYPE_NAME (field_type
)
10490 = rust_fully_qualify (&objfile
->objfile_obstack
,
10491 TYPE_NAME (type
), variant_name
);
10493 /* Install the union in the outer struct type. */
10494 TYPE_NFIELDS (type
) = 1;
10496 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10497 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10498 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10499 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10501 alloc_discriminant_info (union_type
, -1, 0);
10505 struct type
*disr_type
= nullptr;
10506 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10508 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10510 if (TYPE_NFIELDS (disr_type
) == 0)
10512 /* Could be data-less variant, so keep going. */
10514 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10515 "RUST$ENUM$DISR") != 0)
10517 /* Not a Rust enum. */
10527 /* If we got here without a discriminant, then it's probably
10529 if (disr_type
== nullptr)
10532 /* Smash this type to be a structure type. We have to do this
10533 because the type has already been recorded. */
10534 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10536 /* Make a union to hold the variants. */
10537 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10538 struct type
*union_type
= alloc_type (objfile
);
10539 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10540 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10541 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10542 TYPE_FIELDS (union_type
)
10543 = (struct field
*) TYPE_ZALLOC (union_type
,
10544 (TYPE_NFIELDS (union_type
)
10545 * sizeof (struct field
)));
10547 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10548 TYPE_NFIELDS (type
) * sizeof (struct field
));
10550 /* Install the discriminant at index 0 in the union. */
10551 TYPE_FIELD (union_type
, 0) = *disr_field
;
10552 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10553 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10555 /* Install the union in the outer struct type. */
10556 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10557 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10558 TYPE_NFIELDS (type
) = 1;
10560 /* Set the size and offset of the union type. */
10561 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10563 /* We need a way to find the correct discriminant given a
10564 variant name. For convenience we build a map here. */
10565 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10566 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10567 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10569 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10572 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10573 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10577 int n_fields
= TYPE_NFIELDS (union_type
);
10578 struct discriminant_info
*disc
10579 = alloc_discriminant_info (union_type
, 0, -1);
10580 /* Skip the discriminant here. */
10581 for (int i
= 1; i
< n_fields
; ++i
)
10583 /* Find the final word in the name of this variant's type.
10584 That name can be used to look up the correct
10586 const char *variant_name
10587 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10590 auto iter
= discriminant_map
.find (variant_name
);
10591 if (iter
!= discriminant_map
.end ())
10592 disc
->discriminants
[i
] = iter
->second
;
10594 /* Remove the discriminant field. */
10595 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10596 --TYPE_NFIELDS (sub_type
);
10597 ++TYPE_FIELDS (sub_type
);
10598 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10599 TYPE_NAME (sub_type
)
10600 = rust_fully_qualify (&objfile
->objfile_obstack
,
10601 TYPE_NAME (type
), variant_name
);
10606 /* Rewrite some Rust unions to be structures with variants parts. */
10609 rust_union_quirks (struct dwarf2_cu
*cu
)
10611 gdb_assert (cu
->language
== language_rust
);
10612 for (struct type
*type
: cu
->rust_unions
)
10613 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10616 /* Return the symtab for PER_CU. This works properly regardless of
10617 whether we're using the index or psymtabs. */
10619 static struct compunit_symtab
*
10620 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10622 return (per_cu
->dwarf2_per_objfile
->using_index
10623 ? per_cu
->v
.quick
->compunit_symtab
10624 : per_cu
->v
.psymtab
->compunit_symtab
);
10627 /* A helper function for computing the list of all symbol tables
10628 included by PER_CU. */
10631 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10632 htab_t all_children
, htab_t all_type_symtabs
,
10633 struct dwarf2_per_cu_data
*per_cu
,
10634 struct compunit_symtab
*immediate_parent
)
10638 struct compunit_symtab
*cust
;
10639 struct dwarf2_per_cu_data
*iter
;
10641 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10644 /* This inclusion and its children have been processed. */
10649 /* Only add a CU if it has a symbol table. */
10650 cust
= get_compunit_symtab (per_cu
);
10653 /* If this is a type unit only add its symbol table if we haven't
10654 seen it yet (type unit per_cu's can share symtabs). */
10655 if (per_cu
->is_debug_types
)
10657 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10661 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10662 if (cust
->user
== NULL
)
10663 cust
->user
= immediate_parent
;
10668 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10669 if (cust
->user
== NULL
)
10670 cust
->user
= immediate_parent
;
10675 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10678 recursively_compute_inclusions (result
, all_children
,
10679 all_type_symtabs
, iter
, cust
);
10683 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10687 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10689 gdb_assert (! per_cu
->is_debug_types
);
10691 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10694 struct dwarf2_per_cu_data
*per_cu_iter
;
10695 struct compunit_symtab
*compunit_symtab_iter
;
10696 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10697 htab_t all_children
, all_type_symtabs
;
10698 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10700 /* If we don't have a symtab, we can just skip this case. */
10704 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10705 NULL
, xcalloc
, xfree
);
10706 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10707 NULL
, xcalloc
, xfree
);
10710 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10714 recursively_compute_inclusions (&result_symtabs
, all_children
,
10715 all_type_symtabs
, per_cu_iter
,
10719 /* Now we have a transitive closure of all the included symtabs. */
10720 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10722 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10723 struct compunit_symtab
*, len
+ 1);
10725 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10726 compunit_symtab_iter
);
10728 cust
->includes
[ix
] = compunit_symtab_iter
;
10729 cust
->includes
[len
] = NULL
;
10731 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10732 htab_delete (all_children
);
10733 htab_delete (all_type_symtabs
);
10737 /* Compute the 'includes' field for the symtabs of all the CUs we just
10741 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10744 struct dwarf2_per_cu_data
*iter
;
10747 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10751 if (! iter
->is_debug_types
)
10752 compute_compunit_symtab_includes (iter
);
10755 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10758 /* Generate full symbol information for PER_CU, whose DIEs have
10759 already been loaded into memory. */
10762 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10763 enum language pretend_language
)
10765 struct dwarf2_cu
*cu
= per_cu
->cu
;
10766 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10767 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10768 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10769 CORE_ADDR lowpc
, highpc
;
10770 struct compunit_symtab
*cust
;
10771 CORE_ADDR baseaddr
;
10772 struct block
*static_block
;
10775 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10778 scoped_free_pendings free_pending
;
10780 /* Clear the list here in case something was left over. */
10781 cu
->method_list
.clear ();
10783 cu
->list_in_scope
= &file_symbols
;
10785 cu
->language
= pretend_language
;
10786 cu
->language_defn
= language_def (cu
->language
);
10788 /* Do line number decoding in read_file_scope () */
10789 process_die (cu
->dies
, cu
);
10791 /* For now fudge the Go package. */
10792 if (cu
->language
== language_go
)
10793 fixup_go_packaging (cu
);
10795 /* Now that we have processed all the DIEs in the CU, all the types
10796 should be complete, and it should now be safe to compute all of the
10798 compute_delayed_physnames (cu
);
10800 if (cu
->language
== language_rust
)
10801 rust_union_quirks (cu
);
10803 /* Some compilers don't define a DW_AT_high_pc attribute for the
10804 compilation unit. If the DW_AT_high_pc is missing, synthesize
10805 it, by scanning the DIE's below the compilation unit. */
10806 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10808 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10809 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10811 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10812 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10813 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10814 addrmap to help ensure it has an accurate map of pc values belonging to
10816 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10818 cust
= end_symtab_from_static_block (static_block
,
10819 SECT_OFF_TEXT (objfile
), 0);
10823 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10825 /* Set symtab language to language from DW_AT_language. If the
10826 compilation is from a C file generated by language preprocessors, do
10827 not set the language if it was already deduced by start_subfile. */
10828 if (!(cu
->language
== language_c
10829 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10830 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10832 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10833 produce DW_AT_location with location lists but it can be possibly
10834 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10835 there were bugs in prologue debug info, fixed later in GCC-4.5
10836 by "unwind info for epilogues" patch (which is not directly related).
10838 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10839 needed, it would be wrong due to missing DW_AT_producer there.
10841 Still one can confuse GDB by using non-standard GCC compilation
10842 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10844 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10845 cust
->locations_valid
= 1;
10847 if (gcc_4_minor
>= 5)
10848 cust
->epilogue_unwind_valid
= 1;
10850 cust
->call_site_htab
= cu
->call_site_htab
;
10853 if (dwarf2_per_objfile
->using_index
)
10854 per_cu
->v
.quick
->compunit_symtab
= cust
;
10857 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10858 pst
->compunit_symtab
= cust
;
10862 /* Push it for inclusion processing later. */
10863 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10866 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10867 already been loaded into memory. */
10870 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10871 enum language pretend_language
)
10873 struct dwarf2_cu
*cu
= per_cu
->cu
;
10874 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10875 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10876 struct compunit_symtab
*cust
;
10877 struct signatured_type
*sig_type
;
10879 gdb_assert (per_cu
->is_debug_types
);
10880 sig_type
= (struct signatured_type
*) per_cu
;
10883 scoped_free_pendings free_pending
;
10885 /* Clear the list here in case something was left over. */
10886 cu
->method_list
.clear ();
10888 cu
->list_in_scope
= &file_symbols
;
10890 cu
->language
= pretend_language
;
10891 cu
->language_defn
= language_def (cu
->language
);
10893 /* The symbol tables are set up in read_type_unit_scope. */
10894 process_die (cu
->dies
, cu
);
10896 /* For now fudge the Go package. */
10897 if (cu
->language
== language_go
)
10898 fixup_go_packaging (cu
);
10900 /* Now that we have processed all the DIEs in the CU, all the types
10901 should be complete, and it should now be safe to compute all of the
10903 compute_delayed_physnames (cu
);
10905 if (cu
->language
== language_rust
)
10906 rust_union_quirks (cu
);
10908 /* TUs share symbol tables.
10909 If this is the first TU to use this symtab, complete the construction
10910 of it with end_expandable_symtab. Otherwise, complete the addition of
10911 this TU's symbols to the existing symtab. */
10912 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10914 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10915 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10919 /* Set symtab language to language from DW_AT_language. If the
10920 compilation is from a C file generated by language preprocessors,
10921 do not set the language if it was already deduced by
10923 if (!(cu
->language
== language_c
10924 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10925 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10930 augment_type_symtab ();
10931 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10934 if (dwarf2_per_objfile
->using_index
)
10935 per_cu
->v
.quick
->compunit_symtab
= cust
;
10938 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10939 pst
->compunit_symtab
= cust
;
10944 /* Process an imported unit DIE. */
10947 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10949 struct attribute
*attr
;
10951 /* For now we don't handle imported units in type units. */
10952 if (cu
->per_cu
->is_debug_types
)
10954 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10955 " supported in type units [in module %s]"),
10956 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10959 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10962 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10963 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10964 dwarf2_per_cu_data
*per_cu
10965 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10966 cu
->per_cu
->dwarf2_per_objfile
);
10968 /* If necessary, add it to the queue and load its DIEs. */
10969 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10970 load_full_comp_unit (per_cu
, cu
->language
);
10972 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10977 /* RAII object that represents a process_die scope: i.e.,
10978 starts/finishes processing a DIE. */
10979 class process_die_scope
10982 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10983 : m_die (die
), m_cu (cu
)
10985 /* We should only be processing DIEs not already in process. */
10986 gdb_assert (!m_die
->in_process
);
10987 m_die
->in_process
= true;
10990 ~process_die_scope ()
10992 m_die
->in_process
= false;
10994 /* If we're done processing the DIE for the CU that owns the line
10995 header, we don't need the line header anymore. */
10996 if (m_cu
->line_header_die_owner
== m_die
)
10998 delete m_cu
->line_header
;
10999 m_cu
->line_header
= NULL
;
11000 m_cu
->line_header_die_owner
= NULL
;
11009 /* Process a die and its children. */
11012 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11014 process_die_scope
scope (die
, cu
);
11018 case DW_TAG_padding
:
11020 case DW_TAG_compile_unit
:
11021 case DW_TAG_partial_unit
:
11022 read_file_scope (die
, cu
);
11024 case DW_TAG_type_unit
:
11025 read_type_unit_scope (die
, cu
);
11027 case DW_TAG_subprogram
:
11028 case DW_TAG_inlined_subroutine
:
11029 read_func_scope (die
, cu
);
11031 case DW_TAG_lexical_block
:
11032 case DW_TAG_try_block
:
11033 case DW_TAG_catch_block
:
11034 read_lexical_block_scope (die
, cu
);
11036 case DW_TAG_call_site
:
11037 case DW_TAG_GNU_call_site
:
11038 read_call_site_scope (die
, cu
);
11040 case DW_TAG_class_type
:
11041 case DW_TAG_interface_type
:
11042 case DW_TAG_structure_type
:
11043 case DW_TAG_union_type
:
11044 process_structure_scope (die
, cu
);
11046 case DW_TAG_enumeration_type
:
11047 process_enumeration_scope (die
, cu
);
11050 /* These dies have a type, but processing them does not create
11051 a symbol or recurse to process the children. Therefore we can
11052 read them on-demand through read_type_die. */
11053 case DW_TAG_subroutine_type
:
11054 case DW_TAG_set_type
:
11055 case DW_TAG_array_type
:
11056 case DW_TAG_pointer_type
:
11057 case DW_TAG_ptr_to_member_type
:
11058 case DW_TAG_reference_type
:
11059 case DW_TAG_rvalue_reference_type
:
11060 case DW_TAG_string_type
:
11063 case DW_TAG_base_type
:
11064 case DW_TAG_subrange_type
:
11065 case DW_TAG_typedef
:
11066 /* Add a typedef symbol for the type definition, if it has a
11068 new_symbol (die
, read_type_die (die
, cu
), cu
);
11070 case DW_TAG_common_block
:
11071 read_common_block (die
, cu
);
11073 case DW_TAG_common_inclusion
:
11075 case DW_TAG_namespace
:
11076 cu
->processing_has_namespace_info
= 1;
11077 read_namespace (die
, cu
);
11079 case DW_TAG_module
:
11080 cu
->processing_has_namespace_info
= 1;
11081 read_module (die
, cu
);
11083 case DW_TAG_imported_declaration
:
11084 cu
->processing_has_namespace_info
= 1;
11085 if (read_namespace_alias (die
, cu
))
11087 /* The declaration is not a global namespace alias: fall through. */
11088 case DW_TAG_imported_module
:
11089 cu
->processing_has_namespace_info
= 1;
11090 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
11091 || cu
->language
!= language_fortran
))
11092 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
11093 dwarf_tag_name (die
->tag
));
11094 read_import_statement (die
, cu
);
11097 case DW_TAG_imported_unit
:
11098 process_imported_unit_die (die
, cu
);
11101 case DW_TAG_variable
:
11102 read_variable (die
, cu
);
11106 new_symbol (die
, NULL
, cu
);
11111 /* DWARF name computation. */
11113 /* A helper function for dwarf2_compute_name which determines whether DIE
11114 needs to have the name of the scope prepended to the name listed in the
11118 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11120 struct attribute
*attr
;
11124 case DW_TAG_namespace
:
11125 case DW_TAG_typedef
:
11126 case DW_TAG_class_type
:
11127 case DW_TAG_interface_type
:
11128 case DW_TAG_structure_type
:
11129 case DW_TAG_union_type
:
11130 case DW_TAG_enumeration_type
:
11131 case DW_TAG_enumerator
:
11132 case DW_TAG_subprogram
:
11133 case DW_TAG_inlined_subroutine
:
11134 case DW_TAG_member
:
11135 case DW_TAG_imported_declaration
:
11138 case DW_TAG_variable
:
11139 case DW_TAG_constant
:
11140 /* We only need to prefix "globally" visible variables. These include
11141 any variable marked with DW_AT_external or any variable that
11142 lives in a namespace. [Variables in anonymous namespaces
11143 require prefixing, but they are not DW_AT_external.] */
11145 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
11147 struct dwarf2_cu
*spec_cu
= cu
;
11149 return die_needs_namespace (die_specification (die
, &spec_cu
),
11153 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11154 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
11155 && die
->parent
->tag
!= DW_TAG_module
)
11157 /* A variable in a lexical block of some kind does not need a
11158 namespace, even though in C++ such variables may be external
11159 and have a mangled name. */
11160 if (die
->parent
->tag
== DW_TAG_lexical_block
11161 || die
->parent
->tag
== DW_TAG_try_block
11162 || die
->parent
->tag
== DW_TAG_catch_block
11163 || die
->parent
->tag
== DW_TAG_subprogram
)
11172 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
11173 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
11174 defined for the given DIE. */
11176 static struct attribute
*
11177 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
11179 struct attribute
*attr
;
11181 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
11183 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
11188 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
11189 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
11190 defined for the given DIE. */
11192 static const char *
11193 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11195 const char *linkage_name
;
11197 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
11198 if (linkage_name
== NULL
)
11199 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
11201 return linkage_name
;
11204 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
11205 compute the physname for the object, which include a method's:
11206 - formal parameters (C++),
11207 - receiver type (Go),
11209 The term "physname" is a bit confusing.
11210 For C++, for example, it is the demangled name.
11211 For Go, for example, it's the mangled name.
11213 For Ada, return the DIE's linkage name rather than the fully qualified
11214 name. PHYSNAME is ignored..
11216 The result is allocated on the objfile_obstack and canonicalized. */
11218 static const char *
11219 dwarf2_compute_name (const char *name
,
11220 struct die_info
*die
, struct dwarf2_cu
*cu
,
11223 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11226 name
= dwarf2_name (die
, cu
);
11228 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
11229 but otherwise compute it by typename_concat inside GDB.
11230 FIXME: Actually this is not really true, or at least not always true.
11231 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
11232 Fortran names because there is no mangling standard. So new_symbol
11233 will set the demangled name to the result of dwarf2_full_name, and it is
11234 the demangled name that GDB uses if it exists. */
11235 if (cu
->language
== language_ada
11236 || (cu
->language
== language_fortran
&& physname
))
11238 /* For Ada unit, we prefer the linkage name over the name, as
11239 the former contains the exported name, which the user expects
11240 to be able to reference. Ideally, we want the user to be able
11241 to reference this entity using either natural or linkage name,
11242 but we haven't started looking at this enhancement yet. */
11243 const char *linkage_name
= dw2_linkage_name (die
, cu
);
11245 if (linkage_name
!= NULL
)
11246 return linkage_name
;
11249 /* These are the only languages we know how to qualify names in. */
11251 && (cu
->language
== language_cplus
11252 || cu
->language
== language_fortran
|| cu
->language
== language_d
11253 || cu
->language
== language_rust
))
11255 if (die_needs_namespace (die
, cu
))
11257 const char *prefix
;
11258 const char *canonical_name
= NULL
;
11262 prefix
= determine_prefix (die
, cu
);
11263 if (*prefix
!= '\0')
11265 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
11268 buf
.puts (prefixed_name
);
11269 xfree (prefixed_name
);
11274 /* Template parameters may be specified in the DIE's DW_AT_name, or
11275 as children with DW_TAG_template_type_param or
11276 DW_TAG_value_type_param. If the latter, add them to the name
11277 here. If the name already has template parameters, then
11278 skip this step; some versions of GCC emit both, and
11279 it is more efficient to use the pre-computed name.
11281 Something to keep in mind about this process: it is very
11282 unlikely, or in some cases downright impossible, to produce
11283 something that will match the mangled name of a function.
11284 If the definition of the function has the same debug info,
11285 we should be able to match up with it anyway. But fallbacks
11286 using the minimal symbol, for instance to find a method
11287 implemented in a stripped copy of libstdc++, will not work.
11288 If we do not have debug info for the definition, we will have to
11289 match them up some other way.
11291 When we do name matching there is a related problem with function
11292 templates; two instantiated function templates are allowed to
11293 differ only by their return types, which we do not add here. */
11295 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
11297 struct attribute
*attr
;
11298 struct die_info
*child
;
11301 die
->building_fullname
= 1;
11303 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
11307 const gdb_byte
*bytes
;
11308 struct dwarf2_locexpr_baton
*baton
;
11311 if (child
->tag
!= DW_TAG_template_type_param
11312 && child
->tag
!= DW_TAG_template_value_param
)
11323 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
11326 complaint (&symfile_complaints
,
11327 _("template parameter missing DW_AT_type"));
11328 buf
.puts ("UNKNOWN_TYPE");
11331 type
= die_type (child
, cu
);
11333 if (child
->tag
== DW_TAG_template_type_param
)
11335 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
11339 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
11342 complaint (&symfile_complaints
,
11343 _("template parameter missing "
11344 "DW_AT_const_value"));
11345 buf
.puts ("UNKNOWN_VALUE");
11349 dwarf2_const_value_attr (attr
, type
, name
,
11350 &cu
->comp_unit_obstack
, cu
,
11351 &value
, &bytes
, &baton
);
11353 if (TYPE_NOSIGN (type
))
11354 /* GDB prints characters as NUMBER 'CHAR'. If that's
11355 changed, this can use value_print instead. */
11356 c_printchar (value
, type
, &buf
);
11359 struct value_print_options opts
;
11362 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
11366 else if (bytes
!= NULL
)
11368 v
= allocate_value (type
);
11369 memcpy (value_contents_writeable (v
), bytes
,
11370 TYPE_LENGTH (type
));
11373 v
= value_from_longest (type
, value
);
11375 /* Specify decimal so that we do not depend on
11377 get_formatted_print_options (&opts
, 'd');
11379 value_print (v
, &buf
, &opts
);
11385 die
->building_fullname
= 0;
11389 /* Close the argument list, with a space if necessary
11390 (nested templates). */
11391 if (!buf
.empty () && buf
.string ().back () == '>')
11398 /* For C++ methods, append formal parameter type
11399 information, if PHYSNAME. */
11401 if (physname
&& die
->tag
== DW_TAG_subprogram
11402 && cu
->language
== language_cplus
)
11404 struct type
*type
= read_type_die (die
, cu
);
11406 c_type_print_args (type
, &buf
, 1, cu
->language
,
11407 &type_print_raw_options
);
11409 if (cu
->language
== language_cplus
)
11411 /* Assume that an artificial first parameter is
11412 "this", but do not crash if it is not. RealView
11413 marks unnamed (and thus unused) parameters as
11414 artificial; there is no way to differentiate
11416 if (TYPE_NFIELDS (type
) > 0
11417 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11418 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11419 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11421 buf
.puts (" const");
11425 const std::string
&intermediate_name
= buf
.string ();
11427 if (cu
->language
== language_cplus
)
11429 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11430 &objfile
->per_bfd
->storage_obstack
);
11432 /* If we only computed INTERMEDIATE_NAME, or if
11433 INTERMEDIATE_NAME is already canonical, then we need to
11434 copy it to the appropriate obstack. */
11435 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11436 name
= ((const char *)
11437 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11438 intermediate_name
.c_str (),
11439 intermediate_name
.length ()));
11441 name
= canonical_name
;
11448 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11449 If scope qualifiers are appropriate they will be added. The result
11450 will be allocated on the storage_obstack, or NULL if the DIE does
11451 not have a name. NAME may either be from a previous call to
11452 dwarf2_name or NULL.
11454 The output string will be canonicalized (if C++). */
11456 static const char *
11457 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11459 return dwarf2_compute_name (name
, die
, cu
, 0);
11462 /* Construct a physname for the given DIE in CU. NAME may either be
11463 from a previous call to dwarf2_name or NULL. The result will be
11464 allocated on the objfile_objstack or NULL if the DIE does not have a
11467 The output string will be canonicalized (if C++). */
11469 static const char *
11470 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11472 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11473 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11476 /* In this case dwarf2_compute_name is just a shortcut not building anything
11478 if (!die_needs_namespace (die
, cu
))
11479 return dwarf2_compute_name (name
, die
, cu
, 1);
11481 mangled
= dw2_linkage_name (die
, cu
);
11483 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11484 See https://github.com/rust-lang/rust/issues/32925. */
11485 if (cu
->language
== language_rust
&& mangled
!= NULL
11486 && strchr (mangled
, '{') != NULL
)
11489 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11491 gdb::unique_xmalloc_ptr
<char> demangled
;
11492 if (mangled
!= NULL
)
11495 if (cu
->language
== language_go
)
11497 /* This is a lie, but we already lie to the caller new_symbol.
11498 new_symbol assumes we return the mangled name.
11499 This just undoes that lie until things are cleaned up. */
11503 /* Use DMGL_RET_DROP for C++ template functions to suppress
11504 their return type. It is easier for GDB users to search
11505 for such functions as `name(params)' than `long name(params)'.
11506 In such case the minimal symbol names do not match the full
11507 symbol names but for template functions there is never a need
11508 to look up their definition from their declaration so
11509 the only disadvantage remains the minimal symbol variant
11510 `long name(params)' does not have the proper inferior type. */
11511 demangled
.reset (gdb_demangle (mangled
,
11512 (DMGL_PARAMS
| DMGL_ANSI
11513 | DMGL_RET_DROP
)));
11516 canon
= demangled
.get ();
11524 if (canon
== NULL
|| check_physname
)
11526 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11528 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11530 /* It may not mean a bug in GDB. The compiler could also
11531 compute DW_AT_linkage_name incorrectly. But in such case
11532 GDB would need to be bug-to-bug compatible. */
11534 complaint (&symfile_complaints
,
11535 _("Computed physname <%s> does not match demangled <%s> "
11536 "(from linkage <%s>) - DIE at %s [in module %s]"),
11537 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11538 objfile_name (objfile
));
11540 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11541 is available here - over computed PHYSNAME. It is safer
11542 against both buggy GDB and buggy compilers. */
11556 retval
= ((const char *)
11557 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11558 retval
, strlen (retval
)));
11563 /* Inspect DIE in CU for a namespace alias. If one exists, record
11564 a new symbol for it.
11566 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11569 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11571 struct attribute
*attr
;
11573 /* If the die does not have a name, this is not a namespace
11575 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11579 struct die_info
*d
= die
;
11580 struct dwarf2_cu
*imported_cu
= cu
;
11582 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11583 keep inspecting DIEs until we hit the underlying import. */
11584 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11585 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11587 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11591 d
= follow_die_ref (d
, attr
, &imported_cu
);
11592 if (d
->tag
!= DW_TAG_imported_declaration
)
11596 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11598 complaint (&symfile_complaints
,
11599 _("DIE at %s has too many recursively imported "
11600 "declarations"), sect_offset_str (d
->sect_off
));
11607 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11609 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11610 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11612 /* This declaration is a global namespace alias. Add
11613 a symbol for it whose type is the aliased namespace. */
11614 new_symbol (die
, type
, cu
);
11623 /* Return the using directives repository (global or local?) to use in the
11624 current context for LANGUAGE.
11626 For Ada, imported declarations can materialize renamings, which *may* be
11627 global. However it is impossible (for now?) in DWARF to distinguish
11628 "external" imported declarations and "static" ones. As all imported
11629 declarations seem to be static in all other languages, make them all CU-wide
11630 global only in Ada. */
11632 static struct using_direct
**
11633 using_directives (enum language language
)
11635 if (language
== language_ada
&& context_stack_depth
== 0)
11636 return &global_using_directives
;
11638 return &local_using_directives
;
11641 /* Read the import statement specified by the given die and record it. */
11644 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11646 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11647 struct attribute
*import_attr
;
11648 struct die_info
*imported_die
, *child_die
;
11649 struct dwarf2_cu
*imported_cu
;
11650 const char *imported_name
;
11651 const char *imported_name_prefix
;
11652 const char *canonical_name
;
11653 const char *import_alias
;
11654 const char *imported_declaration
= NULL
;
11655 const char *import_prefix
;
11656 std::vector
<const char *> excludes
;
11658 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11659 if (import_attr
== NULL
)
11661 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11662 dwarf_tag_name (die
->tag
));
11667 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11668 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11669 if (imported_name
== NULL
)
11671 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11673 The import in the following code:
11687 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11688 <52> DW_AT_decl_file : 1
11689 <53> DW_AT_decl_line : 6
11690 <54> DW_AT_import : <0x75>
11691 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11692 <59> DW_AT_name : B
11693 <5b> DW_AT_decl_file : 1
11694 <5c> DW_AT_decl_line : 2
11695 <5d> DW_AT_type : <0x6e>
11697 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11698 <76> DW_AT_byte_size : 4
11699 <77> DW_AT_encoding : 5 (signed)
11701 imports the wrong die ( 0x75 instead of 0x58 ).
11702 This case will be ignored until the gcc bug is fixed. */
11706 /* Figure out the local name after import. */
11707 import_alias
= dwarf2_name (die
, cu
);
11709 /* Figure out where the statement is being imported to. */
11710 import_prefix
= determine_prefix (die
, cu
);
11712 /* Figure out what the scope of the imported die is and prepend it
11713 to the name of the imported die. */
11714 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11716 if (imported_die
->tag
!= DW_TAG_namespace
11717 && imported_die
->tag
!= DW_TAG_module
)
11719 imported_declaration
= imported_name
;
11720 canonical_name
= imported_name_prefix
;
11722 else if (strlen (imported_name_prefix
) > 0)
11723 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11724 imported_name_prefix
,
11725 (cu
->language
== language_d
? "." : "::"),
11726 imported_name
, (char *) NULL
);
11728 canonical_name
= imported_name
;
11730 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11731 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11732 child_die
= sibling_die (child_die
))
11734 /* DWARF-4: A Fortran use statement with a “rename list” may be
11735 represented by an imported module entry with an import attribute
11736 referring to the module and owned entries corresponding to those
11737 entities that are renamed as part of being imported. */
11739 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11741 complaint (&symfile_complaints
,
11742 _("child DW_TAG_imported_declaration expected "
11743 "- DIE at %s [in module %s]"),
11744 sect_offset_str (child_die
->sect_off
),
11745 objfile_name (objfile
));
11749 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11750 if (import_attr
== NULL
)
11752 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11753 dwarf_tag_name (child_die
->tag
));
11758 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11760 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11761 if (imported_name
== NULL
)
11763 complaint (&symfile_complaints
,
11764 _("child DW_TAG_imported_declaration has unknown "
11765 "imported name - DIE at %s [in module %s]"),
11766 sect_offset_str (child_die
->sect_off
),
11767 objfile_name (objfile
));
11771 excludes
.push_back (imported_name
);
11773 process_die (child_die
, cu
);
11776 add_using_directive (using_directives (cu
->language
),
11780 imported_declaration
,
11783 &objfile
->objfile_obstack
);
11786 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11787 types, but gives them a size of zero. Starting with version 14,
11788 ICC is compatible with GCC. */
11791 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11793 if (!cu
->checked_producer
)
11794 check_producer (cu
);
11796 return cu
->producer_is_icc_lt_14
;
11799 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11800 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11801 this, it was first present in GCC release 4.3.0. */
11804 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11806 if (!cu
->checked_producer
)
11807 check_producer (cu
);
11809 return cu
->producer_is_gcc_lt_4_3
;
11812 static file_and_directory
11813 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11815 file_and_directory res
;
11817 /* Find the filename. Do not use dwarf2_name here, since the filename
11818 is not a source language identifier. */
11819 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11820 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11822 if (res
.comp_dir
== NULL
11823 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11824 && IS_ABSOLUTE_PATH (res
.name
))
11826 res
.comp_dir_storage
= ldirname (res
.name
);
11827 if (!res
.comp_dir_storage
.empty ())
11828 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11830 if (res
.comp_dir
!= NULL
)
11832 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11833 directory, get rid of it. */
11834 const char *cp
= strchr (res
.comp_dir
, ':');
11836 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11837 res
.comp_dir
= cp
+ 1;
11840 if (res
.name
== NULL
)
11841 res
.name
= "<unknown>";
11846 /* Handle DW_AT_stmt_list for a compilation unit.
11847 DIE is the DW_TAG_compile_unit die for CU.
11848 COMP_DIR is the compilation directory. LOWPC is passed to
11849 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11852 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11853 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11855 struct dwarf2_per_objfile
*dwarf2_per_objfile
11856 = cu
->per_cu
->dwarf2_per_objfile
;
11857 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11858 struct attribute
*attr
;
11859 struct line_header line_header_local
;
11860 hashval_t line_header_local_hash
;
11862 int decode_mapping
;
11864 gdb_assert (! cu
->per_cu
->is_debug_types
);
11866 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11870 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11872 /* The line header hash table is only created if needed (it exists to
11873 prevent redundant reading of the line table for partial_units).
11874 If we're given a partial_unit, we'll need it. If we're given a
11875 compile_unit, then use the line header hash table if it's already
11876 created, but don't create one just yet. */
11878 if (dwarf2_per_objfile
->line_header_hash
== NULL
11879 && die
->tag
== DW_TAG_partial_unit
)
11881 dwarf2_per_objfile
->line_header_hash
11882 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11883 line_header_eq_voidp
,
11884 free_line_header_voidp
,
11885 &objfile
->objfile_obstack
,
11886 hashtab_obstack_allocate
,
11887 dummy_obstack_deallocate
);
11890 line_header_local
.sect_off
= line_offset
;
11891 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11892 line_header_local_hash
= line_header_hash (&line_header_local
);
11893 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11895 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11896 &line_header_local
,
11897 line_header_local_hash
, NO_INSERT
);
11899 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11900 is not present in *SLOT (since if there is something in *SLOT then
11901 it will be for a partial_unit). */
11902 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11904 gdb_assert (*slot
!= NULL
);
11905 cu
->line_header
= (struct line_header
*) *slot
;
11910 /* dwarf_decode_line_header does not yet provide sufficient information.
11911 We always have to call also dwarf_decode_lines for it. */
11912 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11916 cu
->line_header
= lh
.release ();
11917 cu
->line_header_die_owner
= die
;
11919 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11923 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11924 &line_header_local
,
11925 line_header_local_hash
, INSERT
);
11926 gdb_assert (slot
!= NULL
);
11928 if (slot
!= NULL
&& *slot
== NULL
)
11930 /* This newly decoded line number information unit will be owned
11931 by line_header_hash hash table. */
11932 *slot
= cu
->line_header
;
11933 cu
->line_header_die_owner
= NULL
;
11937 /* We cannot free any current entry in (*slot) as that struct line_header
11938 may be already used by multiple CUs. Create only temporary decoded
11939 line_header for this CU - it may happen at most once for each line
11940 number information unit. And if we're not using line_header_hash
11941 then this is what we want as well. */
11942 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11944 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11945 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11950 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11953 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11955 struct dwarf2_per_objfile
*dwarf2_per_objfile
11956 = cu
->per_cu
->dwarf2_per_objfile
;
11957 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11958 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11959 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11960 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11961 struct attribute
*attr
;
11962 struct die_info
*child_die
;
11963 CORE_ADDR baseaddr
;
11965 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11967 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11969 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11970 from finish_block. */
11971 if (lowpc
== ((CORE_ADDR
) -1))
11973 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11975 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11977 prepare_one_comp_unit (cu
, die
, cu
->language
);
11979 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11980 standardised yet. As a workaround for the language detection we fall
11981 back to the DW_AT_producer string. */
11982 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11983 cu
->language
= language_opencl
;
11985 /* Similar hack for Go. */
11986 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11987 set_cu_language (DW_LANG_Go
, cu
);
11989 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11991 /* Decode line number information if present. We do this before
11992 processing child DIEs, so that the line header table is available
11993 for DW_AT_decl_file. */
11994 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11996 /* Process all dies in compilation unit. */
11997 if (die
->child
!= NULL
)
11999 child_die
= die
->child
;
12000 while (child_die
&& child_die
->tag
)
12002 process_die (child_die
, cu
);
12003 child_die
= sibling_die (child_die
);
12007 /* Decode macro information, if present. Dwarf 2 macro information
12008 refers to information in the line number info statement program
12009 header, so we can only read it if we've read the header
12011 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
12013 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
12014 if (attr
&& cu
->line_header
)
12016 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
12017 complaint (&symfile_complaints
,
12018 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
12020 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
12024 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
12025 if (attr
&& cu
->line_header
)
12027 unsigned int macro_offset
= DW_UNSND (attr
);
12029 dwarf_decode_macros (cu
, macro_offset
, 0);
12034 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
12035 Create the set of symtabs used by this TU, or if this TU is sharing
12036 symtabs with another TU and the symtabs have already been created
12037 then restore those symtabs in the line header.
12038 We don't need the pc/line-number mapping for type units. */
12041 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
12043 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
12044 struct type_unit_group
*tu_group
;
12046 struct attribute
*attr
;
12048 struct signatured_type
*sig_type
;
12050 gdb_assert (per_cu
->is_debug_types
);
12051 sig_type
= (struct signatured_type
*) per_cu
;
12053 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
12055 /* If we're using .gdb_index (includes -readnow) then
12056 per_cu->type_unit_group may not have been set up yet. */
12057 if (sig_type
->type_unit_group
== NULL
)
12058 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
12059 tu_group
= sig_type
->type_unit_group
;
12061 /* If we've already processed this stmt_list there's no real need to
12062 do it again, we could fake it and just recreate the part we need
12063 (file name,index -> symtab mapping). If data shows this optimization
12064 is useful we can do it then. */
12065 first_time
= tu_group
->compunit_symtab
== NULL
;
12067 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
12072 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
12073 lh
= dwarf_decode_line_header (line_offset
, cu
);
12078 dwarf2_start_symtab (cu
, "", NULL
, 0);
12081 gdb_assert (tu_group
->symtabs
== NULL
);
12082 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12087 cu
->line_header
= lh
.release ();
12088 cu
->line_header_die_owner
= die
;
12092 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
12094 /* Note: We don't assign tu_group->compunit_symtab yet because we're
12095 still initializing it, and our caller (a few levels up)
12096 process_full_type_unit still needs to know if this is the first
12099 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
12100 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
12101 cu
->line_header
->file_names
.size ());
12103 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12105 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12107 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
12109 if (current_subfile
->symtab
== NULL
)
12111 /* NOTE: start_subfile will recognize when it's been
12112 passed a file it has already seen. So we can't
12113 assume there's a simple mapping from
12114 cu->line_header->file_names to subfiles, plus
12115 cu->line_header->file_names may contain dups. */
12116 current_subfile
->symtab
12117 = allocate_symtab (cust
, current_subfile
->name
);
12120 fe
.symtab
= current_subfile
->symtab
;
12121 tu_group
->symtabs
[i
] = fe
.symtab
;
12126 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12128 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12130 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12132 fe
.symtab
= tu_group
->symtabs
[i
];
12136 /* The main symtab is allocated last. Type units don't have DW_AT_name
12137 so they don't have a "real" (so to speak) symtab anyway.
12138 There is later code that will assign the main symtab to all symbols
12139 that don't have one. We need to handle the case of a symbol with a
12140 missing symtab (DW_AT_decl_file) anyway. */
12143 /* Process DW_TAG_type_unit.
12144 For TUs we want to skip the first top level sibling if it's not the
12145 actual type being defined by this TU. In this case the first top
12146 level sibling is there to provide context only. */
12149 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12151 struct die_info
*child_die
;
12153 prepare_one_comp_unit (cu
, die
, language_minimal
);
12155 /* Initialize (or reinitialize) the machinery for building symtabs.
12156 We do this before processing child DIEs, so that the line header table
12157 is available for DW_AT_decl_file. */
12158 setup_type_unit_groups (die
, cu
);
12160 if (die
->child
!= NULL
)
12162 child_die
= die
->child
;
12163 while (child_die
&& child_die
->tag
)
12165 process_die (child_die
, cu
);
12166 child_die
= sibling_die (child_die
);
12173 http://gcc.gnu.org/wiki/DebugFission
12174 http://gcc.gnu.org/wiki/DebugFissionDWP
12176 To simplify handling of both DWO files ("object" files with the DWARF info)
12177 and DWP files (a file with the DWOs packaged up into one file), we treat
12178 DWP files as having a collection of virtual DWO files. */
12181 hash_dwo_file (const void *item
)
12183 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
12186 hash
= htab_hash_string (dwo_file
->dwo_name
);
12187 if (dwo_file
->comp_dir
!= NULL
)
12188 hash
+= htab_hash_string (dwo_file
->comp_dir
);
12193 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
12195 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
12196 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
12198 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
12200 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
12201 return lhs
->comp_dir
== rhs
->comp_dir
;
12202 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
12205 /* Allocate a hash table for DWO files. */
12208 allocate_dwo_file_hash_table (struct objfile
*objfile
)
12210 return htab_create_alloc_ex (41,
12214 &objfile
->objfile_obstack
,
12215 hashtab_obstack_allocate
,
12216 dummy_obstack_deallocate
);
12219 /* Lookup DWO file DWO_NAME. */
12222 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12223 const char *dwo_name
,
12224 const char *comp_dir
)
12226 struct dwo_file find_entry
;
12229 if (dwarf2_per_objfile
->dwo_files
== NULL
)
12230 dwarf2_per_objfile
->dwo_files
12231 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
12233 memset (&find_entry
, 0, sizeof (find_entry
));
12234 find_entry
.dwo_name
= dwo_name
;
12235 find_entry
.comp_dir
= comp_dir
;
12236 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
12242 hash_dwo_unit (const void *item
)
12244 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12246 /* This drops the top 32 bits of the id, but is ok for a hash. */
12247 return dwo_unit
->signature
;
12251 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
12253 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
12254 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
12256 /* The signature is assumed to be unique within the DWO file.
12257 So while object file CU dwo_id's always have the value zero,
12258 that's OK, assuming each object file DWO file has only one CU,
12259 and that's the rule for now. */
12260 return lhs
->signature
== rhs
->signature
;
12263 /* Allocate a hash table for DWO CUs,TUs.
12264 There is one of these tables for each of CUs,TUs for each DWO file. */
12267 allocate_dwo_unit_table (struct objfile
*objfile
)
12269 /* Start out with a pretty small number.
12270 Generally DWO files contain only one CU and maybe some TUs. */
12271 return htab_create_alloc_ex (3,
12275 &objfile
->objfile_obstack
,
12276 hashtab_obstack_allocate
,
12277 dummy_obstack_deallocate
);
12280 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
12282 struct create_dwo_cu_data
12284 struct dwo_file
*dwo_file
;
12285 struct dwo_unit dwo_unit
;
12288 /* die_reader_func for create_dwo_cu. */
12291 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
12292 const gdb_byte
*info_ptr
,
12293 struct die_info
*comp_unit_die
,
12297 struct dwarf2_cu
*cu
= reader
->cu
;
12298 sect_offset sect_off
= cu
->per_cu
->sect_off
;
12299 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
12300 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
12301 struct dwo_file
*dwo_file
= data
->dwo_file
;
12302 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
12303 struct attribute
*attr
;
12305 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
12308 complaint (&symfile_complaints
,
12309 _("Dwarf Error: debug entry at offset %s is missing"
12310 " its dwo_id [in module %s]"),
12311 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
12315 dwo_unit
->dwo_file
= dwo_file
;
12316 dwo_unit
->signature
= DW_UNSND (attr
);
12317 dwo_unit
->section
= section
;
12318 dwo_unit
->sect_off
= sect_off
;
12319 dwo_unit
->length
= cu
->per_cu
->length
;
12321 if (dwarf_read_debug
)
12322 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
12323 sect_offset_str (sect_off
),
12324 hex_string (dwo_unit
->signature
));
12327 /* Create the dwo_units for the CUs in a DWO_FILE.
12328 Note: This function processes DWO files only, not DWP files. */
12331 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12332 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
12335 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12336 const gdb_byte
*info_ptr
, *end_ptr
;
12338 dwarf2_read_section (objfile
, §ion
);
12339 info_ptr
= section
.buffer
;
12341 if (info_ptr
== NULL
)
12344 if (dwarf_read_debug
)
12346 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12347 get_section_name (§ion
),
12348 get_section_file_name (§ion
));
12351 end_ptr
= info_ptr
+ section
.size
;
12352 while (info_ptr
< end_ptr
)
12354 struct dwarf2_per_cu_data per_cu
;
12355 struct create_dwo_cu_data create_dwo_cu_data
;
12356 struct dwo_unit
*dwo_unit
;
12358 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12360 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12361 sizeof (create_dwo_cu_data
.dwo_unit
));
12362 memset (&per_cu
, 0, sizeof (per_cu
));
12363 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12364 per_cu
.is_debug_types
= 0;
12365 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12366 per_cu
.section
= §ion
;
12367 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12369 init_cutu_and_read_dies_no_follow (
12370 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12371 info_ptr
+= per_cu
.length
;
12373 // If the unit could not be parsed, skip it.
12374 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12377 if (cus_htab
== NULL
)
12378 cus_htab
= allocate_dwo_unit_table (objfile
);
12380 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12381 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12382 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12383 gdb_assert (slot
!= NULL
);
12386 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12387 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12389 complaint (&symfile_complaints
,
12390 _("debug cu entry at offset %s is duplicate to"
12391 " the entry at offset %s, signature %s"),
12392 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12393 hex_string (dwo_unit
->signature
));
12395 *slot
= (void *)dwo_unit
;
12399 /* DWP file .debug_{cu,tu}_index section format:
12400 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12404 Both index sections have the same format, and serve to map a 64-bit
12405 signature to a set of section numbers. Each section begins with a header,
12406 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12407 indexes, and a pool of 32-bit section numbers. The index sections will be
12408 aligned at 8-byte boundaries in the file.
12410 The index section header consists of:
12412 V, 32 bit version number
12414 N, 32 bit number of compilation units or type units in the index
12415 M, 32 bit number of slots in the hash table
12417 Numbers are recorded using the byte order of the application binary.
12419 The hash table begins at offset 16 in the section, and consists of an array
12420 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12421 order of the application binary). Unused slots in the hash table are 0.
12422 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12424 The parallel table begins immediately after the hash table
12425 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12426 array of 32-bit indexes (using the byte order of the application binary),
12427 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12428 table contains a 32-bit index into the pool of section numbers. For unused
12429 hash table slots, the corresponding entry in the parallel table will be 0.
12431 The pool of section numbers begins immediately following the hash table
12432 (at offset 16 + 12 * M from the beginning of the section). The pool of
12433 section numbers consists of an array of 32-bit words (using the byte order
12434 of the application binary). Each item in the array is indexed starting
12435 from 0. The hash table entry provides the index of the first section
12436 number in the set. Additional section numbers in the set follow, and the
12437 set is terminated by a 0 entry (section number 0 is not used in ELF).
12439 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12440 section must be the first entry in the set, and the .debug_abbrev.dwo must
12441 be the second entry. Other members of the set may follow in any order.
12447 DWP Version 2 combines all the .debug_info, etc. sections into one,
12448 and the entries in the index tables are now offsets into these sections.
12449 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12452 Index Section Contents:
12454 Hash Table of Signatures dwp_hash_table.hash_table
12455 Parallel Table of Indices dwp_hash_table.unit_table
12456 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12457 Table of Section Sizes dwp_hash_table.v2.sizes
12459 The index section header consists of:
12461 V, 32 bit version number
12462 L, 32 bit number of columns in the table of section offsets
12463 N, 32 bit number of compilation units or type units in the index
12464 M, 32 bit number of slots in the hash table
12466 Numbers are recorded using the byte order of the application binary.
12468 The hash table has the same format as version 1.
12469 The parallel table of indices has the same format as version 1,
12470 except that the entries are origin-1 indices into the table of sections
12471 offsets and the table of section sizes.
12473 The table of offsets begins immediately following the parallel table
12474 (at offset 16 + 12 * M from the beginning of the section). The table is
12475 a two-dimensional array of 32-bit words (using the byte order of the
12476 application binary), with L columns and N+1 rows, in row-major order.
12477 Each row in the array is indexed starting from 0. The first row provides
12478 a key to the remaining rows: each column in this row provides an identifier
12479 for a debug section, and the offsets in the same column of subsequent rows
12480 refer to that section. The section identifiers are:
12482 DW_SECT_INFO 1 .debug_info.dwo
12483 DW_SECT_TYPES 2 .debug_types.dwo
12484 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12485 DW_SECT_LINE 4 .debug_line.dwo
12486 DW_SECT_LOC 5 .debug_loc.dwo
12487 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12488 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12489 DW_SECT_MACRO 8 .debug_macro.dwo
12491 The offsets provided by the CU and TU index sections are the base offsets
12492 for the contributions made by each CU or TU to the corresponding section
12493 in the package file. Each CU and TU header contains an abbrev_offset
12494 field, used to find the abbreviations table for that CU or TU within the
12495 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12496 be interpreted as relative to the base offset given in the index section.
12497 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12498 should be interpreted as relative to the base offset for .debug_line.dwo,
12499 and offsets into other debug sections obtained from DWARF attributes should
12500 also be interpreted as relative to the corresponding base offset.
12502 The table of sizes begins immediately following the table of offsets.
12503 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12504 with L columns and N rows, in row-major order. Each row in the array is
12505 indexed starting from 1 (row 0 is shared by the two tables).
12509 Hash table lookup is handled the same in version 1 and 2:
12511 We assume that N and M will not exceed 2^32 - 1.
12512 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12514 Given a 64-bit compilation unit signature or a type signature S, an entry
12515 in the hash table is located as follows:
12517 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12518 the low-order k bits all set to 1.
12520 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12522 3) If the hash table entry at index H matches the signature, use that
12523 entry. If the hash table entry at index H is unused (all zeroes),
12524 terminate the search: the signature is not present in the table.
12526 4) Let H = (H + H') modulo M. Repeat at Step 3.
12528 Because M > N and H' and M are relatively prime, the search is guaranteed
12529 to stop at an unused slot or find the match. */
12531 /* Create a hash table to map DWO IDs to their CU/TU entry in
12532 .debug_{info,types}.dwo in DWP_FILE.
12533 Returns NULL if there isn't one.
12534 Note: This function processes DWP files only, not DWO files. */
12536 static struct dwp_hash_table
*
12537 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12538 struct dwp_file
*dwp_file
, int is_debug_types
)
12540 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12541 bfd
*dbfd
= dwp_file
->dbfd
;
12542 const gdb_byte
*index_ptr
, *index_end
;
12543 struct dwarf2_section_info
*index
;
12544 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12545 struct dwp_hash_table
*htab
;
12547 if (is_debug_types
)
12548 index
= &dwp_file
->sections
.tu_index
;
12550 index
= &dwp_file
->sections
.cu_index
;
12552 if (dwarf2_section_empty_p (index
))
12554 dwarf2_read_section (objfile
, index
);
12556 index_ptr
= index
->buffer
;
12557 index_end
= index_ptr
+ index
->size
;
12559 version
= read_4_bytes (dbfd
, index_ptr
);
12562 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12566 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12568 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12571 if (version
!= 1 && version
!= 2)
12573 error (_("Dwarf Error: unsupported DWP file version (%s)"
12574 " [in module %s]"),
12575 pulongest (version
), dwp_file
->name
);
12577 if (nr_slots
!= (nr_slots
& -nr_slots
))
12579 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12580 " is not power of 2 [in module %s]"),
12581 pulongest (nr_slots
), dwp_file
->name
);
12584 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12585 htab
->version
= version
;
12586 htab
->nr_columns
= nr_columns
;
12587 htab
->nr_units
= nr_units
;
12588 htab
->nr_slots
= nr_slots
;
12589 htab
->hash_table
= index_ptr
;
12590 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12592 /* Exit early if the table is empty. */
12593 if (nr_slots
== 0 || nr_units
== 0
12594 || (version
== 2 && nr_columns
== 0))
12596 /* All must be zero. */
12597 if (nr_slots
!= 0 || nr_units
!= 0
12598 || (version
== 2 && nr_columns
!= 0))
12600 complaint (&symfile_complaints
,
12601 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12602 " all zero [in modules %s]"),
12610 htab
->section_pool
.v1
.indices
=
12611 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12612 /* It's harder to decide whether the section is too small in v1.
12613 V1 is deprecated anyway so we punt. */
12617 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12618 int *ids
= htab
->section_pool
.v2
.section_ids
;
12619 /* Reverse map for error checking. */
12620 int ids_seen
[DW_SECT_MAX
+ 1];
12623 if (nr_columns
< 2)
12625 error (_("Dwarf Error: bad DWP hash table, too few columns"
12626 " in section table [in module %s]"),
12629 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12631 error (_("Dwarf Error: bad DWP hash table, too many columns"
12632 " in section table [in module %s]"),
12635 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12636 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12637 for (i
= 0; i
< nr_columns
; ++i
)
12639 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12641 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12643 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12644 " in section table [in module %s]"),
12645 id
, dwp_file
->name
);
12647 if (ids_seen
[id
] != -1)
12649 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12650 " id %d in section table [in module %s]"),
12651 id
, dwp_file
->name
);
12656 /* Must have exactly one info or types section. */
12657 if (((ids_seen
[DW_SECT_INFO
] != -1)
12658 + (ids_seen
[DW_SECT_TYPES
] != -1))
12661 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12662 " DWO info/types section [in module %s]"),
12665 /* Must have an abbrev section. */
12666 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12668 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12669 " section [in module %s]"),
12672 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12673 htab
->section_pool
.v2
.sizes
=
12674 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12675 * nr_units
* nr_columns
);
12676 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12677 * nr_units
* nr_columns
))
12680 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12681 " [in module %s]"),
12689 /* Update SECTIONS with the data from SECTP.
12691 This function is like the other "locate" section routines that are
12692 passed to bfd_map_over_sections, but in this context the sections to
12693 read comes from the DWP V1 hash table, not the full ELF section table.
12695 The result is non-zero for success, or zero if an error was found. */
12698 locate_v1_virtual_dwo_sections (asection
*sectp
,
12699 struct virtual_v1_dwo_sections
*sections
)
12701 const struct dwop_section_names
*names
= &dwop_section_names
;
12703 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12705 /* There can be only one. */
12706 if (sections
->abbrev
.s
.section
!= NULL
)
12708 sections
->abbrev
.s
.section
= sectp
;
12709 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12711 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12712 || section_is_p (sectp
->name
, &names
->types_dwo
))
12714 /* There can be only one. */
12715 if (sections
->info_or_types
.s
.section
!= NULL
)
12717 sections
->info_or_types
.s
.section
= sectp
;
12718 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12720 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12722 /* There can be only one. */
12723 if (sections
->line
.s
.section
!= NULL
)
12725 sections
->line
.s
.section
= sectp
;
12726 sections
->line
.size
= bfd_get_section_size (sectp
);
12728 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12730 /* There can be only one. */
12731 if (sections
->loc
.s
.section
!= NULL
)
12733 sections
->loc
.s
.section
= sectp
;
12734 sections
->loc
.size
= bfd_get_section_size (sectp
);
12736 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12738 /* There can be only one. */
12739 if (sections
->macinfo
.s
.section
!= NULL
)
12741 sections
->macinfo
.s
.section
= sectp
;
12742 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12744 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12746 /* There can be only one. */
12747 if (sections
->macro
.s
.section
!= NULL
)
12749 sections
->macro
.s
.section
= sectp
;
12750 sections
->macro
.size
= bfd_get_section_size (sectp
);
12752 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12754 /* There can be only one. */
12755 if (sections
->str_offsets
.s
.section
!= NULL
)
12757 sections
->str_offsets
.s
.section
= sectp
;
12758 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12762 /* No other kind of section is valid. */
12769 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12770 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12771 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12772 This is for DWP version 1 files. */
12774 static struct dwo_unit
*
12775 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12776 struct dwp_file
*dwp_file
,
12777 uint32_t unit_index
,
12778 const char *comp_dir
,
12779 ULONGEST signature
, int is_debug_types
)
12781 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12782 const struct dwp_hash_table
*dwp_htab
=
12783 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12784 bfd
*dbfd
= dwp_file
->dbfd
;
12785 const char *kind
= is_debug_types
? "TU" : "CU";
12786 struct dwo_file
*dwo_file
;
12787 struct dwo_unit
*dwo_unit
;
12788 struct virtual_v1_dwo_sections sections
;
12789 void **dwo_file_slot
;
12792 gdb_assert (dwp_file
->version
== 1);
12794 if (dwarf_read_debug
)
12796 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12798 pulongest (unit_index
), hex_string (signature
),
12802 /* Fetch the sections of this DWO unit.
12803 Put a limit on the number of sections we look for so that bad data
12804 doesn't cause us to loop forever. */
12806 #define MAX_NR_V1_DWO_SECTIONS \
12807 (1 /* .debug_info or .debug_types */ \
12808 + 1 /* .debug_abbrev */ \
12809 + 1 /* .debug_line */ \
12810 + 1 /* .debug_loc */ \
12811 + 1 /* .debug_str_offsets */ \
12812 + 1 /* .debug_macro or .debug_macinfo */ \
12813 + 1 /* trailing zero */)
12815 memset (§ions
, 0, sizeof (sections
));
12817 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12820 uint32_t section_nr
=
12821 read_4_bytes (dbfd
,
12822 dwp_htab
->section_pool
.v1
.indices
12823 + (unit_index
+ i
) * sizeof (uint32_t));
12825 if (section_nr
== 0)
12827 if (section_nr
>= dwp_file
->num_sections
)
12829 error (_("Dwarf Error: bad DWP hash table, section number too large"
12830 " [in module %s]"),
12834 sectp
= dwp_file
->elf_sections
[section_nr
];
12835 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12837 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12838 " [in module %s]"),
12844 || dwarf2_section_empty_p (§ions
.info_or_types
)
12845 || dwarf2_section_empty_p (§ions
.abbrev
))
12847 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12848 " [in module %s]"),
12851 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12853 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12854 " [in module %s]"),
12858 /* It's easier for the rest of the code if we fake a struct dwo_file and
12859 have dwo_unit "live" in that. At least for now.
12861 The DWP file can be made up of a random collection of CUs and TUs.
12862 However, for each CU + set of TUs that came from the same original DWO
12863 file, we can combine them back into a virtual DWO file to save space
12864 (fewer struct dwo_file objects to allocate). Remember that for really
12865 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12867 std::string virtual_dwo_name
=
12868 string_printf ("virtual-dwo/%d-%d-%d-%d",
12869 get_section_id (§ions
.abbrev
),
12870 get_section_id (§ions
.line
),
12871 get_section_id (§ions
.loc
),
12872 get_section_id (§ions
.str_offsets
));
12873 /* Can we use an existing virtual DWO file? */
12874 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12875 virtual_dwo_name
.c_str (),
12877 /* Create one if necessary. */
12878 if (*dwo_file_slot
== NULL
)
12880 if (dwarf_read_debug
)
12882 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12883 virtual_dwo_name
.c_str ());
12885 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12887 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12888 virtual_dwo_name
.c_str (),
12889 virtual_dwo_name
.size ());
12890 dwo_file
->comp_dir
= comp_dir
;
12891 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12892 dwo_file
->sections
.line
= sections
.line
;
12893 dwo_file
->sections
.loc
= sections
.loc
;
12894 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12895 dwo_file
->sections
.macro
= sections
.macro
;
12896 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12897 /* The "str" section is global to the entire DWP file. */
12898 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12899 /* The info or types section is assigned below to dwo_unit,
12900 there's no need to record it in dwo_file.
12901 Also, we can't simply record type sections in dwo_file because
12902 we record a pointer into the vector in dwo_unit. As we collect more
12903 types we'll grow the vector and eventually have to reallocate space
12904 for it, invalidating all copies of pointers into the previous
12906 *dwo_file_slot
= dwo_file
;
12910 if (dwarf_read_debug
)
12912 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12913 virtual_dwo_name
.c_str ());
12915 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12918 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12919 dwo_unit
->dwo_file
= dwo_file
;
12920 dwo_unit
->signature
= signature
;
12921 dwo_unit
->section
=
12922 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12923 *dwo_unit
->section
= sections
.info_or_types
;
12924 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12929 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12930 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12931 piece within that section used by a TU/CU, return a virtual section
12932 of just that piece. */
12934 static struct dwarf2_section_info
12935 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12936 struct dwarf2_section_info
*section
,
12937 bfd_size_type offset
, bfd_size_type size
)
12939 struct dwarf2_section_info result
;
12942 gdb_assert (section
!= NULL
);
12943 gdb_assert (!section
->is_virtual
);
12945 memset (&result
, 0, sizeof (result
));
12946 result
.s
.containing_section
= section
;
12947 result
.is_virtual
= 1;
12952 sectp
= get_section_bfd_section (section
);
12954 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12955 bounds of the real section. This is a pretty-rare event, so just
12956 flag an error (easier) instead of a warning and trying to cope. */
12958 || offset
+ size
> bfd_get_section_size (sectp
))
12960 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12961 " in section %s [in module %s]"),
12962 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12963 objfile_name (dwarf2_per_objfile
->objfile
));
12966 result
.virtual_offset
= offset
;
12967 result
.size
= size
;
12971 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12972 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12973 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12974 This is for DWP version 2 files. */
12976 static struct dwo_unit
*
12977 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12978 struct dwp_file
*dwp_file
,
12979 uint32_t unit_index
,
12980 const char *comp_dir
,
12981 ULONGEST signature
, int is_debug_types
)
12983 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12984 const struct dwp_hash_table
*dwp_htab
=
12985 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12986 bfd
*dbfd
= dwp_file
->dbfd
;
12987 const char *kind
= is_debug_types
? "TU" : "CU";
12988 struct dwo_file
*dwo_file
;
12989 struct dwo_unit
*dwo_unit
;
12990 struct virtual_v2_dwo_sections sections
;
12991 void **dwo_file_slot
;
12994 gdb_assert (dwp_file
->version
== 2);
12996 if (dwarf_read_debug
)
12998 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
13000 pulongest (unit_index
), hex_string (signature
),
13004 /* Fetch the section offsets of this DWO unit. */
13006 memset (§ions
, 0, sizeof (sections
));
13008 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
13010 uint32_t offset
= read_4_bytes (dbfd
,
13011 dwp_htab
->section_pool
.v2
.offsets
13012 + (((unit_index
- 1) * dwp_htab
->nr_columns
13014 * sizeof (uint32_t)));
13015 uint32_t size
= read_4_bytes (dbfd
,
13016 dwp_htab
->section_pool
.v2
.sizes
13017 + (((unit_index
- 1) * dwp_htab
->nr_columns
13019 * sizeof (uint32_t)));
13021 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
13024 case DW_SECT_TYPES
:
13025 sections
.info_or_types_offset
= offset
;
13026 sections
.info_or_types_size
= size
;
13028 case DW_SECT_ABBREV
:
13029 sections
.abbrev_offset
= offset
;
13030 sections
.abbrev_size
= size
;
13033 sections
.line_offset
= offset
;
13034 sections
.line_size
= size
;
13037 sections
.loc_offset
= offset
;
13038 sections
.loc_size
= size
;
13040 case DW_SECT_STR_OFFSETS
:
13041 sections
.str_offsets_offset
= offset
;
13042 sections
.str_offsets_size
= size
;
13044 case DW_SECT_MACINFO
:
13045 sections
.macinfo_offset
= offset
;
13046 sections
.macinfo_size
= size
;
13048 case DW_SECT_MACRO
:
13049 sections
.macro_offset
= offset
;
13050 sections
.macro_size
= size
;
13055 /* It's easier for the rest of the code if we fake a struct dwo_file and
13056 have dwo_unit "live" in that. At least for now.
13058 The DWP file can be made up of a random collection of CUs and TUs.
13059 However, for each CU + set of TUs that came from the same original DWO
13060 file, we can combine them back into a virtual DWO file to save space
13061 (fewer struct dwo_file objects to allocate). Remember that for really
13062 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
13064 std::string virtual_dwo_name
=
13065 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
13066 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
13067 (long) (sections
.line_size
? sections
.line_offset
: 0),
13068 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
13069 (long) (sections
.str_offsets_size
13070 ? sections
.str_offsets_offset
: 0));
13071 /* Can we use an existing virtual DWO file? */
13072 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13073 virtual_dwo_name
.c_str (),
13075 /* Create one if necessary. */
13076 if (*dwo_file_slot
== NULL
)
13078 if (dwarf_read_debug
)
13080 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
13081 virtual_dwo_name
.c_str ());
13083 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13085 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
13086 virtual_dwo_name
.c_str (),
13087 virtual_dwo_name
.size ());
13088 dwo_file
->comp_dir
= comp_dir
;
13089 dwo_file
->sections
.abbrev
=
13090 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
13091 sections
.abbrev_offset
, sections
.abbrev_size
);
13092 dwo_file
->sections
.line
=
13093 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
13094 sections
.line_offset
, sections
.line_size
);
13095 dwo_file
->sections
.loc
=
13096 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
13097 sections
.loc_offset
, sections
.loc_size
);
13098 dwo_file
->sections
.macinfo
=
13099 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
13100 sections
.macinfo_offset
, sections
.macinfo_size
);
13101 dwo_file
->sections
.macro
=
13102 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
13103 sections
.macro_offset
, sections
.macro_size
);
13104 dwo_file
->sections
.str_offsets
=
13105 create_dwp_v2_section (dwarf2_per_objfile
,
13106 &dwp_file
->sections
.str_offsets
,
13107 sections
.str_offsets_offset
,
13108 sections
.str_offsets_size
);
13109 /* The "str" section is global to the entire DWP file. */
13110 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
13111 /* The info or types section is assigned below to dwo_unit,
13112 there's no need to record it in dwo_file.
13113 Also, we can't simply record type sections in dwo_file because
13114 we record a pointer into the vector in dwo_unit. As we collect more
13115 types we'll grow the vector and eventually have to reallocate space
13116 for it, invalidating all copies of pointers into the previous
13118 *dwo_file_slot
= dwo_file
;
13122 if (dwarf_read_debug
)
13124 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
13125 virtual_dwo_name
.c_str ());
13127 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13130 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
13131 dwo_unit
->dwo_file
= dwo_file
;
13132 dwo_unit
->signature
= signature
;
13133 dwo_unit
->section
=
13134 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
13135 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
13137 ? &dwp_file
->sections
.types
13138 : &dwp_file
->sections
.info
,
13139 sections
.info_or_types_offset
,
13140 sections
.info_or_types_size
);
13141 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
13146 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
13147 Returns NULL if the signature isn't found. */
13149 static struct dwo_unit
*
13150 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13151 struct dwp_file
*dwp_file
, const char *comp_dir
,
13152 ULONGEST signature
, int is_debug_types
)
13154 const struct dwp_hash_table
*dwp_htab
=
13155 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13156 bfd
*dbfd
= dwp_file
->dbfd
;
13157 uint32_t mask
= dwp_htab
->nr_slots
- 1;
13158 uint32_t hash
= signature
& mask
;
13159 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
13162 struct dwo_unit find_dwo_cu
;
13164 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
13165 find_dwo_cu
.signature
= signature
;
13166 slot
= htab_find_slot (is_debug_types
13167 ? dwp_file
->loaded_tus
13168 : dwp_file
->loaded_cus
,
13169 &find_dwo_cu
, INSERT
);
13172 return (struct dwo_unit
*) *slot
;
13174 /* Use a for loop so that we don't loop forever on bad debug info. */
13175 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
13177 ULONGEST signature_in_table
;
13179 signature_in_table
=
13180 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
13181 if (signature_in_table
== signature
)
13183 uint32_t unit_index
=
13184 read_4_bytes (dbfd
,
13185 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
13187 if (dwp_file
->version
== 1)
13189 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
13190 dwp_file
, unit_index
,
13191 comp_dir
, signature
,
13196 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
13197 dwp_file
, unit_index
,
13198 comp_dir
, signature
,
13201 return (struct dwo_unit
*) *slot
;
13203 if (signature_in_table
== 0)
13205 hash
= (hash
+ hash2
) & mask
;
13208 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
13209 " [in module %s]"),
13213 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
13214 Open the file specified by FILE_NAME and hand it off to BFD for
13215 preliminary analysis. Return a newly initialized bfd *, which
13216 includes a canonicalized copy of FILE_NAME.
13217 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
13218 SEARCH_CWD is true if the current directory is to be searched.
13219 It will be searched before debug-file-directory.
13220 If successful, the file is added to the bfd include table of the
13221 objfile's bfd (see gdb_bfd_record_inclusion).
13222 If unable to find/open the file, return NULL.
13223 NOTE: This function is derived from symfile_bfd_open. */
13225 static gdb_bfd_ref_ptr
13226 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13227 const char *file_name
, int is_dwp
, int search_cwd
)
13230 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
13231 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
13232 to debug_file_directory. */
13233 const char *search_path
;
13234 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
13236 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
13239 if (*debug_file_directory
!= '\0')
13241 search_path_holder
.reset (concat (".", dirname_separator_string
,
13242 debug_file_directory
,
13244 search_path
= search_path_holder
.get ();
13250 search_path
= debug_file_directory
;
13252 openp_flags flags
= OPF_RETURN_REALPATH
;
13254 flags
|= OPF_SEARCH_IN_PATH
;
13256 gdb::unique_xmalloc_ptr
<char> absolute_name
;
13257 desc
= openp (search_path
, flags
, file_name
,
13258 O_RDONLY
| O_BINARY
, &absolute_name
);
13262 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
13264 if (sym_bfd
== NULL
)
13266 bfd_set_cacheable (sym_bfd
.get (), 1);
13268 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
13271 /* Success. Record the bfd as having been included by the objfile's bfd.
13272 This is important because things like demangled_names_hash lives in the
13273 objfile's per_bfd space and may have references to things like symbol
13274 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
13275 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
13280 /* Try to open DWO file FILE_NAME.
13281 COMP_DIR is the DW_AT_comp_dir attribute.
13282 The result is the bfd handle of the file.
13283 If there is a problem finding or opening the file, return NULL.
13284 Upon success, the canonicalized path of the file is stored in the bfd,
13285 same as symfile_bfd_open. */
13287 static gdb_bfd_ref_ptr
13288 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13289 const char *file_name
, const char *comp_dir
)
13291 if (IS_ABSOLUTE_PATH (file_name
))
13292 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13293 0 /*is_dwp*/, 0 /*search_cwd*/);
13295 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
13297 if (comp_dir
!= NULL
)
13299 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
13300 file_name
, (char *) NULL
);
13302 /* NOTE: If comp_dir is a relative path, this will also try the
13303 search path, which seems useful. */
13304 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
13307 1 /*search_cwd*/));
13308 xfree (path_to_try
);
13313 /* That didn't work, try debug-file-directory, which, despite its name,
13314 is a list of paths. */
13316 if (*debug_file_directory
== '\0')
13319 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13320 0 /*is_dwp*/, 1 /*search_cwd*/);
13323 /* This function is mapped across the sections and remembers the offset and
13324 size of each of the DWO debugging sections we are interested in. */
13327 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
13329 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
13330 const struct dwop_section_names
*names
= &dwop_section_names
;
13332 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13334 dwo_sections
->abbrev
.s
.section
= sectp
;
13335 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
13337 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13339 dwo_sections
->info
.s
.section
= sectp
;
13340 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
13342 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13344 dwo_sections
->line
.s
.section
= sectp
;
13345 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
13347 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13349 dwo_sections
->loc
.s
.section
= sectp
;
13350 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
13352 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13354 dwo_sections
->macinfo
.s
.section
= sectp
;
13355 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
13357 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13359 dwo_sections
->macro
.s
.section
= sectp
;
13360 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
13362 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13364 dwo_sections
->str
.s
.section
= sectp
;
13365 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
13367 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13369 dwo_sections
->str_offsets
.s
.section
= sectp
;
13370 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
13372 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13374 struct dwarf2_section_info type_section
;
13376 memset (&type_section
, 0, sizeof (type_section
));
13377 type_section
.s
.section
= sectp
;
13378 type_section
.size
= bfd_get_section_size (sectp
);
13379 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
13384 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13385 by PER_CU. This is for the non-DWP case.
13386 The result is NULL if DWO_NAME can't be found. */
13388 static struct dwo_file
*
13389 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13390 const char *dwo_name
, const char *comp_dir
)
13392 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13393 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13394 struct dwo_file
*dwo_file
;
13395 struct cleanup
*cleanups
;
13397 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
13400 if (dwarf_read_debug
)
13401 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13404 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13405 dwo_file
->dwo_name
= dwo_name
;
13406 dwo_file
->comp_dir
= comp_dir
;
13407 dwo_file
->dbfd
= dbfd
.release ();
13409 free_dwo_file_cleanup_data
*cleanup_data
= XNEW (free_dwo_file_cleanup_data
);
13410 cleanup_data
->dwo_file
= dwo_file
;
13411 cleanup_data
->dwarf2_per_objfile
= dwarf2_per_objfile
;
13413 cleanups
= make_cleanup (free_dwo_file_cleanup
, cleanup_data
);
13415 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13416 &dwo_file
->sections
);
13418 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13421 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
,
13422 dwo_file
->sections
.types
, dwo_file
->tus
);
13424 discard_cleanups (cleanups
);
13426 if (dwarf_read_debug
)
13427 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13432 /* This function is mapped across the sections and remembers the offset and
13433 size of each of the DWP debugging sections common to version 1 and 2 that
13434 we are interested in. */
13437 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13438 void *dwp_file_ptr
)
13440 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13441 const struct dwop_section_names
*names
= &dwop_section_names
;
13442 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13444 /* Record the ELF section number for later lookup: this is what the
13445 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13446 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13447 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13449 /* Look for specific sections that we need. */
13450 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13452 dwp_file
->sections
.str
.s
.section
= sectp
;
13453 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13455 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13457 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13458 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13460 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13462 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13463 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13467 /* This function is mapped across the sections and remembers the offset and
13468 size of each of the DWP version 2 debugging sections that we are interested
13469 in. This is split into a separate function because we don't know if we
13470 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13473 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13475 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13476 const struct dwop_section_names
*names
= &dwop_section_names
;
13477 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13479 /* Record the ELF section number for later lookup: this is what the
13480 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13481 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13482 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13484 /* Look for specific sections that we need. */
13485 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13487 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13488 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13490 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13492 dwp_file
->sections
.info
.s
.section
= sectp
;
13493 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13495 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13497 dwp_file
->sections
.line
.s
.section
= sectp
;
13498 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13500 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13502 dwp_file
->sections
.loc
.s
.section
= sectp
;
13503 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13505 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13507 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13508 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13510 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13512 dwp_file
->sections
.macro
.s
.section
= sectp
;
13513 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13515 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13517 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13518 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13520 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13522 dwp_file
->sections
.types
.s
.section
= sectp
;
13523 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13527 /* Hash function for dwp_file loaded CUs/TUs. */
13530 hash_dwp_loaded_cutus (const void *item
)
13532 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13534 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13535 return dwo_unit
->signature
;
13538 /* Equality function for dwp_file loaded CUs/TUs. */
13541 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13543 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13544 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13546 return dua
->signature
== dub
->signature
;
13549 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13552 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13554 return htab_create_alloc_ex (3,
13555 hash_dwp_loaded_cutus
,
13556 eq_dwp_loaded_cutus
,
13558 &objfile
->objfile_obstack
,
13559 hashtab_obstack_allocate
,
13560 dummy_obstack_deallocate
);
13563 /* Try to open DWP file FILE_NAME.
13564 The result is the bfd handle of the file.
13565 If there is a problem finding or opening the file, return NULL.
13566 Upon success, the canonicalized path of the file is stored in the bfd,
13567 same as symfile_bfd_open. */
13569 static gdb_bfd_ref_ptr
13570 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13571 const char *file_name
)
13573 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13575 1 /*search_cwd*/));
13579 /* Work around upstream bug 15652.
13580 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13581 [Whether that's a "bug" is debatable, but it is getting in our way.]
13582 We have no real idea where the dwp file is, because gdb's realpath-ing
13583 of the executable's path may have discarded the needed info.
13584 [IWBN if the dwp file name was recorded in the executable, akin to
13585 .gnu_debuglink, but that doesn't exist yet.]
13586 Strip the directory from FILE_NAME and search again. */
13587 if (*debug_file_directory
!= '\0')
13589 /* Don't implicitly search the current directory here.
13590 If the user wants to search "." to handle this case,
13591 it must be added to debug-file-directory. */
13592 return try_open_dwop_file (dwarf2_per_objfile
,
13593 lbasename (file_name
), 1 /*is_dwp*/,
13600 /* Initialize the use of the DWP file for the current objfile.
13601 By convention the name of the DWP file is ${objfile}.dwp.
13602 The result is NULL if it can't be found. */
13604 static struct dwp_file
*
13605 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13607 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13608 struct dwp_file
*dwp_file
;
13610 /* Try to find first .dwp for the binary file before any symbolic links
13613 /* If the objfile is a debug file, find the name of the real binary
13614 file and get the name of dwp file from there. */
13615 std::string dwp_name
;
13616 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13618 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13619 const char *backlink_basename
= lbasename (backlink
->original_name
);
13621 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13624 dwp_name
= objfile
->original_name
;
13626 dwp_name
+= ".dwp";
13628 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13630 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13632 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13633 dwp_name
= objfile_name (objfile
);
13634 dwp_name
+= ".dwp";
13635 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13640 if (dwarf_read_debug
)
13641 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13644 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13645 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13646 dwp_file
->dbfd
= dbfd
.release ();
13648 /* +1: section 0 is unused */
13649 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13650 dwp_file
->elf_sections
=
13651 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13652 dwp_file
->num_sections
, asection
*);
13654 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13657 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13659 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13661 /* The DWP file version is stored in the hash table. Oh well. */
13662 if (dwp_file
->cus
&& dwp_file
->tus
13663 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13665 /* Technically speaking, we should try to limp along, but this is
13666 pretty bizarre. We use pulongest here because that's the established
13667 portability solution (e.g, we cannot use %u for uint32_t). */
13668 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13669 " TU version %s [in DWP file %s]"),
13670 pulongest (dwp_file
->cus
->version
),
13671 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13675 dwp_file
->version
= dwp_file
->cus
->version
;
13676 else if (dwp_file
->tus
)
13677 dwp_file
->version
= dwp_file
->tus
->version
;
13679 dwp_file
->version
= 2;
13681 if (dwp_file
->version
== 2)
13682 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13685 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13686 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13688 if (dwarf_read_debug
)
13690 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13691 fprintf_unfiltered (gdb_stdlog
,
13692 " %s CUs, %s TUs\n",
13693 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13694 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13700 /* Wrapper around open_and_init_dwp_file, only open it once. */
13702 static struct dwp_file
*
13703 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13705 if (! dwarf2_per_objfile
->dwp_checked
)
13707 dwarf2_per_objfile
->dwp_file
13708 = open_and_init_dwp_file (dwarf2_per_objfile
);
13709 dwarf2_per_objfile
->dwp_checked
= 1;
13711 return dwarf2_per_objfile
->dwp_file
;
13714 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13715 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13716 or in the DWP file for the objfile, referenced by THIS_UNIT.
13717 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13718 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13720 This is called, for example, when wanting to read a variable with a
13721 complex location. Therefore we don't want to do file i/o for every call.
13722 Therefore we don't want to look for a DWO file on every call.
13723 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13724 then we check if we've already seen DWO_NAME, and only THEN do we check
13727 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13728 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13730 static struct dwo_unit
*
13731 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13732 const char *dwo_name
, const char *comp_dir
,
13733 ULONGEST signature
, int is_debug_types
)
13735 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13736 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13737 const char *kind
= is_debug_types
? "TU" : "CU";
13738 void **dwo_file_slot
;
13739 struct dwo_file
*dwo_file
;
13740 struct dwp_file
*dwp_file
;
13742 /* First see if there's a DWP file.
13743 If we have a DWP file but didn't find the DWO inside it, don't
13744 look for the original DWO file. It makes gdb behave differently
13745 depending on whether one is debugging in the build tree. */
13747 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13748 if (dwp_file
!= NULL
)
13750 const struct dwp_hash_table
*dwp_htab
=
13751 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13753 if (dwp_htab
!= NULL
)
13755 struct dwo_unit
*dwo_cutu
=
13756 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13757 signature
, is_debug_types
);
13759 if (dwo_cutu
!= NULL
)
13761 if (dwarf_read_debug
)
13763 fprintf_unfiltered (gdb_stdlog
,
13764 "Virtual DWO %s %s found: @%s\n",
13765 kind
, hex_string (signature
),
13766 host_address_to_string (dwo_cutu
));
13774 /* No DWP file, look for the DWO file. */
13776 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13777 dwo_name
, comp_dir
);
13778 if (*dwo_file_slot
== NULL
)
13780 /* Read in the file and build a table of the CUs/TUs it contains. */
13781 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13783 /* NOTE: This will be NULL if unable to open the file. */
13784 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13786 if (dwo_file
!= NULL
)
13788 struct dwo_unit
*dwo_cutu
= NULL
;
13790 if (is_debug_types
&& dwo_file
->tus
)
13792 struct dwo_unit find_dwo_cutu
;
13794 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13795 find_dwo_cutu
.signature
= signature
;
13797 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13799 else if (!is_debug_types
&& dwo_file
->cus
)
13801 struct dwo_unit find_dwo_cutu
;
13803 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13804 find_dwo_cutu
.signature
= signature
;
13805 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13809 if (dwo_cutu
!= NULL
)
13811 if (dwarf_read_debug
)
13813 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13814 kind
, dwo_name
, hex_string (signature
),
13815 host_address_to_string (dwo_cutu
));
13822 /* We didn't find it. This could mean a dwo_id mismatch, or
13823 someone deleted the DWO/DWP file, or the search path isn't set up
13824 correctly to find the file. */
13826 if (dwarf_read_debug
)
13828 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13829 kind
, dwo_name
, hex_string (signature
));
13832 /* This is a warning and not a complaint because it can be caused by
13833 pilot error (e.g., user accidentally deleting the DWO). */
13835 /* Print the name of the DWP file if we looked there, helps the user
13836 better diagnose the problem. */
13837 std::string dwp_text
;
13839 if (dwp_file
!= NULL
)
13840 dwp_text
= string_printf (" [in DWP file %s]",
13841 lbasename (dwp_file
->name
));
13843 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13844 " [in module %s]"),
13845 kind
, dwo_name
, hex_string (signature
),
13847 this_unit
->is_debug_types
? "TU" : "CU",
13848 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13853 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13854 See lookup_dwo_cutu_unit for details. */
13856 static struct dwo_unit
*
13857 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13858 const char *dwo_name
, const char *comp_dir
,
13859 ULONGEST signature
)
13861 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13864 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13865 See lookup_dwo_cutu_unit for details. */
13867 static struct dwo_unit
*
13868 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13869 const char *dwo_name
, const char *comp_dir
)
13871 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13874 /* Traversal function for queue_and_load_all_dwo_tus. */
13877 queue_and_load_dwo_tu (void **slot
, void *info
)
13879 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13880 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13881 ULONGEST signature
= dwo_unit
->signature
;
13882 struct signatured_type
*sig_type
=
13883 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13885 if (sig_type
!= NULL
)
13887 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13889 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13890 a real dependency of PER_CU on SIG_TYPE. That is detected later
13891 while processing PER_CU. */
13892 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13893 load_full_type_unit (sig_cu
);
13894 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13900 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13901 The DWO may have the only definition of the type, though it may not be
13902 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13903 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13906 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13908 struct dwo_unit
*dwo_unit
;
13909 struct dwo_file
*dwo_file
;
13911 gdb_assert (!per_cu
->is_debug_types
);
13912 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13913 gdb_assert (per_cu
->cu
!= NULL
);
13915 dwo_unit
= per_cu
->cu
->dwo_unit
;
13916 gdb_assert (dwo_unit
!= NULL
);
13918 dwo_file
= dwo_unit
->dwo_file
;
13919 if (dwo_file
->tus
!= NULL
)
13920 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13923 /* Free all resources associated with DWO_FILE.
13924 Close the DWO file and munmap the sections.
13925 All memory should be on the objfile obstack. */
13928 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
13931 /* Note: dbfd is NULL for virtual DWO files. */
13932 gdb_bfd_unref (dwo_file
->dbfd
);
13934 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13937 /* Wrapper for free_dwo_file for use in cleanups. */
13940 free_dwo_file_cleanup (void *arg
)
13942 struct free_dwo_file_cleanup_data
*data
13943 = (struct free_dwo_file_cleanup_data
*) arg
;
13944 struct objfile
*objfile
= data
->dwarf2_per_objfile
->objfile
;
13946 free_dwo_file (data
->dwo_file
, objfile
);
13951 /* Traversal function for free_dwo_files. */
13954 free_dwo_file_from_slot (void **slot
, void *info
)
13956 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13957 struct objfile
*objfile
= (struct objfile
*) info
;
13959 free_dwo_file (dwo_file
, objfile
);
13964 /* Free all resources associated with DWO_FILES. */
13967 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13969 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13972 /* Read in various DIEs. */
13974 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13975 Inherit only the children of the DW_AT_abstract_origin DIE not being
13976 already referenced by DW_AT_abstract_origin from the children of the
13980 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13982 struct die_info
*child_die
;
13983 sect_offset
*offsetp
;
13984 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13985 struct die_info
*origin_die
;
13986 /* Iterator of the ORIGIN_DIE children. */
13987 struct die_info
*origin_child_die
;
13988 struct attribute
*attr
;
13989 struct dwarf2_cu
*origin_cu
;
13990 struct pending
**origin_previous_list_in_scope
;
13992 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13996 /* Note that following die references may follow to a die in a
14000 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
14002 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
14004 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
14005 origin_cu
->list_in_scope
= cu
->list_in_scope
;
14007 if (die
->tag
!= origin_die
->tag
14008 && !(die
->tag
== DW_TAG_inlined_subroutine
14009 && origin_die
->tag
== DW_TAG_subprogram
))
14010 complaint (&symfile_complaints
,
14011 _("DIE %s and its abstract origin %s have different tags"),
14012 sect_offset_str (die
->sect_off
),
14013 sect_offset_str (origin_die
->sect_off
));
14015 std::vector
<sect_offset
> offsets
;
14017 for (child_die
= die
->child
;
14018 child_die
&& child_die
->tag
;
14019 child_die
= sibling_die (child_die
))
14021 struct die_info
*child_origin_die
;
14022 struct dwarf2_cu
*child_origin_cu
;
14024 /* We are trying to process concrete instance entries:
14025 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
14026 it's not relevant to our analysis here. i.e. detecting DIEs that are
14027 present in the abstract instance but not referenced in the concrete
14029 if (child_die
->tag
== DW_TAG_call_site
14030 || child_die
->tag
== DW_TAG_GNU_call_site
)
14033 /* For each CHILD_DIE, find the corresponding child of
14034 ORIGIN_DIE. If there is more than one layer of
14035 DW_AT_abstract_origin, follow them all; there shouldn't be,
14036 but GCC versions at least through 4.4 generate this (GCC PR
14038 child_origin_die
= child_die
;
14039 child_origin_cu
= cu
;
14042 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
14046 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
14050 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
14051 counterpart may exist. */
14052 if (child_origin_die
!= child_die
)
14054 if (child_die
->tag
!= child_origin_die
->tag
14055 && !(child_die
->tag
== DW_TAG_inlined_subroutine
14056 && child_origin_die
->tag
== DW_TAG_subprogram
))
14057 complaint (&symfile_complaints
,
14058 _("Child DIE %s and its abstract origin %s have "
14060 sect_offset_str (child_die
->sect_off
),
14061 sect_offset_str (child_origin_die
->sect_off
));
14062 if (child_origin_die
->parent
!= origin_die
)
14063 complaint (&symfile_complaints
,
14064 _("Child DIE %s and its abstract origin %s have "
14065 "different parents"),
14066 sect_offset_str (child_die
->sect_off
),
14067 sect_offset_str (child_origin_die
->sect_off
));
14069 offsets
.push_back (child_origin_die
->sect_off
);
14072 std::sort (offsets
.begin (), offsets
.end ());
14073 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
14074 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
14075 if (offsetp
[-1] == *offsetp
)
14076 complaint (&symfile_complaints
,
14077 _("Multiple children of DIE %s refer "
14078 "to DIE %s as their abstract origin"),
14079 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
14081 offsetp
= offsets
.data ();
14082 origin_child_die
= origin_die
->child
;
14083 while (origin_child_die
&& origin_child_die
->tag
)
14085 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
14086 while (offsetp
< offsets_end
14087 && *offsetp
< origin_child_die
->sect_off
)
14089 if (offsetp
>= offsets_end
14090 || *offsetp
> origin_child_die
->sect_off
)
14092 /* Found that ORIGIN_CHILD_DIE is really not referenced.
14093 Check whether we're already processing ORIGIN_CHILD_DIE.
14094 This can happen with mutually referenced abstract_origins.
14096 if (!origin_child_die
->in_process
)
14097 process_die (origin_child_die
, origin_cu
);
14099 origin_child_die
= sibling_die (origin_child_die
);
14101 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
14105 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14107 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14108 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14109 struct context_stack
*newobj
;
14112 struct die_info
*child_die
;
14113 struct attribute
*attr
, *call_line
, *call_file
;
14115 CORE_ADDR baseaddr
;
14116 struct block
*block
;
14117 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14118 std::vector
<struct symbol
*> template_args
;
14119 struct template_symbol
*templ_func
= NULL
;
14123 /* If we do not have call site information, we can't show the
14124 caller of this inlined function. That's too confusing, so
14125 only use the scope for local variables. */
14126 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
14127 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
14128 if (call_line
== NULL
|| call_file
== NULL
)
14130 read_lexical_block_scope (die
, cu
);
14135 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14137 name
= dwarf2_name (die
, cu
);
14139 /* Ignore functions with missing or empty names. These are actually
14140 illegal according to the DWARF standard. */
14143 complaint (&symfile_complaints
,
14144 _("missing name for subprogram DIE at %s"),
14145 sect_offset_str (die
->sect_off
));
14149 /* Ignore functions with missing or invalid low and high pc attributes. */
14150 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
14151 <= PC_BOUNDS_INVALID
)
14153 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
14154 if (!attr
|| !DW_UNSND (attr
))
14155 complaint (&symfile_complaints
,
14156 _("cannot get low and high bounds "
14157 "for subprogram DIE at %s"),
14158 sect_offset_str (die
->sect_off
));
14162 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14163 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14165 /* If we have any template arguments, then we must allocate a
14166 different sort of symbol. */
14167 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
14169 if (child_die
->tag
== DW_TAG_template_type_param
14170 || child_die
->tag
== DW_TAG_template_value_param
)
14172 templ_func
= allocate_template_symbol (objfile
);
14173 templ_func
->subclass
= SYMBOL_TEMPLATE
;
14178 newobj
= push_context (0, lowpc
);
14179 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
14180 (struct symbol
*) templ_func
);
14182 /* If there is a location expression for DW_AT_frame_base, record
14184 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
14186 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
14188 /* If there is a location for the static link, record it. */
14189 newobj
->static_link
= NULL
;
14190 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
14193 newobj
->static_link
14194 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
14195 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
14198 cu
->list_in_scope
= &local_symbols
;
14200 if (die
->child
!= NULL
)
14202 child_die
= die
->child
;
14203 while (child_die
&& child_die
->tag
)
14205 if (child_die
->tag
== DW_TAG_template_type_param
14206 || child_die
->tag
== DW_TAG_template_value_param
)
14208 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
14211 template_args
.push_back (arg
);
14214 process_die (child_die
, cu
);
14215 child_die
= sibling_die (child_die
);
14219 inherit_abstract_dies (die
, cu
);
14221 /* If we have a DW_AT_specification, we might need to import using
14222 directives from the context of the specification DIE. See the
14223 comment in determine_prefix. */
14224 if (cu
->language
== language_cplus
14225 && dwarf2_attr (die
, DW_AT_specification
, cu
))
14227 struct dwarf2_cu
*spec_cu
= cu
;
14228 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
14232 child_die
= spec_die
->child
;
14233 while (child_die
&& child_die
->tag
)
14235 if (child_die
->tag
== DW_TAG_imported_module
)
14236 process_die (child_die
, spec_cu
);
14237 child_die
= sibling_die (child_die
);
14240 /* In some cases, GCC generates specification DIEs that
14241 themselves contain DW_AT_specification attributes. */
14242 spec_die
= die_specification (spec_die
, &spec_cu
);
14246 newobj
= pop_context ();
14247 /* Make a block for the local symbols within. */
14248 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
14249 newobj
->static_link
, lowpc
, highpc
);
14251 /* For C++, set the block's scope. */
14252 if ((cu
->language
== language_cplus
14253 || cu
->language
== language_fortran
14254 || cu
->language
== language_d
14255 || cu
->language
== language_rust
)
14256 && cu
->processing_has_namespace_info
)
14257 block_set_scope (block
, determine_prefix (die
, cu
),
14258 &objfile
->objfile_obstack
);
14260 /* If we have address ranges, record them. */
14261 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14263 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
14265 /* Attach template arguments to function. */
14266 if (!template_args
.empty ())
14268 gdb_assert (templ_func
!= NULL
);
14270 templ_func
->n_template_arguments
= template_args
.size ();
14271 templ_func
->template_arguments
14272 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
14273 templ_func
->n_template_arguments
);
14274 memcpy (templ_func
->template_arguments
,
14275 template_args
.data (),
14276 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
14279 /* In C++, we can have functions nested inside functions (e.g., when
14280 a function declares a class that has methods). This means that
14281 when we finish processing a function scope, we may need to go
14282 back to building a containing block's symbol lists. */
14283 local_symbols
= newobj
->locals
;
14284 local_using_directives
= newobj
->local_using_directives
;
14286 /* If we've finished processing a top-level function, subsequent
14287 symbols go in the file symbol list. */
14288 if (outermost_context_p ())
14289 cu
->list_in_scope
= &file_symbols
;
14292 /* Process all the DIES contained within a lexical block scope. Start
14293 a new scope, process the dies, and then close the scope. */
14296 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14298 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14299 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14300 struct context_stack
*newobj
;
14301 CORE_ADDR lowpc
, highpc
;
14302 struct die_info
*child_die
;
14303 CORE_ADDR baseaddr
;
14305 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14307 /* Ignore blocks with missing or invalid low and high pc attributes. */
14308 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
14309 as multiple lexical blocks? Handling children in a sane way would
14310 be nasty. Might be easier to properly extend generic blocks to
14311 describe ranges. */
14312 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
14314 case PC_BOUNDS_NOT_PRESENT
:
14315 /* DW_TAG_lexical_block has no attributes, process its children as if
14316 there was no wrapping by that DW_TAG_lexical_block.
14317 GCC does no longer produces such DWARF since GCC r224161. */
14318 for (child_die
= die
->child
;
14319 child_die
!= NULL
&& child_die
->tag
;
14320 child_die
= sibling_die (child_die
))
14321 process_die (child_die
, cu
);
14323 case PC_BOUNDS_INVALID
:
14326 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14327 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14329 push_context (0, lowpc
);
14330 if (die
->child
!= NULL
)
14332 child_die
= die
->child
;
14333 while (child_die
&& child_die
->tag
)
14335 process_die (child_die
, cu
);
14336 child_die
= sibling_die (child_die
);
14339 inherit_abstract_dies (die
, cu
);
14340 newobj
= pop_context ();
14342 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
14344 struct block
*block
14345 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
14346 newobj
->start_addr
, highpc
);
14348 /* Note that recording ranges after traversing children, as we
14349 do here, means that recording a parent's ranges entails
14350 walking across all its children's ranges as they appear in
14351 the address map, which is quadratic behavior.
14353 It would be nicer to record the parent's ranges before
14354 traversing its children, simply overriding whatever you find
14355 there. But since we don't even decide whether to create a
14356 block until after we've traversed its children, that's hard
14358 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14360 local_symbols
= newobj
->locals
;
14361 local_using_directives
= newobj
->local_using_directives
;
14364 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
14367 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14369 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14370 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14371 CORE_ADDR pc
, baseaddr
;
14372 struct attribute
*attr
;
14373 struct call_site
*call_site
, call_site_local
;
14376 struct die_info
*child_die
;
14378 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14380 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
14383 /* This was a pre-DWARF-5 GNU extension alias
14384 for DW_AT_call_return_pc. */
14385 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14389 complaint (&symfile_complaints
,
14390 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
14391 "DIE %s [in module %s]"),
14392 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14395 pc
= attr_value_as_address (attr
) + baseaddr
;
14396 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14398 if (cu
->call_site_htab
== NULL
)
14399 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14400 NULL
, &objfile
->objfile_obstack
,
14401 hashtab_obstack_allocate
, NULL
);
14402 call_site_local
.pc
= pc
;
14403 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14406 complaint (&symfile_complaints
,
14407 _("Duplicate PC %s for DW_TAG_call_site "
14408 "DIE %s [in module %s]"),
14409 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14410 objfile_name (objfile
));
14414 /* Count parameters at the caller. */
14417 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14418 child_die
= sibling_die (child_die
))
14420 if (child_die
->tag
!= DW_TAG_call_site_parameter
14421 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14423 complaint (&symfile_complaints
,
14424 _("Tag %d is not DW_TAG_call_site_parameter in "
14425 "DW_TAG_call_site child DIE %s [in module %s]"),
14426 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14427 objfile_name (objfile
));
14435 = ((struct call_site
*)
14436 obstack_alloc (&objfile
->objfile_obstack
,
14437 sizeof (*call_site
)
14438 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14440 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14441 call_site
->pc
= pc
;
14443 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14444 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14446 struct die_info
*func_die
;
14448 /* Skip also over DW_TAG_inlined_subroutine. */
14449 for (func_die
= die
->parent
;
14450 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14451 && func_die
->tag
!= DW_TAG_subroutine_type
;
14452 func_die
= func_die
->parent
);
14454 /* DW_AT_call_all_calls is a superset
14455 of DW_AT_call_all_tail_calls. */
14457 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14458 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14459 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14460 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14462 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14463 not complete. But keep CALL_SITE for look ups via call_site_htab,
14464 both the initial caller containing the real return address PC and
14465 the final callee containing the current PC of a chain of tail
14466 calls do not need to have the tail call list complete. But any
14467 function candidate for a virtual tail call frame searched via
14468 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14469 determined unambiguously. */
14473 struct type
*func_type
= NULL
;
14476 func_type
= get_die_type (func_die
, cu
);
14477 if (func_type
!= NULL
)
14479 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14481 /* Enlist this call site to the function. */
14482 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14483 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14486 complaint (&symfile_complaints
,
14487 _("Cannot find function owning DW_TAG_call_site "
14488 "DIE %s [in module %s]"),
14489 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14493 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14495 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14497 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14500 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14501 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14503 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14504 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14505 /* Keep NULL DWARF_BLOCK. */;
14506 else if (attr_form_is_block (attr
))
14508 struct dwarf2_locexpr_baton
*dlbaton
;
14510 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14511 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14512 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14513 dlbaton
->per_cu
= cu
->per_cu
;
14515 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14517 else if (attr_form_is_ref (attr
))
14519 struct dwarf2_cu
*target_cu
= cu
;
14520 struct die_info
*target_die
;
14522 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14523 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14524 if (die_is_declaration (target_die
, target_cu
))
14526 const char *target_physname
;
14528 /* Prefer the mangled name; otherwise compute the demangled one. */
14529 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14530 if (target_physname
== NULL
)
14531 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14532 if (target_physname
== NULL
)
14533 complaint (&symfile_complaints
,
14534 _("DW_AT_call_target target DIE has invalid "
14535 "physname, for referencing DIE %s [in module %s]"),
14536 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14538 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14544 /* DW_AT_entry_pc should be preferred. */
14545 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14546 <= PC_BOUNDS_INVALID
)
14547 complaint (&symfile_complaints
,
14548 _("DW_AT_call_target target DIE has invalid "
14549 "low pc, for referencing DIE %s [in module %s]"),
14550 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14553 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14554 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14559 complaint (&symfile_complaints
,
14560 _("DW_TAG_call_site DW_AT_call_target is neither "
14561 "block nor reference, for DIE %s [in module %s]"),
14562 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14564 call_site
->per_cu
= cu
->per_cu
;
14566 for (child_die
= die
->child
;
14567 child_die
&& child_die
->tag
;
14568 child_die
= sibling_die (child_die
))
14570 struct call_site_parameter
*parameter
;
14571 struct attribute
*loc
, *origin
;
14573 if (child_die
->tag
!= DW_TAG_call_site_parameter
14574 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14576 /* Already printed the complaint above. */
14580 gdb_assert (call_site
->parameter_count
< nparams
);
14581 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14583 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14584 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14585 register is contained in DW_AT_call_value. */
14587 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14588 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14589 if (origin
== NULL
)
14591 /* This was a pre-DWARF-5 GNU extension alias
14592 for DW_AT_call_parameter. */
14593 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14595 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14597 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14599 sect_offset sect_off
14600 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14601 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14603 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14604 binding can be done only inside one CU. Such referenced DIE
14605 therefore cannot be even moved to DW_TAG_partial_unit. */
14606 complaint (&symfile_complaints
,
14607 _("DW_AT_call_parameter offset is not in CU for "
14608 "DW_TAG_call_site child DIE %s [in module %s]"),
14609 sect_offset_str (child_die
->sect_off
),
14610 objfile_name (objfile
));
14613 parameter
->u
.param_cu_off
14614 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14616 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14618 complaint (&symfile_complaints
,
14619 _("No DW_FORM_block* DW_AT_location for "
14620 "DW_TAG_call_site child DIE %s [in module %s]"),
14621 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14626 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14627 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14628 if (parameter
->u
.dwarf_reg
!= -1)
14629 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14630 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14631 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14632 ¶meter
->u
.fb_offset
))
14633 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14636 complaint (&symfile_complaints
,
14637 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14638 "for DW_FORM_block* DW_AT_location is supported for "
14639 "DW_TAG_call_site child DIE %s "
14641 sect_offset_str (child_die
->sect_off
),
14642 objfile_name (objfile
));
14647 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14649 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14650 if (!attr_form_is_block (attr
))
14652 complaint (&symfile_complaints
,
14653 _("No DW_FORM_block* DW_AT_call_value for "
14654 "DW_TAG_call_site child DIE %s [in module %s]"),
14655 sect_offset_str (child_die
->sect_off
),
14656 objfile_name (objfile
));
14659 parameter
->value
= DW_BLOCK (attr
)->data
;
14660 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14662 /* Parameters are not pre-cleared by memset above. */
14663 parameter
->data_value
= NULL
;
14664 parameter
->data_value_size
= 0;
14665 call_site
->parameter_count
++;
14667 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14669 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14672 if (!attr_form_is_block (attr
))
14673 complaint (&symfile_complaints
,
14674 _("No DW_FORM_block* DW_AT_call_data_value for "
14675 "DW_TAG_call_site child DIE %s [in module %s]"),
14676 sect_offset_str (child_die
->sect_off
),
14677 objfile_name (objfile
));
14680 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14681 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14687 /* Helper function for read_variable. If DIE represents a virtual
14688 table, then return the type of the concrete object that is
14689 associated with the virtual table. Otherwise, return NULL. */
14691 static struct type
*
14692 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14694 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14698 /* Find the type DIE. */
14699 struct die_info
*type_die
= NULL
;
14700 struct dwarf2_cu
*type_cu
= cu
;
14702 if (attr_form_is_ref (attr
))
14703 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14704 if (type_die
== NULL
)
14707 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14709 return die_containing_type (type_die
, type_cu
);
14712 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14715 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14717 struct rust_vtable_symbol
*storage
= NULL
;
14719 if (cu
->language
== language_rust
)
14721 struct type
*containing_type
= rust_containing_type (die
, cu
);
14723 if (containing_type
!= NULL
)
14725 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14727 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14728 struct rust_vtable_symbol
);
14729 initialize_objfile_symbol (storage
);
14730 storage
->concrete_type
= containing_type
;
14731 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14735 new_symbol (die
, NULL
, cu
, storage
);
14738 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14739 reading .debug_rnglists.
14740 Callback's type should be:
14741 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14742 Return true if the attributes are present and valid, otherwise,
14745 template <typename Callback
>
14747 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14748 Callback
&&callback
)
14750 struct dwarf2_per_objfile
*dwarf2_per_objfile
14751 = cu
->per_cu
->dwarf2_per_objfile
;
14752 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14753 bfd
*obfd
= objfile
->obfd
;
14754 /* Base address selection entry. */
14757 const gdb_byte
*buffer
;
14758 CORE_ADDR baseaddr
;
14759 bool overflow
= false;
14761 found_base
= cu
->base_known
;
14762 base
= cu
->base_address
;
14764 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14765 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14767 complaint (&symfile_complaints
,
14768 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14772 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14774 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14778 /* Initialize it due to a false compiler warning. */
14779 CORE_ADDR range_beginning
= 0, range_end
= 0;
14780 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14781 + dwarf2_per_objfile
->rnglists
.size
);
14782 unsigned int bytes_read
;
14784 if (buffer
== buf_end
)
14789 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14792 case DW_RLE_end_of_list
:
14794 case DW_RLE_base_address
:
14795 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14800 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14802 buffer
+= bytes_read
;
14804 case DW_RLE_start_length
:
14805 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14810 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14811 buffer
+= bytes_read
;
14812 range_end
= (range_beginning
14813 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14814 buffer
+= bytes_read
;
14815 if (buffer
> buf_end
)
14821 case DW_RLE_offset_pair
:
14822 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14823 buffer
+= bytes_read
;
14824 if (buffer
> buf_end
)
14829 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14830 buffer
+= bytes_read
;
14831 if (buffer
> buf_end
)
14837 case DW_RLE_start_end
:
14838 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14843 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14844 buffer
+= bytes_read
;
14845 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14846 buffer
+= bytes_read
;
14849 complaint (&symfile_complaints
,
14850 _("Invalid .debug_rnglists data (no base address)"));
14853 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14855 if (rlet
== DW_RLE_base_address
)
14860 /* We have no valid base address for the ranges
14862 complaint (&symfile_complaints
,
14863 _("Invalid .debug_rnglists data (no base address)"));
14867 if (range_beginning
> range_end
)
14869 /* Inverted range entries are invalid. */
14870 complaint (&symfile_complaints
,
14871 _("Invalid .debug_rnglists data (inverted range)"));
14875 /* Empty range entries have no effect. */
14876 if (range_beginning
== range_end
)
14879 range_beginning
+= base
;
14882 /* A not-uncommon case of bad debug info.
14883 Don't pollute the addrmap with bad data. */
14884 if (range_beginning
+ baseaddr
== 0
14885 && !dwarf2_per_objfile
->has_section_at_zero
)
14887 complaint (&symfile_complaints
,
14888 _(".debug_rnglists entry has start address of zero"
14889 " [in module %s]"), objfile_name (objfile
));
14893 callback (range_beginning
, range_end
);
14898 complaint (&symfile_complaints
,
14899 _("Offset %d is not terminated "
14900 "for DW_AT_ranges attribute"),
14908 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14909 Callback's type should be:
14910 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14911 Return 1 if the attributes are present and valid, otherwise, return 0. */
14913 template <typename Callback
>
14915 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14916 Callback
&&callback
)
14918 struct dwarf2_per_objfile
*dwarf2_per_objfile
14919 = cu
->per_cu
->dwarf2_per_objfile
;
14920 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14921 struct comp_unit_head
*cu_header
= &cu
->header
;
14922 bfd
*obfd
= objfile
->obfd
;
14923 unsigned int addr_size
= cu_header
->addr_size
;
14924 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14925 /* Base address selection entry. */
14928 unsigned int dummy
;
14929 const gdb_byte
*buffer
;
14930 CORE_ADDR baseaddr
;
14932 if (cu_header
->version
>= 5)
14933 return dwarf2_rnglists_process (offset
, cu
, callback
);
14935 found_base
= cu
->base_known
;
14936 base
= cu
->base_address
;
14938 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14939 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14941 complaint (&symfile_complaints
,
14942 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14946 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14948 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14952 CORE_ADDR range_beginning
, range_end
;
14954 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14955 buffer
+= addr_size
;
14956 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14957 buffer
+= addr_size
;
14958 offset
+= 2 * addr_size
;
14960 /* An end of list marker is a pair of zero addresses. */
14961 if (range_beginning
== 0 && range_end
== 0)
14962 /* Found the end of list entry. */
14965 /* Each base address selection entry is a pair of 2 values.
14966 The first is the largest possible address, the second is
14967 the base address. Check for a base address here. */
14968 if ((range_beginning
& mask
) == mask
)
14970 /* If we found the largest possible address, then we already
14971 have the base address in range_end. */
14979 /* We have no valid base address for the ranges
14981 complaint (&symfile_complaints
,
14982 _("Invalid .debug_ranges data (no base address)"));
14986 if (range_beginning
> range_end
)
14988 /* Inverted range entries are invalid. */
14989 complaint (&symfile_complaints
,
14990 _("Invalid .debug_ranges data (inverted range)"));
14994 /* Empty range entries have no effect. */
14995 if (range_beginning
== range_end
)
14998 range_beginning
+= base
;
15001 /* A not-uncommon case of bad debug info.
15002 Don't pollute the addrmap with bad data. */
15003 if (range_beginning
+ baseaddr
== 0
15004 && !dwarf2_per_objfile
->has_section_at_zero
)
15006 complaint (&symfile_complaints
,
15007 _(".debug_ranges entry has start address of zero"
15008 " [in module %s]"), objfile_name (objfile
));
15012 callback (range_beginning
, range_end
);
15018 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
15019 Return 1 if the attributes are present and valid, otherwise, return 0.
15020 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
15023 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
15024 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
15025 struct partial_symtab
*ranges_pst
)
15027 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15028 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15029 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
15030 SECT_OFF_TEXT (objfile
));
15033 CORE_ADDR high
= 0;
15036 retval
= dwarf2_ranges_process (offset
, cu
,
15037 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
15039 if (ranges_pst
!= NULL
)
15044 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15045 range_beginning
+ baseaddr
);
15046 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15047 range_end
+ baseaddr
);
15048 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
15052 /* FIXME: This is recording everything as a low-high
15053 segment of consecutive addresses. We should have a
15054 data structure for discontiguous block ranges
15058 low
= range_beginning
;
15064 if (range_beginning
< low
)
15065 low
= range_beginning
;
15066 if (range_end
> high
)
15074 /* If the first entry is an end-of-list marker, the range
15075 describes an empty scope, i.e. no instructions. */
15081 *high_return
= high
;
15085 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
15086 definition for the return value. *LOWPC and *HIGHPC are set iff
15087 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
15089 static enum pc_bounds_kind
15090 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
15091 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
15092 struct partial_symtab
*pst
)
15094 struct dwarf2_per_objfile
*dwarf2_per_objfile
15095 = cu
->per_cu
->dwarf2_per_objfile
;
15096 struct attribute
*attr
;
15097 struct attribute
*attr_high
;
15099 CORE_ADDR high
= 0;
15100 enum pc_bounds_kind ret
;
15102 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15105 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15108 low
= attr_value_as_address (attr
);
15109 high
= attr_value_as_address (attr_high
);
15110 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15114 /* Found high w/o low attribute. */
15115 return PC_BOUNDS_INVALID
;
15117 /* Found consecutive range of addresses. */
15118 ret
= PC_BOUNDS_HIGH_LOW
;
15122 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15125 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15126 We take advantage of the fact that DW_AT_ranges does not appear
15127 in DW_TAG_compile_unit of DWO files. */
15128 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15129 unsigned int ranges_offset
= (DW_UNSND (attr
)
15130 + (need_ranges_base
15134 /* Value of the DW_AT_ranges attribute is the offset in the
15135 .debug_ranges section. */
15136 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
15137 return PC_BOUNDS_INVALID
;
15138 /* Found discontinuous range of addresses. */
15139 ret
= PC_BOUNDS_RANGES
;
15142 return PC_BOUNDS_NOT_PRESENT
;
15145 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
15147 return PC_BOUNDS_INVALID
;
15149 /* When using the GNU linker, .gnu.linkonce. sections are used to
15150 eliminate duplicate copies of functions and vtables and such.
15151 The linker will arbitrarily choose one and discard the others.
15152 The AT_*_pc values for such functions refer to local labels in
15153 these sections. If the section from that file was discarded, the
15154 labels are not in the output, so the relocs get a value of 0.
15155 If this is a discarded function, mark the pc bounds as invalid,
15156 so that GDB will ignore it. */
15157 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15158 return PC_BOUNDS_INVALID
;
15166 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
15167 its low and high PC addresses. Do nothing if these addresses could not
15168 be determined. Otherwise, set LOWPC to the low address if it is smaller,
15169 and HIGHPC to the high address if greater than HIGHPC. */
15172 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
15173 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15174 struct dwarf2_cu
*cu
)
15176 CORE_ADDR low
, high
;
15177 struct die_info
*child
= die
->child
;
15179 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
15181 *lowpc
= std::min (*lowpc
, low
);
15182 *highpc
= std::max (*highpc
, high
);
15185 /* If the language does not allow nested subprograms (either inside
15186 subprograms or lexical blocks), we're done. */
15187 if (cu
->language
!= language_ada
)
15190 /* Check all the children of the given DIE. If it contains nested
15191 subprograms, then check their pc bounds. Likewise, we need to
15192 check lexical blocks as well, as they may also contain subprogram
15194 while (child
&& child
->tag
)
15196 if (child
->tag
== DW_TAG_subprogram
15197 || child
->tag
== DW_TAG_lexical_block
)
15198 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
15199 child
= sibling_die (child
);
15203 /* Get the low and high pc's represented by the scope DIE, and store
15204 them in *LOWPC and *HIGHPC. If the correct values can't be
15205 determined, set *LOWPC to -1 and *HIGHPC to 0. */
15208 get_scope_pc_bounds (struct die_info
*die
,
15209 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15210 struct dwarf2_cu
*cu
)
15212 CORE_ADDR best_low
= (CORE_ADDR
) -1;
15213 CORE_ADDR best_high
= (CORE_ADDR
) 0;
15214 CORE_ADDR current_low
, current_high
;
15216 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
15217 >= PC_BOUNDS_RANGES
)
15219 best_low
= current_low
;
15220 best_high
= current_high
;
15224 struct die_info
*child
= die
->child
;
15226 while (child
&& child
->tag
)
15228 switch (child
->tag
) {
15229 case DW_TAG_subprogram
:
15230 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
15232 case DW_TAG_namespace
:
15233 case DW_TAG_module
:
15234 /* FIXME: carlton/2004-01-16: Should we do this for
15235 DW_TAG_class_type/DW_TAG_structure_type, too? I think
15236 that current GCC's always emit the DIEs corresponding
15237 to definitions of methods of classes as children of a
15238 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
15239 the DIEs giving the declarations, which could be
15240 anywhere). But I don't see any reason why the
15241 standards says that they have to be there. */
15242 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
15244 if (current_low
!= ((CORE_ADDR
) -1))
15246 best_low
= std::min (best_low
, current_low
);
15247 best_high
= std::max (best_high
, current_high
);
15255 child
= sibling_die (child
);
15260 *highpc
= best_high
;
15263 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
15267 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
15268 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
15270 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15271 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15272 struct attribute
*attr
;
15273 struct attribute
*attr_high
;
15275 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15278 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15281 CORE_ADDR low
= attr_value_as_address (attr
);
15282 CORE_ADDR high
= attr_value_as_address (attr_high
);
15284 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15287 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
15288 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
15289 record_block_range (block
, low
, high
- 1);
15293 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15296 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15297 We take advantage of the fact that DW_AT_ranges does not appear
15298 in DW_TAG_compile_unit of DWO files. */
15299 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15301 /* The value of the DW_AT_ranges attribute is the offset of the
15302 address range list in the .debug_ranges section. */
15303 unsigned long offset
= (DW_UNSND (attr
)
15304 + (need_ranges_base
? cu
->ranges_base
: 0));
15305 const gdb_byte
*buffer
;
15307 /* For some target architectures, but not others, the
15308 read_address function sign-extends the addresses it returns.
15309 To recognize base address selection entries, we need a
15311 unsigned int addr_size
= cu
->header
.addr_size
;
15312 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
15314 /* The base address, to which the next pair is relative. Note
15315 that this 'base' is a DWARF concept: most entries in a range
15316 list are relative, to reduce the number of relocs against the
15317 debugging information. This is separate from this function's
15318 'baseaddr' argument, which GDB uses to relocate debugging
15319 information from a shared library based on the address at
15320 which the library was loaded. */
15321 CORE_ADDR base
= cu
->base_address
;
15322 int base_known
= cu
->base_known
;
15324 dwarf2_ranges_process (offset
, cu
,
15325 [&] (CORE_ADDR start
, CORE_ADDR end
)
15329 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
15330 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
15331 record_block_range (block
, start
, end
- 1);
15336 /* Check whether the producer field indicates either of GCC < 4.6, or the
15337 Intel C/C++ compiler, and cache the result in CU. */
15340 check_producer (struct dwarf2_cu
*cu
)
15344 if (cu
->producer
== NULL
)
15346 /* For unknown compilers expect their behavior is DWARF version
15349 GCC started to support .debug_types sections by -gdwarf-4 since
15350 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
15351 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
15352 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
15353 interpreted incorrectly by GDB now - GCC PR debug/48229. */
15355 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
15357 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
15358 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
15360 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
15361 cu
->producer_is_icc_lt_14
= major
< 14;
15364 /* For other non-GCC compilers, expect their behavior is DWARF version
15368 cu
->checked_producer
= 1;
15371 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
15372 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
15373 during 4.6.0 experimental. */
15376 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
15378 if (!cu
->checked_producer
)
15379 check_producer (cu
);
15381 return cu
->producer_is_gxx_lt_4_6
;
15384 /* Return the default accessibility type if it is not overriden by
15385 DW_AT_accessibility. */
15387 static enum dwarf_access_attribute
15388 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15390 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15392 /* The default DWARF 2 accessibility for members is public, the default
15393 accessibility for inheritance is private. */
15395 if (die
->tag
!= DW_TAG_inheritance
)
15396 return DW_ACCESS_public
;
15398 return DW_ACCESS_private
;
15402 /* DWARF 3+ defines the default accessibility a different way. The same
15403 rules apply now for DW_TAG_inheritance as for the members and it only
15404 depends on the container kind. */
15406 if (die
->parent
->tag
== DW_TAG_class_type
)
15407 return DW_ACCESS_private
;
15409 return DW_ACCESS_public
;
15413 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15414 offset. If the attribute was not found return 0, otherwise return
15415 1. If it was found but could not properly be handled, set *OFFSET
15419 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15422 struct attribute
*attr
;
15424 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15429 /* Note that we do not check for a section offset first here.
15430 This is because DW_AT_data_member_location is new in DWARF 4,
15431 so if we see it, we can assume that a constant form is really
15432 a constant and not a section offset. */
15433 if (attr_form_is_constant (attr
))
15434 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15435 else if (attr_form_is_section_offset (attr
))
15436 dwarf2_complex_location_expr_complaint ();
15437 else if (attr_form_is_block (attr
))
15438 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15440 dwarf2_complex_location_expr_complaint ();
15448 /* Add an aggregate field to the field list. */
15451 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15452 struct dwarf2_cu
*cu
)
15454 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15455 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15456 struct nextfield
*new_field
;
15457 struct attribute
*attr
;
15459 const char *fieldname
= "";
15461 if (die
->tag
== DW_TAG_inheritance
)
15463 fip
->baseclasses
.emplace_back ();
15464 new_field
= &fip
->baseclasses
.back ();
15468 fip
->fields
.emplace_back ();
15469 new_field
= &fip
->fields
.back ();
15474 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15476 new_field
->accessibility
= DW_UNSND (attr
);
15478 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15479 if (new_field
->accessibility
!= DW_ACCESS_public
)
15480 fip
->non_public_fields
= 1;
15482 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15484 new_field
->virtuality
= DW_UNSND (attr
);
15486 new_field
->virtuality
= DW_VIRTUALITY_none
;
15488 fp
= &new_field
->field
;
15490 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15494 /* Data member other than a C++ static data member. */
15496 /* Get type of field. */
15497 fp
->type
= die_type (die
, cu
);
15499 SET_FIELD_BITPOS (*fp
, 0);
15501 /* Get bit size of field (zero if none). */
15502 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15505 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15509 FIELD_BITSIZE (*fp
) = 0;
15512 /* Get bit offset of field. */
15513 if (handle_data_member_location (die
, cu
, &offset
))
15514 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15515 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15518 if (gdbarch_bits_big_endian (gdbarch
))
15520 /* For big endian bits, the DW_AT_bit_offset gives the
15521 additional bit offset from the MSB of the containing
15522 anonymous object to the MSB of the field. We don't
15523 have to do anything special since we don't need to
15524 know the size of the anonymous object. */
15525 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15529 /* For little endian bits, compute the bit offset to the
15530 MSB of the anonymous object, subtract off the number of
15531 bits from the MSB of the field to the MSB of the
15532 object, and then subtract off the number of bits of
15533 the field itself. The result is the bit offset of
15534 the LSB of the field. */
15535 int anonymous_size
;
15536 int bit_offset
= DW_UNSND (attr
);
15538 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15541 /* The size of the anonymous object containing
15542 the bit field is explicit, so use the
15543 indicated size (in bytes). */
15544 anonymous_size
= DW_UNSND (attr
);
15548 /* The size of the anonymous object containing
15549 the bit field must be inferred from the type
15550 attribute of the data member containing the
15552 anonymous_size
= TYPE_LENGTH (fp
->type
);
15554 SET_FIELD_BITPOS (*fp
,
15555 (FIELD_BITPOS (*fp
)
15556 + anonymous_size
* bits_per_byte
15557 - bit_offset
- FIELD_BITSIZE (*fp
)));
15560 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15562 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15563 + dwarf2_get_attr_constant_value (attr
, 0)));
15565 /* Get name of field. */
15566 fieldname
= dwarf2_name (die
, cu
);
15567 if (fieldname
== NULL
)
15570 /* The name is already allocated along with this objfile, so we don't
15571 need to duplicate it for the type. */
15572 fp
->name
= fieldname
;
15574 /* Change accessibility for artificial fields (e.g. virtual table
15575 pointer or virtual base class pointer) to private. */
15576 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15578 FIELD_ARTIFICIAL (*fp
) = 1;
15579 new_field
->accessibility
= DW_ACCESS_private
;
15580 fip
->non_public_fields
= 1;
15583 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15585 /* C++ static member. */
15587 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15588 is a declaration, but all versions of G++ as of this writing
15589 (so through at least 3.2.1) incorrectly generate
15590 DW_TAG_variable tags. */
15592 const char *physname
;
15594 /* Get name of field. */
15595 fieldname
= dwarf2_name (die
, cu
);
15596 if (fieldname
== NULL
)
15599 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15601 /* Only create a symbol if this is an external value.
15602 new_symbol checks this and puts the value in the global symbol
15603 table, which we want. If it is not external, new_symbol
15604 will try to put the value in cu->list_in_scope which is wrong. */
15605 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15607 /* A static const member, not much different than an enum as far as
15608 we're concerned, except that we can support more types. */
15609 new_symbol (die
, NULL
, cu
);
15612 /* Get physical name. */
15613 physname
= dwarf2_physname (fieldname
, die
, cu
);
15615 /* The name is already allocated along with this objfile, so we don't
15616 need to duplicate it for the type. */
15617 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15618 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15619 FIELD_NAME (*fp
) = fieldname
;
15621 else if (die
->tag
== DW_TAG_inheritance
)
15625 /* C++ base class field. */
15626 if (handle_data_member_location (die
, cu
, &offset
))
15627 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15628 FIELD_BITSIZE (*fp
) = 0;
15629 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15630 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15632 else if (die
->tag
== DW_TAG_variant_part
)
15634 /* process_structure_scope will treat this DIE as a union. */
15635 process_structure_scope (die
, cu
);
15637 /* The variant part is relative to the start of the enclosing
15639 SET_FIELD_BITPOS (*fp
, 0);
15640 fp
->type
= get_die_type (die
, cu
);
15641 fp
->artificial
= 1;
15642 fp
->name
= "<<variant>>";
15645 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15648 /* Can the type given by DIE define another type? */
15651 type_can_define_types (const struct die_info
*die
)
15655 case DW_TAG_typedef
:
15656 case DW_TAG_class_type
:
15657 case DW_TAG_structure_type
:
15658 case DW_TAG_union_type
:
15659 case DW_TAG_enumeration_type
:
15667 /* Add a type definition defined in the scope of the FIP's class. */
15670 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15671 struct dwarf2_cu
*cu
)
15673 struct decl_field fp
;
15674 memset (&fp
, 0, sizeof (fp
));
15676 gdb_assert (type_can_define_types (die
));
15678 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15679 fp
.name
= dwarf2_name (die
, cu
);
15680 fp
.type
= read_type_die (die
, cu
);
15682 /* Save accessibility. */
15683 enum dwarf_access_attribute accessibility
;
15684 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15686 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15688 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15689 switch (accessibility
)
15691 case DW_ACCESS_public
:
15692 /* The assumed value if neither private nor protected. */
15694 case DW_ACCESS_private
:
15697 case DW_ACCESS_protected
:
15698 fp
.is_protected
= 1;
15701 complaint (&symfile_complaints
,
15702 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15705 if (die
->tag
== DW_TAG_typedef
)
15706 fip
->typedef_field_list
.push_back (fp
);
15708 fip
->nested_types_list
.push_back (fp
);
15711 /* Create the vector of fields, and attach it to the type. */
15714 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15715 struct dwarf2_cu
*cu
)
15717 int nfields
= fip
->nfields
;
15719 /* Record the field count, allocate space for the array of fields,
15720 and create blank accessibility bitfields if necessary. */
15721 TYPE_NFIELDS (type
) = nfields
;
15722 TYPE_FIELDS (type
) = (struct field
*)
15723 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15725 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15727 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15729 TYPE_FIELD_PRIVATE_BITS (type
) =
15730 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15731 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15733 TYPE_FIELD_PROTECTED_BITS (type
) =
15734 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15735 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15737 TYPE_FIELD_IGNORE_BITS (type
) =
15738 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15739 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15742 /* If the type has baseclasses, allocate and clear a bit vector for
15743 TYPE_FIELD_VIRTUAL_BITS. */
15744 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15746 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15747 unsigned char *pointer
;
15749 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15750 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15751 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15752 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15753 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15756 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15758 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15760 for (int index
= 0; index
< nfields
; ++index
)
15762 struct nextfield
&field
= fip
->fields
[index
];
15764 if (field
.variant
.is_discriminant
)
15765 di
->discriminant_index
= index
;
15766 else if (field
.variant
.default_branch
)
15767 di
->default_index
= index
;
15769 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15773 /* Copy the saved-up fields into the field vector. */
15774 for (int i
= 0; i
< nfields
; ++i
)
15776 struct nextfield
&field
15777 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15778 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15780 TYPE_FIELD (type
, i
) = field
.field
;
15781 switch (field
.accessibility
)
15783 case DW_ACCESS_private
:
15784 if (cu
->language
!= language_ada
)
15785 SET_TYPE_FIELD_PRIVATE (type
, i
);
15788 case DW_ACCESS_protected
:
15789 if (cu
->language
!= language_ada
)
15790 SET_TYPE_FIELD_PROTECTED (type
, i
);
15793 case DW_ACCESS_public
:
15797 /* Unknown accessibility. Complain and treat it as public. */
15799 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15800 field
.accessibility
);
15804 if (i
< fip
->baseclasses
.size ())
15806 switch (field
.virtuality
)
15808 case DW_VIRTUALITY_virtual
:
15809 case DW_VIRTUALITY_pure_virtual
:
15810 if (cu
->language
== language_ada
)
15811 error (_("unexpected virtuality in component of Ada type"));
15812 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15819 /* Return true if this member function is a constructor, false
15823 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15825 const char *fieldname
;
15826 const char *type_name
;
15829 if (die
->parent
== NULL
)
15832 if (die
->parent
->tag
!= DW_TAG_structure_type
15833 && die
->parent
->tag
!= DW_TAG_union_type
15834 && die
->parent
->tag
!= DW_TAG_class_type
)
15837 fieldname
= dwarf2_name (die
, cu
);
15838 type_name
= dwarf2_name (die
->parent
, cu
);
15839 if (fieldname
== NULL
|| type_name
== NULL
)
15842 len
= strlen (fieldname
);
15843 return (strncmp (fieldname
, type_name
, len
) == 0
15844 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15847 /* Add a member function to the proper fieldlist. */
15850 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15851 struct type
*type
, struct dwarf2_cu
*cu
)
15853 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15854 struct attribute
*attr
;
15856 struct fnfieldlist
*flp
= nullptr;
15857 struct fn_field
*fnp
;
15858 const char *fieldname
;
15859 struct type
*this_type
;
15860 enum dwarf_access_attribute accessibility
;
15862 if (cu
->language
== language_ada
)
15863 error (_("unexpected member function in Ada type"));
15865 /* Get name of member function. */
15866 fieldname
= dwarf2_name (die
, cu
);
15867 if (fieldname
== NULL
)
15870 /* Look up member function name in fieldlist. */
15871 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15873 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15875 flp
= &fip
->fnfieldlists
[i
];
15880 /* Create a new fnfieldlist if necessary. */
15881 if (flp
== nullptr)
15883 fip
->fnfieldlists
.emplace_back ();
15884 flp
= &fip
->fnfieldlists
.back ();
15885 flp
->name
= fieldname
;
15886 i
= fip
->fnfieldlists
.size () - 1;
15889 /* Create a new member function field and add it to the vector of
15891 flp
->fnfields
.emplace_back ();
15892 fnp
= &flp
->fnfields
.back ();
15894 /* Delay processing of the physname until later. */
15895 if (cu
->language
== language_cplus
)
15896 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15900 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15901 fnp
->physname
= physname
? physname
: "";
15904 fnp
->type
= alloc_type (objfile
);
15905 this_type
= read_type_die (die
, cu
);
15906 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15908 int nparams
= TYPE_NFIELDS (this_type
);
15910 /* TYPE is the domain of this method, and THIS_TYPE is the type
15911 of the method itself (TYPE_CODE_METHOD). */
15912 smash_to_method_type (fnp
->type
, type
,
15913 TYPE_TARGET_TYPE (this_type
),
15914 TYPE_FIELDS (this_type
),
15915 TYPE_NFIELDS (this_type
),
15916 TYPE_VARARGS (this_type
));
15918 /* Handle static member functions.
15919 Dwarf2 has no clean way to discern C++ static and non-static
15920 member functions. G++ helps GDB by marking the first
15921 parameter for non-static member functions (which is the this
15922 pointer) as artificial. We obtain this information from
15923 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15924 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15925 fnp
->voffset
= VOFFSET_STATIC
;
15928 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15929 dwarf2_full_name (fieldname
, die
, cu
));
15931 /* Get fcontext from DW_AT_containing_type if present. */
15932 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15933 fnp
->fcontext
= die_containing_type (die
, cu
);
15935 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15936 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15938 /* Get accessibility. */
15939 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15941 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15943 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15944 switch (accessibility
)
15946 case DW_ACCESS_private
:
15947 fnp
->is_private
= 1;
15949 case DW_ACCESS_protected
:
15950 fnp
->is_protected
= 1;
15954 /* Check for artificial methods. */
15955 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15956 if (attr
&& DW_UNSND (attr
) != 0)
15957 fnp
->is_artificial
= 1;
15959 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15961 /* Get index in virtual function table if it is a virtual member
15962 function. For older versions of GCC, this is an offset in the
15963 appropriate virtual table, as specified by DW_AT_containing_type.
15964 For everyone else, it is an expression to be evaluated relative
15965 to the object address. */
15967 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15970 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15972 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15974 /* Old-style GCC. */
15975 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15977 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15978 || (DW_BLOCK (attr
)->size
> 1
15979 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15980 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15982 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15983 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15984 dwarf2_complex_location_expr_complaint ();
15986 fnp
->voffset
/= cu
->header
.addr_size
;
15990 dwarf2_complex_location_expr_complaint ();
15992 if (!fnp
->fcontext
)
15994 /* If there is no `this' field and no DW_AT_containing_type,
15995 we cannot actually find a base class context for the
15997 if (TYPE_NFIELDS (this_type
) == 0
15998 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
16000 complaint (&symfile_complaints
,
16001 _("cannot determine context for virtual member "
16002 "function \"%s\" (offset %s)"),
16003 fieldname
, sect_offset_str (die
->sect_off
));
16008 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
16012 else if (attr_form_is_section_offset (attr
))
16014 dwarf2_complex_location_expr_complaint ();
16018 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
16024 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
16025 if (attr
&& DW_UNSND (attr
))
16027 /* GCC does this, as of 2008-08-25; PR debug/37237. */
16028 complaint (&symfile_complaints
,
16029 _("Member function \"%s\" (offset %s) is virtual "
16030 "but the vtable offset is not specified"),
16031 fieldname
, sect_offset_str (die
->sect_off
));
16032 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16033 TYPE_CPLUS_DYNAMIC (type
) = 1;
16038 /* Create the vector of member function fields, and attach it to the type. */
16041 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
16042 struct dwarf2_cu
*cu
)
16044 if (cu
->language
== language_ada
)
16045 error (_("unexpected member functions in Ada type"));
16047 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16048 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
16050 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
16052 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
16054 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
16055 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
16057 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
16058 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
16059 fn_flp
->fn_fields
= (struct fn_field
*)
16060 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
16062 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
16063 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
16066 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
16069 /* Returns non-zero if NAME is the name of a vtable member in CU's
16070 language, zero otherwise. */
16072 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
16074 static const char vptr
[] = "_vptr";
16076 /* Look for the C++ form of the vtable. */
16077 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
16083 /* GCC outputs unnamed structures that are really pointers to member
16084 functions, with the ABI-specified layout. If TYPE describes
16085 such a structure, smash it into a member function type.
16087 GCC shouldn't do this; it should just output pointer to member DIEs.
16088 This is GCC PR debug/28767. */
16091 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
16093 struct type
*pfn_type
, *self_type
, *new_type
;
16095 /* Check for a structure with no name and two children. */
16096 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
16099 /* Check for __pfn and __delta members. */
16100 if (TYPE_FIELD_NAME (type
, 0) == NULL
16101 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
16102 || TYPE_FIELD_NAME (type
, 1) == NULL
16103 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
16106 /* Find the type of the method. */
16107 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
16108 if (pfn_type
== NULL
16109 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
16110 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
16113 /* Look for the "this" argument. */
16114 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
16115 if (TYPE_NFIELDS (pfn_type
) == 0
16116 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
16117 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
16120 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
16121 new_type
= alloc_type (objfile
);
16122 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
16123 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
16124 TYPE_VARARGS (pfn_type
));
16125 smash_to_methodptr_type (type
, new_type
);
16129 /* Called when we find the DIE that starts a structure or union scope
16130 (definition) to create a type for the structure or union. Fill in
16131 the type's name and general properties; the members will not be
16132 processed until process_structure_scope. A symbol table entry for
16133 the type will also not be done until process_structure_scope (assuming
16134 the type has a name).
16136 NOTE: we need to call these functions regardless of whether or not the
16137 DIE has a DW_AT_name attribute, since it might be an anonymous
16138 structure or union. This gets the type entered into our set of
16139 user defined types. */
16141 static struct type
*
16142 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16144 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16146 struct attribute
*attr
;
16149 /* If the definition of this type lives in .debug_types, read that type.
16150 Don't follow DW_AT_specification though, that will take us back up
16151 the chain and we want to go down. */
16152 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16155 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16157 /* The type's CU may not be the same as CU.
16158 Ensure TYPE is recorded with CU in die_type_hash. */
16159 return set_die_type (die
, type
, cu
);
16162 type
= alloc_type (objfile
);
16163 INIT_CPLUS_SPECIFIC (type
);
16165 name
= dwarf2_name (die
, cu
);
16168 if (cu
->language
== language_cplus
16169 || cu
->language
== language_d
16170 || cu
->language
== language_rust
)
16172 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16174 /* dwarf2_full_name might have already finished building the DIE's
16175 type. If so, there is no need to continue. */
16176 if (get_die_type (die
, cu
) != NULL
)
16177 return get_die_type (die
, cu
);
16179 TYPE_TAG_NAME (type
) = full_name
;
16180 if (die
->tag
== DW_TAG_structure_type
16181 || die
->tag
== DW_TAG_class_type
)
16182 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16186 /* The name is already allocated along with this objfile, so
16187 we don't need to duplicate it for the type. */
16188 TYPE_TAG_NAME (type
) = name
;
16189 if (die
->tag
== DW_TAG_class_type
)
16190 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16194 if (die
->tag
== DW_TAG_structure_type
)
16196 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16198 else if (die
->tag
== DW_TAG_union_type
)
16200 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16202 else if (die
->tag
== DW_TAG_variant_part
)
16204 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16205 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
16209 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16212 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16213 TYPE_DECLARED_CLASS (type
) = 1;
16215 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16218 if (attr_form_is_constant (attr
))
16219 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16222 /* For the moment, dynamic type sizes are not supported
16223 by GDB's struct type. The actual size is determined
16224 on-demand when resolving the type of a given object,
16225 so set the type's length to zero for now. Otherwise,
16226 we record an expression as the length, and that expression
16227 could lead to a very large value, which could eventually
16228 lead to us trying to allocate that much memory when creating
16229 a value of that type. */
16230 TYPE_LENGTH (type
) = 0;
16235 TYPE_LENGTH (type
) = 0;
16238 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16240 /* ICC<14 does not output the required DW_AT_declaration on
16241 incomplete types, but gives them a size of zero. */
16242 TYPE_STUB (type
) = 1;
16245 TYPE_STUB_SUPPORTED (type
) = 1;
16247 if (die_is_declaration (die
, cu
))
16248 TYPE_STUB (type
) = 1;
16249 else if (attr
== NULL
&& die
->child
== NULL
16250 && producer_is_realview (cu
->producer
))
16251 /* RealView does not output the required DW_AT_declaration
16252 on incomplete types. */
16253 TYPE_STUB (type
) = 1;
16255 /* We need to add the type field to the die immediately so we don't
16256 infinitely recurse when dealing with pointers to the structure
16257 type within the structure itself. */
16258 set_die_type (die
, type
, cu
);
16260 /* set_die_type should be already done. */
16261 set_descriptive_type (type
, die
, cu
);
16266 /* A helper for process_structure_scope that handles a single member
16270 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16271 struct field_info
*fi
,
16272 std::vector
<struct symbol
*> *template_args
,
16273 struct dwarf2_cu
*cu
)
16275 if (child_die
->tag
== DW_TAG_member
16276 || child_die
->tag
== DW_TAG_variable
16277 || child_die
->tag
== DW_TAG_variant_part
)
16279 /* NOTE: carlton/2002-11-05: A C++ static data member
16280 should be a DW_TAG_member that is a declaration, but
16281 all versions of G++ as of this writing (so through at
16282 least 3.2.1) incorrectly generate DW_TAG_variable
16283 tags for them instead. */
16284 dwarf2_add_field (fi
, child_die
, cu
);
16286 else if (child_die
->tag
== DW_TAG_subprogram
)
16288 /* Rust doesn't have member functions in the C++ sense.
16289 However, it does emit ordinary functions as children
16290 of a struct DIE. */
16291 if (cu
->language
== language_rust
)
16292 read_func_scope (child_die
, cu
);
16295 /* C++ member function. */
16296 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16299 else if (child_die
->tag
== DW_TAG_inheritance
)
16301 /* C++ base class field. */
16302 dwarf2_add_field (fi
, child_die
, cu
);
16304 else if (type_can_define_types (child_die
))
16305 dwarf2_add_type_defn (fi
, child_die
, cu
);
16306 else if (child_die
->tag
== DW_TAG_template_type_param
16307 || child_die
->tag
== DW_TAG_template_value_param
)
16309 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16312 template_args
->push_back (arg
);
16314 else if (child_die
->tag
== DW_TAG_variant
)
16316 /* In a variant we want to get the discriminant and also add a
16317 field for our sole member child. */
16318 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16320 for (struct die_info
*variant_child
= child_die
->child
;
16321 variant_child
!= NULL
;
16322 variant_child
= sibling_die (variant_child
))
16324 if (variant_child
->tag
== DW_TAG_member
)
16326 handle_struct_member_die (variant_child
, type
, fi
,
16327 template_args
, cu
);
16328 /* Only handle the one. */
16333 /* We don't handle this but we might as well report it if we see
16335 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16336 complaint (&symfile_complaints
,
16337 _("DW_AT_discr_list is not supported yet"
16338 " - DIE at %s [in module %s]"),
16339 sect_offset_str (child_die
->sect_off
),
16340 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16342 /* The first field was just added, so we can stash the
16343 discriminant there. */
16344 gdb_assert (!fi
->fields
.empty ());
16346 fi
->fields
.back ().variant
.default_branch
= true;
16348 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16352 /* Finish creating a structure or union type, including filling in
16353 its members and creating a symbol for it. */
16356 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16358 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16359 struct die_info
*child_die
;
16362 type
= get_die_type (die
, cu
);
16364 type
= read_structure_type (die
, cu
);
16366 /* When reading a DW_TAG_variant_part, we need to notice when we
16367 read the discriminant member, so we can record it later in the
16368 discriminant_info. */
16369 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16370 sect_offset discr_offset
;
16372 if (is_variant_part
)
16374 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16377 /* Maybe it's a univariant form, an extension we support.
16378 In this case arrange not to check the offset. */
16379 is_variant_part
= false;
16381 else if (attr_form_is_ref (discr
))
16383 struct dwarf2_cu
*target_cu
= cu
;
16384 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16386 discr_offset
= target_die
->sect_off
;
16390 complaint (&symfile_complaints
,
16391 _("DW_AT_discr does not have DIE reference form"
16392 " - DIE at %s [in module %s]"),
16393 sect_offset_str (die
->sect_off
),
16394 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16395 is_variant_part
= false;
16399 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16401 struct field_info fi
;
16402 std::vector
<struct symbol
*> template_args
;
16404 child_die
= die
->child
;
16406 while (child_die
&& child_die
->tag
)
16408 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16410 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16411 fi
.fields
.back ().variant
.is_discriminant
= true;
16413 child_die
= sibling_die (child_die
);
16416 /* Attach template arguments to type. */
16417 if (!template_args
.empty ())
16419 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16420 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16421 TYPE_TEMPLATE_ARGUMENTS (type
)
16422 = XOBNEWVEC (&objfile
->objfile_obstack
,
16424 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16425 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16426 template_args
.data (),
16427 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16428 * sizeof (struct symbol
*)));
16431 /* Attach fields and member functions to the type. */
16433 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16434 if (!fi
.fnfieldlists
.empty ())
16436 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16438 /* Get the type which refers to the base class (possibly this
16439 class itself) which contains the vtable pointer for the current
16440 class from the DW_AT_containing_type attribute. This use of
16441 DW_AT_containing_type is a GNU extension. */
16443 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16445 struct type
*t
= die_containing_type (die
, cu
);
16447 set_type_vptr_basetype (type
, t
);
16452 /* Our own class provides vtbl ptr. */
16453 for (i
= TYPE_NFIELDS (t
) - 1;
16454 i
>= TYPE_N_BASECLASSES (t
);
16457 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16459 if (is_vtable_name (fieldname
, cu
))
16461 set_type_vptr_fieldno (type
, i
);
16466 /* Complain if virtual function table field not found. */
16467 if (i
< TYPE_N_BASECLASSES (t
))
16468 complaint (&symfile_complaints
,
16469 _("virtual function table pointer "
16470 "not found when defining class '%s'"),
16471 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16476 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16479 else if (cu
->producer
16480 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16482 /* The IBM XLC compiler does not provide direct indication
16483 of the containing type, but the vtable pointer is
16484 always named __vfp. */
16488 for (i
= TYPE_NFIELDS (type
) - 1;
16489 i
>= TYPE_N_BASECLASSES (type
);
16492 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16494 set_type_vptr_fieldno (type
, i
);
16495 set_type_vptr_basetype (type
, type
);
16502 /* Copy fi.typedef_field_list linked list elements content into the
16503 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16504 if (!fi
.typedef_field_list
.empty ())
16506 int count
= fi
.typedef_field_list
.size ();
16508 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16509 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16510 = ((struct decl_field
*)
16512 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16513 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16515 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16516 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16519 /* Copy fi.nested_types_list linked list elements content into the
16520 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16521 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16523 int count
= fi
.nested_types_list
.size ();
16525 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16526 TYPE_NESTED_TYPES_ARRAY (type
)
16527 = ((struct decl_field
*)
16528 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16529 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16531 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16532 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16536 quirk_gcc_member_function_pointer (type
, objfile
);
16537 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16538 cu
->rust_unions
.push_back (type
);
16540 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16541 snapshots) has been known to create a die giving a declaration
16542 for a class that has, as a child, a die giving a definition for a
16543 nested class. So we have to process our children even if the
16544 current die is a declaration. Normally, of course, a declaration
16545 won't have any children at all. */
16547 child_die
= die
->child
;
16549 while (child_die
!= NULL
&& child_die
->tag
)
16551 if (child_die
->tag
== DW_TAG_member
16552 || child_die
->tag
== DW_TAG_variable
16553 || child_die
->tag
== DW_TAG_inheritance
16554 || child_die
->tag
== DW_TAG_template_value_param
16555 || child_die
->tag
== DW_TAG_template_type_param
)
16560 process_die (child_die
, cu
);
16562 child_die
= sibling_die (child_die
);
16565 /* Do not consider external references. According to the DWARF standard,
16566 these DIEs are identified by the fact that they have no byte_size
16567 attribute, and a declaration attribute. */
16568 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16569 || !die_is_declaration (die
, cu
))
16570 new_symbol (die
, type
, cu
);
16573 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16574 update TYPE using some information only available in DIE's children. */
16577 update_enumeration_type_from_children (struct die_info
*die
,
16579 struct dwarf2_cu
*cu
)
16581 struct die_info
*child_die
;
16582 int unsigned_enum
= 1;
16586 auto_obstack obstack
;
16588 for (child_die
= die
->child
;
16589 child_die
!= NULL
&& child_die
->tag
;
16590 child_die
= sibling_die (child_die
))
16592 struct attribute
*attr
;
16594 const gdb_byte
*bytes
;
16595 struct dwarf2_locexpr_baton
*baton
;
16598 if (child_die
->tag
!= DW_TAG_enumerator
)
16601 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16605 name
= dwarf2_name (child_die
, cu
);
16607 name
= "<anonymous enumerator>";
16609 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16610 &value
, &bytes
, &baton
);
16616 else if ((mask
& value
) != 0)
16621 /* If we already know that the enum type is neither unsigned, nor
16622 a flag type, no need to look at the rest of the enumerates. */
16623 if (!unsigned_enum
&& !flag_enum
)
16628 TYPE_UNSIGNED (type
) = 1;
16630 TYPE_FLAG_ENUM (type
) = 1;
16633 /* Given a DW_AT_enumeration_type die, set its type. We do not
16634 complete the type's fields yet, or create any symbols. */
16636 static struct type
*
16637 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16639 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16641 struct attribute
*attr
;
16644 /* If the definition of this type lives in .debug_types, read that type.
16645 Don't follow DW_AT_specification though, that will take us back up
16646 the chain and we want to go down. */
16647 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16650 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16652 /* The type's CU may not be the same as CU.
16653 Ensure TYPE is recorded with CU in die_type_hash. */
16654 return set_die_type (die
, type
, cu
);
16657 type
= alloc_type (objfile
);
16659 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16660 name
= dwarf2_full_name (NULL
, die
, cu
);
16662 TYPE_TAG_NAME (type
) = name
;
16664 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16667 struct type
*underlying_type
= die_type (die
, cu
);
16669 TYPE_TARGET_TYPE (type
) = underlying_type
;
16672 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16675 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16679 TYPE_LENGTH (type
) = 0;
16682 /* The enumeration DIE can be incomplete. In Ada, any type can be
16683 declared as private in the package spec, and then defined only
16684 inside the package body. Such types are known as Taft Amendment
16685 Types. When another package uses such a type, an incomplete DIE
16686 may be generated by the compiler. */
16687 if (die_is_declaration (die
, cu
))
16688 TYPE_STUB (type
) = 1;
16690 /* Finish the creation of this type by using the enum's children.
16691 We must call this even when the underlying type has been provided
16692 so that we can determine if we're looking at a "flag" enum. */
16693 update_enumeration_type_from_children (die
, type
, cu
);
16695 /* If this type has an underlying type that is not a stub, then we
16696 may use its attributes. We always use the "unsigned" attribute
16697 in this situation, because ordinarily we guess whether the type
16698 is unsigned -- but the guess can be wrong and the underlying type
16699 can tell us the reality. However, we defer to a local size
16700 attribute if one exists, because this lets the compiler override
16701 the underlying type if needed. */
16702 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16704 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16705 if (TYPE_LENGTH (type
) == 0)
16706 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16709 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16711 return set_die_type (die
, type
, cu
);
16714 /* Given a pointer to a die which begins an enumeration, process all
16715 the dies that define the members of the enumeration, and create the
16716 symbol for the enumeration type.
16718 NOTE: We reverse the order of the element list. */
16721 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16723 struct type
*this_type
;
16725 this_type
= get_die_type (die
, cu
);
16726 if (this_type
== NULL
)
16727 this_type
= read_enumeration_type (die
, cu
);
16729 if (die
->child
!= NULL
)
16731 struct die_info
*child_die
;
16732 struct symbol
*sym
;
16733 struct field
*fields
= NULL
;
16734 int num_fields
= 0;
16737 child_die
= die
->child
;
16738 while (child_die
&& child_die
->tag
)
16740 if (child_die
->tag
!= DW_TAG_enumerator
)
16742 process_die (child_die
, cu
);
16746 name
= dwarf2_name (child_die
, cu
);
16749 sym
= new_symbol (child_die
, this_type
, cu
);
16751 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16753 fields
= (struct field
*)
16755 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16756 * sizeof (struct field
));
16759 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16760 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16761 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16762 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16768 child_die
= sibling_die (child_die
);
16773 TYPE_NFIELDS (this_type
) = num_fields
;
16774 TYPE_FIELDS (this_type
) = (struct field
*)
16775 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16776 memcpy (TYPE_FIELDS (this_type
), fields
,
16777 sizeof (struct field
) * num_fields
);
16782 /* If we are reading an enum from a .debug_types unit, and the enum
16783 is a declaration, and the enum is not the signatured type in the
16784 unit, then we do not want to add a symbol for it. Adding a
16785 symbol would in some cases obscure the true definition of the
16786 enum, giving users an incomplete type when the definition is
16787 actually available. Note that we do not want to do this for all
16788 enums which are just declarations, because C++0x allows forward
16789 enum declarations. */
16790 if (cu
->per_cu
->is_debug_types
16791 && die_is_declaration (die
, cu
))
16793 struct signatured_type
*sig_type
;
16795 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16796 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16797 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16801 new_symbol (die
, this_type
, cu
);
16804 /* Extract all information from a DW_TAG_array_type DIE and put it in
16805 the DIE's type field. For now, this only handles one dimensional
16808 static struct type
*
16809 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16811 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16812 struct die_info
*child_die
;
16814 struct type
*element_type
, *range_type
, *index_type
;
16815 struct attribute
*attr
;
16817 struct dynamic_prop
*byte_stride_prop
= NULL
;
16818 unsigned int bit_stride
= 0;
16820 element_type
= die_type (die
, cu
);
16822 /* The die_type call above may have already set the type for this DIE. */
16823 type
= get_die_type (die
, cu
);
16827 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16833 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16834 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16837 complaint (&symfile_complaints
,
16838 _("unable to read array DW_AT_byte_stride "
16839 " - DIE at %s [in module %s]"),
16840 sect_offset_str (die
->sect_off
),
16841 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16842 /* Ignore this attribute. We will likely not be able to print
16843 arrays of this type correctly, but there is little we can do
16844 to help if we cannot read the attribute's value. */
16845 byte_stride_prop
= NULL
;
16849 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16851 bit_stride
= DW_UNSND (attr
);
16853 /* Irix 6.2 native cc creates array types without children for
16854 arrays with unspecified length. */
16855 if (die
->child
== NULL
)
16857 index_type
= objfile_type (objfile
)->builtin_int
;
16858 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16859 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16860 byte_stride_prop
, bit_stride
);
16861 return set_die_type (die
, type
, cu
);
16864 std::vector
<struct type
*> range_types
;
16865 child_die
= die
->child
;
16866 while (child_die
&& child_die
->tag
)
16868 if (child_die
->tag
== DW_TAG_subrange_type
)
16870 struct type
*child_type
= read_type_die (child_die
, cu
);
16872 if (child_type
!= NULL
)
16874 /* The range type was succesfully read. Save it for the
16875 array type creation. */
16876 range_types
.push_back (child_type
);
16879 child_die
= sibling_die (child_die
);
16882 /* Dwarf2 dimensions are output from left to right, create the
16883 necessary array types in backwards order. */
16885 type
= element_type
;
16887 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16891 while (i
< range_types
.size ())
16892 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16893 byte_stride_prop
, bit_stride
);
16897 size_t ndim
= range_types
.size ();
16899 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16900 byte_stride_prop
, bit_stride
);
16903 /* Understand Dwarf2 support for vector types (like they occur on
16904 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16905 array type. This is not part of the Dwarf2/3 standard yet, but a
16906 custom vendor extension. The main difference between a regular
16907 array and the vector variant is that vectors are passed by value
16909 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16911 make_vector_type (type
);
16913 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16914 implementation may choose to implement triple vectors using this
16916 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16919 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16920 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16922 complaint (&symfile_complaints
,
16923 _("DW_AT_byte_size for array type smaller "
16924 "than the total size of elements"));
16927 name
= dwarf2_name (die
, cu
);
16929 TYPE_NAME (type
) = name
;
16931 /* Install the type in the die. */
16932 set_die_type (die
, type
, cu
);
16934 /* set_die_type should be already done. */
16935 set_descriptive_type (type
, die
, cu
);
16940 static enum dwarf_array_dim_ordering
16941 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16943 struct attribute
*attr
;
16945 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16948 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16950 /* GNU F77 is a special case, as at 08/2004 array type info is the
16951 opposite order to the dwarf2 specification, but data is still
16952 laid out as per normal fortran.
16954 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16955 version checking. */
16957 if (cu
->language
== language_fortran
16958 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16960 return DW_ORD_row_major
;
16963 switch (cu
->language_defn
->la_array_ordering
)
16965 case array_column_major
:
16966 return DW_ORD_col_major
;
16967 case array_row_major
:
16969 return DW_ORD_row_major
;
16973 /* Extract all information from a DW_TAG_set_type DIE and put it in
16974 the DIE's type field. */
16976 static struct type
*
16977 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16979 struct type
*domain_type
, *set_type
;
16980 struct attribute
*attr
;
16982 domain_type
= die_type (die
, cu
);
16984 /* The die_type call above may have already set the type for this DIE. */
16985 set_type
= get_die_type (die
, cu
);
16989 set_type
= create_set_type (NULL
, domain_type
);
16991 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16993 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16995 return set_die_type (die
, set_type
, cu
);
16998 /* A helper for read_common_block that creates a locexpr baton.
16999 SYM is the symbol which we are marking as computed.
17000 COMMON_DIE is the DIE for the common block.
17001 COMMON_LOC is the location expression attribute for the common
17003 MEMBER_LOC is the location expression attribute for the particular
17004 member of the common block that we are processing.
17005 CU is the CU from which the above come. */
17008 mark_common_block_symbol_computed (struct symbol
*sym
,
17009 struct die_info
*common_die
,
17010 struct attribute
*common_loc
,
17011 struct attribute
*member_loc
,
17012 struct dwarf2_cu
*cu
)
17014 struct dwarf2_per_objfile
*dwarf2_per_objfile
17015 = cu
->per_cu
->dwarf2_per_objfile
;
17016 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17017 struct dwarf2_locexpr_baton
*baton
;
17019 unsigned int cu_off
;
17020 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
17021 LONGEST offset
= 0;
17023 gdb_assert (common_loc
&& member_loc
);
17024 gdb_assert (attr_form_is_block (common_loc
));
17025 gdb_assert (attr_form_is_block (member_loc
)
17026 || attr_form_is_constant (member_loc
));
17028 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17029 baton
->per_cu
= cu
->per_cu
;
17030 gdb_assert (baton
->per_cu
);
17032 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17034 if (attr_form_is_constant (member_loc
))
17036 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
17037 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17040 baton
->size
+= DW_BLOCK (member_loc
)->size
;
17042 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17045 *ptr
++ = DW_OP_call4
;
17046 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17047 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17050 if (attr_form_is_constant (member_loc
))
17052 *ptr
++ = DW_OP_addr
;
17053 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17054 ptr
+= cu
->header
.addr_size
;
17058 /* We have to copy the data here, because DW_OP_call4 will only
17059 use a DW_AT_location attribute. */
17060 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
17061 ptr
+= DW_BLOCK (member_loc
)->size
;
17064 *ptr
++ = DW_OP_plus
;
17065 gdb_assert (ptr
- baton
->data
== baton
->size
);
17067 SYMBOL_LOCATION_BATON (sym
) = baton
;
17068 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17071 /* Create appropriate locally-scoped variables for all the
17072 DW_TAG_common_block entries. Also create a struct common_block
17073 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17074 is used to sepate the common blocks name namespace from regular
17078 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17080 struct attribute
*attr
;
17082 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17085 /* Support the .debug_loc offsets. */
17086 if (attr_form_is_block (attr
))
17090 else if (attr_form_is_section_offset (attr
))
17092 dwarf2_complex_location_expr_complaint ();
17097 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17098 "common block member");
17103 if (die
->child
!= NULL
)
17105 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17106 struct die_info
*child_die
;
17107 size_t n_entries
= 0, size
;
17108 struct common_block
*common_block
;
17109 struct symbol
*sym
;
17111 for (child_die
= die
->child
;
17112 child_die
&& child_die
->tag
;
17113 child_die
= sibling_die (child_die
))
17116 size
= (sizeof (struct common_block
)
17117 + (n_entries
- 1) * sizeof (struct symbol
*));
17119 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17121 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17122 common_block
->n_entries
= 0;
17124 for (child_die
= die
->child
;
17125 child_die
&& child_die
->tag
;
17126 child_die
= sibling_die (child_die
))
17128 /* Create the symbol in the DW_TAG_common_block block in the current
17130 sym
= new_symbol (child_die
, NULL
, cu
);
17133 struct attribute
*member_loc
;
17135 common_block
->contents
[common_block
->n_entries
++] = sym
;
17137 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17141 /* GDB has handled this for a long time, but it is
17142 not specified by DWARF. It seems to have been
17143 emitted by gfortran at least as recently as:
17144 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17145 complaint (&symfile_complaints
,
17146 _("Variable in common block has "
17147 "DW_AT_data_member_location "
17148 "- DIE at %s [in module %s]"),
17149 sect_offset_str (child_die
->sect_off
),
17150 objfile_name (objfile
));
17152 if (attr_form_is_section_offset (member_loc
))
17153 dwarf2_complex_location_expr_complaint ();
17154 else if (attr_form_is_constant (member_loc
)
17155 || attr_form_is_block (member_loc
))
17158 mark_common_block_symbol_computed (sym
, die
, attr
,
17162 dwarf2_complex_location_expr_complaint ();
17167 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17168 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17172 /* Create a type for a C++ namespace. */
17174 static struct type
*
17175 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17177 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17178 const char *previous_prefix
, *name
;
17182 /* For extensions, reuse the type of the original namespace. */
17183 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17185 struct die_info
*ext_die
;
17186 struct dwarf2_cu
*ext_cu
= cu
;
17188 ext_die
= dwarf2_extension (die
, &ext_cu
);
17189 type
= read_type_die (ext_die
, ext_cu
);
17191 /* EXT_CU may not be the same as CU.
17192 Ensure TYPE is recorded with CU in die_type_hash. */
17193 return set_die_type (die
, type
, cu
);
17196 name
= namespace_name (die
, &is_anonymous
, cu
);
17198 /* Now build the name of the current namespace. */
17200 previous_prefix
= determine_prefix (die
, cu
);
17201 if (previous_prefix
[0] != '\0')
17202 name
= typename_concat (&objfile
->objfile_obstack
,
17203 previous_prefix
, name
, 0, cu
);
17205 /* Create the type. */
17206 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17207 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17209 return set_die_type (die
, type
, cu
);
17212 /* Read a namespace scope. */
17215 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17217 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17220 /* Add a symbol associated to this if we haven't seen the namespace
17221 before. Also, add a using directive if it's an anonymous
17224 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17228 type
= read_type_die (die
, cu
);
17229 new_symbol (die
, type
, cu
);
17231 namespace_name (die
, &is_anonymous
, cu
);
17234 const char *previous_prefix
= determine_prefix (die
, cu
);
17236 std::vector
<const char *> excludes
;
17237 add_using_directive (using_directives (cu
->language
),
17238 previous_prefix
, TYPE_NAME (type
), NULL
,
17239 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17243 if (die
->child
!= NULL
)
17245 struct die_info
*child_die
= die
->child
;
17247 while (child_die
&& child_die
->tag
)
17249 process_die (child_die
, cu
);
17250 child_die
= sibling_die (child_die
);
17255 /* Read a Fortran module as type. This DIE can be only a declaration used for
17256 imported module. Still we need that type as local Fortran "use ... only"
17257 declaration imports depend on the created type in determine_prefix. */
17259 static struct type
*
17260 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17262 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17263 const char *module_name
;
17266 module_name
= dwarf2_name (die
, cu
);
17268 complaint (&symfile_complaints
,
17269 _("DW_TAG_module has no name, offset %s"),
17270 sect_offset_str (die
->sect_off
));
17271 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17273 /* determine_prefix uses TYPE_TAG_NAME. */
17274 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17276 return set_die_type (die
, type
, cu
);
17279 /* Read a Fortran module. */
17282 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17284 struct die_info
*child_die
= die
->child
;
17287 type
= read_type_die (die
, cu
);
17288 new_symbol (die
, type
, cu
);
17290 while (child_die
&& child_die
->tag
)
17292 process_die (child_die
, cu
);
17293 child_die
= sibling_die (child_die
);
17297 /* Return the name of the namespace represented by DIE. Set
17298 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17301 static const char *
17302 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17304 struct die_info
*current_die
;
17305 const char *name
= NULL
;
17307 /* Loop through the extensions until we find a name. */
17309 for (current_die
= die
;
17310 current_die
!= NULL
;
17311 current_die
= dwarf2_extension (die
, &cu
))
17313 /* We don't use dwarf2_name here so that we can detect the absence
17314 of a name -> anonymous namespace. */
17315 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17321 /* Is it an anonymous namespace? */
17323 *is_anonymous
= (name
== NULL
);
17325 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17330 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17331 the user defined type vector. */
17333 static struct type
*
17334 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17336 struct gdbarch
*gdbarch
17337 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17338 struct comp_unit_head
*cu_header
= &cu
->header
;
17340 struct attribute
*attr_byte_size
;
17341 struct attribute
*attr_address_class
;
17342 int byte_size
, addr_class
;
17343 struct type
*target_type
;
17345 target_type
= die_type (die
, cu
);
17347 /* The die_type call above may have already set the type for this DIE. */
17348 type
= get_die_type (die
, cu
);
17352 type
= lookup_pointer_type (target_type
);
17354 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17355 if (attr_byte_size
)
17356 byte_size
= DW_UNSND (attr_byte_size
);
17358 byte_size
= cu_header
->addr_size
;
17360 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17361 if (attr_address_class
)
17362 addr_class
= DW_UNSND (attr_address_class
);
17364 addr_class
= DW_ADDR_none
;
17366 /* If the pointer size or address class is different than the
17367 default, create a type variant marked as such and set the
17368 length accordingly. */
17369 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
17371 if (gdbarch_address_class_type_flags_p (gdbarch
))
17375 type_flags
= gdbarch_address_class_type_flags
17376 (gdbarch
, byte_size
, addr_class
);
17377 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17379 type
= make_type_with_address_space (type
, type_flags
);
17381 else if (TYPE_LENGTH (type
) != byte_size
)
17383 complaint (&symfile_complaints
,
17384 _("invalid pointer size %d"), byte_size
);
17388 /* Should we also complain about unhandled address classes? */
17392 TYPE_LENGTH (type
) = byte_size
;
17393 return set_die_type (die
, type
, cu
);
17396 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17397 the user defined type vector. */
17399 static struct type
*
17400 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17403 struct type
*to_type
;
17404 struct type
*domain
;
17406 to_type
= die_type (die
, cu
);
17407 domain
= die_containing_type (die
, cu
);
17409 /* The calls above may have already set the type for this DIE. */
17410 type
= get_die_type (die
, cu
);
17414 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17415 type
= lookup_methodptr_type (to_type
);
17416 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17418 struct type
*new_type
17419 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17421 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17422 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17423 TYPE_VARARGS (to_type
));
17424 type
= lookup_methodptr_type (new_type
);
17427 type
= lookup_memberptr_type (to_type
, domain
);
17429 return set_die_type (die
, type
, cu
);
17432 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17433 the user defined type vector. */
17435 static struct type
*
17436 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17437 enum type_code refcode
)
17439 struct comp_unit_head
*cu_header
= &cu
->header
;
17440 struct type
*type
, *target_type
;
17441 struct attribute
*attr
;
17443 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17445 target_type
= die_type (die
, cu
);
17447 /* The die_type call above may have already set the type for this DIE. */
17448 type
= get_die_type (die
, cu
);
17452 type
= lookup_reference_type (target_type
, refcode
);
17453 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17456 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17460 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17462 return set_die_type (die
, type
, cu
);
17465 /* Add the given cv-qualifiers to the element type of the array. GCC
17466 outputs DWARF type qualifiers that apply to an array, not the
17467 element type. But GDB relies on the array element type to carry
17468 the cv-qualifiers. This mimics section 6.7.3 of the C99
17471 static struct type
*
17472 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17473 struct type
*base_type
, int cnst
, int voltl
)
17475 struct type
*el_type
, *inner_array
;
17477 base_type
= copy_type (base_type
);
17478 inner_array
= base_type
;
17480 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17482 TYPE_TARGET_TYPE (inner_array
) =
17483 copy_type (TYPE_TARGET_TYPE (inner_array
));
17484 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17487 el_type
= TYPE_TARGET_TYPE (inner_array
);
17488 cnst
|= TYPE_CONST (el_type
);
17489 voltl
|= TYPE_VOLATILE (el_type
);
17490 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17492 return set_die_type (die
, base_type
, cu
);
17495 static struct type
*
17496 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17498 struct type
*base_type
, *cv_type
;
17500 base_type
= die_type (die
, cu
);
17502 /* The die_type call above may have already set the type for this DIE. */
17503 cv_type
= get_die_type (die
, cu
);
17507 /* In case the const qualifier is applied to an array type, the element type
17508 is so qualified, not the array type (section 6.7.3 of C99). */
17509 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17510 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17512 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17513 return set_die_type (die
, cv_type
, cu
);
17516 static struct type
*
17517 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17519 struct type
*base_type
, *cv_type
;
17521 base_type
= die_type (die
, cu
);
17523 /* The die_type call above may have already set the type for this DIE. */
17524 cv_type
= get_die_type (die
, cu
);
17528 /* In case the volatile qualifier is applied to an array type, the
17529 element type is so qualified, not the array type (section 6.7.3
17531 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17532 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17534 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17535 return set_die_type (die
, cv_type
, cu
);
17538 /* Handle DW_TAG_restrict_type. */
17540 static struct type
*
17541 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17543 struct type
*base_type
, *cv_type
;
17545 base_type
= die_type (die
, cu
);
17547 /* The die_type call above may have already set the type for this DIE. */
17548 cv_type
= get_die_type (die
, cu
);
17552 cv_type
= make_restrict_type (base_type
);
17553 return set_die_type (die
, cv_type
, cu
);
17556 /* Handle DW_TAG_atomic_type. */
17558 static struct type
*
17559 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17561 struct type
*base_type
, *cv_type
;
17563 base_type
= die_type (die
, cu
);
17565 /* The die_type call above may have already set the type for this DIE. */
17566 cv_type
= get_die_type (die
, cu
);
17570 cv_type
= make_atomic_type (base_type
);
17571 return set_die_type (die
, cv_type
, cu
);
17574 /* Extract all information from a DW_TAG_string_type DIE and add to
17575 the user defined type vector. It isn't really a user defined type,
17576 but it behaves like one, with other DIE's using an AT_user_def_type
17577 attribute to reference it. */
17579 static struct type
*
17580 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17582 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17583 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17584 struct type
*type
, *range_type
, *index_type
, *char_type
;
17585 struct attribute
*attr
;
17586 unsigned int length
;
17588 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17591 length
= DW_UNSND (attr
);
17595 /* Check for the DW_AT_byte_size attribute. */
17596 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17599 length
= DW_UNSND (attr
);
17607 index_type
= objfile_type (objfile
)->builtin_int
;
17608 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17609 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17610 type
= create_string_type (NULL
, char_type
, range_type
);
17612 return set_die_type (die
, type
, cu
);
17615 /* Assuming that DIE corresponds to a function, returns nonzero
17616 if the function is prototyped. */
17619 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17621 struct attribute
*attr
;
17623 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17624 if (attr
&& (DW_UNSND (attr
) != 0))
17627 /* The DWARF standard implies that the DW_AT_prototyped attribute
17628 is only meaninful for C, but the concept also extends to other
17629 languages that allow unprototyped functions (Eg: Objective C).
17630 For all other languages, assume that functions are always
17632 if (cu
->language
!= language_c
17633 && cu
->language
!= language_objc
17634 && cu
->language
!= language_opencl
)
17637 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17638 prototyped and unprototyped functions; default to prototyped,
17639 since that is more common in modern code (and RealView warns
17640 about unprototyped functions). */
17641 if (producer_is_realview (cu
->producer
))
17647 /* Handle DIES due to C code like:
17651 int (*funcp)(int a, long l);
17655 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17657 static struct type
*
17658 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17660 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17661 struct type
*type
; /* Type that this function returns. */
17662 struct type
*ftype
; /* Function that returns above type. */
17663 struct attribute
*attr
;
17665 type
= die_type (die
, cu
);
17667 /* The die_type call above may have already set the type for this DIE. */
17668 ftype
= get_die_type (die
, cu
);
17672 ftype
= lookup_function_type (type
);
17674 if (prototyped_function_p (die
, cu
))
17675 TYPE_PROTOTYPED (ftype
) = 1;
17677 /* Store the calling convention in the type if it's available in
17678 the subroutine die. Otherwise set the calling convention to
17679 the default value DW_CC_normal. */
17680 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17682 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17683 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17684 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17686 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17688 /* Record whether the function returns normally to its caller or not
17689 if the DWARF producer set that information. */
17690 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17691 if (attr
&& (DW_UNSND (attr
) != 0))
17692 TYPE_NO_RETURN (ftype
) = 1;
17694 /* We need to add the subroutine type to the die immediately so
17695 we don't infinitely recurse when dealing with parameters
17696 declared as the same subroutine type. */
17697 set_die_type (die
, ftype
, cu
);
17699 if (die
->child
!= NULL
)
17701 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17702 struct die_info
*child_die
;
17703 int nparams
, iparams
;
17705 /* Count the number of parameters.
17706 FIXME: GDB currently ignores vararg functions, but knows about
17707 vararg member functions. */
17709 child_die
= die
->child
;
17710 while (child_die
&& child_die
->tag
)
17712 if (child_die
->tag
== DW_TAG_formal_parameter
)
17714 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17715 TYPE_VARARGS (ftype
) = 1;
17716 child_die
= sibling_die (child_die
);
17719 /* Allocate storage for parameters and fill them in. */
17720 TYPE_NFIELDS (ftype
) = nparams
;
17721 TYPE_FIELDS (ftype
) = (struct field
*)
17722 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17724 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17725 even if we error out during the parameters reading below. */
17726 for (iparams
= 0; iparams
< nparams
; iparams
++)
17727 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17730 child_die
= die
->child
;
17731 while (child_die
&& child_die
->tag
)
17733 if (child_die
->tag
== DW_TAG_formal_parameter
)
17735 struct type
*arg_type
;
17737 /* DWARF version 2 has no clean way to discern C++
17738 static and non-static member functions. G++ helps
17739 GDB by marking the first parameter for non-static
17740 member functions (which is the this pointer) as
17741 artificial. We pass this information to
17742 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17744 DWARF version 3 added DW_AT_object_pointer, which GCC
17745 4.5 does not yet generate. */
17746 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17748 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17750 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17751 arg_type
= die_type (child_die
, cu
);
17753 /* RealView does not mark THIS as const, which the testsuite
17754 expects. GCC marks THIS as const in method definitions,
17755 but not in the class specifications (GCC PR 43053). */
17756 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17757 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17760 struct dwarf2_cu
*arg_cu
= cu
;
17761 const char *name
= dwarf2_name (child_die
, cu
);
17763 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17766 /* If the compiler emits this, use it. */
17767 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17770 else if (name
&& strcmp (name
, "this") == 0)
17771 /* Function definitions will have the argument names. */
17773 else if (name
== NULL
&& iparams
== 0)
17774 /* Declarations may not have the names, so like
17775 elsewhere in GDB, assume an artificial first
17776 argument is "this". */
17780 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17784 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17787 child_die
= sibling_die (child_die
);
17794 static struct type
*
17795 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17797 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17798 const char *name
= NULL
;
17799 struct type
*this_type
, *target_type
;
17801 name
= dwarf2_full_name (NULL
, die
, cu
);
17802 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17803 TYPE_TARGET_STUB (this_type
) = 1;
17804 set_die_type (die
, this_type
, cu
);
17805 target_type
= die_type (die
, cu
);
17806 if (target_type
!= this_type
)
17807 TYPE_TARGET_TYPE (this_type
) = target_type
;
17810 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17811 spec and cause infinite loops in GDB. */
17812 complaint (&symfile_complaints
,
17813 _("Self-referential DW_TAG_typedef "
17814 "- DIE at %s [in module %s]"),
17815 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17816 TYPE_TARGET_TYPE (this_type
) = NULL
;
17821 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17822 (which may be different from NAME) to the architecture back-end to allow
17823 it to guess the correct format if necessary. */
17825 static struct type
*
17826 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17827 const char *name_hint
)
17829 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17830 const struct floatformat
**format
;
17833 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17835 type
= init_float_type (objfile
, bits
, name
, format
);
17837 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17842 /* Find a representation of a given base type and install
17843 it in the TYPE field of the die. */
17845 static struct type
*
17846 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17848 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17850 struct attribute
*attr
;
17851 int encoding
= 0, bits
= 0;
17854 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17857 encoding
= DW_UNSND (attr
);
17859 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17862 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17864 name
= dwarf2_name (die
, cu
);
17867 complaint (&symfile_complaints
,
17868 _("DW_AT_name missing from DW_TAG_base_type"));
17873 case DW_ATE_address
:
17874 /* Turn DW_ATE_address into a void * pointer. */
17875 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17876 type
= init_pointer_type (objfile
, bits
, name
, type
);
17878 case DW_ATE_boolean
:
17879 type
= init_boolean_type (objfile
, bits
, 1, name
);
17881 case DW_ATE_complex_float
:
17882 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17883 type
= init_complex_type (objfile
, name
, type
);
17885 case DW_ATE_decimal_float
:
17886 type
= init_decfloat_type (objfile
, bits
, name
);
17889 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17891 case DW_ATE_signed
:
17892 type
= init_integer_type (objfile
, bits
, 0, name
);
17894 case DW_ATE_unsigned
:
17895 if (cu
->language
== language_fortran
17897 && startswith (name
, "character("))
17898 type
= init_character_type (objfile
, bits
, 1, name
);
17900 type
= init_integer_type (objfile
, bits
, 1, name
);
17902 case DW_ATE_signed_char
:
17903 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17904 || cu
->language
== language_pascal
17905 || cu
->language
== language_fortran
)
17906 type
= init_character_type (objfile
, bits
, 0, name
);
17908 type
= init_integer_type (objfile
, bits
, 0, name
);
17910 case DW_ATE_unsigned_char
:
17911 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17912 || cu
->language
== language_pascal
17913 || cu
->language
== language_fortran
17914 || cu
->language
== language_rust
)
17915 type
= init_character_type (objfile
, bits
, 1, name
);
17917 type
= init_integer_type (objfile
, bits
, 1, name
);
17921 gdbarch
*arch
= get_objfile_arch (objfile
);
17924 type
= builtin_type (arch
)->builtin_char16
;
17925 else if (bits
== 32)
17926 type
= builtin_type (arch
)->builtin_char32
;
17929 complaint (&symfile_complaints
,
17930 _("unsupported DW_ATE_UTF bit size: '%d'"),
17932 type
= init_integer_type (objfile
, bits
, 1, name
);
17934 return set_die_type (die
, type
, cu
);
17939 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17940 dwarf_type_encoding_name (encoding
));
17941 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17945 if (name
&& strcmp (name
, "char") == 0)
17946 TYPE_NOSIGN (type
) = 1;
17948 return set_die_type (die
, type
, cu
);
17951 /* Parse dwarf attribute if it's a block, reference or constant and put the
17952 resulting value of the attribute into struct bound_prop.
17953 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17956 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17957 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17959 struct dwarf2_property_baton
*baton
;
17960 struct obstack
*obstack
17961 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17963 if (attr
== NULL
|| prop
== NULL
)
17966 if (attr_form_is_block (attr
))
17968 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17969 baton
->referenced_type
= NULL
;
17970 baton
->locexpr
.per_cu
= cu
->per_cu
;
17971 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17972 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17973 prop
->data
.baton
= baton
;
17974 prop
->kind
= PROP_LOCEXPR
;
17975 gdb_assert (prop
->data
.baton
!= NULL
);
17977 else if (attr_form_is_ref (attr
))
17979 struct dwarf2_cu
*target_cu
= cu
;
17980 struct die_info
*target_die
;
17981 struct attribute
*target_attr
;
17983 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17984 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17985 if (target_attr
== NULL
)
17986 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17988 if (target_attr
== NULL
)
17991 switch (target_attr
->name
)
17993 case DW_AT_location
:
17994 if (attr_form_is_section_offset (target_attr
))
17996 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17997 baton
->referenced_type
= die_type (target_die
, target_cu
);
17998 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17999 prop
->data
.baton
= baton
;
18000 prop
->kind
= PROP_LOCLIST
;
18001 gdb_assert (prop
->data
.baton
!= NULL
);
18003 else if (attr_form_is_block (target_attr
))
18005 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18006 baton
->referenced_type
= die_type (target_die
, target_cu
);
18007 baton
->locexpr
.per_cu
= cu
->per_cu
;
18008 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
18009 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
18010 prop
->data
.baton
= baton
;
18011 prop
->kind
= PROP_LOCEXPR
;
18012 gdb_assert (prop
->data
.baton
!= NULL
);
18016 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18017 "dynamic property");
18021 case DW_AT_data_member_location
:
18025 if (!handle_data_member_location (target_die
, target_cu
,
18029 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18030 baton
->referenced_type
= read_type_die (target_die
->parent
,
18032 baton
->offset_info
.offset
= offset
;
18033 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18034 prop
->data
.baton
= baton
;
18035 prop
->kind
= PROP_ADDR_OFFSET
;
18040 else if (attr_form_is_constant (attr
))
18042 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18043 prop
->kind
= PROP_CONST
;
18047 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18048 dwarf2_name (die
, cu
));
18055 /* Read the given DW_AT_subrange DIE. */
18057 static struct type
*
18058 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18060 struct type
*base_type
, *orig_base_type
;
18061 struct type
*range_type
;
18062 struct attribute
*attr
;
18063 struct dynamic_prop low
, high
;
18064 int low_default_is_valid
;
18065 int high_bound_is_count
= 0;
18067 LONGEST negative_mask
;
18069 orig_base_type
= die_type (die
, cu
);
18070 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18071 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18072 creating the range type, but we use the result of check_typedef
18073 when examining properties of the type. */
18074 base_type
= check_typedef (orig_base_type
);
18076 /* The die_type call above may have already set the type for this DIE. */
18077 range_type
= get_die_type (die
, cu
);
18081 low
.kind
= PROP_CONST
;
18082 high
.kind
= PROP_CONST
;
18083 high
.data
.const_val
= 0;
18085 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18086 omitting DW_AT_lower_bound. */
18087 switch (cu
->language
)
18090 case language_cplus
:
18091 low
.data
.const_val
= 0;
18092 low_default_is_valid
= 1;
18094 case language_fortran
:
18095 low
.data
.const_val
= 1;
18096 low_default_is_valid
= 1;
18099 case language_objc
:
18100 case language_rust
:
18101 low
.data
.const_val
= 0;
18102 low_default_is_valid
= (cu
->header
.version
>= 4);
18106 case language_pascal
:
18107 low
.data
.const_val
= 1;
18108 low_default_is_valid
= (cu
->header
.version
>= 4);
18111 low
.data
.const_val
= 0;
18112 low_default_is_valid
= 0;
18116 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18118 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
18119 else if (!low_default_is_valid
)
18120 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
18121 "- DIE at %s [in module %s]"),
18122 sect_offset_str (die
->sect_off
),
18123 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18125 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18126 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18128 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
18129 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18131 /* If bounds are constant do the final calculation here. */
18132 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18133 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18135 high_bound_is_count
= 1;
18139 /* Dwarf-2 specifications explicitly allows to create subrange types
18140 without specifying a base type.
18141 In that case, the base type must be set to the type of
18142 the lower bound, upper bound or count, in that order, if any of these
18143 three attributes references an object that has a type.
18144 If no base type is found, the Dwarf-2 specifications say that
18145 a signed integer type of size equal to the size of an address should
18147 For the following C code: `extern char gdb_int [];'
18148 GCC produces an empty range DIE.
18149 FIXME: muller/2010-05-28: Possible references to object for low bound,
18150 high bound or count are not yet handled by this code. */
18151 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
18153 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18154 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18155 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
18156 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
18158 /* Test "int", "long int", and "long long int" objfile types,
18159 and select the first one having a size above or equal to the
18160 architecture address size. */
18161 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18162 base_type
= int_type
;
18165 int_type
= objfile_type (objfile
)->builtin_long
;
18166 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18167 base_type
= int_type
;
18170 int_type
= objfile_type (objfile
)->builtin_long_long
;
18171 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18172 base_type
= int_type
;
18177 /* Normally, the DWARF producers are expected to use a signed
18178 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18179 But this is unfortunately not always the case, as witnessed
18180 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18181 is used instead. To work around that ambiguity, we treat
18182 the bounds as signed, and thus sign-extend their values, when
18183 the base type is signed. */
18185 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18186 if (low
.kind
== PROP_CONST
18187 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18188 low
.data
.const_val
|= negative_mask
;
18189 if (high
.kind
== PROP_CONST
18190 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18191 high
.data
.const_val
|= negative_mask
;
18193 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
18195 if (high_bound_is_count
)
18196 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18198 /* Ada expects an empty array on no boundary attributes. */
18199 if (attr
== NULL
&& cu
->language
!= language_ada
)
18200 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18202 name
= dwarf2_name (die
, cu
);
18204 TYPE_NAME (range_type
) = name
;
18206 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18208 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18210 set_die_type (die
, range_type
, cu
);
18212 /* set_die_type should be already done. */
18213 set_descriptive_type (range_type
, die
, cu
);
18218 static struct type
*
18219 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18223 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18225 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18227 /* In Ada, an unspecified type is typically used when the description
18228 of the type is defered to a different unit. When encountering
18229 such a type, we treat it as a stub, and try to resolve it later on,
18231 if (cu
->language
== language_ada
)
18232 TYPE_STUB (type
) = 1;
18234 return set_die_type (die
, type
, cu
);
18237 /* Read a single die and all its descendents. Set the die's sibling
18238 field to NULL; set other fields in the die correctly, and set all
18239 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18240 location of the info_ptr after reading all of those dies. PARENT
18241 is the parent of the die in question. */
18243 static struct die_info
*
18244 read_die_and_children (const struct die_reader_specs
*reader
,
18245 const gdb_byte
*info_ptr
,
18246 const gdb_byte
**new_info_ptr
,
18247 struct die_info
*parent
)
18249 struct die_info
*die
;
18250 const gdb_byte
*cur_ptr
;
18253 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18256 *new_info_ptr
= cur_ptr
;
18259 store_in_ref_table (die
, reader
->cu
);
18262 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18266 *new_info_ptr
= cur_ptr
;
18269 die
->sibling
= NULL
;
18270 die
->parent
= parent
;
18274 /* Read a die, all of its descendents, and all of its siblings; set
18275 all of the fields of all of the dies correctly. Arguments are as
18276 in read_die_and_children. */
18278 static struct die_info
*
18279 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18280 const gdb_byte
*info_ptr
,
18281 const gdb_byte
**new_info_ptr
,
18282 struct die_info
*parent
)
18284 struct die_info
*first_die
, *last_sibling
;
18285 const gdb_byte
*cur_ptr
;
18287 cur_ptr
= info_ptr
;
18288 first_die
= last_sibling
= NULL
;
18292 struct die_info
*die
18293 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18297 *new_info_ptr
= cur_ptr
;
18304 last_sibling
->sibling
= die
;
18306 last_sibling
= die
;
18310 /* Read a die, all of its descendents, and all of its siblings; set
18311 all of the fields of all of the dies correctly. Arguments are as
18312 in read_die_and_children.
18313 This the main entry point for reading a DIE and all its children. */
18315 static struct die_info
*
18316 read_die_and_siblings (const struct die_reader_specs
*reader
,
18317 const gdb_byte
*info_ptr
,
18318 const gdb_byte
**new_info_ptr
,
18319 struct die_info
*parent
)
18321 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18322 new_info_ptr
, parent
);
18324 if (dwarf_die_debug
)
18326 fprintf_unfiltered (gdb_stdlog
,
18327 "Read die from %s@0x%x of %s:\n",
18328 get_section_name (reader
->die_section
),
18329 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18330 bfd_get_filename (reader
->abfd
));
18331 dump_die (die
, dwarf_die_debug
);
18337 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18339 The caller is responsible for filling in the extra attributes
18340 and updating (*DIEP)->num_attrs.
18341 Set DIEP to point to a newly allocated die with its information,
18342 except for its child, sibling, and parent fields.
18343 Set HAS_CHILDREN to tell whether the die has children or not. */
18345 static const gdb_byte
*
18346 read_full_die_1 (const struct die_reader_specs
*reader
,
18347 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18348 int *has_children
, int num_extra_attrs
)
18350 unsigned int abbrev_number
, bytes_read
, i
;
18351 struct abbrev_info
*abbrev
;
18352 struct die_info
*die
;
18353 struct dwarf2_cu
*cu
= reader
->cu
;
18354 bfd
*abfd
= reader
->abfd
;
18356 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18357 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18358 info_ptr
+= bytes_read
;
18359 if (!abbrev_number
)
18366 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18368 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18370 bfd_get_filename (abfd
));
18372 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18373 die
->sect_off
= sect_off
;
18374 die
->tag
= abbrev
->tag
;
18375 die
->abbrev
= abbrev_number
;
18377 /* Make the result usable.
18378 The caller needs to update num_attrs after adding the extra
18380 die
->num_attrs
= abbrev
->num_attrs
;
18382 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18383 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18387 *has_children
= abbrev
->has_children
;
18391 /* Read a die and all its attributes.
18392 Set DIEP to point to a newly allocated die with its information,
18393 except for its child, sibling, and parent fields.
18394 Set HAS_CHILDREN to tell whether the die has children or not. */
18396 static const gdb_byte
*
18397 read_full_die (const struct die_reader_specs
*reader
,
18398 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18401 const gdb_byte
*result
;
18403 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18405 if (dwarf_die_debug
)
18407 fprintf_unfiltered (gdb_stdlog
,
18408 "Read die from %s@0x%x of %s:\n",
18409 get_section_name (reader
->die_section
),
18410 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18411 bfd_get_filename (reader
->abfd
));
18412 dump_die (*diep
, dwarf_die_debug
);
18418 /* Abbreviation tables.
18420 In DWARF version 2, the description of the debugging information is
18421 stored in a separate .debug_abbrev section. Before we read any
18422 dies from a section we read in all abbreviations and install them
18423 in a hash table. */
18425 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18427 struct abbrev_info
*
18428 abbrev_table::alloc_abbrev ()
18430 struct abbrev_info
*abbrev
;
18432 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18433 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18438 /* Add an abbreviation to the table. */
18441 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18442 struct abbrev_info
*abbrev
)
18444 unsigned int hash_number
;
18446 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18447 abbrev
->next
= m_abbrevs
[hash_number
];
18448 m_abbrevs
[hash_number
] = abbrev
;
18451 /* Look up an abbrev in the table.
18452 Returns NULL if the abbrev is not found. */
18454 struct abbrev_info
*
18455 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18457 unsigned int hash_number
;
18458 struct abbrev_info
*abbrev
;
18460 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18461 abbrev
= m_abbrevs
[hash_number
];
18465 if (abbrev
->number
== abbrev_number
)
18467 abbrev
= abbrev
->next
;
18472 /* Read in an abbrev table. */
18474 static abbrev_table_up
18475 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18476 struct dwarf2_section_info
*section
,
18477 sect_offset sect_off
)
18479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18480 bfd
*abfd
= get_section_bfd_owner (section
);
18481 const gdb_byte
*abbrev_ptr
;
18482 struct abbrev_info
*cur_abbrev
;
18483 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18484 unsigned int abbrev_form
;
18485 struct attr_abbrev
*cur_attrs
;
18486 unsigned int allocated_attrs
;
18488 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18490 dwarf2_read_section (objfile
, section
);
18491 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18492 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18493 abbrev_ptr
+= bytes_read
;
18495 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18496 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18498 /* Loop until we reach an abbrev number of 0. */
18499 while (abbrev_number
)
18501 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18503 /* read in abbrev header */
18504 cur_abbrev
->number
= abbrev_number
;
18506 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18507 abbrev_ptr
+= bytes_read
;
18508 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18511 /* now read in declarations */
18514 LONGEST implicit_const
;
18516 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18517 abbrev_ptr
+= bytes_read
;
18518 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18519 abbrev_ptr
+= bytes_read
;
18520 if (abbrev_form
== DW_FORM_implicit_const
)
18522 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18524 abbrev_ptr
+= bytes_read
;
18528 /* Initialize it due to a false compiler warning. */
18529 implicit_const
= -1;
18532 if (abbrev_name
== 0)
18535 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18537 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18539 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18542 cur_attrs
[cur_abbrev
->num_attrs
].name
18543 = (enum dwarf_attribute
) abbrev_name
;
18544 cur_attrs
[cur_abbrev
->num_attrs
].form
18545 = (enum dwarf_form
) abbrev_form
;
18546 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18547 ++cur_abbrev
->num_attrs
;
18550 cur_abbrev
->attrs
=
18551 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18552 cur_abbrev
->num_attrs
);
18553 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18554 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18556 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18558 /* Get next abbreviation.
18559 Under Irix6 the abbreviations for a compilation unit are not
18560 always properly terminated with an abbrev number of 0.
18561 Exit loop if we encounter an abbreviation which we have
18562 already read (which means we are about to read the abbreviations
18563 for the next compile unit) or if the end of the abbreviation
18564 table is reached. */
18565 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18567 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18568 abbrev_ptr
+= bytes_read
;
18569 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18574 return abbrev_table
;
18577 /* Returns nonzero if TAG represents a type that we might generate a partial
18581 is_type_tag_for_partial (int tag
)
18586 /* Some types that would be reasonable to generate partial symbols for,
18587 that we don't at present. */
18588 case DW_TAG_array_type
:
18589 case DW_TAG_file_type
:
18590 case DW_TAG_ptr_to_member_type
:
18591 case DW_TAG_set_type
:
18592 case DW_TAG_string_type
:
18593 case DW_TAG_subroutine_type
:
18595 case DW_TAG_base_type
:
18596 case DW_TAG_class_type
:
18597 case DW_TAG_interface_type
:
18598 case DW_TAG_enumeration_type
:
18599 case DW_TAG_structure_type
:
18600 case DW_TAG_subrange_type
:
18601 case DW_TAG_typedef
:
18602 case DW_TAG_union_type
:
18609 /* Load all DIEs that are interesting for partial symbols into memory. */
18611 static struct partial_die_info
*
18612 load_partial_dies (const struct die_reader_specs
*reader
,
18613 const gdb_byte
*info_ptr
, int building_psymtab
)
18615 struct dwarf2_cu
*cu
= reader
->cu
;
18616 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18617 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18618 unsigned int bytes_read
;
18619 unsigned int load_all
= 0;
18620 int nesting_level
= 1;
18625 gdb_assert (cu
->per_cu
!= NULL
);
18626 if (cu
->per_cu
->load_all_dies
)
18630 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18634 &cu
->comp_unit_obstack
,
18635 hashtab_obstack_allocate
,
18636 dummy_obstack_deallocate
);
18640 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18642 /* A NULL abbrev means the end of a series of children. */
18643 if (abbrev
== NULL
)
18645 if (--nesting_level
== 0)
18648 info_ptr
+= bytes_read
;
18649 last_die
= parent_die
;
18650 parent_die
= parent_die
->die_parent
;
18654 /* Check for template arguments. We never save these; if
18655 they're seen, we just mark the parent, and go on our way. */
18656 if (parent_die
!= NULL
18657 && cu
->language
== language_cplus
18658 && (abbrev
->tag
== DW_TAG_template_type_param
18659 || abbrev
->tag
== DW_TAG_template_value_param
))
18661 parent_die
->has_template_arguments
= 1;
18665 /* We don't need a partial DIE for the template argument. */
18666 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18671 /* We only recurse into c++ subprograms looking for template arguments.
18672 Skip their other children. */
18674 && cu
->language
== language_cplus
18675 && parent_die
!= NULL
18676 && parent_die
->tag
== DW_TAG_subprogram
)
18678 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18682 /* Check whether this DIE is interesting enough to save. Normally
18683 we would not be interested in members here, but there may be
18684 later variables referencing them via DW_AT_specification (for
18685 static members). */
18687 && !is_type_tag_for_partial (abbrev
->tag
)
18688 && abbrev
->tag
!= DW_TAG_constant
18689 && abbrev
->tag
!= DW_TAG_enumerator
18690 && abbrev
->tag
!= DW_TAG_subprogram
18691 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18692 && abbrev
->tag
!= DW_TAG_lexical_block
18693 && abbrev
->tag
!= DW_TAG_variable
18694 && abbrev
->tag
!= DW_TAG_namespace
18695 && abbrev
->tag
!= DW_TAG_module
18696 && abbrev
->tag
!= DW_TAG_member
18697 && abbrev
->tag
!= DW_TAG_imported_unit
18698 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18700 /* Otherwise we skip to the next sibling, if any. */
18701 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18705 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18708 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18710 /* This two-pass algorithm for processing partial symbols has a
18711 high cost in cache pressure. Thus, handle some simple cases
18712 here which cover the majority of C partial symbols. DIEs
18713 which neither have specification tags in them, nor could have
18714 specification tags elsewhere pointing at them, can simply be
18715 processed and discarded.
18717 This segment is also optional; scan_partial_symbols and
18718 add_partial_symbol will handle these DIEs if we chain
18719 them in normally. When compilers which do not emit large
18720 quantities of duplicate debug information are more common,
18721 this code can probably be removed. */
18723 /* Any complete simple types at the top level (pretty much all
18724 of them, for a language without namespaces), can be processed
18726 if (parent_die
== NULL
18727 && pdi
.has_specification
== 0
18728 && pdi
.is_declaration
== 0
18729 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18730 || pdi
.tag
== DW_TAG_base_type
18731 || pdi
.tag
== DW_TAG_subrange_type
))
18733 if (building_psymtab
&& pdi
.name
!= NULL
)
18734 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18735 VAR_DOMAIN
, LOC_TYPEDEF
,
18736 &objfile
->static_psymbols
,
18737 0, cu
->language
, objfile
);
18738 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18742 /* The exception for DW_TAG_typedef with has_children above is
18743 a workaround of GCC PR debug/47510. In the case of this complaint
18744 type_name_no_tag_or_error will error on such types later.
18746 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18747 it could not find the child DIEs referenced later, this is checked
18748 above. In correct DWARF DW_TAG_typedef should have no children. */
18750 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18751 complaint (&symfile_complaints
,
18752 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18753 "- DIE at %s [in module %s]"),
18754 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18756 /* If we're at the second level, and we're an enumerator, and
18757 our parent has no specification (meaning possibly lives in a
18758 namespace elsewhere), then we can add the partial symbol now
18759 instead of queueing it. */
18760 if (pdi
.tag
== DW_TAG_enumerator
18761 && parent_die
!= NULL
18762 && parent_die
->die_parent
== NULL
18763 && parent_die
->tag
== DW_TAG_enumeration_type
18764 && parent_die
->has_specification
== 0)
18766 if (pdi
.name
== NULL
)
18767 complaint (&symfile_complaints
,
18768 _("malformed enumerator DIE ignored"));
18769 else if (building_psymtab
)
18770 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18771 VAR_DOMAIN
, LOC_CONST
,
18772 cu
->language
== language_cplus
18773 ? &objfile
->global_psymbols
18774 : &objfile
->static_psymbols
,
18775 0, cu
->language
, objfile
);
18777 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18781 struct partial_die_info
*part_die
18782 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18784 /* We'll save this DIE so link it in. */
18785 part_die
->die_parent
= parent_die
;
18786 part_die
->die_sibling
= NULL
;
18787 part_die
->die_child
= NULL
;
18789 if (last_die
&& last_die
== parent_die
)
18790 last_die
->die_child
= part_die
;
18792 last_die
->die_sibling
= part_die
;
18794 last_die
= part_die
;
18796 if (first_die
== NULL
)
18797 first_die
= part_die
;
18799 /* Maybe add the DIE to the hash table. Not all DIEs that we
18800 find interesting need to be in the hash table, because we
18801 also have the parent/sibling/child chains; only those that we
18802 might refer to by offset later during partial symbol reading.
18804 For now this means things that might have be the target of a
18805 DW_AT_specification, DW_AT_abstract_origin, or
18806 DW_AT_extension. DW_AT_extension will refer only to
18807 namespaces; DW_AT_abstract_origin refers to functions (and
18808 many things under the function DIE, but we do not recurse
18809 into function DIEs during partial symbol reading) and
18810 possibly variables as well; DW_AT_specification refers to
18811 declarations. Declarations ought to have the DW_AT_declaration
18812 flag. It happens that GCC forgets to put it in sometimes, but
18813 only for functions, not for types.
18815 Adding more things than necessary to the hash table is harmless
18816 except for the performance cost. Adding too few will result in
18817 wasted time in find_partial_die, when we reread the compilation
18818 unit with load_all_dies set. */
18821 || abbrev
->tag
== DW_TAG_constant
18822 || abbrev
->tag
== DW_TAG_subprogram
18823 || abbrev
->tag
== DW_TAG_variable
18824 || abbrev
->tag
== DW_TAG_namespace
18825 || part_die
->is_declaration
)
18829 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18830 to_underlying (part_die
->sect_off
),
18835 /* For some DIEs we want to follow their children (if any). For C
18836 we have no reason to follow the children of structures; for other
18837 languages we have to, so that we can get at method physnames
18838 to infer fully qualified class names, for DW_AT_specification,
18839 and for C++ template arguments. For C++, we also look one level
18840 inside functions to find template arguments (if the name of the
18841 function does not already contain the template arguments).
18843 For Ada, we need to scan the children of subprograms and lexical
18844 blocks as well because Ada allows the definition of nested
18845 entities that could be interesting for the debugger, such as
18846 nested subprograms for instance. */
18847 if (last_die
->has_children
18849 || last_die
->tag
== DW_TAG_namespace
18850 || last_die
->tag
== DW_TAG_module
18851 || last_die
->tag
== DW_TAG_enumeration_type
18852 || (cu
->language
== language_cplus
18853 && last_die
->tag
== DW_TAG_subprogram
18854 && (last_die
->name
== NULL
18855 || strchr (last_die
->name
, '<') == NULL
))
18856 || (cu
->language
!= language_c
18857 && (last_die
->tag
== DW_TAG_class_type
18858 || last_die
->tag
== DW_TAG_interface_type
18859 || last_die
->tag
== DW_TAG_structure_type
18860 || last_die
->tag
== DW_TAG_union_type
))
18861 || (cu
->language
== language_ada
18862 && (last_die
->tag
== DW_TAG_subprogram
18863 || last_die
->tag
== DW_TAG_lexical_block
))))
18866 parent_die
= last_die
;
18870 /* Otherwise we skip to the next sibling, if any. */
18871 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18873 /* Back to the top, do it again. */
18877 partial_die_info::partial_die_info (sect_offset sect_off_
,
18878 struct abbrev_info
*abbrev
)
18879 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18883 /* Read a minimal amount of information into the minimal die structure.
18884 INFO_PTR should point just after the initial uleb128 of a DIE. */
18887 partial_die_info::read (const struct die_reader_specs
*reader
,
18888 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18890 struct dwarf2_cu
*cu
= reader
->cu
;
18891 struct dwarf2_per_objfile
*dwarf2_per_objfile
18892 = cu
->per_cu
->dwarf2_per_objfile
;
18894 int has_low_pc_attr
= 0;
18895 int has_high_pc_attr
= 0;
18896 int high_pc_relative
= 0;
18898 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18900 struct attribute attr
;
18902 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18904 /* Store the data if it is of an attribute we want to keep in a
18905 partial symbol table. */
18911 case DW_TAG_compile_unit
:
18912 case DW_TAG_partial_unit
:
18913 case DW_TAG_type_unit
:
18914 /* Compilation units have a DW_AT_name that is a filename, not
18915 a source language identifier. */
18916 case DW_TAG_enumeration_type
:
18917 case DW_TAG_enumerator
:
18918 /* These tags always have simple identifiers already; no need
18919 to canonicalize them. */
18920 name
= DW_STRING (&attr
);
18924 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18927 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18928 &objfile
->per_bfd
->storage_obstack
);
18933 case DW_AT_linkage_name
:
18934 case DW_AT_MIPS_linkage_name
:
18935 /* Note that both forms of linkage name might appear. We
18936 assume they will be the same, and we only store the last
18938 if (cu
->language
== language_ada
)
18939 name
= DW_STRING (&attr
);
18940 linkage_name
= DW_STRING (&attr
);
18943 has_low_pc_attr
= 1;
18944 lowpc
= attr_value_as_address (&attr
);
18946 case DW_AT_high_pc
:
18947 has_high_pc_attr
= 1;
18948 highpc
= attr_value_as_address (&attr
);
18949 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18950 high_pc_relative
= 1;
18952 case DW_AT_location
:
18953 /* Support the .debug_loc offsets. */
18954 if (attr_form_is_block (&attr
))
18956 d
.locdesc
= DW_BLOCK (&attr
);
18958 else if (attr_form_is_section_offset (&attr
))
18960 dwarf2_complex_location_expr_complaint ();
18964 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18965 "partial symbol information");
18968 case DW_AT_external
:
18969 is_external
= DW_UNSND (&attr
);
18971 case DW_AT_declaration
:
18972 is_declaration
= DW_UNSND (&attr
);
18977 case DW_AT_abstract_origin
:
18978 case DW_AT_specification
:
18979 case DW_AT_extension
:
18980 has_specification
= 1;
18981 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18982 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18983 || cu
->per_cu
->is_dwz
);
18985 case DW_AT_sibling
:
18986 /* Ignore absolute siblings, they might point outside of
18987 the current compile unit. */
18988 if (attr
.form
== DW_FORM_ref_addr
)
18989 complaint (&symfile_complaints
,
18990 _("ignoring absolute DW_AT_sibling"));
18993 const gdb_byte
*buffer
= reader
->buffer
;
18994 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18995 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18997 if (sibling_ptr
< info_ptr
)
18998 complaint (&symfile_complaints
,
18999 _("DW_AT_sibling points backwards"));
19000 else if (sibling_ptr
> reader
->buffer_end
)
19001 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19003 sibling
= sibling_ptr
;
19006 case DW_AT_byte_size
:
19009 case DW_AT_const_value
:
19010 has_const_value
= 1;
19012 case DW_AT_calling_convention
:
19013 /* DWARF doesn't provide a way to identify a program's source-level
19014 entry point. DW_AT_calling_convention attributes are only meant
19015 to describe functions' calling conventions.
19017 However, because it's a necessary piece of information in
19018 Fortran, and before DWARF 4 DW_CC_program was the only
19019 piece of debugging information whose definition refers to
19020 a 'main program' at all, several compilers marked Fortran
19021 main programs with DW_CC_program --- even when those
19022 functions use the standard calling conventions.
19024 Although DWARF now specifies a way to provide this
19025 information, we support this practice for backward
19027 if (DW_UNSND (&attr
) == DW_CC_program
19028 && cu
->language
== language_fortran
)
19029 main_subprogram
= 1;
19032 if (DW_UNSND (&attr
) == DW_INL_inlined
19033 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19034 may_be_inlined
= 1;
19038 if (tag
== DW_TAG_imported_unit
)
19040 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19041 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19042 || cu
->per_cu
->is_dwz
);
19046 case DW_AT_main_subprogram
:
19047 main_subprogram
= DW_UNSND (&attr
);
19055 if (high_pc_relative
)
19058 if (has_low_pc_attr
&& has_high_pc_attr
)
19060 /* When using the GNU linker, .gnu.linkonce. sections are used to
19061 eliminate duplicate copies of functions and vtables and such.
19062 The linker will arbitrarily choose one and discard the others.
19063 The AT_*_pc values for such functions refer to local labels in
19064 these sections. If the section from that file was discarded, the
19065 labels are not in the output, so the relocs get a value of 0.
19066 If this is a discarded function, mark the pc bounds as invalid,
19067 so that GDB will ignore it. */
19068 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19070 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19071 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19073 complaint (&symfile_complaints
,
19074 _("DW_AT_low_pc %s is zero "
19075 "for DIE at %s [in module %s]"),
19076 paddress (gdbarch
, lowpc
),
19077 sect_offset_str (sect_off
),
19078 objfile_name (objfile
));
19080 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19081 else if (lowpc
>= highpc
)
19083 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19084 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19086 complaint (&symfile_complaints
,
19087 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19088 "for DIE at %s [in module %s]"),
19089 paddress (gdbarch
, lowpc
),
19090 paddress (gdbarch
, highpc
),
19091 sect_offset_str (sect_off
),
19092 objfile_name (objfile
));
19101 /* Find a cached partial DIE at OFFSET in CU. */
19103 struct partial_die_info
*
19104 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19106 struct partial_die_info
*lookup_die
= NULL
;
19107 struct partial_die_info
part_die (sect_off
);
19109 lookup_die
= ((struct partial_die_info
*)
19110 htab_find_with_hash (partial_dies
, &part_die
,
19111 to_underlying (sect_off
)));
19116 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19117 except in the case of .debug_types DIEs which do not reference
19118 outside their CU (they do however referencing other types via
19119 DW_FORM_ref_sig8). */
19121 static struct partial_die_info
*
19122 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19124 struct dwarf2_per_objfile
*dwarf2_per_objfile
19125 = cu
->per_cu
->dwarf2_per_objfile
;
19126 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19127 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19128 struct partial_die_info
*pd
= NULL
;
19130 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19131 && offset_in_cu_p (&cu
->header
, sect_off
))
19133 pd
= cu
->find_partial_die (sect_off
);
19136 /* We missed recording what we needed.
19137 Load all dies and try again. */
19138 per_cu
= cu
->per_cu
;
19142 /* TUs don't reference other CUs/TUs (except via type signatures). */
19143 if (cu
->per_cu
->is_debug_types
)
19145 error (_("Dwarf Error: Type Unit at offset %s contains"
19146 " external reference to offset %s [in module %s].\n"),
19147 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19148 bfd_get_filename (objfile
->obfd
));
19150 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19151 dwarf2_per_objfile
);
19153 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19154 load_partial_comp_unit (per_cu
);
19156 per_cu
->cu
->last_used
= 0;
19157 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19160 /* If we didn't find it, and not all dies have been loaded,
19161 load them all and try again. */
19163 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19165 per_cu
->load_all_dies
= 1;
19167 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19168 THIS_CU->cu may already be in use. So we can't just free it and
19169 replace its DIEs with the ones we read in. Instead, we leave those
19170 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19171 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19173 load_partial_comp_unit (per_cu
);
19175 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19179 internal_error (__FILE__
, __LINE__
,
19180 _("could not find partial DIE %s "
19181 "in cache [from module %s]\n"),
19182 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19186 /* See if we can figure out if the class lives in a namespace. We do
19187 this by looking for a member function; its demangled name will
19188 contain namespace info, if there is any. */
19191 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19192 struct dwarf2_cu
*cu
)
19194 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19195 what template types look like, because the demangler
19196 frequently doesn't give the same name as the debug info. We
19197 could fix this by only using the demangled name to get the
19198 prefix (but see comment in read_structure_type). */
19200 struct partial_die_info
*real_pdi
;
19201 struct partial_die_info
*child_pdi
;
19203 /* If this DIE (this DIE's specification, if any) has a parent, then
19204 we should not do this. We'll prepend the parent's fully qualified
19205 name when we create the partial symbol. */
19207 real_pdi
= struct_pdi
;
19208 while (real_pdi
->has_specification
)
19209 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
19210 real_pdi
->spec_is_dwz
, cu
);
19212 if (real_pdi
->die_parent
!= NULL
)
19215 for (child_pdi
= struct_pdi
->die_child
;
19217 child_pdi
= child_pdi
->die_sibling
)
19219 if (child_pdi
->tag
== DW_TAG_subprogram
19220 && child_pdi
->linkage_name
!= NULL
)
19222 char *actual_class_name
19223 = language_class_name_from_physname (cu
->language_defn
,
19224 child_pdi
->linkage_name
);
19225 if (actual_class_name
!= NULL
)
19227 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19230 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19232 strlen (actual_class_name
)));
19233 xfree (actual_class_name
);
19241 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19243 /* Once we've fixed up a die, there's no point in doing so again.
19244 This also avoids a memory leak if we were to call
19245 guess_partial_die_structure_name multiple times. */
19249 /* If we found a reference attribute and the DIE has no name, try
19250 to find a name in the referred to DIE. */
19252 if (name
== NULL
&& has_specification
)
19254 struct partial_die_info
*spec_die
;
19256 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19258 spec_die
->fixup (cu
);
19260 if (spec_die
->name
)
19262 name
= spec_die
->name
;
19264 /* Copy DW_AT_external attribute if it is set. */
19265 if (spec_die
->is_external
)
19266 is_external
= spec_die
->is_external
;
19270 /* Set default names for some unnamed DIEs. */
19272 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19273 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19275 /* If there is no parent die to provide a namespace, and there are
19276 children, see if we can determine the namespace from their linkage
19278 if (cu
->language
== language_cplus
19279 && !VEC_empty (dwarf2_section_info_def
,
19280 cu
->per_cu
->dwarf2_per_objfile
->types
)
19281 && die_parent
== NULL
19283 && (tag
== DW_TAG_class_type
19284 || tag
== DW_TAG_structure_type
19285 || tag
== DW_TAG_union_type
))
19286 guess_partial_die_structure_name (this, cu
);
19288 /* GCC might emit a nameless struct or union that has a linkage
19289 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19291 && (tag
== DW_TAG_class_type
19292 || tag
== DW_TAG_interface_type
19293 || tag
== DW_TAG_structure_type
19294 || tag
== DW_TAG_union_type
)
19295 && linkage_name
!= NULL
)
19299 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19304 /* Strip any leading namespaces/classes, keep only the base name.
19305 DW_AT_name for named DIEs does not contain the prefixes. */
19306 base
= strrchr (demangled
, ':');
19307 if (base
&& base
> demangled
&& base
[-1] == ':')
19312 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19315 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19316 base
, strlen (base
)));
19324 /* Read an attribute value described by an attribute form. */
19326 static const gdb_byte
*
19327 read_attribute_value (const struct die_reader_specs
*reader
,
19328 struct attribute
*attr
, unsigned form
,
19329 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19331 struct dwarf2_cu
*cu
= reader
->cu
;
19332 struct dwarf2_per_objfile
*dwarf2_per_objfile
19333 = cu
->per_cu
->dwarf2_per_objfile
;
19334 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19335 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19336 bfd
*abfd
= reader
->abfd
;
19337 struct comp_unit_head
*cu_header
= &cu
->header
;
19338 unsigned int bytes_read
;
19339 struct dwarf_block
*blk
;
19341 attr
->form
= (enum dwarf_form
) form
;
19344 case DW_FORM_ref_addr
:
19345 if (cu
->header
.version
== 2)
19346 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19348 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19349 &cu
->header
, &bytes_read
);
19350 info_ptr
+= bytes_read
;
19352 case DW_FORM_GNU_ref_alt
:
19353 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19354 info_ptr
+= bytes_read
;
19357 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19358 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19359 info_ptr
+= bytes_read
;
19361 case DW_FORM_block2
:
19362 blk
= dwarf_alloc_block (cu
);
19363 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19365 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19366 info_ptr
+= blk
->size
;
19367 DW_BLOCK (attr
) = blk
;
19369 case DW_FORM_block4
:
19370 blk
= dwarf_alloc_block (cu
);
19371 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19373 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19374 info_ptr
+= blk
->size
;
19375 DW_BLOCK (attr
) = blk
;
19377 case DW_FORM_data2
:
19378 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19381 case DW_FORM_data4
:
19382 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19385 case DW_FORM_data8
:
19386 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19389 case DW_FORM_data16
:
19390 blk
= dwarf_alloc_block (cu
);
19392 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19394 DW_BLOCK (attr
) = blk
;
19396 case DW_FORM_sec_offset
:
19397 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19398 info_ptr
+= bytes_read
;
19400 case DW_FORM_string
:
19401 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19402 DW_STRING_IS_CANONICAL (attr
) = 0;
19403 info_ptr
+= bytes_read
;
19406 if (!cu
->per_cu
->is_dwz
)
19408 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19409 abfd
, info_ptr
, cu_header
,
19411 DW_STRING_IS_CANONICAL (attr
) = 0;
19412 info_ptr
+= bytes_read
;
19416 case DW_FORM_line_strp
:
19417 if (!cu
->per_cu
->is_dwz
)
19419 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19421 cu_header
, &bytes_read
);
19422 DW_STRING_IS_CANONICAL (attr
) = 0;
19423 info_ptr
+= bytes_read
;
19427 case DW_FORM_GNU_strp_alt
:
19429 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19430 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19433 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19435 DW_STRING_IS_CANONICAL (attr
) = 0;
19436 info_ptr
+= bytes_read
;
19439 case DW_FORM_exprloc
:
19440 case DW_FORM_block
:
19441 blk
= dwarf_alloc_block (cu
);
19442 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19443 info_ptr
+= bytes_read
;
19444 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19445 info_ptr
+= blk
->size
;
19446 DW_BLOCK (attr
) = blk
;
19448 case DW_FORM_block1
:
19449 blk
= dwarf_alloc_block (cu
);
19450 blk
->size
= read_1_byte (abfd
, info_ptr
);
19452 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19453 info_ptr
+= blk
->size
;
19454 DW_BLOCK (attr
) = blk
;
19456 case DW_FORM_data1
:
19457 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19461 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19464 case DW_FORM_flag_present
:
19465 DW_UNSND (attr
) = 1;
19467 case DW_FORM_sdata
:
19468 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19469 info_ptr
+= bytes_read
;
19471 case DW_FORM_udata
:
19472 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19473 info_ptr
+= bytes_read
;
19476 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19477 + read_1_byte (abfd
, info_ptr
));
19481 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19482 + read_2_bytes (abfd
, info_ptr
));
19486 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19487 + read_4_bytes (abfd
, info_ptr
));
19491 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19492 + read_8_bytes (abfd
, info_ptr
));
19495 case DW_FORM_ref_sig8
:
19496 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19499 case DW_FORM_ref_udata
:
19500 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19501 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19502 info_ptr
+= bytes_read
;
19504 case DW_FORM_indirect
:
19505 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19506 info_ptr
+= bytes_read
;
19507 if (form
== DW_FORM_implicit_const
)
19509 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19510 info_ptr
+= bytes_read
;
19512 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19515 case DW_FORM_implicit_const
:
19516 DW_SND (attr
) = implicit_const
;
19518 case DW_FORM_GNU_addr_index
:
19519 if (reader
->dwo_file
== NULL
)
19521 /* For now flag a hard error.
19522 Later we can turn this into a complaint. */
19523 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19524 dwarf_form_name (form
),
19525 bfd_get_filename (abfd
));
19527 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19528 info_ptr
+= bytes_read
;
19530 case DW_FORM_GNU_str_index
:
19531 if (reader
->dwo_file
== NULL
)
19533 /* For now flag a hard error.
19534 Later we can turn this into a complaint if warranted. */
19535 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19536 dwarf_form_name (form
),
19537 bfd_get_filename (abfd
));
19540 ULONGEST str_index
=
19541 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19543 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19544 DW_STRING_IS_CANONICAL (attr
) = 0;
19545 info_ptr
+= bytes_read
;
19549 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19550 dwarf_form_name (form
),
19551 bfd_get_filename (abfd
));
19555 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19556 attr
->form
= DW_FORM_GNU_ref_alt
;
19558 /* We have seen instances where the compiler tried to emit a byte
19559 size attribute of -1 which ended up being encoded as an unsigned
19560 0xffffffff. Although 0xffffffff is technically a valid size value,
19561 an object of this size seems pretty unlikely so we can relatively
19562 safely treat these cases as if the size attribute was invalid and
19563 treat them as zero by default. */
19564 if (attr
->name
== DW_AT_byte_size
19565 && form
== DW_FORM_data4
19566 && DW_UNSND (attr
) >= 0xffffffff)
19569 (&symfile_complaints
,
19570 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19571 hex_string (DW_UNSND (attr
)));
19572 DW_UNSND (attr
) = 0;
19578 /* Read an attribute described by an abbreviated attribute. */
19580 static const gdb_byte
*
19581 read_attribute (const struct die_reader_specs
*reader
,
19582 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19583 const gdb_byte
*info_ptr
)
19585 attr
->name
= abbrev
->name
;
19586 return read_attribute_value (reader
, attr
, abbrev
->form
,
19587 abbrev
->implicit_const
, info_ptr
);
19590 /* Read dwarf information from a buffer. */
19592 static unsigned int
19593 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19595 return bfd_get_8 (abfd
, buf
);
19599 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19601 return bfd_get_signed_8 (abfd
, buf
);
19604 static unsigned int
19605 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19607 return bfd_get_16 (abfd
, buf
);
19611 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19613 return bfd_get_signed_16 (abfd
, buf
);
19616 static unsigned int
19617 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19619 return bfd_get_32 (abfd
, buf
);
19623 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19625 return bfd_get_signed_32 (abfd
, buf
);
19629 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19631 return bfd_get_64 (abfd
, buf
);
19635 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19636 unsigned int *bytes_read
)
19638 struct comp_unit_head
*cu_header
= &cu
->header
;
19639 CORE_ADDR retval
= 0;
19641 if (cu_header
->signed_addr_p
)
19643 switch (cu_header
->addr_size
)
19646 retval
= bfd_get_signed_16 (abfd
, buf
);
19649 retval
= bfd_get_signed_32 (abfd
, buf
);
19652 retval
= bfd_get_signed_64 (abfd
, buf
);
19655 internal_error (__FILE__
, __LINE__
,
19656 _("read_address: bad switch, signed [in module %s]"),
19657 bfd_get_filename (abfd
));
19662 switch (cu_header
->addr_size
)
19665 retval
= bfd_get_16 (abfd
, buf
);
19668 retval
= bfd_get_32 (abfd
, buf
);
19671 retval
= bfd_get_64 (abfd
, buf
);
19674 internal_error (__FILE__
, __LINE__
,
19675 _("read_address: bad switch, "
19676 "unsigned [in module %s]"),
19677 bfd_get_filename (abfd
));
19681 *bytes_read
= cu_header
->addr_size
;
19685 /* Read the initial length from a section. The (draft) DWARF 3
19686 specification allows the initial length to take up either 4 bytes
19687 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19688 bytes describe the length and all offsets will be 8 bytes in length
19691 An older, non-standard 64-bit format is also handled by this
19692 function. The older format in question stores the initial length
19693 as an 8-byte quantity without an escape value. Lengths greater
19694 than 2^32 aren't very common which means that the initial 4 bytes
19695 is almost always zero. Since a length value of zero doesn't make
19696 sense for the 32-bit format, this initial zero can be considered to
19697 be an escape value which indicates the presence of the older 64-bit
19698 format. As written, the code can't detect (old format) lengths
19699 greater than 4GB. If it becomes necessary to handle lengths
19700 somewhat larger than 4GB, we could allow other small values (such
19701 as the non-sensical values of 1, 2, and 3) to also be used as
19702 escape values indicating the presence of the old format.
19704 The value returned via bytes_read should be used to increment the
19705 relevant pointer after calling read_initial_length().
19707 [ Note: read_initial_length() and read_offset() are based on the
19708 document entitled "DWARF Debugging Information Format", revision
19709 3, draft 8, dated November 19, 2001. This document was obtained
19712 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19714 This document is only a draft and is subject to change. (So beware.)
19716 Details regarding the older, non-standard 64-bit format were
19717 determined empirically by examining 64-bit ELF files produced by
19718 the SGI toolchain on an IRIX 6.5 machine.
19720 - Kevin, July 16, 2002
19724 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19726 LONGEST length
= bfd_get_32 (abfd
, buf
);
19728 if (length
== 0xffffffff)
19730 length
= bfd_get_64 (abfd
, buf
+ 4);
19733 else if (length
== 0)
19735 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19736 length
= bfd_get_64 (abfd
, buf
);
19747 /* Cover function for read_initial_length.
19748 Returns the length of the object at BUF, and stores the size of the
19749 initial length in *BYTES_READ and stores the size that offsets will be in
19751 If the initial length size is not equivalent to that specified in
19752 CU_HEADER then issue a complaint.
19753 This is useful when reading non-comp-unit headers. */
19756 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19757 const struct comp_unit_head
*cu_header
,
19758 unsigned int *bytes_read
,
19759 unsigned int *offset_size
)
19761 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19763 gdb_assert (cu_header
->initial_length_size
== 4
19764 || cu_header
->initial_length_size
== 8
19765 || cu_header
->initial_length_size
== 12);
19767 if (cu_header
->initial_length_size
!= *bytes_read
)
19768 complaint (&symfile_complaints
,
19769 _("intermixed 32-bit and 64-bit DWARF sections"));
19771 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19775 /* Read an offset from the data stream. The size of the offset is
19776 given by cu_header->offset_size. */
19779 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19780 const struct comp_unit_head
*cu_header
,
19781 unsigned int *bytes_read
)
19783 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19785 *bytes_read
= cu_header
->offset_size
;
19789 /* Read an offset from the data stream. */
19792 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19794 LONGEST retval
= 0;
19796 switch (offset_size
)
19799 retval
= bfd_get_32 (abfd
, buf
);
19802 retval
= bfd_get_64 (abfd
, buf
);
19805 internal_error (__FILE__
, __LINE__
,
19806 _("read_offset_1: bad switch [in module %s]"),
19807 bfd_get_filename (abfd
));
19813 static const gdb_byte
*
19814 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19816 /* If the size of a host char is 8 bits, we can return a pointer
19817 to the buffer, otherwise we have to copy the data to a buffer
19818 allocated on the temporary obstack. */
19819 gdb_assert (HOST_CHAR_BIT
== 8);
19823 static const char *
19824 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19825 unsigned int *bytes_read_ptr
)
19827 /* If the size of a host char is 8 bits, we can return a pointer
19828 to the string, otherwise we have to copy the string to a buffer
19829 allocated on the temporary obstack. */
19830 gdb_assert (HOST_CHAR_BIT
== 8);
19833 *bytes_read_ptr
= 1;
19836 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19837 return (const char *) buf
;
19840 /* Return pointer to string at section SECT offset STR_OFFSET with error
19841 reporting strings FORM_NAME and SECT_NAME. */
19843 static const char *
19844 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19845 bfd
*abfd
, LONGEST str_offset
,
19846 struct dwarf2_section_info
*sect
,
19847 const char *form_name
,
19848 const char *sect_name
)
19850 dwarf2_read_section (objfile
, sect
);
19851 if (sect
->buffer
== NULL
)
19852 error (_("%s used without %s section [in module %s]"),
19853 form_name
, sect_name
, bfd_get_filename (abfd
));
19854 if (str_offset
>= sect
->size
)
19855 error (_("%s pointing outside of %s section [in module %s]"),
19856 form_name
, sect_name
, bfd_get_filename (abfd
));
19857 gdb_assert (HOST_CHAR_BIT
== 8);
19858 if (sect
->buffer
[str_offset
] == '\0')
19860 return (const char *) (sect
->buffer
+ str_offset
);
19863 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19865 static const char *
19866 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19867 bfd
*abfd
, LONGEST str_offset
)
19869 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19871 &dwarf2_per_objfile
->str
,
19872 "DW_FORM_strp", ".debug_str");
19875 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19877 static const char *
19878 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19879 bfd
*abfd
, LONGEST str_offset
)
19881 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19883 &dwarf2_per_objfile
->line_str
,
19884 "DW_FORM_line_strp",
19885 ".debug_line_str");
19888 /* Read a string at offset STR_OFFSET in the .debug_str section from
19889 the .dwz file DWZ. Throw an error if the offset is too large. If
19890 the string consists of a single NUL byte, return NULL; otherwise
19891 return a pointer to the string. */
19893 static const char *
19894 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19895 LONGEST str_offset
)
19897 dwarf2_read_section (objfile
, &dwz
->str
);
19899 if (dwz
->str
.buffer
== NULL
)
19900 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19901 "section [in module %s]"),
19902 bfd_get_filename (dwz
->dwz_bfd
));
19903 if (str_offset
>= dwz
->str
.size
)
19904 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19905 ".debug_str section [in module %s]"),
19906 bfd_get_filename (dwz
->dwz_bfd
));
19907 gdb_assert (HOST_CHAR_BIT
== 8);
19908 if (dwz
->str
.buffer
[str_offset
] == '\0')
19910 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19913 /* Return pointer to string at .debug_str offset as read from BUF.
19914 BUF is assumed to be in a compilation unit described by CU_HEADER.
19915 Return *BYTES_READ_PTR count of bytes read from BUF. */
19917 static const char *
19918 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19919 const gdb_byte
*buf
,
19920 const struct comp_unit_head
*cu_header
,
19921 unsigned int *bytes_read_ptr
)
19923 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19925 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19928 /* Return pointer to string at .debug_line_str offset as read from BUF.
19929 BUF is assumed to be in a compilation unit described by CU_HEADER.
19930 Return *BYTES_READ_PTR count of bytes read from BUF. */
19932 static const char *
19933 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19934 bfd
*abfd
, const gdb_byte
*buf
,
19935 const struct comp_unit_head
*cu_header
,
19936 unsigned int *bytes_read_ptr
)
19938 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19940 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19945 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19946 unsigned int *bytes_read_ptr
)
19949 unsigned int num_read
;
19951 unsigned char byte
;
19958 byte
= bfd_get_8 (abfd
, buf
);
19961 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19962 if ((byte
& 128) == 0)
19968 *bytes_read_ptr
= num_read
;
19973 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19974 unsigned int *bytes_read_ptr
)
19977 int shift
, num_read
;
19978 unsigned char byte
;
19985 byte
= bfd_get_8 (abfd
, buf
);
19988 result
|= ((LONGEST
) (byte
& 127) << shift
);
19990 if ((byte
& 128) == 0)
19995 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19996 result
|= -(((LONGEST
) 1) << shift
);
19997 *bytes_read_ptr
= num_read
;
20001 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20002 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20003 ADDR_SIZE is the size of addresses from the CU header. */
20006 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20007 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20009 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20010 bfd
*abfd
= objfile
->obfd
;
20011 const gdb_byte
*info_ptr
;
20013 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20014 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20015 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20016 objfile_name (objfile
));
20017 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20018 error (_("DW_FORM_addr_index pointing outside of "
20019 ".debug_addr section [in module %s]"),
20020 objfile_name (objfile
));
20021 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20022 + addr_base
+ addr_index
* addr_size
);
20023 if (addr_size
== 4)
20024 return bfd_get_32 (abfd
, info_ptr
);
20026 return bfd_get_64 (abfd
, info_ptr
);
20029 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20032 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20034 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20035 cu
->addr_base
, cu
->header
.addr_size
);
20038 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20041 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20042 unsigned int *bytes_read
)
20044 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20045 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20047 return read_addr_index (cu
, addr_index
);
20050 /* Data structure to pass results from dwarf2_read_addr_index_reader
20051 back to dwarf2_read_addr_index. */
20053 struct dwarf2_read_addr_index_data
20055 ULONGEST addr_base
;
20059 /* die_reader_func for dwarf2_read_addr_index. */
20062 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20063 const gdb_byte
*info_ptr
,
20064 struct die_info
*comp_unit_die
,
20068 struct dwarf2_cu
*cu
= reader
->cu
;
20069 struct dwarf2_read_addr_index_data
*aidata
=
20070 (struct dwarf2_read_addr_index_data
*) data
;
20072 aidata
->addr_base
= cu
->addr_base
;
20073 aidata
->addr_size
= cu
->header
.addr_size
;
20076 /* Given an index in .debug_addr, fetch the value.
20077 NOTE: This can be called during dwarf expression evaluation,
20078 long after the debug information has been read, and thus per_cu->cu
20079 may no longer exist. */
20082 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20083 unsigned int addr_index
)
20085 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20086 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20087 struct dwarf2_cu
*cu
= per_cu
->cu
;
20088 ULONGEST addr_base
;
20091 /* We need addr_base and addr_size.
20092 If we don't have PER_CU->cu, we have to get it.
20093 Nasty, but the alternative is storing the needed info in PER_CU,
20094 which at this point doesn't seem justified: it's not clear how frequently
20095 it would get used and it would increase the size of every PER_CU.
20096 Entry points like dwarf2_per_cu_addr_size do a similar thing
20097 so we're not in uncharted territory here.
20098 Alas we need to be a bit more complicated as addr_base is contained
20101 We don't need to read the entire CU(/TU).
20102 We just need the header and top level die.
20104 IWBN to use the aging mechanism to let us lazily later discard the CU.
20105 For now we skip this optimization. */
20109 addr_base
= cu
->addr_base
;
20110 addr_size
= cu
->header
.addr_size
;
20114 struct dwarf2_read_addr_index_data aidata
;
20116 /* Note: We can't use init_cutu_and_read_dies_simple here,
20117 we need addr_base. */
20118 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
20119 dwarf2_read_addr_index_reader
, &aidata
);
20120 addr_base
= aidata
.addr_base
;
20121 addr_size
= aidata
.addr_size
;
20124 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20128 /* Given a DW_FORM_GNU_str_index, fetch the string.
20129 This is only used by the Fission support. */
20131 static const char *
20132 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20134 struct dwarf2_cu
*cu
= reader
->cu
;
20135 struct dwarf2_per_objfile
*dwarf2_per_objfile
20136 = cu
->per_cu
->dwarf2_per_objfile
;
20137 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20138 const char *objf_name
= objfile_name (objfile
);
20139 bfd
*abfd
= objfile
->obfd
;
20140 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20141 struct dwarf2_section_info
*str_offsets_section
=
20142 &reader
->dwo_file
->sections
.str_offsets
;
20143 const gdb_byte
*info_ptr
;
20144 ULONGEST str_offset
;
20145 static const char form_name
[] = "DW_FORM_GNU_str_index";
20147 dwarf2_read_section (objfile
, str_section
);
20148 dwarf2_read_section (objfile
, str_offsets_section
);
20149 if (str_section
->buffer
== NULL
)
20150 error (_("%s used without .debug_str.dwo section"
20151 " in CU at offset %s [in module %s]"),
20152 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20153 if (str_offsets_section
->buffer
== NULL
)
20154 error (_("%s used without .debug_str_offsets.dwo section"
20155 " in CU at offset %s [in module %s]"),
20156 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20157 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20158 error (_("%s pointing outside of .debug_str_offsets.dwo"
20159 " section in CU at offset %s [in module %s]"),
20160 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20161 info_ptr
= (str_offsets_section
->buffer
20162 + str_index
* cu
->header
.offset_size
);
20163 if (cu
->header
.offset_size
== 4)
20164 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20166 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20167 if (str_offset
>= str_section
->size
)
20168 error (_("Offset from %s pointing outside of"
20169 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20170 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20171 return (const char *) (str_section
->buffer
+ str_offset
);
20174 /* Return the length of an LEB128 number in BUF. */
20177 leb128_size (const gdb_byte
*buf
)
20179 const gdb_byte
*begin
= buf
;
20185 if ((byte
& 128) == 0)
20186 return buf
- begin
;
20191 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20200 cu
->language
= language_c
;
20203 case DW_LANG_C_plus_plus
:
20204 case DW_LANG_C_plus_plus_11
:
20205 case DW_LANG_C_plus_plus_14
:
20206 cu
->language
= language_cplus
;
20209 cu
->language
= language_d
;
20211 case DW_LANG_Fortran77
:
20212 case DW_LANG_Fortran90
:
20213 case DW_LANG_Fortran95
:
20214 case DW_LANG_Fortran03
:
20215 case DW_LANG_Fortran08
:
20216 cu
->language
= language_fortran
;
20219 cu
->language
= language_go
;
20221 case DW_LANG_Mips_Assembler
:
20222 cu
->language
= language_asm
;
20224 case DW_LANG_Ada83
:
20225 case DW_LANG_Ada95
:
20226 cu
->language
= language_ada
;
20228 case DW_LANG_Modula2
:
20229 cu
->language
= language_m2
;
20231 case DW_LANG_Pascal83
:
20232 cu
->language
= language_pascal
;
20235 cu
->language
= language_objc
;
20238 case DW_LANG_Rust_old
:
20239 cu
->language
= language_rust
;
20241 case DW_LANG_Cobol74
:
20242 case DW_LANG_Cobol85
:
20244 cu
->language
= language_minimal
;
20247 cu
->language_defn
= language_def (cu
->language
);
20250 /* Return the named attribute or NULL if not there. */
20252 static struct attribute
*
20253 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20258 struct attribute
*spec
= NULL
;
20260 for (i
= 0; i
< die
->num_attrs
; ++i
)
20262 if (die
->attrs
[i
].name
== name
)
20263 return &die
->attrs
[i
];
20264 if (die
->attrs
[i
].name
== DW_AT_specification
20265 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20266 spec
= &die
->attrs
[i
];
20272 die
= follow_die_ref (die
, spec
, &cu
);
20278 /* Return the named attribute or NULL if not there,
20279 but do not follow DW_AT_specification, etc.
20280 This is for use in contexts where we're reading .debug_types dies.
20281 Following DW_AT_specification, DW_AT_abstract_origin will take us
20282 back up the chain, and we want to go down. */
20284 static struct attribute
*
20285 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20289 for (i
= 0; i
< die
->num_attrs
; ++i
)
20290 if (die
->attrs
[i
].name
== name
)
20291 return &die
->attrs
[i
];
20296 /* Return the string associated with a string-typed attribute, or NULL if it
20297 is either not found or is of an incorrect type. */
20299 static const char *
20300 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20302 struct attribute
*attr
;
20303 const char *str
= NULL
;
20305 attr
= dwarf2_attr (die
, name
, cu
);
20309 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20310 || attr
->form
== DW_FORM_string
20311 || attr
->form
== DW_FORM_GNU_str_index
20312 || attr
->form
== DW_FORM_GNU_strp_alt
)
20313 str
= DW_STRING (attr
);
20315 complaint (&symfile_complaints
,
20316 _("string type expected for attribute %s for "
20317 "DIE at %s in module %s"),
20318 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20319 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20325 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20326 and holds a non-zero value. This function should only be used for
20327 DW_FORM_flag or DW_FORM_flag_present attributes. */
20330 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20332 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20334 return (attr
&& DW_UNSND (attr
));
20338 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20340 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20341 which value is non-zero. However, we have to be careful with
20342 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20343 (via dwarf2_flag_true_p) follows this attribute. So we may
20344 end up accidently finding a declaration attribute that belongs
20345 to a different DIE referenced by the specification attribute,
20346 even though the given DIE does not have a declaration attribute. */
20347 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20348 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20351 /* Return the die giving the specification for DIE, if there is
20352 one. *SPEC_CU is the CU containing DIE on input, and the CU
20353 containing the return value on output. If there is no
20354 specification, but there is an abstract origin, that is
20357 static struct die_info
*
20358 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20360 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20363 if (spec_attr
== NULL
)
20364 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20366 if (spec_attr
== NULL
)
20369 return follow_die_ref (die
, spec_attr
, spec_cu
);
20372 /* Stub for free_line_header to match void * callback types. */
20375 free_line_header_voidp (void *arg
)
20377 struct line_header
*lh
= (struct line_header
*) arg
;
20383 line_header::add_include_dir (const char *include_dir
)
20385 if (dwarf_line_debug
>= 2)
20386 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20387 include_dirs
.size () + 1, include_dir
);
20389 include_dirs
.push_back (include_dir
);
20393 line_header::add_file_name (const char *name
,
20395 unsigned int mod_time
,
20396 unsigned int length
)
20398 if (dwarf_line_debug
>= 2)
20399 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20400 (unsigned) file_names
.size () + 1, name
);
20402 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20405 /* A convenience function to find the proper .debug_line section for a CU. */
20407 static struct dwarf2_section_info
*
20408 get_debug_line_section (struct dwarf2_cu
*cu
)
20410 struct dwarf2_section_info
*section
;
20411 struct dwarf2_per_objfile
*dwarf2_per_objfile
20412 = cu
->per_cu
->dwarf2_per_objfile
;
20414 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20416 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20417 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20418 else if (cu
->per_cu
->is_dwz
)
20420 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20422 section
= &dwz
->line
;
20425 section
= &dwarf2_per_objfile
->line
;
20430 /* Read directory or file name entry format, starting with byte of
20431 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20432 entries count and the entries themselves in the described entry
20436 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20437 bfd
*abfd
, const gdb_byte
**bufp
,
20438 struct line_header
*lh
,
20439 const struct comp_unit_head
*cu_header
,
20440 void (*callback
) (struct line_header
*lh
,
20443 unsigned int mod_time
,
20444 unsigned int length
))
20446 gdb_byte format_count
, formati
;
20447 ULONGEST data_count
, datai
;
20448 const gdb_byte
*buf
= *bufp
;
20449 const gdb_byte
*format_header_data
;
20450 unsigned int bytes_read
;
20452 format_count
= read_1_byte (abfd
, buf
);
20454 format_header_data
= buf
;
20455 for (formati
= 0; formati
< format_count
; formati
++)
20457 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20459 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20463 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20465 for (datai
= 0; datai
< data_count
; datai
++)
20467 const gdb_byte
*format
= format_header_data
;
20468 struct file_entry fe
;
20470 for (formati
= 0; formati
< format_count
; formati
++)
20472 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20473 format
+= bytes_read
;
20475 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20476 format
+= bytes_read
;
20478 gdb::optional
<const char *> string
;
20479 gdb::optional
<unsigned int> uint
;
20483 case DW_FORM_string
:
20484 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20488 case DW_FORM_line_strp
:
20489 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20496 case DW_FORM_data1
:
20497 uint
.emplace (read_1_byte (abfd
, buf
));
20501 case DW_FORM_data2
:
20502 uint
.emplace (read_2_bytes (abfd
, buf
));
20506 case DW_FORM_data4
:
20507 uint
.emplace (read_4_bytes (abfd
, buf
));
20511 case DW_FORM_data8
:
20512 uint
.emplace (read_8_bytes (abfd
, buf
));
20516 case DW_FORM_udata
:
20517 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20521 case DW_FORM_block
:
20522 /* It is valid only for DW_LNCT_timestamp which is ignored by
20527 switch (content_type
)
20530 if (string
.has_value ())
20533 case DW_LNCT_directory_index
:
20534 if (uint
.has_value ())
20535 fe
.d_index
= (dir_index
) *uint
;
20537 case DW_LNCT_timestamp
:
20538 if (uint
.has_value ())
20539 fe
.mod_time
= *uint
;
20542 if (uint
.has_value ())
20548 complaint (&symfile_complaints
,
20549 _("Unknown format content type %s"),
20550 pulongest (content_type
));
20554 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20560 /* Read the statement program header starting at OFFSET in
20561 .debug_line, or .debug_line.dwo. Return a pointer
20562 to a struct line_header, allocated using xmalloc.
20563 Returns NULL if there is a problem reading the header, e.g., if it
20564 has a version we don't understand.
20566 NOTE: the strings in the include directory and file name tables of
20567 the returned object point into the dwarf line section buffer,
20568 and must not be freed. */
20570 static line_header_up
20571 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20573 const gdb_byte
*line_ptr
;
20574 unsigned int bytes_read
, offset_size
;
20576 const char *cur_dir
, *cur_file
;
20577 struct dwarf2_section_info
*section
;
20579 struct dwarf2_per_objfile
*dwarf2_per_objfile
20580 = cu
->per_cu
->dwarf2_per_objfile
;
20582 section
= get_debug_line_section (cu
);
20583 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20584 if (section
->buffer
== NULL
)
20586 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20587 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20589 complaint (&symfile_complaints
, _("missing .debug_line section"));
20593 /* We can't do this until we know the section is non-empty.
20594 Only then do we know we have such a section. */
20595 abfd
= get_section_bfd_owner (section
);
20597 /* Make sure that at least there's room for the total_length field.
20598 That could be 12 bytes long, but we're just going to fudge that. */
20599 if (to_underlying (sect_off
) + 4 >= section
->size
)
20601 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20605 line_header_up
lh (new line_header ());
20607 lh
->sect_off
= sect_off
;
20608 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20610 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20612 /* Read in the header. */
20614 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20615 &bytes_read
, &offset_size
);
20616 line_ptr
+= bytes_read
;
20617 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20619 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20622 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20623 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20625 if (lh
->version
> 5)
20627 /* This is a version we don't understand. The format could have
20628 changed in ways we don't handle properly so just punt. */
20629 complaint (&symfile_complaints
,
20630 _("unsupported version in .debug_line section"));
20633 if (lh
->version
>= 5)
20635 gdb_byte segment_selector_size
;
20637 /* Skip address size. */
20638 read_1_byte (abfd
, line_ptr
);
20641 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20643 if (segment_selector_size
!= 0)
20645 complaint (&symfile_complaints
,
20646 _("unsupported segment selector size %u "
20647 "in .debug_line section"),
20648 segment_selector_size
);
20652 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20653 line_ptr
+= offset_size
;
20654 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20656 if (lh
->version
>= 4)
20658 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20662 lh
->maximum_ops_per_instruction
= 1;
20664 if (lh
->maximum_ops_per_instruction
== 0)
20666 lh
->maximum_ops_per_instruction
= 1;
20667 complaint (&symfile_complaints
,
20668 _("invalid maximum_ops_per_instruction "
20669 "in `.debug_line' section"));
20672 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20674 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20676 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20678 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20680 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20682 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20683 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20685 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20689 if (lh
->version
>= 5)
20691 /* Read directory table. */
20692 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20694 [] (struct line_header
*lh
, const char *name
,
20695 dir_index d_index
, unsigned int mod_time
,
20696 unsigned int length
)
20698 lh
->add_include_dir (name
);
20701 /* Read file name table. */
20702 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20704 [] (struct line_header
*lh
, const char *name
,
20705 dir_index d_index
, unsigned int mod_time
,
20706 unsigned int length
)
20708 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20713 /* Read directory table. */
20714 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20716 line_ptr
+= bytes_read
;
20717 lh
->add_include_dir (cur_dir
);
20719 line_ptr
+= bytes_read
;
20721 /* Read file name table. */
20722 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20724 unsigned int mod_time
, length
;
20727 line_ptr
+= bytes_read
;
20728 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20729 line_ptr
+= bytes_read
;
20730 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20731 line_ptr
+= bytes_read
;
20732 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20733 line_ptr
+= bytes_read
;
20735 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20737 line_ptr
+= bytes_read
;
20739 lh
->statement_program_start
= line_ptr
;
20741 if (line_ptr
> (section
->buffer
+ section
->size
))
20742 complaint (&symfile_complaints
,
20743 _("line number info header doesn't "
20744 "fit in `.debug_line' section"));
20749 /* Subroutine of dwarf_decode_lines to simplify it.
20750 Return the file name of the psymtab for included file FILE_INDEX
20751 in line header LH of PST.
20752 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20753 If space for the result is malloc'd, *NAME_HOLDER will be set.
20754 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20756 static const char *
20757 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20758 const struct partial_symtab
*pst
,
20759 const char *comp_dir
,
20760 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20762 const file_entry
&fe
= lh
->file_names
[file_index
];
20763 const char *include_name
= fe
.name
;
20764 const char *include_name_to_compare
= include_name
;
20765 const char *pst_filename
;
20768 const char *dir_name
= fe
.include_dir (lh
);
20770 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20771 if (!IS_ABSOLUTE_PATH (include_name
)
20772 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20774 /* Avoid creating a duplicate psymtab for PST.
20775 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20776 Before we do the comparison, however, we need to account
20777 for DIR_NAME and COMP_DIR.
20778 First prepend dir_name (if non-NULL). If we still don't
20779 have an absolute path prepend comp_dir (if non-NULL).
20780 However, the directory we record in the include-file's
20781 psymtab does not contain COMP_DIR (to match the
20782 corresponding symtab(s)).
20787 bash$ gcc -g ./hello.c
20788 include_name = "hello.c"
20790 DW_AT_comp_dir = comp_dir = "/tmp"
20791 DW_AT_name = "./hello.c"
20795 if (dir_name
!= NULL
)
20797 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20798 include_name
, (char *) NULL
));
20799 include_name
= name_holder
->get ();
20800 include_name_to_compare
= include_name
;
20802 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20804 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20805 include_name
, (char *) NULL
));
20806 include_name_to_compare
= hold_compare
.get ();
20810 pst_filename
= pst
->filename
;
20811 gdb::unique_xmalloc_ptr
<char> copied_name
;
20812 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20814 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20815 pst_filename
, (char *) NULL
));
20816 pst_filename
= copied_name
.get ();
20819 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20823 return include_name
;
20826 /* State machine to track the state of the line number program. */
20828 class lnp_state_machine
20831 /* Initialize a machine state for the start of a line number
20833 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20835 file_entry
*current_file ()
20837 /* lh->file_names is 0-based, but the file name numbers in the
20838 statement program are 1-based. */
20839 return m_line_header
->file_name_at (m_file
);
20842 /* Record the line in the state machine. END_SEQUENCE is true if
20843 we're processing the end of a sequence. */
20844 void record_line (bool end_sequence
);
20846 /* Check address and if invalid nop-out the rest of the lines in this
20848 void check_line_address (struct dwarf2_cu
*cu
,
20849 const gdb_byte
*line_ptr
,
20850 CORE_ADDR lowpc
, CORE_ADDR address
);
20852 void handle_set_discriminator (unsigned int discriminator
)
20854 m_discriminator
= discriminator
;
20855 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20858 /* Handle DW_LNE_set_address. */
20859 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20862 address
+= baseaddr
;
20863 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20866 /* Handle DW_LNS_advance_pc. */
20867 void handle_advance_pc (CORE_ADDR adjust
);
20869 /* Handle a special opcode. */
20870 void handle_special_opcode (unsigned char op_code
);
20872 /* Handle DW_LNS_advance_line. */
20873 void handle_advance_line (int line_delta
)
20875 advance_line (line_delta
);
20878 /* Handle DW_LNS_set_file. */
20879 void handle_set_file (file_name_index file
);
20881 /* Handle DW_LNS_negate_stmt. */
20882 void handle_negate_stmt ()
20884 m_is_stmt
= !m_is_stmt
;
20887 /* Handle DW_LNS_const_add_pc. */
20888 void handle_const_add_pc ();
20890 /* Handle DW_LNS_fixed_advance_pc. */
20891 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20893 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20897 /* Handle DW_LNS_copy. */
20898 void handle_copy ()
20900 record_line (false);
20901 m_discriminator
= 0;
20904 /* Handle DW_LNE_end_sequence. */
20905 void handle_end_sequence ()
20907 m_record_line_callback
= ::record_line
;
20911 /* Advance the line by LINE_DELTA. */
20912 void advance_line (int line_delta
)
20914 m_line
+= line_delta
;
20916 if (line_delta
!= 0)
20917 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20920 gdbarch
*m_gdbarch
;
20922 /* True if we're recording lines.
20923 Otherwise we're building partial symtabs and are just interested in
20924 finding include files mentioned by the line number program. */
20925 bool m_record_lines_p
;
20927 /* The line number header. */
20928 line_header
*m_line_header
;
20930 /* These are part of the standard DWARF line number state machine,
20931 and initialized according to the DWARF spec. */
20933 unsigned char m_op_index
= 0;
20934 /* The line table index (1-based) of the current file. */
20935 file_name_index m_file
= (file_name_index
) 1;
20936 unsigned int m_line
= 1;
20938 /* These are initialized in the constructor. */
20940 CORE_ADDR m_address
;
20942 unsigned int m_discriminator
;
20944 /* Additional bits of state we need to track. */
20946 /* The last file that we called dwarf2_start_subfile for.
20947 This is only used for TLLs. */
20948 unsigned int m_last_file
= 0;
20949 /* The last file a line number was recorded for. */
20950 struct subfile
*m_last_subfile
= NULL
;
20952 /* The function to call to record a line. */
20953 record_line_ftype
*m_record_line_callback
= NULL
;
20955 /* The last line number that was recorded, used to coalesce
20956 consecutive entries for the same line. This can happen, for
20957 example, when discriminators are present. PR 17276. */
20958 unsigned int m_last_line
= 0;
20959 bool m_line_has_non_zero_discriminator
= false;
20963 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20965 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20966 / m_line_header
->maximum_ops_per_instruction
)
20967 * m_line_header
->minimum_instruction_length
);
20968 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20969 m_op_index
= ((m_op_index
+ adjust
)
20970 % m_line_header
->maximum_ops_per_instruction
);
20974 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20976 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20977 CORE_ADDR addr_adj
= (((m_op_index
20978 + (adj_opcode
/ m_line_header
->line_range
))
20979 / m_line_header
->maximum_ops_per_instruction
)
20980 * m_line_header
->minimum_instruction_length
);
20981 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20982 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20983 % m_line_header
->maximum_ops_per_instruction
);
20985 int line_delta
= (m_line_header
->line_base
20986 + (adj_opcode
% m_line_header
->line_range
));
20987 advance_line (line_delta
);
20988 record_line (false);
20989 m_discriminator
= 0;
20993 lnp_state_machine::handle_set_file (file_name_index file
)
20997 const file_entry
*fe
= current_file ();
20999 dwarf2_debug_line_missing_file_complaint ();
21000 else if (m_record_lines_p
)
21002 const char *dir
= fe
->include_dir (m_line_header
);
21004 m_last_subfile
= current_subfile
;
21005 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21006 dwarf2_start_subfile (fe
->name
, dir
);
21011 lnp_state_machine::handle_const_add_pc ()
21014 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21017 = (((m_op_index
+ adjust
)
21018 / m_line_header
->maximum_ops_per_instruction
)
21019 * m_line_header
->minimum_instruction_length
);
21021 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21022 m_op_index
= ((m_op_index
+ adjust
)
21023 % m_line_header
->maximum_ops_per_instruction
);
21026 /* Ignore this record_line request. */
21029 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
21034 /* Return non-zero if we should add LINE to the line number table.
21035 LINE is the line to add, LAST_LINE is the last line that was added,
21036 LAST_SUBFILE is the subfile for LAST_LINE.
21037 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21038 had a non-zero discriminator.
21040 We have to be careful in the presence of discriminators.
21041 E.g., for this line:
21043 for (i = 0; i < 100000; i++);
21045 clang can emit four line number entries for that one line,
21046 each with a different discriminator.
21047 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21049 However, we want gdb to coalesce all four entries into one.
21050 Otherwise the user could stepi into the middle of the line and
21051 gdb would get confused about whether the pc really was in the
21052 middle of the line.
21054 Things are further complicated by the fact that two consecutive
21055 line number entries for the same line is a heuristic used by gcc
21056 to denote the end of the prologue. So we can't just discard duplicate
21057 entries, we have to be selective about it. The heuristic we use is
21058 that we only collapse consecutive entries for the same line if at least
21059 one of those entries has a non-zero discriminator. PR 17276.
21061 Note: Addresses in the line number state machine can never go backwards
21062 within one sequence, thus this coalescing is ok. */
21065 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
21066 int line_has_non_zero_discriminator
,
21067 struct subfile
*last_subfile
)
21069 if (current_subfile
!= last_subfile
)
21071 if (line
!= last_line
)
21073 /* Same line for the same file that we've seen already.
21074 As a last check, for pr 17276, only record the line if the line
21075 has never had a non-zero discriminator. */
21076 if (!line_has_non_zero_discriminator
)
21081 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
21082 in the line table of subfile SUBFILE. */
21085 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21086 unsigned int line
, CORE_ADDR address
,
21087 record_line_ftype p_record_line
)
21089 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21091 if (dwarf_line_debug
)
21093 fprintf_unfiltered (gdb_stdlog
,
21094 "Recording line %u, file %s, address %s\n",
21095 line
, lbasename (subfile
->name
),
21096 paddress (gdbarch
, address
));
21099 (*p_record_line
) (subfile
, line
, addr
);
21102 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21103 Mark the end of a set of line number records.
21104 The arguments are the same as for dwarf_record_line_1.
21105 If SUBFILE is NULL the request is ignored. */
21108 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21109 CORE_ADDR address
, record_line_ftype p_record_line
)
21111 if (subfile
== NULL
)
21114 if (dwarf_line_debug
)
21116 fprintf_unfiltered (gdb_stdlog
,
21117 "Finishing current line, file %s, address %s\n",
21118 lbasename (subfile
->name
),
21119 paddress (gdbarch
, address
));
21122 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
21126 lnp_state_machine::record_line (bool end_sequence
)
21128 if (dwarf_line_debug
)
21130 fprintf_unfiltered (gdb_stdlog
,
21131 "Processing actual line %u: file %u,"
21132 " address %s, is_stmt %u, discrim %u\n",
21133 m_line
, to_underlying (m_file
),
21134 paddress (m_gdbarch
, m_address
),
21135 m_is_stmt
, m_discriminator
);
21138 file_entry
*fe
= current_file ();
21141 dwarf2_debug_line_missing_file_complaint ();
21142 /* For now we ignore lines not starting on an instruction boundary.
21143 But not when processing end_sequence for compatibility with the
21144 previous version of the code. */
21145 else if (m_op_index
== 0 || end_sequence
)
21147 fe
->included_p
= 1;
21148 if (m_record_lines_p
&& m_is_stmt
)
21150 if (m_last_subfile
!= current_subfile
|| end_sequence
)
21152 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
21153 m_address
, m_record_line_callback
);
21158 if (dwarf_record_line_p (m_line
, m_last_line
,
21159 m_line_has_non_zero_discriminator
,
21162 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
21164 m_record_line_callback
);
21166 m_last_subfile
= current_subfile
;
21167 m_last_line
= m_line
;
21173 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
21174 bool record_lines_p
)
21177 m_record_lines_p
= record_lines_p
;
21178 m_line_header
= lh
;
21180 m_record_line_callback
= ::record_line
;
21182 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21183 was a line entry for it so that the backend has a chance to adjust it
21184 and also record it in case it needs it. This is currently used by MIPS
21185 code, cf. `mips_adjust_dwarf2_line'. */
21186 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21187 m_is_stmt
= lh
->default_is_stmt
;
21188 m_discriminator
= 0;
21192 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21193 const gdb_byte
*line_ptr
,
21194 CORE_ADDR lowpc
, CORE_ADDR address
)
21196 /* If address < lowpc then it's not a usable value, it's outside the
21197 pc range of the CU. However, we restrict the test to only address
21198 values of zero to preserve GDB's previous behaviour which is to
21199 handle the specific case of a function being GC'd by the linker. */
21201 if (address
== 0 && address
< lowpc
)
21203 /* This line table is for a function which has been
21204 GCd by the linker. Ignore it. PR gdb/12528 */
21206 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21207 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21209 complaint (&symfile_complaints
,
21210 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21211 line_offset
, objfile_name (objfile
));
21212 m_record_line_callback
= noop_record_line
;
21213 /* Note: record_line_callback is left as noop_record_line until
21214 we see DW_LNE_end_sequence. */
21218 /* Subroutine of dwarf_decode_lines to simplify it.
21219 Process the line number information in LH.
21220 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21221 program in order to set included_p for every referenced header. */
21224 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21225 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21227 const gdb_byte
*line_ptr
, *extended_end
;
21228 const gdb_byte
*line_end
;
21229 unsigned int bytes_read
, extended_len
;
21230 unsigned char op_code
, extended_op
;
21231 CORE_ADDR baseaddr
;
21232 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21233 bfd
*abfd
= objfile
->obfd
;
21234 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21235 /* True if we're recording line info (as opposed to building partial
21236 symtabs and just interested in finding include files mentioned by
21237 the line number program). */
21238 bool record_lines_p
= !decode_for_pst_p
;
21240 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21242 line_ptr
= lh
->statement_program_start
;
21243 line_end
= lh
->statement_program_end
;
21245 /* Read the statement sequences until there's nothing left. */
21246 while (line_ptr
< line_end
)
21248 /* The DWARF line number program state machine. Reset the state
21249 machine at the start of each sequence. */
21250 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
21251 bool end_sequence
= false;
21253 if (record_lines_p
)
21255 /* Start a subfile for the current file of the state
21257 const file_entry
*fe
= state_machine
.current_file ();
21260 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
21263 /* Decode the table. */
21264 while (line_ptr
< line_end
&& !end_sequence
)
21266 op_code
= read_1_byte (abfd
, line_ptr
);
21269 if (op_code
>= lh
->opcode_base
)
21271 /* Special opcode. */
21272 state_machine
.handle_special_opcode (op_code
);
21274 else switch (op_code
)
21276 case DW_LNS_extended_op
:
21277 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21279 line_ptr
+= bytes_read
;
21280 extended_end
= line_ptr
+ extended_len
;
21281 extended_op
= read_1_byte (abfd
, line_ptr
);
21283 switch (extended_op
)
21285 case DW_LNE_end_sequence
:
21286 state_machine
.handle_end_sequence ();
21287 end_sequence
= true;
21289 case DW_LNE_set_address
:
21292 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21293 line_ptr
+= bytes_read
;
21295 state_machine
.check_line_address (cu
, line_ptr
,
21297 state_machine
.handle_set_address (baseaddr
, address
);
21300 case DW_LNE_define_file
:
21302 const char *cur_file
;
21303 unsigned int mod_time
, length
;
21306 cur_file
= read_direct_string (abfd
, line_ptr
,
21308 line_ptr
+= bytes_read
;
21309 dindex
= (dir_index
)
21310 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21311 line_ptr
+= bytes_read
;
21313 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21314 line_ptr
+= bytes_read
;
21316 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21317 line_ptr
+= bytes_read
;
21318 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21321 case DW_LNE_set_discriminator
:
21323 /* The discriminator is not interesting to the
21324 debugger; just ignore it. We still need to
21325 check its value though:
21326 if there are consecutive entries for the same
21327 (non-prologue) line we want to coalesce them.
21330 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21331 line_ptr
+= bytes_read
;
21333 state_machine
.handle_set_discriminator (discr
);
21337 complaint (&symfile_complaints
,
21338 _("mangled .debug_line section"));
21341 /* Make sure that we parsed the extended op correctly. If e.g.
21342 we expected a different address size than the producer used,
21343 we may have read the wrong number of bytes. */
21344 if (line_ptr
!= extended_end
)
21346 complaint (&symfile_complaints
,
21347 _("mangled .debug_line section"));
21352 state_machine
.handle_copy ();
21354 case DW_LNS_advance_pc
:
21357 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21358 line_ptr
+= bytes_read
;
21360 state_machine
.handle_advance_pc (adjust
);
21363 case DW_LNS_advance_line
:
21366 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21367 line_ptr
+= bytes_read
;
21369 state_machine
.handle_advance_line (line_delta
);
21372 case DW_LNS_set_file
:
21374 file_name_index file
21375 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21377 line_ptr
+= bytes_read
;
21379 state_machine
.handle_set_file (file
);
21382 case DW_LNS_set_column
:
21383 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21384 line_ptr
+= bytes_read
;
21386 case DW_LNS_negate_stmt
:
21387 state_machine
.handle_negate_stmt ();
21389 case DW_LNS_set_basic_block
:
21391 /* Add to the address register of the state machine the
21392 address increment value corresponding to special opcode
21393 255. I.e., this value is scaled by the minimum
21394 instruction length since special opcode 255 would have
21395 scaled the increment. */
21396 case DW_LNS_const_add_pc
:
21397 state_machine
.handle_const_add_pc ();
21399 case DW_LNS_fixed_advance_pc
:
21401 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21404 state_machine
.handle_fixed_advance_pc (addr_adj
);
21409 /* Unknown standard opcode, ignore it. */
21412 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21414 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21415 line_ptr
+= bytes_read
;
21422 dwarf2_debug_line_missing_end_sequence_complaint ();
21424 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21425 in which case we still finish recording the last line). */
21426 state_machine
.record_line (true);
21430 /* Decode the Line Number Program (LNP) for the given line_header
21431 structure and CU. The actual information extracted and the type
21432 of structures created from the LNP depends on the value of PST.
21434 1. If PST is NULL, then this procedure uses the data from the program
21435 to create all necessary symbol tables, and their linetables.
21437 2. If PST is not NULL, this procedure reads the program to determine
21438 the list of files included by the unit represented by PST, and
21439 builds all the associated partial symbol tables.
21441 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21442 It is used for relative paths in the line table.
21443 NOTE: When processing partial symtabs (pst != NULL),
21444 comp_dir == pst->dirname.
21446 NOTE: It is important that psymtabs have the same file name (via strcmp)
21447 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21448 symtab we don't use it in the name of the psymtabs we create.
21449 E.g. expand_line_sal requires this when finding psymtabs to expand.
21450 A good testcase for this is mb-inline.exp.
21452 LOWPC is the lowest address in CU (or 0 if not known).
21454 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21455 for its PC<->lines mapping information. Otherwise only the filename
21456 table is read in. */
21459 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21460 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21461 CORE_ADDR lowpc
, int decode_mapping
)
21463 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21464 const int decode_for_pst_p
= (pst
!= NULL
);
21466 if (decode_mapping
)
21467 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21469 if (decode_for_pst_p
)
21473 /* Now that we're done scanning the Line Header Program, we can
21474 create the psymtab of each included file. */
21475 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21476 if (lh
->file_names
[file_index
].included_p
== 1)
21478 gdb::unique_xmalloc_ptr
<char> name_holder
;
21479 const char *include_name
=
21480 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21482 if (include_name
!= NULL
)
21483 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21488 /* Make sure a symtab is created for every file, even files
21489 which contain only variables (i.e. no code with associated
21491 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21494 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21496 file_entry
&fe
= lh
->file_names
[i
];
21498 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21500 if (current_subfile
->symtab
== NULL
)
21502 current_subfile
->symtab
21503 = allocate_symtab (cust
, current_subfile
->name
);
21505 fe
.symtab
= current_subfile
->symtab
;
21510 /* Start a subfile for DWARF. FILENAME is the name of the file and
21511 DIRNAME the name of the source directory which contains FILENAME
21512 or NULL if not known.
21513 This routine tries to keep line numbers from identical absolute and
21514 relative file names in a common subfile.
21516 Using the `list' example from the GDB testsuite, which resides in
21517 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21518 of /srcdir/list0.c yields the following debugging information for list0.c:
21520 DW_AT_name: /srcdir/list0.c
21521 DW_AT_comp_dir: /compdir
21522 files.files[0].name: list0.h
21523 files.files[0].dir: /srcdir
21524 files.files[1].name: list0.c
21525 files.files[1].dir: /srcdir
21527 The line number information for list0.c has to end up in a single
21528 subfile, so that `break /srcdir/list0.c:1' works as expected.
21529 start_subfile will ensure that this happens provided that we pass the
21530 concatenation of files.files[1].dir and files.files[1].name as the
21534 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21538 /* In order not to lose the line information directory,
21539 we concatenate it to the filename when it makes sense.
21540 Note that the Dwarf3 standard says (speaking of filenames in line
21541 information): ``The directory index is ignored for file names
21542 that represent full path names''. Thus ignoring dirname in the
21543 `else' branch below isn't an issue. */
21545 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21547 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21551 start_subfile (filename
);
21557 /* Start a symtab for DWARF.
21558 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21560 static struct compunit_symtab
*
21561 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21562 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21564 struct compunit_symtab
*cust
21565 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21566 low_pc
, cu
->language
);
21568 record_debugformat ("DWARF 2");
21569 record_producer (cu
->producer
);
21571 /* We assume that we're processing GCC output. */
21572 processing_gcc_compilation
= 2;
21574 cu
->processing_has_namespace_info
= 0;
21580 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21581 struct dwarf2_cu
*cu
)
21583 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21584 struct comp_unit_head
*cu_header
= &cu
->header
;
21586 /* NOTE drow/2003-01-30: There used to be a comment and some special
21587 code here to turn a symbol with DW_AT_external and a
21588 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21589 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21590 with some versions of binutils) where shared libraries could have
21591 relocations against symbols in their debug information - the
21592 minimal symbol would have the right address, but the debug info
21593 would not. It's no longer necessary, because we will explicitly
21594 apply relocations when we read in the debug information now. */
21596 /* A DW_AT_location attribute with no contents indicates that a
21597 variable has been optimized away. */
21598 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21600 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21604 /* Handle one degenerate form of location expression specially, to
21605 preserve GDB's previous behavior when section offsets are
21606 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21607 then mark this symbol as LOC_STATIC. */
21609 if (attr_form_is_block (attr
)
21610 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21611 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21612 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21613 && (DW_BLOCK (attr
)->size
21614 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21616 unsigned int dummy
;
21618 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21619 SYMBOL_VALUE_ADDRESS (sym
) =
21620 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21622 SYMBOL_VALUE_ADDRESS (sym
) =
21623 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21624 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21625 fixup_symbol_section (sym
, objfile
);
21626 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21627 SYMBOL_SECTION (sym
));
21631 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21632 expression evaluator, and use LOC_COMPUTED only when necessary
21633 (i.e. when the value of a register or memory location is
21634 referenced, or a thread-local block, etc.). Then again, it might
21635 not be worthwhile. I'm assuming that it isn't unless performance
21636 or memory numbers show me otherwise. */
21638 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21640 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21641 cu
->has_loclist
= 1;
21644 /* Given a pointer to a DWARF information entry, figure out if we need
21645 to make a symbol table entry for it, and if so, create a new entry
21646 and return a pointer to it.
21647 If TYPE is NULL, determine symbol type from the die, otherwise
21648 used the passed type.
21649 If SPACE is not NULL, use it to hold the new symbol. If it is
21650 NULL, allocate a new symbol on the objfile's obstack. */
21652 static struct symbol
*
21653 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21654 struct symbol
*space
)
21656 struct dwarf2_per_objfile
*dwarf2_per_objfile
21657 = cu
->per_cu
->dwarf2_per_objfile
;
21658 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21659 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21660 struct symbol
*sym
= NULL
;
21662 struct attribute
*attr
= NULL
;
21663 struct attribute
*attr2
= NULL
;
21664 CORE_ADDR baseaddr
;
21665 struct pending
**list_to_add
= NULL
;
21667 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21669 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21671 name
= dwarf2_name (die
, cu
);
21674 const char *linkagename
;
21675 int suppress_add
= 0;
21680 sym
= allocate_symbol (objfile
);
21681 OBJSTAT (objfile
, n_syms
++);
21683 /* Cache this symbol's name and the name's demangled form (if any). */
21684 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21685 linkagename
= dwarf2_physname (name
, die
, cu
);
21686 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21688 /* Fortran does not have mangling standard and the mangling does differ
21689 between gfortran, iFort etc. */
21690 if (cu
->language
== language_fortran
21691 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21692 symbol_set_demangled_name (&(sym
->ginfo
),
21693 dwarf2_full_name (name
, die
, cu
),
21696 /* Default assumptions.
21697 Use the passed type or decode it from the die. */
21698 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21699 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21701 SYMBOL_TYPE (sym
) = type
;
21703 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21704 attr
= dwarf2_attr (die
,
21705 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21709 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21712 attr
= dwarf2_attr (die
,
21713 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21717 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21718 struct file_entry
*fe
;
21720 if (cu
->line_header
!= NULL
)
21721 fe
= cu
->line_header
->file_name_at (file_index
);
21726 complaint (&symfile_complaints
,
21727 _("file index out of range"));
21729 symbol_set_symtab (sym
, fe
->symtab
);
21735 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21740 addr
= attr_value_as_address (attr
);
21741 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21742 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21744 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21745 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21746 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21747 add_symbol_to_list (sym
, cu
->list_in_scope
);
21749 case DW_TAG_subprogram
:
21750 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21752 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21753 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21754 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21755 || cu
->language
== language_ada
)
21757 /* Subprograms marked external are stored as a global symbol.
21758 Ada subprograms, whether marked external or not, are always
21759 stored as a global symbol, because we want to be able to
21760 access them globally. For instance, we want to be able
21761 to break on a nested subprogram without having to
21762 specify the context. */
21763 list_to_add
= &global_symbols
;
21767 list_to_add
= cu
->list_in_scope
;
21770 case DW_TAG_inlined_subroutine
:
21771 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21773 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21774 SYMBOL_INLINED (sym
) = 1;
21775 list_to_add
= cu
->list_in_scope
;
21777 case DW_TAG_template_value_param
:
21779 /* Fall through. */
21780 case DW_TAG_constant
:
21781 case DW_TAG_variable
:
21782 case DW_TAG_member
:
21783 /* Compilation with minimal debug info may result in
21784 variables with missing type entries. Change the
21785 misleading `void' type to something sensible. */
21786 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21787 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21789 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21790 /* In the case of DW_TAG_member, we should only be called for
21791 static const members. */
21792 if (die
->tag
== DW_TAG_member
)
21794 /* dwarf2_add_field uses die_is_declaration,
21795 so we do the same. */
21796 gdb_assert (die_is_declaration (die
, cu
));
21801 dwarf2_const_value (attr
, sym
, cu
);
21802 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21805 if (attr2
&& (DW_UNSND (attr2
) != 0))
21806 list_to_add
= &global_symbols
;
21808 list_to_add
= cu
->list_in_scope
;
21812 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21815 var_decode_location (attr
, sym
, cu
);
21816 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21818 /* Fortran explicitly imports any global symbols to the local
21819 scope by DW_TAG_common_block. */
21820 if (cu
->language
== language_fortran
&& die
->parent
21821 && die
->parent
->tag
== DW_TAG_common_block
)
21824 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21825 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21826 && !dwarf2_per_objfile
->has_section_at_zero
)
21828 /* When a static variable is eliminated by the linker,
21829 the corresponding debug information is not stripped
21830 out, but the variable address is set to null;
21831 do not add such variables into symbol table. */
21833 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21835 /* Workaround gfortran PR debug/40040 - it uses
21836 DW_AT_location for variables in -fPIC libraries which may
21837 get overriden by other libraries/executable and get
21838 a different address. Resolve it by the minimal symbol
21839 which may come from inferior's executable using copy
21840 relocation. Make this workaround only for gfortran as for
21841 other compilers GDB cannot guess the minimal symbol
21842 Fortran mangling kind. */
21843 if (cu
->language
== language_fortran
&& die
->parent
21844 && die
->parent
->tag
== DW_TAG_module
21846 && startswith (cu
->producer
, "GNU Fortran"))
21847 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21849 /* A variable with DW_AT_external is never static,
21850 but it may be block-scoped. */
21851 list_to_add
= (cu
->list_in_scope
== &file_symbols
21852 ? &global_symbols
: cu
->list_in_scope
);
21855 list_to_add
= cu
->list_in_scope
;
21859 /* We do not know the address of this symbol.
21860 If it is an external symbol and we have type information
21861 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21862 The address of the variable will then be determined from
21863 the minimal symbol table whenever the variable is
21865 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21867 /* Fortran explicitly imports any global symbols to the local
21868 scope by DW_TAG_common_block. */
21869 if (cu
->language
== language_fortran
&& die
->parent
21870 && die
->parent
->tag
== DW_TAG_common_block
)
21872 /* SYMBOL_CLASS doesn't matter here because
21873 read_common_block is going to reset it. */
21875 list_to_add
= cu
->list_in_scope
;
21877 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21878 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21880 /* A variable with DW_AT_external is never static, but it
21881 may be block-scoped. */
21882 list_to_add
= (cu
->list_in_scope
== &file_symbols
21883 ? &global_symbols
: cu
->list_in_scope
);
21885 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21887 else if (!die_is_declaration (die
, cu
))
21889 /* Use the default LOC_OPTIMIZED_OUT class. */
21890 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21892 list_to_add
= cu
->list_in_scope
;
21896 case DW_TAG_formal_parameter
:
21897 /* If we are inside a function, mark this as an argument. If
21898 not, we might be looking at an argument to an inlined function
21899 when we do not have enough information to show inlined frames;
21900 pretend it's a local variable in that case so that the user can
21902 if (context_stack_depth
> 0
21903 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21904 SYMBOL_IS_ARGUMENT (sym
) = 1;
21905 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21908 var_decode_location (attr
, sym
, cu
);
21910 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21913 dwarf2_const_value (attr
, sym
, cu
);
21916 list_to_add
= cu
->list_in_scope
;
21918 case DW_TAG_unspecified_parameters
:
21919 /* From varargs functions; gdb doesn't seem to have any
21920 interest in this information, so just ignore it for now.
21923 case DW_TAG_template_type_param
:
21925 /* Fall through. */
21926 case DW_TAG_class_type
:
21927 case DW_TAG_interface_type
:
21928 case DW_TAG_structure_type
:
21929 case DW_TAG_union_type
:
21930 case DW_TAG_set_type
:
21931 case DW_TAG_enumeration_type
:
21932 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21933 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21936 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21937 really ever be static objects: otherwise, if you try
21938 to, say, break of a class's method and you're in a file
21939 which doesn't mention that class, it won't work unless
21940 the check for all static symbols in lookup_symbol_aux
21941 saves you. See the OtherFileClass tests in
21942 gdb.c++/namespace.exp. */
21946 list_to_add
= (cu
->list_in_scope
== &file_symbols
21947 && cu
->language
== language_cplus
21948 ? &global_symbols
: cu
->list_in_scope
);
21950 /* The semantics of C++ state that "struct foo {
21951 ... }" also defines a typedef for "foo". */
21952 if (cu
->language
== language_cplus
21953 || cu
->language
== language_ada
21954 || cu
->language
== language_d
21955 || cu
->language
== language_rust
)
21957 /* The symbol's name is already allocated along
21958 with this objfile, so we don't need to
21959 duplicate it for the type. */
21960 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21961 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21966 case DW_TAG_typedef
:
21967 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21968 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21969 list_to_add
= cu
->list_in_scope
;
21971 case DW_TAG_base_type
:
21972 case DW_TAG_subrange_type
:
21973 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21974 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21975 list_to_add
= cu
->list_in_scope
;
21977 case DW_TAG_enumerator
:
21978 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21981 dwarf2_const_value (attr
, sym
, cu
);
21984 /* NOTE: carlton/2003-11-10: See comment above in the
21985 DW_TAG_class_type, etc. block. */
21987 list_to_add
= (cu
->list_in_scope
== &file_symbols
21988 && cu
->language
== language_cplus
21989 ? &global_symbols
: cu
->list_in_scope
);
21992 case DW_TAG_imported_declaration
:
21993 case DW_TAG_namespace
:
21994 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21995 list_to_add
= &global_symbols
;
21997 case DW_TAG_module
:
21998 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21999 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22000 list_to_add
= &global_symbols
;
22002 case DW_TAG_common_block
:
22003 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22004 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22005 add_symbol_to_list (sym
, cu
->list_in_scope
);
22008 /* Not a tag we recognize. Hopefully we aren't processing
22009 trash data, but since we must specifically ignore things
22010 we don't recognize, there is nothing else we should do at
22012 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
22013 dwarf_tag_name (die
->tag
));
22019 sym
->hash_next
= objfile
->template_symbols
;
22020 objfile
->template_symbols
= sym
;
22021 list_to_add
= NULL
;
22024 if (list_to_add
!= NULL
)
22025 add_symbol_to_list (sym
, list_to_add
);
22027 /* For the benefit of old versions of GCC, check for anonymous
22028 namespaces based on the demangled name. */
22029 if (!cu
->processing_has_namespace_info
22030 && cu
->language
== language_cplus
)
22031 cp_scan_for_anonymous_namespaces (sym
, objfile
);
22036 /* Given an attr with a DW_FORM_dataN value in host byte order,
22037 zero-extend it as appropriate for the symbol's type. The DWARF
22038 standard (v4) is not entirely clear about the meaning of using
22039 DW_FORM_dataN for a constant with a signed type, where the type is
22040 wider than the data. The conclusion of a discussion on the DWARF
22041 list was that this is unspecified. We choose to always zero-extend
22042 because that is the interpretation long in use by GCC. */
22045 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22046 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22048 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22049 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22050 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22051 LONGEST l
= DW_UNSND (attr
);
22053 if (bits
< sizeof (*value
) * 8)
22055 l
&= ((LONGEST
) 1 << bits
) - 1;
22058 else if (bits
== sizeof (*value
) * 8)
22062 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22063 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22070 /* Read a constant value from an attribute. Either set *VALUE, or if
22071 the value does not fit in *VALUE, set *BYTES - either already
22072 allocated on the objfile obstack, or newly allocated on OBSTACK,
22073 or, set *BATON, if we translated the constant to a location
22077 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22078 const char *name
, struct obstack
*obstack
,
22079 struct dwarf2_cu
*cu
,
22080 LONGEST
*value
, const gdb_byte
**bytes
,
22081 struct dwarf2_locexpr_baton
**baton
)
22083 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22084 struct comp_unit_head
*cu_header
= &cu
->header
;
22085 struct dwarf_block
*blk
;
22086 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22087 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22093 switch (attr
->form
)
22096 case DW_FORM_GNU_addr_index
:
22100 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22101 dwarf2_const_value_length_mismatch_complaint (name
,
22102 cu_header
->addr_size
,
22103 TYPE_LENGTH (type
));
22104 /* Symbols of this form are reasonably rare, so we just
22105 piggyback on the existing location code rather than writing
22106 a new implementation of symbol_computed_ops. */
22107 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22108 (*baton
)->per_cu
= cu
->per_cu
;
22109 gdb_assert ((*baton
)->per_cu
);
22111 (*baton
)->size
= 2 + cu_header
->addr_size
;
22112 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22113 (*baton
)->data
= data
;
22115 data
[0] = DW_OP_addr
;
22116 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22117 byte_order
, DW_ADDR (attr
));
22118 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22121 case DW_FORM_string
:
22123 case DW_FORM_GNU_str_index
:
22124 case DW_FORM_GNU_strp_alt
:
22125 /* DW_STRING is already allocated on the objfile obstack, point
22127 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22129 case DW_FORM_block1
:
22130 case DW_FORM_block2
:
22131 case DW_FORM_block4
:
22132 case DW_FORM_block
:
22133 case DW_FORM_exprloc
:
22134 case DW_FORM_data16
:
22135 blk
= DW_BLOCK (attr
);
22136 if (TYPE_LENGTH (type
) != blk
->size
)
22137 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22138 TYPE_LENGTH (type
));
22139 *bytes
= blk
->data
;
22142 /* The DW_AT_const_value attributes are supposed to carry the
22143 symbol's value "represented as it would be on the target
22144 architecture." By the time we get here, it's already been
22145 converted to host endianness, so we just need to sign- or
22146 zero-extend it as appropriate. */
22147 case DW_FORM_data1
:
22148 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22150 case DW_FORM_data2
:
22151 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22153 case DW_FORM_data4
:
22154 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22156 case DW_FORM_data8
:
22157 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22160 case DW_FORM_sdata
:
22161 case DW_FORM_implicit_const
:
22162 *value
= DW_SND (attr
);
22165 case DW_FORM_udata
:
22166 *value
= DW_UNSND (attr
);
22170 complaint (&symfile_complaints
,
22171 _("unsupported const value attribute form: '%s'"),
22172 dwarf_form_name (attr
->form
));
22179 /* Copy constant value from an attribute to a symbol. */
22182 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22183 struct dwarf2_cu
*cu
)
22185 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22187 const gdb_byte
*bytes
;
22188 struct dwarf2_locexpr_baton
*baton
;
22190 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22191 SYMBOL_PRINT_NAME (sym
),
22192 &objfile
->objfile_obstack
, cu
,
22193 &value
, &bytes
, &baton
);
22197 SYMBOL_LOCATION_BATON (sym
) = baton
;
22198 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22200 else if (bytes
!= NULL
)
22202 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22203 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22207 SYMBOL_VALUE (sym
) = value
;
22208 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22212 /* Return the type of the die in question using its DW_AT_type attribute. */
22214 static struct type
*
22215 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22217 struct attribute
*type_attr
;
22219 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22222 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22223 /* A missing DW_AT_type represents a void type. */
22224 return objfile_type (objfile
)->builtin_void
;
22227 return lookup_die_type (die
, type_attr
, cu
);
22230 /* True iff CU's producer generates GNAT Ada auxiliary information
22231 that allows to find parallel types through that information instead
22232 of having to do expensive parallel lookups by type name. */
22235 need_gnat_info (struct dwarf2_cu
*cu
)
22237 /* Assume that the Ada compiler was GNAT, which always produces
22238 the auxiliary information. */
22239 return (cu
->language
== language_ada
);
22242 /* Return the auxiliary type of the die in question using its
22243 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22244 attribute is not present. */
22246 static struct type
*
22247 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22249 struct attribute
*type_attr
;
22251 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22255 return lookup_die_type (die
, type_attr
, cu
);
22258 /* If DIE has a descriptive_type attribute, then set the TYPE's
22259 descriptive type accordingly. */
22262 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22263 struct dwarf2_cu
*cu
)
22265 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22267 if (descriptive_type
)
22269 ALLOCATE_GNAT_AUX_TYPE (type
);
22270 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22274 /* Return the containing type of the die in question using its
22275 DW_AT_containing_type attribute. */
22277 static struct type
*
22278 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22280 struct attribute
*type_attr
;
22281 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22283 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22285 error (_("Dwarf Error: Problem turning containing type into gdb type "
22286 "[in module %s]"), objfile_name (objfile
));
22288 return lookup_die_type (die
, type_attr
, cu
);
22291 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22293 static struct type
*
22294 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22296 struct dwarf2_per_objfile
*dwarf2_per_objfile
22297 = cu
->per_cu
->dwarf2_per_objfile
;
22298 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22299 char *message
, *saved
;
22301 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
22302 objfile_name (objfile
),
22303 sect_offset_str (cu
->header
.sect_off
),
22304 sect_offset_str (die
->sect_off
));
22305 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
22306 message
, strlen (message
));
22309 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22312 /* Look up the type of DIE in CU using its type attribute ATTR.
22313 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22314 DW_AT_containing_type.
22315 If there is no type substitute an error marker. */
22317 static struct type
*
22318 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22319 struct dwarf2_cu
*cu
)
22321 struct dwarf2_per_objfile
*dwarf2_per_objfile
22322 = cu
->per_cu
->dwarf2_per_objfile
;
22323 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22324 struct type
*this_type
;
22326 gdb_assert (attr
->name
== DW_AT_type
22327 || attr
->name
== DW_AT_GNAT_descriptive_type
22328 || attr
->name
== DW_AT_containing_type
);
22330 /* First see if we have it cached. */
22332 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22334 struct dwarf2_per_cu_data
*per_cu
;
22335 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22337 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22338 dwarf2_per_objfile
);
22339 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22341 else if (attr_form_is_ref (attr
))
22343 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22345 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22347 else if (attr
->form
== DW_FORM_ref_sig8
)
22349 ULONGEST signature
= DW_SIGNATURE (attr
);
22351 return get_signatured_type (die
, signature
, cu
);
22355 complaint (&symfile_complaints
,
22356 _("Dwarf Error: Bad type attribute %s in DIE"
22357 " at %s [in module %s]"),
22358 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22359 objfile_name (objfile
));
22360 return build_error_marker_type (cu
, die
);
22363 /* If not cached we need to read it in. */
22365 if (this_type
== NULL
)
22367 struct die_info
*type_die
= NULL
;
22368 struct dwarf2_cu
*type_cu
= cu
;
22370 if (attr_form_is_ref (attr
))
22371 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22372 if (type_die
== NULL
)
22373 return build_error_marker_type (cu
, die
);
22374 /* If we find the type now, it's probably because the type came
22375 from an inter-CU reference and the type's CU got expanded before
22377 this_type
= read_type_die (type_die
, type_cu
);
22380 /* If we still don't have a type use an error marker. */
22382 if (this_type
== NULL
)
22383 return build_error_marker_type (cu
, die
);
22388 /* Return the type in DIE, CU.
22389 Returns NULL for invalid types.
22391 This first does a lookup in die_type_hash,
22392 and only reads the die in if necessary.
22394 NOTE: This can be called when reading in partial or full symbols. */
22396 static struct type
*
22397 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22399 struct type
*this_type
;
22401 this_type
= get_die_type (die
, cu
);
22405 return read_type_die_1 (die
, cu
);
22408 /* Read the type in DIE, CU.
22409 Returns NULL for invalid types. */
22411 static struct type
*
22412 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22414 struct type
*this_type
= NULL
;
22418 case DW_TAG_class_type
:
22419 case DW_TAG_interface_type
:
22420 case DW_TAG_structure_type
:
22421 case DW_TAG_union_type
:
22422 this_type
= read_structure_type (die
, cu
);
22424 case DW_TAG_enumeration_type
:
22425 this_type
= read_enumeration_type (die
, cu
);
22427 case DW_TAG_subprogram
:
22428 case DW_TAG_subroutine_type
:
22429 case DW_TAG_inlined_subroutine
:
22430 this_type
= read_subroutine_type (die
, cu
);
22432 case DW_TAG_array_type
:
22433 this_type
= read_array_type (die
, cu
);
22435 case DW_TAG_set_type
:
22436 this_type
= read_set_type (die
, cu
);
22438 case DW_TAG_pointer_type
:
22439 this_type
= read_tag_pointer_type (die
, cu
);
22441 case DW_TAG_ptr_to_member_type
:
22442 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22444 case DW_TAG_reference_type
:
22445 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22447 case DW_TAG_rvalue_reference_type
:
22448 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22450 case DW_TAG_const_type
:
22451 this_type
= read_tag_const_type (die
, cu
);
22453 case DW_TAG_volatile_type
:
22454 this_type
= read_tag_volatile_type (die
, cu
);
22456 case DW_TAG_restrict_type
:
22457 this_type
= read_tag_restrict_type (die
, cu
);
22459 case DW_TAG_string_type
:
22460 this_type
= read_tag_string_type (die
, cu
);
22462 case DW_TAG_typedef
:
22463 this_type
= read_typedef (die
, cu
);
22465 case DW_TAG_subrange_type
:
22466 this_type
= read_subrange_type (die
, cu
);
22468 case DW_TAG_base_type
:
22469 this_type
= read_base_type (die
, cu
);
22471 case DW_TAG_unspecified_type
:
22472 this_type
= read_unspecified_type (die
, cu
);
22474 case DW_TAG_namespace
:
22475 this_type
= read_namespace_type (die
, cu
);
22477 case DW_TAG_module
:
22478 this_type
= read_module_type (die
, cu
);
22480 case DW_TAG_atomic_type
:
22481 this_type
= read_tag_atomic_type (die
, cu
);
22484 complaint (&symfile_complaints
,
22485 _("unexpected tag in read_type_die: '%s'"),
22486 dwarf_tag_name (die
->tag
));
22493 /* See if we can figure out if the class lives in a namespace. We do
22494 this by looking for a member function; its demangled name will
22495 contain namespace info, if there is any.
22496 Return the computed name or NULL.
22497 Space for the result is allocated on the objfile's obstack.
22498 This is the full-die version of guess_partial_die_structure_name.
22499 In this case we know DIE has no useful parent. */
22502 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22504 struct die_info
*spec_die
;
22505 struct dwarf2_cu
*spec_cu
;
22506 struct die_info
*child
;
22507 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22510 spec_die
= die_specification (die
, &spec_cu
);
22511 if (spec_die
!= NULL
)
22517 for (child
= die
->child
;
22519 child
= child
->sibling
)
22521 if (child
->tag
== DW_TAG_subprogram
)
22523 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22525 if (linkage_name
!= NULL
)
22528 = language_class_name_from_physname (cu
->language_defn
,
22532 if (actual_name
!= NULL
)
22534 const char *die_name
= dwarf2_name (die
, cu
);
22536 if (die_name
!= NULL
22537 && strcmp (die_name
, actual_name
) != 0)
22539 /* Strip off the class name from the full name.
22540 We want the prefix. */
22541 int die_name_len
= strlen (die_name
);
22542 int actual_name_len
= strlen (actual_name
);
22544 /* Test for '::' as a sanity check. */
22545 if (actual_name_len
> die_name_len
+ 2
22546 && actual_name
[actual_name_len
22547 - die_name_len
- 1] == ':')
22548 name
= (char *) obstack_copy0 (
22549 &objfile
->per_bfd
->storage_obstack
,
22550 actual_name
, actual_name_len
- die_name_len
- 2);
22553 xfree (actual_name
);
22562 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22563 prefix part in such case. See
22564 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22566 static const char *
22567 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22569 struct attribute
*attr
;
22572 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22573 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22576 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22579 attr
= dw2_linkage_name_attr (die
, cu
);
22580 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22583 /* dwarf2_name had to be already called. */
22584 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22586 /* Strip the base name, keep any leading namespaces/classes. */
22587 base
= strrchr (DW_STRING (attr
), ':');
22588 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22591 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22592 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22594 &base
[-1] - DW_STRING (attr
));
22597 /* Return the name of the namespace/class that DIE is defined within,
22598 or "" if we can't tell. The caller should not xfree the result.
22600 For example, if we're within the method foo() in the following
22610 then determine_prefix on foo's die will return "N::C". */
22612 static const char *
22613 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22615 struct dwarf2_per_objfile
*dwarf2_per_objfile
22616 = cu
->per_cu
->dwarf2_per_objfile
;
22617 struct die_info
*parent
, *spec_die
;
22618 struct dwarf2_cu
*spec_cu
;
22619 struct type
*parent_type
;
22620 const char *retval
;
22622 if (cu
->language
!= language_cplus
22623 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22624 && cu
->language
!= language_rust
)
22627 retval
= anonymous_struct_prefix (die
, cu
);
22631 /* We have to be careful in the presence of DW_AT_specification.
22632 For example, with GCC 3.4, given the code
22636 // Definition of N::foo.
22640 then we'll have a tree of DIEs like this:
22642 1: DW_TAG_compile_unit
22643 2: DW_TAG_namespace // N
22644 3: DW_TAG_subprogram // declaration of N::foo
22645 4: DW_TAG_subprogram // definition of N::foo
22646 DW_AT_specification // refers to die #3
22648 Thus, when processing die #4, we have to pretend that we're in
22649 the context of its DW_AT_specification, namely the contex of die
22652 spec_die
= die_specification (die
, &spec_cu
);
22653 if (spec_die
== NULL
)
22654 parent
= die
->parent
;
22657 parent
= spec_die
->parent
;
22661 if (parent
== NULL
)
22663 else if (parent
->building_fullname
)
22666 const char *parent_name
;
22668 /* It has been seen on RealView 2.2 built binaries,
22669 DW_TAG_template_type_param types actually _defined_ as
22670 children of the parent class:
22673 template class <class Enum> Class{};
22674 Class<enum E> class_e;
22676 1: DW_TAG_class_type (Class)
22677 2: DW_TAG_enumeration_type (E)
22678 3: DW_TAG_enumerator (enum1:0)
22679 3: DW_TAG_enumerator (enum2:1)
22681 2: DW_TAG_template_type_param
22682 DW_AT_type DW_FORM_ref_udata (E)
22684 Besides being broken debug info, it can put GDB into an
22685 infinite loop. Consider:
22687 When we're building the full name for Class<E>, we'll start
22688 at Class, and go look over its template type parameters,
22689 finding E. We'll then try to build the full name of E, and
22690 reach here. We're now trying to build the full name of E,
22691 and look over the parent DIE for containing scope. In the
22692 broken case, if we followed the parent DIE of E, we'd again
22693 find Class, and once again go look at its template type
22694 arguments, etc., etc. Simply don't consider such parent die
22695 as source-level parent of this die (it can't be, the language
22696 doesn't allow it), and break the loop here. */
22697 name
= dwarf2_name (die
, cu
);
22698 parent_name
= dwarf2_name (parent
, cu
);
22699 complaint (&symfile_complaints
,
22700 _("template param type '%s' defined within parent '%s'"),
22701 name
? name
: "<unknown>",
22702 parent_name
? parent_name
: "<unknown>");
22706 switch (parent
->tag
)
22708 case DW_TAG_namespace
:
22709 parent_type
= read_type_die (parent
, cu
);
22710 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22711 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22712 Work around this problem here. */
22713 if (cu
->language
== language_cplus
22714 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22716 /* We give a name to even anonymous namespaces. */
22717 return TYPE_TAG_NAME (parent_type
);
22718 case DW_TAG_class_type
:
22719 case DW_TAG_interface_type
:
22720 case DW_TAG_structure_type
:
22721 case DW_TAG_union_type
:
22722 case DW_TAG_module
:
22723 parent_type
= read_type_die (parent
, cu
);
22724 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22725 return TYPE_TAG_NAME (parent_type
);
22727 /* An anonymous structure is only allowed non-static data
22728 members; no typedefs, no member functions, et cetera.
22729 So it does not need a prefix. */
22731 case DW_TAG_compile_unit
:
22732 case DW_TAG_partial_unit
:
22733 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22734 if (cu
->language
== language_cplus
22735 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22736 && die
->child
!= NULL
22737 && (die
->tag
== DW_TAG_class_type
22738 || die
->tag
== DW_TAG_structure_type
22739 || die
->tag
== DW_TAG_union_type
))
22741 char *name
= guess_full_die_structure_name (die
, cu
);
22746 case DW_TAG_enumeration_type
:
22747 parent_type
= read_type_die (parent
, cu
);
22748 if (TYPE_DECLARED_CLASS (parent_type
))
22750 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22751 return TYPE_TAG_NAME (parent_type
);
22754 /* Fall through. */
22756 return determine_prefix (parent
, cu
);
22760 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22761 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22762 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22763 an obconcat, otherwise allocate storage for the result. The CU argument is
22764 used to determine the language and hence, the appropriate separator. */
22766 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22769 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22770 int physname
, struct dwarf2_cu
*cu
)
22772 const char *lead
= "";
22775 if (suffix
== NULL
|| suffix
[0] == '\0'
22776 || prefix
== NULL
|| prefix
[0] == '\0')
22778 else if (cu
->language
== language_d
)
22780 /* For D, the 'main' function could be defined in any module, but it
22781 should never be prefixed. */
22782 if (strcmp (suffix
, "D main") == 0)
22790 else if (cu
->language
== language_fortran
&& physname
)
22792 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22793 DW_AT_MIPS_linkage_name is preferred and used instead. */
22801 if (prefix
== NULL
)
22803 if (suffix
== NULL
)
22810 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22812 strcpy (retval
, lead
);
22813 strcat (retval
, prefix
);
22814 strcat (retval
, sep
);
22815 strcat (retval
, suffix
);
22820 /* We have an obstack. */
22821 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22825 /* Return sibling of die, NULL if no sibling. */
22827 static struct die_info
*
22828 sibling_die (struct die_info
*die
)
22830 return die
->sibling
;
22833 /* Get name of a die, return NULL if not found. */
22835 static const char *
22836 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22837 struct obstack
*obstack
)
22839 if (name
&& cu
->language
== language_cplus
)
22841 std::string canon_name
= cp_canonicalize_string (name
);
22843 if (!canon_name
.empty ())
22845 if (canon_name
!= name
)
22846 name
= (const char *) obstack_copy0 (obstack
,
22847 canon_name
.c_str (),
22848 canon_name
.length ());
22855 /* Get name of a die, return NULL if not found.
22856 Anonymous namespaces are converted to their magic string. */
22858 static const char *
22859 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22861 struct attribute
*attr
;
22862 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22864 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22865 if ((!attr
|| !DW_STRING (attr
))
22866 && die
->tag
!= DW_TAG_namespace
22867 && die
->tag
!= DW_TAG_class_type
22868 && die
->tag
!= DW_TAG_interface_type
22869 && die
->tag
!= DW_TAG_structure_type
22870 && die
->tag
!= DW_TAG_union_type
)
22875 case DW_TAG_compile_unit
:
22876 case DW_TAG_partial_unit
:
22877 /* Compilation units have a DW_AT_name that is a filename, not
22878 a source language identifier. */
22879 case DW_TAG_enumeration_type
:
22880 case DW_TAG_enumerator
:
22881 /* These tags always have simple identifiers already; no need
22882 to canonicalize them. */
22883 return DW_STRING (attr
);
22885 case DW_TAG_namespace
:
22886 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22887 return DW_STRING (attr
);
22888 return CP_ANONYMOUS_NAMESPACE_STR
;
22890 case DW_TAG_class_type
:
22891 case DW_TAG_interface_type
:
22892 case DW_TAG_structure_type
:
22893 case DW_TAG_union_type
:
22894 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22895 structures or unions. These were of the form "._%d" in GCC 4.1,
22896 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22897 and GCC 4.4. We work around this problem by ignoring these. */
22898 if (attr
&& DW_STRING (attr
)
22899 && (startswith (DW_STRING (attr
), "._")
22900 || startswith (DW_STRING (attr
), "<anonymous")))
22903 /* GCC might emit a nameless typedef that has a linkage name. See
22904 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22905 if (!attr
|| DW_STRING (attr
) == NULL
)
22907 char *demangled
= NULL
;
22909 attr
= dw2_linkage_name_attr (die
, cu
);
22910 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22913 /* Avoid demangling DW_STRING (attr) the second time on a second
22914 call for the same DIE. */
22915 if (!DW_STRING_IS_CANONICAL (attr
))
22916 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22922 /* FIXME: we already did this for the partial symbol... */
22925 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22926 demangled
, strlen (demangled
)));
22927 DW_STRING_IS_CANONICAL (attr
) = 1;
22930 /* Strip any leading namespaces/classes, keep only the base name.
22931 DW_AT_name for named DIEs does not contain the prefixes. */
22932 base
= strrchr (DW_STRING (attr
), ':');
22933 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22936 return DW_STRING (attr
);
22945 if (!DW_STRING_IS_CANONICAL (attr
))
22948 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22949 &objfile
->per_bfd
->storage_obstack
);
22950 DW_STRING_IS_CANONICAL (attr
) = 1;
22952 return DW_STRING (attr
);
22955 /* Return the die that this die in an extension of, or NULL if there
22956 is none. *EXT_CU is the CU containing DIE on input, and the CU
22957 containing the return value on output. */
22959 static struct die_info
*
22960 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22962 struct attribute
*attr
;
22964 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22968 return follow_die_ref (die
, attr
, ext_cu
);
22971 /* Convert a DIE tag into its string name. */
22973 static const char *
22974 dwarf_tag_name (unsigned tag
)
22976 const char *name
= get_DW_TAG_name (tag
);
22979 return "DW_TAG_<unknown>";
22984 /* Convert a DWARF attribute code into its string name. */
22986 static const char *
22987 dwarf_attr_name (unsigned attr
)
22991 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22992 if (attr
== DW_AT_MIPS_fde
)
22993 return "DW_AT_MIPS_fde";
22995 if (attr
== DW_AT_HP_block_index
)
22996 return "DW_AT_HP_block_index";
22999 name
= get_DW_AT_name (attr
);
23002 return "DW_AT_<unknown>";
23007 /* Convert a DWARF value form code into its string name. */
23009 static const char *
23010 dwarf_form_name (unsigned form
)
23012 const char *name
= get_DW_FORM_name (form
);
23015 return "DW_FORM_<unknown>";
23020 static const char *
23021 dwarf_bool_name (unsigned mybool
)
23029 /* Convert a DWARF type code into its string name. */
23031 static const char *
23032 dwarf_type_encoding_name (unsigned enc
)
23034 const char *name
= get_DW_ATE_name (enc
);
23037 return "DW_ATE_<unknown>";
23043 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23047 print_spaces (indent
, f
);
23048 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23049 dwarf_tag_name (die
->tag
), die
->abbrev
,
23050 sect_offset_str (die
->sect_off
));
23052 if (die
->parent
!= NULL
)
23054 print_spaces (indent
, f
);
23055 fprintf_unfiltered (f
, " parent at offset: %s\n",
23056 sect_offset_str (die
->parent
->sect_off
));
23059 print_spaces (indent
, f
);
23060 fprintf_unfiltered (f
, " has children: %s\n",
23061 dwarf_bool_name (die
->child
!= NULL
));
23063 print_spaces (indent
, f
);
23064 fprintf_unfiltered (f
, " attributes:\n");
23066 for (i
= 0; i
< die
->num_attrs
; ++i
)
23068 print_spaces (indent
, f
);
23069 fprintf_unfiltered (f
, " %s (%s) ",
23070 dwarf_attr_name (die
->attrs
[i
].name
),
23071 dwarf_form_name (die
->attrs
[i
].form
));
23073 switch (die
->attrs
[i
].form
)
23076 case DW_FORM_GNU_addr_index
:
23077 fprintf_unfiltered (f
, "address: ");
23078 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23080 case DW_FORM_block2
:
23081 case DW_FORM_block4
:
23082 case DW_FORM_block
:
23083 case DW_FORM_block1
:
23084 fprintf_unfiltered (f
, "block: size %s",
23085 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23087 case DW_FORM_exprloc
:
23088 fprintf_unfiltered (f
, "expression: size %s",
23089 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23091 case DW_FORM_data16
:
23092 fprintf_unfiltered (f
, "constant of 16 bytes");
23094 case DW_FORM_ref_addr
:
23095 fprintf_unfiltered (f
, "ref address: ");
23096 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23098 case DW_FORM_GNU_ref_alt
:
23099 fprintf_unfiltered (f
, "alt ref address: ");
23100 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23106 case DW_FORM_ref_udata
:
23107 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23108 (long) (DW_UNSND (&die
->attrs
[i
])));
23110 case DW_FORM_data1
:
23111 case DW_FORM_data2
:
23112 case DW_FORM_data4
:
23113 case DW_FORM_data8
:
23114 case DW_FORM_udata
:
23115 case DW_FORM_sdata
:
23116 fprintf_unfiltered (f
, "constant: %s",
23117 pulongest (DW_UNSND (&die
->attrs
[i
])));
23119 case DW_FORM_sec_offset
:
23120 fprintf_unfiltered (f
, "section offset: %s",
23121 pulongest (DW_UNSND (&die
->attrs
[i
])));
23123 case DW_FORM_ref_sig8
:
23124 fprintf_unfiltered (f
, "signature: %s",
23125 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23127 case DW_FORM_string
:
23129 case DW_FORM_line_strp
:
23130 case DW_FORM_GNU_str_index
:
23131 case DW_FORM_GNU_strp_alt
:
23132 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23133 DW_STRING (&die
->attrs
[i
])
23134 ? DW_STRING (&die
->attrs
[i
]) : "",
23135 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23138 if (DW_UNSND (&die
->attrs
[i
]))
23139 fprintf_unfiltered (f
, "flag: TRUE");
23141 fprintf_unfiltered (f
, "flag: FALSE");
23143 case DW_FORM_flag_present
:
23144 fprintf_unfiltered (f
, "flag: TRUE");
23146 case DW_FORM_indirect
:
23147 /* The reader will have reduced the indirect form to
23148 the "base form" so this form should not occur. */
23149 fprintf_unfiltered (f
,
23150 "unexpected attribute form: DW_FORM_indirect");
23152 case DW_FORM_implicit_const
:
23153 fprintf_unfiltered (f
, "constant: %s",
23154 plongest (DW_SND (&die
->attrs
[i
])));
23157 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23158 die
->attrs
[i
].form
);
23161 fprintf_unfiltered (f
, "\n");
23166 dump_die_for_error (struct die_info
*die
)
23168 dump_die_shallow (gdb_stderr
, 0, die
);
23172 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23174 int indent
= level
* 4;
23176 gdb_assert (die
!= NULL
);
23178 if (level
>= max_level
)
23181 dump_die_shallow (f
, indent
, die
);
23183 if (die
->child
!= NULL
)
23185 print_spaces (indent
, f
);
23186 fprintf_unfiltered (f
, " Children:");
23187 if (level
+ 1 < max_level
)
23189 fprintf_unfiltered (f
, "\n");
23190 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23194 fprintf_unfiltered (f
,
23195 " [not printed, max nesting level reached]\n");
23199 if (die
->sibling
!= NULL
&& level
> 0)
23201 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23205 /* This is called from the pdie macro in gdbinit.in.
23206 It's not static so gcc will keep a copy callable from gdb. */
23209 dump_die (struct die_info
*die
, int max_level
)
23211 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23215 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23219 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23220 to_underlying (die
->sect_off
),
23226 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23230 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23232 if (attr_form_is_ref (attr
))
23233 return (sect_offset
) DW_UNSND (attr
);
23235 complaint (&symfile_complaints
,
23236 _("unsupported die ref attribute form: '%s'"),
23237 dwarf_form_name (attr
->form
));
23241 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23242 * the value held by the attribute is not constant. */
23245 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23247 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23248 return DW_SND (attr
);
23249 else if (attr
->form
== DW_FORM_udata
23250 || attr
->form
== DW_FORM_data1
23251 || attr
->form
== DW_FORM_data2
23252 || attr
->form
== DW_FORM_data4
23253 || attr
->form
== DW_FORM_data8
)
23254 return DW_UNSND (attr
);
23257 /* For DW_FORM_data16 see attr_form_is_constant. */
23258 complaint (&symfile_complaints
,
23259 _("Attribute value is not a constant (%s)"),
23260 dwarf_form_name (attr
->form
));
23261 return default_value
;
23265 /* Follow reference or signature attribute ATTR of SRC_DIE.
23266 On entry *REF_CU is the CU of SRC_DIE.
23267 On exit *REF_CU is the CU of the result. */
23269 static struct die_info
*
23270 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23271 struct dwarf2_cu
**ref_cu
)
23273 struct die_info
*die
;
23275 if (attr_form_is_ref (attr
))
23276 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23277 else if (attr
->form
== DW_FORM_ref_sig8
)
23278 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23281 dump_die_for_error (src_die
);
23282 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23283 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23289 /* Follow reference OFFSET.
23290 On entry *REF_CU is the CU of the source die referencing OFFSET.
23291 On exit *REF_CU is the CU of the result.
23292 Returns NULL if OFFSET is invalid. */
23294 static struct die_info
*
23295 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23296 struct dwarf2_cu
**ref_cu
)
23298 struct die_info temp_die
;
23299 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23300 struct dwarf2_per_objfile
*dwarf2_per_objfile
23301 = cu
->per_cu
->dwarf2_per_objfile
;
23302 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23304 gdb_assert (cu
->per_cu
!= NULL
);
23308 if (cu
->per_cu
->is_debug_types
)
23310 /* .debug_types CUs cannot reference anything outside their CU.
23311 If they need to, they have to reference a signatured type via
23312 DW_FORM_ref_sig8. */
23313 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23316 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23317 || !offset_in_cu_p (&cu
->header
, sect_off
))
23319 struct dwarf2_per_cu_data
*per_cu
;
23321 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23322 dwarf2_per_objfile
);
23324 /* If necessary, add it to the queue and load its DIEs. */
23325 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23326 load_full_comp_unit (per_cu
, cu
->language
);
23328 target_cu
= per_cu
->cu
;
23330 else if (cu
->dies
== NULL
)
23332 /* We're loading full DIEs during partial symbol reading. */
23333 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23334 load_full_comp_unit (cu
->per_cu
, language_minimal
);
23337 *ref_cu
= target_cu
;
23338 temp_die
.sect_off
= sect_off
;
23339 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23341 to_underlying (sect_off
));
23344 /* Follow reference attribute ATTR of SRC_DIE.
23345 On entry *REF_CU is the CU of SRC_DIE.
23346 On exit *REF_CU is the CU of the result. */
23348 static struct die_info
*
23349 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23350 struct dwarf2_cu
**ref_cu
)
23352 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23353 struct dwarf2_cu
*cu
= *ref_cu
;
23354 struct die_info
*die
;
23356 die
= follow_die_offset (sect_off
,
23357 (attr
->form
== DW_FORM_GNU_ref_alt
23358 || cu
->per_cu
->is_dwz
),
23361 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23362 "at %s [in module %s]"),
23363 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23364 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23369 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23370 Returned value is intended for DW_OP_call*. Returned
23371 dwarf2_locexpr_baton->data has lifetime of
23372 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23374 struct dwarf2_locexpr_baton
23375 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23376 struct dwarf2_per_cu_data
*per_cu
,
23377 CORE_ADDR (*get_frame_pc
) (void *baton
),
23380 struct dwarf2_cu
*cu
;
23381 struct die_info
*die
;
23382 struct attribute
*attr
;
23383 struct dwarf2_locexpr_baton retval
;
23384 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23385 struct dwarf2_per_objfile
*dwarf2_per_objfile
23386 = get_dwarf2_per_objfile (objfile
);
23388 if (per_cu
->cu
== NULL
)
23393 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23394 Instead just throw an error, not much else we can do. */
23395 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23396 sect_offset_str (sect_off
), objfile_name (objfile
));
23399 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23401 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23402 sect_offset_str (sect_off
), objfile_name (objfile
));
23404 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23407 /* DWARF: "If there is no such attribute, then there is no effect.".
23408 DATA is ignored if SIZE is 0. */
23410 retval
.data
= NULL
;
23413 else if (attr_form_is_section_offset (attr
))
23415 struct dwarf2_loclist_baton loclist_baton
;
23416 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23419 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23421 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23423 retval
.size
= size
;
23427 if (!attr_form_is_block (attr
))
23428 error (_("Dwarf Error: DIE at %s referenced in module %s "
23429 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23430 sect_offset_str (sect_off
), objfile_name (objfile
));
23432 retval
.data
= DW_BLOCK (attr
)->data
;
23433 retval
.size
= DW_BLOCK (attr
)->size
;
23435 retval
.per_cu
= cu
->per_cu
;
23437 age_cached_comp_units (dwarf2_per_objfile
);
23442 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23445 struct dwarf2_locexpr_baton
23446 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23447 struct dwarf2_per_cu_data
*per_cu
,
23448 CORE_ADDR (*get_frame_pc
) (void *baton
),
23451 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23453 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23456 /* Write a constant of a given type as target-ordered bytes into
23459 static const gdb_byte
*
23460 write_constant_as_bytes (struct obstack
*obstack
,
23461 enum bfd_endian byte_order
,
23468 *len
= TYPE_LENGTH (type
);
23469 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23470 store_unsigned_integer (result
, *len
, byte_order
, value
);
23475 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23476 pointer to the constant bytes and set LEN to the length of the
23477 data. If memory is needed, allocate it on OBSTACK. If the DIE
23478 does not have a DW_AT_const_value, return NULL. */
23481 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23482 struct dwarf2_per_cu_data
*per_cu
,
23483 struct obstack
*obstack
,
23486 struct dwarf2_cu
*cu
;
23487 struct die_info
*die
;
23488 struct attribute
*attr
;
23489 const gdb_byte
*result
= NULL
;
23492 enum bfd_endian byte_order
;
23493 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23495 if (per_cu
->cu
== NULL
)
23500 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23501 Instead just throw an error, not much else we can do. */
23502 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23503 sect_offset_str (sect_off
), objfile_name (objfile
));
23506 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23508 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23509 sect_offset_str (sect_off
), objfile_name (objfile
));
23511 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23515 byte_order
= (bfd_big_endian (objfile
->obfd
)
23516 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23518 switch (attr
->form
)
23521 case DW_FORM_GNU_addr_index
:
23525 *len
= cu
->header
.addr_size
;
23526 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23527 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23531 case DW_FORM_string
:
23533 case DW_FORM_GNU_str_index
:
23534 case DW_FORM_GNU_strp_alt
:
23535 /* DW_STRING is already allocated on the objfile obstack, point
23537 result
= (const gdb_byte
*) DW_STRING (attr
);
23538 *len
= strlen (DW_STRING (attr
));
23540 case DW_FORM_block1
:
23541 case DW_FORM_block2
:
23542 case DW_FORM_block4
:
23543 case DW_FORM_block
:
23544 case DW_FORM_exprloc
:
23545 case DW_FORM_data16
:
23546 result
= DW_BLOCK (attr
)->data
;
23547 *len
= DW_BLOCK (attr
)->size
;
23550 /* The DW_AT_const_value attributes are supposed to carry the
23551 symbol's value "represented as it would be on the target
23552 architecture." By the time we get here, it's already been
23553 converted to host endianness, so we just need to sign- or
23554 zero-extend it as appropriate. */
23555 case DW_FORM_data1
:
23556 type
= die_type (die
, cu
);
23557 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23558 if (result
== NULL
)
23559 result
= write_constant_as_bytes (obstack
, byte_order
,
23562 case DW_FORM_data2
:
23563 type
= die_type (die
, cu
);
23564 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23565 if (result
== NULL
)
23566 result
= write_constant_as_bytes (obstack
, byte_order
,
23569 case DW_FORM_data4
:
23570 type
= die_type (die
, cu
);
23571 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23572 if (result
== NULL
)
23573 result
= write_constant_as_bytes (obstack
, byte_order
,
23576 case DW_FORM_data8
:
23577 type
= die_type (die
, cu
);
23578 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23579 if (result
== NULL
)
23580 result
= write_constant_as_bytes (obstack
, byte_order
,
23584 case DW_FORM_sdata
:
23585 case DW_FORM_implicit_const
:
23586 type
= die_type (die
, cu
);
23587 result
= write_constant_as_bytes (obstack
, byte_order
,
23588 type
, DW_SND (attr
), len
);
23591 case DW_FORM_udata
:
23592 type
= die_type (die
, cu
);
23593 result
= write_constant_as_bytes (obstack
, byte_order
,
23594 type
, DW_UNSND (attr
), len
);
23598 complaint (&symfile_complaints
,
23599 _("unsupported const value attribute form: '%s'"),
23600 dwarf_form_name (attr
->form
));
23607 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23608 valid type for this die is found. */
23611 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23612 struct dwarf2_per_cu_data
*per_cu
)
23614 struct dwarf2_cu
*cu
;
23615 struct die_info
*die
;
23617 if (per_cu
->cu
== NULL
)
23623 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23627 return die_type (die
, cu
);
23630 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23634 dwarf2_get_die_type (cu_offset die_offset
,
23635 struct dwarf2_per_cu_data
*per_cu
)
23637 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23638 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23641 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23642 On entry *REF_CU is the CU of SRC_DIE.
23643 On exit *REF_CU is the CU of the result.
23644 Returns NULL if the referenced DIE isn't found. */
23646 static struct die_info
*
23647 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23648 struct dwarf2_cu
**ref_cu
)
23650 struct die_info temp_die
;
23651 struct dwarf2_cu
*sig_cu
;
23652 struct die_info
*die
;
23654 /* While it might be nice to assert sig_type->type == NULL here,
23655 we can get here for DW_AT_imported_declaration where we need
23656 the DIE not the type. */
23658 /* If necessary, add it to the queue and load its DIEs. */
23660 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23661 read_signatured_type (sig_type
);
23663 sig_cu
= sig_type
->per_cu
.cu
;
23664 gdb_assert (sig_cu
!= NULL
);
23665 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23666 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23667 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23668 to_underlying (temp_die
.sect_off
));
23671 struct dwarf2_per_objfile
*dwarf2_per_objfile
23672 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23674 /* For .gdb_index version 7 keep track of included TUs.
23675 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23676 if (dwarf2_per_objfile
->index_table
!= NULL
23677 && dwarf2_per_objfile
->index_table
->version
<= 7)
23679 VEC_safe_push (dwarf2_per_cu_ptr
,
23680 (*ref_cu
)->per_cu
->imported_symtabs
,
23691 /* Follow signatured type referenced by ATTR in SRC_DIE.
23692 On entry *REF_CU is the CU of SRC_DIE.
23693 On exit *REF_CU is the CU of the result.
23694 The result is the DIE of the type.
23695 If the referenced type cannot be found an error is thrown. */
23697 static struct die_info
*
23698 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23699 struct dwarf2_cu
**ref_cu
)
23701 ULONGEST signature
= DW_SIGNATURE (attr
);
23702 struct signatured_type
*sig_type
;
23703 struct die_info
*die
;
23705 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23707 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23708 /* sig_type will be NULL if the signatured type is missing from
23710 if (sig_type
== NULL
)
23712 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23713 " from DIE at %s [in module %s]"),
23714 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23715 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23718 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23721 dump_die_for_error (src_die
);
23722 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23723 " from DIE at %s [in module %s]"),
23724 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23725 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23731 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23732 reading in and processing the type unit if necessary. */
23734 static struct type
*
23735 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23736 struct dwarf2_cu
*cu
)
23738 struct dwarf2_per_objfile
*dwarf2_per_objfile
23739 = cu
->per_cu
->dwarf2_per_objfile
;
23740 struct signatured_type
*sig_type
;
23741 struct dwarf2_cu
*type_cu
;
23742 struct die_info
*type_die
;
23745 sig_type
= lookup_signatured_type (cu
, signature
);
23746 /* sig_type will be NULL if the signatured type is missing from
23748 if (sig_type
== NULL
)
23750 complaint (&symfile_complaints
,
23751 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23752 " from DIE at %s [in module %s]"),
23753 hex_string (signature
), sect_offset_str (die
->sect_off
),
23754 objfile_name (dwarf2_per_objfile
->objfile
));
23755 return build_error_marker_type (cu
, die
);
23758 /* If we already know the type we're done. */
23759 if (sig_type
->type
!= NULL
)
23760 return sig_type
->type
;
23763 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23764 if (type_die
!= NULL
)
23766 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23767 is created. This is important, for example, because for c++ classes
23768 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23769 type
= read_type_die (type_die
, type_cu
);
23772 complaint (&symfile_complaints
,
23773 _("Dwarf Error: Cannot build signatured type %s"
23774 " referenced from DIE at %s [in module %s]"),
23775 hex_string (signature
), sect_offset_str (die
->sect_off
),
23776 objfile_name (dwarf2_per_objfile
->objfile
));
23777 type
= build_error_marker_type (cu
, die
);
23782 complaint (&symfile_complaints
,
23783 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23784 " from DIE at %s [in module %s]"),
23785 hex_string (signature
), sect_offset_str (die
->sect_off
),
23786 objfile_name (dwarf2_per_objfile
->objfile
));
23787 type
= build_error_marker_type (cu
, die
);
23789 sig_type
->type
= type
;
23794 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23795 reading in and processing the type unit if necessary. */
23797 static struct type
*
23798 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23799 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23801 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23802 if (attr_form_is_ref (attr
))
23804 struct dwarf2_cu
*type_cu
= cu
;
23805 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23807 return read_type_die (type_die
, type_cu
);
23809 else if (attr
->form
== DW_FORM_ref_sig8
)
23811 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23815 struct dwarf2_per_objfile
*dwarf2_per_objfile
23816 = cu
->per_cu
->dwarf2_per_objfile
;
23818 complaint (&symfile_complaints
,
23819 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23820 " at %s [in module %s]"),
23821 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23822 objfile_name (dwarf2_per_objfile
->objfile
));
23823 return build_error_marker_type (cu
, die
);
23827 /* Load the DIEs associated with type unit PER_CU into memory. */
23830 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23832 struct signatured_type
*sig_type
;
23834 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23835 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23837 /* We have the per_cu, but we need the signatured_type.
23838 Fortunately this is an easy translation. */
23839 gdb_assert (per_cu
->is_debug_types
);
23840 sig_type
= (struct signatured_type
*) per_cu
;
23842 gdb_assert (per_cu
->cu
== NULL
);
23844 read_signatured_type (sig_type
);
23846 gdb_assert (per_cu
->cu
!= NULL
);
23849 /* die_reader_func for read_signatured_type.
23850 This is identical to load_full_comp_unit_reader,
23851 but is kept separate for now. */
23854 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23855 const gdb_byte
*info_ptr
,
23856 struct die_info
*comp_unit_die
,
23860 struct dwarf2_cu
*cu
= reader
->cu
;
23862 gdb_assert (cu
->die_hash
== NULL
);
23864 htab_create_alloc_ex (cu
->header
.length
/ 12,
23868 &cu
->comp_unit_obstack
,
23869 hashtab_obstack_allocate
,
23870 dummy_obstack_deallocate
);
23873 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23874 &info_ptr
, comp_unit_die
);
23875 cu
->dies
= comp_unit_die
;
23876 /* comp_unit_die is not stored in die_hash, no need. */
23878 /* We try not to read any attributes in this function, because not
23879 all CUs needed for references have been loaded yet, and symbol
23880 table processing isn't initialized. But we have to set the CU language,
23881 or we won't be able to build types correctly.
23882 Similarly, if we do not read the producer, we can not apply
23883 producer-specific interpretation. */
23884 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23887 /* Read in a signatured type and build its CU and DIEs.
23888 If the type is a stub for the real type in a DWO file,
23889 read in the real type from the DWO file as well. */
23892 read_signatured_type (struct signatured_type
*sig_type
)
23894 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23896 gdb_assert (per_cu
->is_debug_types
);
23897 gdb_assert (per_cu
->cu
== NULL
);
23899 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23900 read_signatured_type_reader
, NULL
);
23901 sig_type
->per_cu
.tu_read
= 1;
23904 /* Decode simple location descriptions.
23905 Given a pointer to a dwarf block that defines a location, compute
23906 the location and return the value.
23908 NOTE drow/2003-11-18: This function is called in two situations
23909 now: for the address of static or global variables (partial symbols
23910 only) and for offsets into structures which are expected to be
23911 (more or less) constant. The partial symbol case should go away,
23912 and only the constant case should remain. That will let this
23913 function complain more accurately. A few special modes are allowed
23914 without complaint for global variables (for instance, global
23915 register values and thread-local values).
23917 A location description containing no operations indicates that the
23918 object is optimized out. The return value is 0 for that case.
23919 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23920 callers will only want a very basic result and this can become a
23923 Note that stack[0] is unused except as a default error return. */
23926 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23928 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23930 size_t size
= blk
->size
;
23931 const gdb_byte
*data
= blk
->data
;
23932 CORE_ADDR stack
[64];
23934 unsigned int bytes_read
, unsnd
;
23940 stack
[++stacki
] = 0;
23979 stack
[++stacki
] = op
- DW_OP_lit0
;
24014 stack
[++stacki
] = op
- DW_OP_reg0
;
24016 dwarf2_complex_location_expr_complaint ();
24020 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24022 stack
[++stacki
] = unsnd
;
24024 dwarf2_complex_location_expr_complaint ();
24028 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24033 case DW_OP_const1u
:
24034 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24038 case DW_OP_const1s
:
24039 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24043 case DW_OP_const2u
:
24044 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24048 case DW_OP_const2s
:
24049 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24053 case DW_OP_const4u
:
24054 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24058 case DW_OP_const4s
:
24059 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24063 case DW_OP_const8u
:
24064 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24069 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24075 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24080 stack
[stacki
+ 1] = stack
[stacki
];
24085 stack
[stacki
- 1] += stack
[stacki
];
24089 case DW_OP_plus_uconst
:
24090 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24096 stack
[stacki
- 1] -= stack
[stacki
];
24101 /* If we're not the last op, then we definitely can't encode
24102 this using GDB's address_class enum. This is valid for partial
24103 global symbols, although the variable's address will be bogus
24106 dwarf2_complex_location_expr_complaint ();
24109 case DW_OP_GNU_push_tls_address
:
24110 case DW_OP_form_tls_address
:
24111 /* The top of the stack has the offset from the beginning
24112 of the thread control block at which the variable is located. */
24113 /* Nothing should follow this operator, so the top of stack would
24115 /* This is valid for partial global symbols, but the variable's
24116 address will be bogus in the psymtab. Make it always at least
24117 non-zero to not look as a variable garbage collected by linker
24118 which have DW_OP_addr 0. */
24120 dwarf2_complex_location_expr_complaint ();
24124 case DW_OP_GNU_uninit
:
24127 case DW_OP_GNU_addr_index
:
24128 case DW_OP_GNU_const_index
:
24129 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24136 const char *name
= get_DW_OP_name (op
);
24139 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
24142 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
24146 return (stack
[stacki
]);
24149 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24150 outside of the allocated space. Also enforce minimum>0. */
24151 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24153 complaint (&symfile_complaints
,
24154 _("location description stack overflow"));
24160 complaint (&symfile_complaints
,
24161 _("location description stack underflow"));
24165 return (stack
[stacki
]);
24168 /* memory allocation interface */
24170 static struct dwarf_block
*
24171 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24173 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24176 static struct die_info
*
24177 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24179 struct die_info
*die
;
24180 size_t size
= sizeof (struct die_info
);
24183 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24185 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24186 memset (die
, 0, sizeof (struct die_info
));
24191 /* Macro support. */
24193 /* Return file name relative to the compilation directory of file number I in
24194 *LH's file name table. The result is allocated using xmalloc; the caller is
24195 responsible for freeing it. */
24198 file_file_name (int file
, struct line_header
*lh
)
24200 /* Is the file number a valid index into the line header's file name
24201 table? Remember that file numbers start with one, not zero. */
24202 if (1 <= file
&& file
<= lh
->file_names
.size ())
24204 const file_entry
&fe
= lh
->file_names
[file
- 1];
24206 if (!IS_ABSOLUTE_PATH (fe
.name
))
24208 const char *dir
= fe
.include_dir (lh
);
24210 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24212 return xstrdup (fe
.name
);
24216 /* The compiler produced a bogus file number. We can at least
24217 record the macro definitions made in the file, even if we
24218 won't be able to find the file by name. */
24219 char fake_name
[80];
24221 xsnprintf (fake_name
, sizeof (fake_name
),
24222 "<bad macro file number %d>", file
);
24224 complaint (&symfile_complaints
,
24225 _("bad file number in macro information (%d)"),
24228 return xstrdup (fake_name
);
24232 /* Return the full name of file number I in *LH's file name table.
24233 Use COMP_DIR as the name of the current directory of the
24234 compilation. The result is allocated using xmalloc; the caller is
24235 responsible for freeing it. */
24237 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24239 /* Is the file number a valid index into the line header's file name
24240 table? Remember that file numbers start with one, not zero. */
24241 if (1 <= file
&& file
<= lh
->file_names
.size ())
24243 char *relative
= file_file_name (file
, lh
);
24245 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24247 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24248 relative
, (char *) NULL
);
24251 return file_file_name (file
, lh
);
24255 static struct macro_source_file
*
24256 macro_start_file (int file
, int line
,
24257 struct macro_source_file
*current_file
,
24258 struct line_header
*lh
)
24260 /* File name relative to the compilation directory of this source file. */
24261 char *file_name
= file_file_name (file
, lh
);
24263 if (! current_file
)
24265 /* Note: We don't create a macro table for this compilation unit
24266 at all until we actually get a filename. */
24267 struct macro_table
*macro_table
= get_macro_table ();
24269 /* If we have no current file, then this must be the start_file
24270 directive for the compilation unit's main source file. */
24271 current_file
= macro_set_main (macro_table
, file_name
);
24272 macro_define_special (macro_table
);
24275 current_file
= macro_include (current_file
, line
, file_name
);
24279 return current_file
;
24282 static const char *
24283 consume_improper_spaces (const char *p
, const char *body
)
24287 complaint (&symfile_complaints
,
24288 _("macro definition contains spaces "
24289 "in formal argument list:\n`%s'"),
24301 parse_macro_definition (struct macro_source_file
*file
, int line
,
24306 /* The body string takes one of two forms. For object-like macro
24307 definitions, it should be:
24309 <macro name> " " <definition>
24311 For function-like macro definitions, it should be:
24313 <macro name> "() " <definition>
24315 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24317 Spaces may appear only where explicitly indicated, and in the
24320 The Dwarf 2 spec says that an object-like macro's name is always
24321 followed by a space, but versions of GCC around March 2002 omit
24322 the space when the macro's definition is the empty string.
24324 The Dwarf 2 spec says that there should be no spaces between the
24325 formal arguments in a function-like macro's formal argument list,
24326 but versions of GCC around March 2002 include spaces after the
24330 /* Find the extent of the macro name. The macro name is terminated
24331 by either a space or null character (for an object-like macro) or
24332 an opening paren (for a function-like macro). */
24333 for (p
= body
; *p
; p
++)
24334 if (*p
== ' ' || *p
== '(')
24337 if (*p
== ' ' || *p
== '\0')
24339 /* It's an object-like macro. */
24340 int name_len
= p
- body
;
24341 char *name
= savestring (body
, name_len
);
24342 const char *replacement
;
24345 replacement
= body
+ name_len
+ 1;
24348 dwarf2_macro_malformed_definition_complaint (body
);
24349 replacement
= body
+ name_len
;
24352 macro_define_object (file
, line
, name
, replacement
);
24356 else if (*p
== '(')
24358 /* It's a function-like macro. */
24359 char *name
= savestring (body
, p
- body
);
24362 char **argv
= XNEWVEC (char *, argv_size
);
24366 p
= consume_improper_spaces (p
, body
);
24368 /* Parse the formal argument list. */
24369 while (*p
&& *p
!= ')')
24371 /* Find the extent of the current argument name. */
24372 const char *arg_start
= p
;
24374 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24377 if (! *p
|| p
== arg_start
)
24378 dwarf2_macro_malformed_definition_complaint (body
);
24381 /* Make sure argv has room for the new argument. */
24382 if (argc
>= argv_size
)
24385 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24388 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24391 p
= consume_improper_spaces (p
, body
);
24393 /* Consume the comma, if present. */
24398 p
= consume_improper_spaces (p
, body
);
24407 /* Perfectly formed definition, no complaints. */
24408 macro_define_function (file
, line
, name
,
24409 argc
, (const char **) argv
,
24411 else if (*p
== '\0')
24413 /* Complain, but do define it. */
24414 dwarf2_macro_malformed_definition_complaint (body
);
24415 macro_define_function (file
, line
, name
,
24416 argc
, (const char **) argv
,
24420 /* Just complain. */
24421 dwarf2_macro_malformed_definition_complaint (body
);
24424 /* Just complain. */
24425 dwarf2_macro_malformed_definition_complaint (body
);
24431 for (i
= 0; i
< argc
; i
++)
24437 dwarf2_macro_malformed_definition_complaint (body
);
24440 /* Skip some bytes from BYTES according to the form given in FORM.
24441 Returns the new pointer. */
24443 static const gdb_byte
*
24444 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24445 enum dwarf_form form
,
24446 unsigned int offset_size
,
24447 struct dwarf2_section_info
*section
)
24449 unsigned int bytes_read
;
24453 case DW_FORM_data1
:
24458 case DW_FORM_data2
:
24462 case DW_FORM_data4
:
24466 case DW_FORM_data8
:
24470 case DW_FORM_data16
:
24474 case DW_FORM_string
:
24475 read_direct_string (abfd
, bytes
, &bytes_read
);
24476 bytes
+= bytes_read
;
24479 case DW_FORM_sec_offset
:
24481 case DW_FORM_GNU_strp_alt
:
24482 bytes
+= offset_size
;
24485 case DW_FORM_block
:
24486 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24487 bytes
+= bytes_read
;
24490 case DW_FORM_block1
:
24491 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24493 case DW_FORM_block2
:
24494 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24496 case DW_FORM_block4
:
24497 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24500 case DW_FORM_sdata
:
24501 case DW_FORM_udata
:
24502 case DW_FORM_GNU_addr_index
:
24503 case DW_FORM_GNU_str_index
:
24504 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24507 dwarf2_section_buffer_overflow_complaint (section
);
24512 case DW_FORM_implicit_const
:
24517 complaint (&symfile_complaints
,
24518 _("invalid form 0x%x in `%s'"),
24519 form
, get_section_name (section
));
24527 /* A helper for dwarf_decode_macros that handles skipping an unknown
24528 opcode. Returns an updated pointer to the macro data buffer; or,
24529 on error, issues a complaint and returns NULL. */
24531 static const gdb_byte
*
24532 skip_unknown_opcode (unsigned int opcode
,
24533 const gdb_byte
**opcode_definitions
,
24534 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24536 unsigned int offset_size
,
24537 struct dwarf2_section_info
*section
)
24539 unsigned int bytes_read
, i
;
24541 const gdb_byte
*defn
;
24543 if (opcode_definitions
[opcode
] == NULL
)
24545 complaint (&symfile_complaints
,
24546 _("unrecognized DW_MACFINO opcode 0x%x"),
24551 defn
= opcode_definitions
[opcode
];
24552 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24553 defn
+= bytes_read
;
24555 for (i
= 0; i
< arg
; ++i
)
24557 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24558 (enum dwarf_form
) defn
[i
], offset_size
,
24560 if (mac_ptr
== NULL
)
24562 /* skip_form_bytes already issued the complaint. */
24570 /* A helper function which parses the header of a macro section.
24571 If the macro section is the extended (for now called "GNU") type,
24572 then this updates *OFFSET_SIZE. Returns a pointer to just after
24573 the header, or issues a complaint and returns NULL on error. */
24575 static const gdb_byte
*
24576 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24578 const gdb_byte
*mac_ptr
,
24579 unsigned int *offset_size
,
24580 int section_is_gnu
)
24582 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24584 if (section_is_gnu
)
24586 unsigned int version
, flags
;
24588 version
= read_2_bytes (abfd
, mac_ptr
);
24589 if (version
!= 4 && version
!= 5)
24591 complaint (&symfile_complaints
,
24592 _("unrecognized version `%d' in .debug_macro section"),
24598 flags
= read_1_byte (abfd
, mac_ptr
);
24600 *offset_size
= (flags
& 1) ? 8 : 4;
24602 if ((flags
& 2) != 0)
24603 /* We don't need the line table offset. */
24604 mac_ptr
+= *offset_size
;
24606 /* Vendor opcode descriptions. */
24607 if ((flags
& 4) != 0)
24609 unsigned int i
, count
;
24611 count
= read_1_byte (abfd
, mac_ptr
);
24613 for (i
= 0; i
< count
; ++i
)
24615 unsigned int opcode
, bytes_read
;
24618 opcode
= read_1_byte (abfd
, mac_ptr
);
24620 opcode_definitions
[opcode
] = mac_ptr
;
24621 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24622 mac_ptr
+= bytes_read
;
24631 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24632 including DW_MACRO_import. */
24635 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24637 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24638 struct macro_source_file
*current_file
,
24639 struct line_header
*lh
,
24640 struct dwarf2_section_info
*section
,
24641 int section_is_gnu
, int section_is_dwz
,
24642 unsigned int offset_size
,
24643 htab_t include_hash
)
24645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24646 enum dwarf_macro_record_type macinfo_type
;
24647 int at_commandline
;
24648 const gdb_byte
*opcode_definitions
[256];
24650 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24651 &offset_size
, section_is_gnu
);
24652 if (mac_ptr
== NULL
)
24654 /* We already issued a complaint. */
24658 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24659 GDB is still reading the definitions from command line. First
24660 DW_MACINFO_start_file will need to be ignored as it was already executed
24661 to create CURRENT_FILE for the main source holding also the command line
24662 definitions. On first met DW_MACINFO_start_file this flag is reset to
24663 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24665 at_commandline
= 1;
24669 /* Do we at least have room for a macinfo type byte? */
24670 if (mac_ptr
>= mac_end
)
24672 dwarf2_section_buffer_overflow_complaint (section
);
24676 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24679 /* Note that we rely on the fact that the corresponding GNU and
24680 DWARF constants are the same. */
24682 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24683 switch (macinfo_type
)
24685 /* A zero macinfo type indicates the end of the macro
24690 case DW_MACRO_define
:
24691 case DW_MACRO_undef
:
24692 case DW_MACRO_define_strp
:
24693 case DW_MACRO_undef_strp
:
24694 case DW_MACRO_define_sup
:
24695 case DW_MACRO_undef_sup
:
24697 unsigned int bytes_read
;
24702 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24703 mac_ptr
+= bytes_read
;
24705 if (macinfo_type
== DW_MACRO_define
24706 || macinfo_type
== DW_MACRO_undef
)
24708 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24709 mac_ptr
+= bytes_read
;
24713 LONGEST str_offset
;
24715 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24716 mac_ptr
+= offset_size
;
24718 if (macinfo_type
== DW_MACRO_define_sup
24719 || macinfo_type
== DW_MACRO_undef_sup
24722 struct dwz_file
*dwz
24723 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24725 body
= read_indirect_string_from_dwz (objfile
,
24729 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24733 is_define
= (macinfo_type
== DW_MACRO_define
24734 || macinfo_type
== DW_MACRO_define_strp
24735 || macinfo_type
== DW_MACRO_define_sup
);
24736 if (! current_file
)
24738 /* DWARF violation as no main source is present. */
24739 complaint (&symfile_complaints
,
24740 _("debug info with no main source gives macro %s "
24742 is_define
? _("definition") : _("undefinition"),
24746 if ((line
== 0 && !at_commandline
)
24747 || (line
!= 0 && at_commandline
))
24748 complaint (&symfile_complaints
,
24749 _("debug info gives %s macro %s with %s line %d: %s"),
24750 at_commandline
? _("command-line") : _("in-file"),
24751 is_define
? _("definition") : _("undefinition"),
24752 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24755 parse_macro_definition (current_file
, line
, body
);
24758 gdb_assert (macinfo_type
== DW_MACRO_undef
24759 || macinfo_type
== DW_MACRO_undef_strp
24760 || macinfo_type
== DW_MACRO_undef_sup
);
24761 macro_undef (current_file
, line
, body
);
24766 case DW_MACRO_start_file
:
24768 unsigned int bytes_read
;
24771 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24772 mac_ptr
+= bytes_read
;
24773 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24774 mac_ptr
+= bytes_read
;
24776 if ((line
== 0 && !at_commandline
)
24777 || (line
!= 0 && at_commandline
))
24778 complaint (&symfile_complaints
,
24779 _("debug info gives source %d included "
24780 "from %s at %s line %d"),
24781 file
, at_commandline
? _("command-line") : _("file"),
24782 line
== 0 ? _("zero") : _("non-zero"), line
);
24784 if (at_commandline
)
24786 /* This DW_MACRO_start_file was executed in the
24788 at_commandline
= 0;
24791 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24795 case DW_MACRO_end_file
:
24796 if (! current_file
)
24797 complaint (&symfile_complaints
,
24798 _("macro debug info has an unmatched "
24799 "`close_file' directive"));
24802 current_file
= current_file
->included_by
;
24803 if (! current_file
)
24805 enum dwarf_macro_record_type next_type
;
24807 /* GCC circa March 2002 doesn't produce the zero
24808 type byte marking the end of the compilation
24809 unit. Complain if it's not there, but exit no
24812 /* Do we at least have room for a macinfo type byte? */
24813 if (mac_ptr
>= mac_end
)
24815 dwarf2_section_buffer_overflow_complaint (section
);
24819 /* We don't increment mac_ptr here, so this is just
24822 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24824 if (next_type
!= 0)
24825 complaint (&symfile_complaints
,
24826 _("no terminating 0-type entry for "
24827 "macros in `.debug_macinfo' section"));
24834 case DW_MACRO_import
:
24835 case DW_MACRO_import_sup
:
24839 bfd
*include_bfd
= abfd
;
24840 struct dwarf2_section_info
*include_section
= section
;
24841 const gdb_byte
*include_mac_end
= mac_end
;
24842 int is_dwz
= section_is_dwz
;
24843 const gdb_byte
*new_mac_ptr
;
24845 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24846 mac_ptr
+= offset_size
;
24848 if (macinfo_type
== DW_MACRO_import_sup
)
24850 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24852 dwarf2_read_section (objfile
, &dwz
->macro
);
24854 include_section
= &dwz
->macro
;
24855 include_bfd
= get_section_bfd_owner (include_section
);
24856 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24860 new_mac_ptr
= include_section
->buffer
+ offset
;
24861 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24865 /* This has actually happened; see
24866 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24867 complaint (&symfile_complaints
,
24868 _("recursive DW_MACRO_import in "
24869 ".debug_macro section"));
24873 *slot
= (void *) new_mac_ptr
;
24875 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24876 include_bfd
, new_mac_ptr
,
24877 include_mac_end
, current_file
, lh
,
24878 section
, section_is_gnu
, is_dwz
,
24879 offset_size
, include_hash
);
24881 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24886 case DW_MACINFO_vendor_ext
:
24887 if (!section_is_gnu
)
24889 unsigned int bytes_read
;
24891 /* This reads the constant, but since we don't recognize
24892 any vendor extensions, we ignore it. */
24893 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24894 mac_ptr
+= bytes_read
;
24895 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24896 mac_ptr
+= bytes_read
;
24898 /* We don't recognize any vendor extensions. */
24904 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24905 mac_ptr
, mac_end
, abfd
, offset_size
,
24907 if (mac_ptr
== NULL
)
24912 } while (macinfo_type
!= 0);
24916 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24917 int section_is_gnu
)
24919 struct dwarf2_per_objfile
*dwarf2_per_objfile
24920 = cu
->per_cu
->dwarf2_per_objfile
;
24921 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24922 struct line_header
*lh
= cu
->line_header
;
24924 const gdb_byte
*mac_ptr
, *mac_end
;
24925 struct macro_source_file
*current_file
= 0;
24926 enum dwarf_macro_record_type macinfo_type
;
24927 unsigned int offset_size
= cu
->header
.offset_size
;
24928 const gdb_byte
*opcode_definitions
[256];
24930 struct dwarf2_section_info
*section
;
24931 const char *section_name
;
24933 if (cu
->dwo_unit
!= NULL
)
24935 if (section_is_gnu
)
24937 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24938 section_name
= ".debug_macro.dwo";
24942 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24943 section_name
= ".debug_macinfo.dwo";
24948 if (section_is_gnu
)
24950 section
= &dwarf2_per_objfile
->macro
;
24951 section_name
= ".debug_macro";
24955 section
= &dwarf2_per_objfile
->macinfo
;
24956 section_name
= ".debug_macinfo";
24960 dwarf2_read_section (objfile
, section
);
24961 if (section
->buffer
== NULL
)
24963 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24966 abfd
= get_section_bfd_owner (section
);
24968 /* First pass: Find the name of the base filename.
24969 This filename is needed in order to process all macros whose definition
24970 (or undefinition) comes from the command line. These macros are defined
24971 before the first DW_MACINFO_start_file entry, and yet still need to be
24972 associated to the base file.
24974 To determine the base file name, we scan the macro definitions until we
24975 reach the first DW_MACINFO_start_file entry. We then initialize
24976 CURRENT_FILE accordingly so that any macro definition found before the
24977 first DW_MACINFO_start_file can still be associated to the base file. */
24979 mac_ptr
= section
->buffer
+ offset
;
24980 mac_end
= section
->buffer
+ section
->size
;
24982 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24983 &offset_size
, section_is_gnu
);
24984 if (mac_ptr
== NULL
)
24986 /* We already issued a complaint. */
24992 /* Do we at least have room for a macinfo type byte? */
24993 if (mac_ptr
>= mac_end
)
24995 /* Complaint is printed during the second pass as GDB will probably
24996 stop the first pass earlier upon finding
24997 DW_MACINFO_start_file. */
25001 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25004 /* Note that we rely on the fact that the corresponding GNU and
25005 DWARF constants are the same. */
25007 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25008 switch (macinfo_type
)
25010 /* A zero macinfo type indicates the end of the macro
25015 case DW_MACRO_define
:
25016 case DW_MACRO_undef
:
25017 /* Only skip the data by MAC_PTR. */
25019 unsigned int bytes_read
;
25021 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25022 mac_ptr
+= bytes_read
;
25023 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25024 mac_ptr
+= bytes_read
;
25028 case DW_MACRO_start_file
:
25030 unsigned int bytes_read
;
25033 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25034 mac_ptr
+= bytes_read
;
25035 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25036 mac_ptr
+= bytes_read
;
25038 current_file
= macro_start_file (file
, line
, current_file
, lh
);
25042 case DW_MACRO_end_file
:
25043 /* No data to skip by MAC_PTR. */
25046 case DW_MACRO_define_strp
:
25047 case DW_MACRO_undef_strp
:
25048 case DW_MACRO_define_sup
:
25049 case DW_MACRO_undef_sup
:
25051 unsigned int bytes_read
;
25053 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25054 mac_ptr
+= bytes_read
;
25055 mac_ptr
+= offset_size
;
25059 case DW_MACRO_import
:
25060 case DW_MACRO_import_sup
:
25061 /* Note that, according to the spec, a transparent include
25062 chain cannot call DW_MACRO_start_file. So, we can just
25063 skip this opcode. */
25064 mac_ptr
+= offset_size
;
25067 case DW_MACINFO_vendor_ext
:
25068 /* Only skip the data by MAC_PTR. */
25069 if (!section_is_gnu
)
25071 unsigned int bytes_read
;
25073 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25074 mac_ptr
+= bytes_read
;
25075 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25076 mac_ptr
+= bytes_read
;
25081 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25082 mac_ptr
, mac_end
, abfd
, offset_size
,
25084 if (mac_ptr
== NULL
)
25089 } while (macinfo_type
!= 0 && current_file
== NULL
);
25091 /* Second pass: Process all entries.
25093 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25094 command-line macro definitions/undefinitions. This flag is unset when we
25095 reach the first DW_MACINFO_start_file entry. */
25097 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25099 NULL
, xcalloc
, xfree
));
25100 mac_ptr
= section
->buffer
+ offset
;
25101 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25102 *slot
= (void *) mac_ptr
;
25103 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
25104 abfd
, mac_ptr
, mac_end
,
25105 current_file
, lh
, section
,
25106 section_is_gnu
, 0, offset_size
,
25107 include_hash
.get ());
25110 /* Check if the attribute's form is a DW_FORM_block*
25111 if so return true else false. */
25114 attr_form_is_block (const struct attribute
*attr
)
25116 return (attr
== NULL
? 0 :
25117 attr
->form
== DW_FORM_block1
25118 || attr
->form
== DW_FORM_block2
25119 || attr
->form
== DW_FORM_block4
25120 || attr
->form
== DW_FORM_block
25121 || attr
->form
== DW_FORM_exprloc
);
25124 /* Return non-zero if ATTR's value is a section offset --- classes
25125 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25126 You may use DW_UNSND (attr) to retrieve such offsets.
25128 Section 7.5.4, "Attribute Encodings", explains that no attribute
25129 may have a value that belongs to more than one of these classes; it
25130 would be ambiguous if we did, because we use the same forms for all
25134 attr_form_is_section_offset (const struct attribute
*attr
)
25136 return (attr
->form
== DW_FORM_data4
25137 || attr
->form
== DW_FORM_data8
25138 || attr
->form
== DW_FORM_sec_offset
);
25141 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25142 zero otherwise. When this function returns true, you can apply
25143 dwarf2_get_attr_constant_value to it.
25145 However, note that for some attributes you must check
25146 attr_form_is_section_offset before using this test. DW_FORM_data4
25147 and DW_FORM_data8 are members of both the constant class, and of
25148 the classes that contain offsets into other debug sections
25149 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25150 that, if an attribute's can be either a constant or one of the
25151 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25152 taken as section offsets, not constants.
25154 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25155 cannot handle that. */
25158 attr_form_is_constant (const struct attribute
*attr
)
25160 switch (attr
->form
)
25162 case DW_FORM_sdata
:
25163 case DW_FORM_udata
:
25164 case DW_FORM_data1
:
25165 case DW_FORM_data2
:
25166 case DW_FORM_data4
:
25167 case DW_FORM_data8
:
25168 case DW_FORM_implicit_const
:
25176 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25177 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25180 attr_form_is_ref (const struct attribute
*attr
)
25182 switch (attr
->form
)
25184 case DW_FORM_ref_addr
:
25189 case DW_FORM_ref_udata
:
25190 case DW_FORM_GNU_ref_alt
:
25197 /* Return the .debug_loc section to use for CU.
25198 For DWO files use .debug_loc.dwo. */
25200 static struct dwarf2_section_info
*
25201 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25203 struct dwarf2_per_objfile
*dwarf2_per_objfile
25204 = cu
->per_cu
->dwarf2_per_objfile
;
25208 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25210 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25212 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25213 : &dwarf2_per_objfile
->loc
);
25216 /* A helper function that fills in a dwarf2_loclist_baton. */
25219 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25220 struct dwarf2_loclist_baton
*baton
,
25221 const struct attribute
*attr
)
25223 struct dwarf2_per_objfile
*dwarf2_per_objfile
25224 = cu
->per_cu
->dwarf2_per_objfile
;
25225 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25227 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25229 baton
->per_cu
= cu
->per_cu
;
25230 gdb_assert (baton
->per_cu
);
25231 /* We don't know how long the location list is, but make sure we
25232 don't run off the edge of the section. */
25233 baton
->size
= section
->size
- DW_UNSND (attr
);
25234 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25235 baton
->base_address
= cu
->base_address
;
25236 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25240 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25241 struct dwarf2_cu
*cu
, int is_block
)
25243 struct dwarf2_per_objfile
*dwarf2_per_objfile
25244 = cu
->per_cu
->dwarf2_per_objfile
;
25245 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25246 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25248 if (attr_form_is_section_offset (attr
)
25249 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25250 the section. If so, fall through to the complaint in the
25252 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25254 struct dwarf2_loclist_baton
*baton
;
25256 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25258 fill_in_loclist_baton (cu
, baton
, attr
);
25260 if (cu
->base_known
== 0)
25261 complaint (&symfile_complaints
,
25262 _("Location list used without "
25263 "specifying the CU base address."));
25265 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25266 ? dwarf2_loclist_block_index
25267 : dwarf2_loclist_index
);
25268 SYMBOL_LOCATION_BATON (sym
) = baton
;
25272 struct dwarf2_locexpr_baton
*baton
;
25274 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25275 baton
->per_cu
= cu
->per_cu
;
25276 gdb_assert (baton
->per_cu
);
25278 if (attr_form_is_block (attr
))
25280 /* Note that we're just copying the block's data pointer
25281 here, not the actual data. We're still pointing into the
25282 info_buffer for SYM's objfile; right now we never release
25283 that buffer, but when we do clean up properly this may
25285 baton
->size
= DW_BLOCK (attr
)->size
;
25286 baton
->data
= DW_BLOCK (attr
)->data
;
25290 dwarf2_invalid_attrib_class_complaint ("location description",
25291 SYMBOL_NATURAL_NAME (sym
));
25295 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25296 ? dwarf2_locexpr_block_index
25297 : dwarf2_locexpr_index
);
25298 SYMBOL_LOCATION_BATON (sym
) = baton
;
25302 /* Return the OBJFILE associated with the compilation unit CU. If CU
25303 came from a separate debuginfo file, then the master objfile is
25307 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25309 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25311 /* Return the master objfile, so that we can report and look up the
25312 correct file containing this variable. */
25313 if (objfile
->separate_debug_objfile_backlink
)
25314 objfile
= objfile
->separate_debug_objfile_backlink
;
25319 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25320 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25321 CU_HEADERP first. */
25323 static const struct comp_unit_head
*
25324 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25325 struct dwarf2_per_cu_data
*per_cu
)
25327 const gdb_byte
*info_ptr
;
25330 return &per_cu
->cu
->header
;
25332 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25334 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25335 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25336 rcuh_kind::COMPILE
);
25341 /* Return the address size given in the compilation unit header for CU. */
25344 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25346 struct comp_unit_head cu_header_local
;
25347 const struct comp_unit_head
*cu_headerp
;
25349 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25351 return cu_headerp
->addr_size
;
25354 /* Return the offset size given in the compilation unit header for CU. */
25357 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25359 struct comp_unit_head cu_header_local
;
25360 const struct comp_unit_head
*cu_headerp
;
25362 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25364 return cu_headerp
->offset_size
;
25367 /* See its dwarf2loc.h declaration. */
25370 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25372 struct comp_unit_head cu_header_local
;
25373 const struct comp_unit_head
*cu_headerp
;
25375 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25377 if (cu_headerp
->version
== 2)
25378 return cu_headerp
->addr_size
;
25380 return cu_headerp
->offset_size
;
25383 /* Return the text offset of the CU. The returned offset comes from
25384 this CU's objfile. If this objfile came from a separate debuginfo
25385 file, then the offset may be different from the corresponding
25386 offset in the parent objfile. */
25389 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25391 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25393 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25396 /* Return DWARF version number of PER_CU. */
25399 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25401 return per_cu
->dwarf_version
;
25404 /* Locate the .debug_info compilation unit from CU's objfile which contains
25405 the DIE at OFFSET. Raises an error on failure. */
25407 static struct dwarf2_per_cu_data
*
25408 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25409 unsigned int offset_in_dwz
,
25410 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25412 struct dwarf2_per_cu_data
*this_cu
;
25414 const sect_offset
*cu_off
;
25417 high
= dwarf2_per_objfile
->n_comp_units
- 1;
25420 struct dwarf2_per_cu_data
*mid_cu
;
25421 int mid
= low
+ (high
- low
) / 2;
25423 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25424 cu_off
= &mid_cu
->sect_off
;
25425 if (mid_cu
->is_dwz
> offset_in_dwz
25426 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25431 gdb_assert (low
== high
);
25432 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25433 cu_off
= &this_cu
->sect_off
;
25434 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25436 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25437 error (_("Dwarf Error: could not find partial DIE containing "
25438 "offset %s [in module %s]"),
25439 sect_offset_str (sect_off
),
25440 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25442 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25444 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25448 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25449 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25450 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25451 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25452 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25457 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25459 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25460 : per_cu (per_cu_
),
25463 checked_producer (0),
25464 producer_is_gxx_lt_4_6 (0),
25465 producer_is_gcc_lt_4_3 (0),
25466 producer_is_icc_lt_14 (0),
25467 processing_has_namespace_info (0)
25472 /* Destroy a dwarf2_cu. */
25474 dwarf2_cu::~dwarf2_cu ()
25479 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25482 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25483 enum language pretend_language
)
25485 struct attribute
*attr
;
25487 /* Set the language we're debugging. */
25488 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25490 set_cu_language (DW_UNSND (attr
), cu
);
25493 cu
->language
= pretend_language
;
25494 cu
->language_defn
= language_def (cu
->language
);
25497 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25500 /* Free all cached compilation units. */
25503 free_cached_comp_units (void *data
)
25505 struct dwarf2_per_objfile
*dwarf2_per_objfile
25506 = (struct dwarf2_per_objfile
*) data
;
25508 dwarf2_per_objfile
->free_cached_comp_units ();
25511 /* Increase the age counter on each cached compilation unit, and free
25512 any that are too old. */
25515 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25517 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25519 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25520 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25521 while (per_cu
!= NULL
)
25523 per_cu
->cu
->last_used
++;
25524 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25525 dwarf2_mark (per_cu
->cu
);
25526 per_cu
= per_cu
->cu
->read_in_chain
;
25529 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25530 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25531 while (per_cu
!= NULL
)
25533 struct dwarf2_per_cu_data
*next_cu
;
25535 next_cu
= per_cu
->cu
->read_in_chain
;
25537 if (!per_cu
->cu
->mark
)
25540 *last_chain
= next_cu
;
25543 last_chain
= &per_cu
->cu
->read_in_chain
;
25549 /* Remove a single compilation unit from the cache. */
25552 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25554 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25555 struct dwarf2_per_objfile
*dwarf2_per_objfile
25556 = target_per_cu
->dwarf2_per_objfile
;
25558 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25559 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25560 while (per_cu
!= NULL
)
25562 struct dwarf2_per_cu_data
*next_cu
;
25564 next_cu
= per_cu
->cu
->read_in_chain
;
25566 if (per_cu
== target_per_cu
)
25570 *last_chain
= next_cu
;
25574 last_chain
= &per_cu
->cu
->read_in_chain
;
25580 /* Release all extra memory associated with OBJFILE. */
25583 dwarf2_free_objfile (struct objfile
*objfile
)
25585 struct dwarf2_per_objfile
*dwarf2_per_objfile
25586 = get_dwarf2_per_objfile (objfile
);
25588 delete dwarf2_per_objfile
;
25591 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25592 We store these in a hash table separate from the DIEs, and preserve them
25593 when the DIEs are flushed out of cache.
25595 The CU "per_cu" pointer is needed because offset alone is not enough to
25596 uniquely identify the type. A file may have multiple .debug_types sections,
25597 or the type may come from a DWO file. Furthermore, while it's more logical
25598 to use per_cu->section+offset, with Fission the section with the data is in
25599 the DWO file but we don't know that section at the point we need it.
25600 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25601 because we can enter the lookup routine, get_die_type_at_offset, from
25602 outside this file, and thus won't necessarily have PER_CU->cu.
25603 Fortunately, PER_CU is stable for the life of the objfile. */
25605 struct dwarf2_per_cu_offset_and_type
25607 const struct dwarf2_per_cu_data
*per_cu
;
25608 sect_offset sect_off
;
25612 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25615 per_cu_offset_and_type_hash (const void *item
)
25617 const struct dwarf2_per_cu_offset_and_type
*ofs
25618 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25620 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25623 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25626 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25628 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25629 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25630 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25631 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25633 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25634 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25637 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25638 table if necessary. For convenience, return TYPE.
25640 The DIEs reading must have careful ordering to:
25641 * Not cause infite loops trying to read in DIEs as a prerequisite for
25642 reading current DIE.
25643 * Not trying to dereference contents of still incompletely read in types
25644 while reading in other DIEs.
25645 * Enable referencing still incompletely read in types just by a pointer to
25646 the type without accessing its fields.
25648 Therefore caller should follow these rules:
25649 * Try to fetch any prerequisite types we may need to build this DIE type
25650 before building the type and calling set_die_type.
25651 * After building type call set_die_type for current DIE as soon as
25652 possible before fetching more types to complete the current type.
25653 * Make the type as complete as possible before fetching more types. */
25655 static struct type
*
25656 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25658 struct dwarf2_per_objfile
*dwarf2_per_objfile
25659 = cu
->per_cu
->dwarf2_per_objfile
;
25660 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25661 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25662 struct attribute
*attr
;
25663 struct dynamic_prop prop
;
25665 /* For Ada types, make sure that the gnat-specific data is always
25666 initialized (if not already set). There are a few types where
25667 we should not be doing so, because the type-specific area is
25668 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25669 where the type-specific area is used to store the floatformat).
25670 But this is not a problem, because the gnat-specific information
25671 is actually not needed for these types. */
25672 if (need_gnat_info (cu
)
25673 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25674 && TYPE_CODE (type
) != TYPE_CODE_FLT
25675 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25676 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25677 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25678 && !HAVE_GNAT_AUX_INFO (type
))
25679 INIT_GNAT_SPECIFIC (type
);
25681 /* Read DW_AT_allocated and set in type. */
25682 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25683 if (attr_form_is_block (attr
))
25685 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25686 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25688 else if (attr
!= NULL
)
25690 complaint (&symfile_complaints
,
25691 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25692 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25693 sect_offset_str (die
->sect_off
));
25696 /* Read DW_AT_associated and set in type. */
25697 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25698 if (attr_form_is_block (attr
))
25700 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25701 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25703 else if (attr
!= NULL
)
25705 complaint (&symfile_complaints
,
25706 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25707 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25708 sect_offset_str (die
->sect_off
));
25711 /* Read DW_AT_data_location and set in type. */
25712 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25713 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25714 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25716 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25718 dwarf2_per_objfile
->die_type_hash
=
25719 htab_create_alloc_ex (127,
25720 per_cu_offset_and_type_hash
,
25721 per_cu_offset_and_type_eq
,
25723 &objfile
->objfile_obstack
,
25724 hashtab_obstack_allocate
,
25725 dummy_obstack_deallocate
);
25728 ofs
.per_cu
= cu
->per_cu
;
25729 ofs
.sect_off
= die
->sect_off
;
25731 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25732 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25734 complaint (&symfile_complaints
,
25735 _("A problem internal to GDB: DIE %s has type already set"),
25736 sect_offset_str (die
->sect_off
));
25737 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25738 struct dwarf2_per_cu_offset_and_type
);
25743 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25744 or return NULL if the die does not have a saved type. */
25746 static struct type
*
25747 get_die_type_at_offset (sect_offset sect_off
,
25748 struct dwarf2_per_cu_data
*per_cu
)
25750 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25751 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25753 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25756 ofs
.per_cu
= per_cu
;
25757 ofs
.sect_off
= sect_off
;
25758 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25759 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25766 /* Look up the type for DIE in CU in die_type_hash,
25767 or return NULL if DIE does not have a saved type. */
25769 static struct type
*
25770 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25772 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25775 /* Add a dependence relationship from CU to REF_PER_CU. */
25778 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25779 struct dwarf2_per_cu_data
*ref_per_cu
)
25783 if (cu
->dependencies
== NULL
)
25785 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25786 NULL
, &cu
->comp_unit_obstack
,
25787 hashtab_obstack_allocate
,
25788 dummy_obstack_deallocate
);
25790 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25792 *slot
= ref_per_cu
;
25795 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25796 Set the mark field in every compilation unit in the
25797 cache that we must keep because we are keeping CU. */
25800 dwarf2_mark_helper (void **slot
, void *data
)
25802 struct dwarf2_per_cu_data
*per_cu
;
25804 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25806 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25807 reading of the chain. As such dependencies remain valid it is not much
25808 useful to track and undo them during QUIT cleanups. */
25809 if (per_cu
->cu
== NULL
)
25812 if (per_cu
->cu
->mark
)
25814 per_cu
->cu
->mark
= 1;
25816 if (per_cu
->cu
->dependencies
!= NULL
)
25817 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25822 /* Set the mark field in CU and in every other compilation unit in the
25823 cache that we must keep because we are keeping CU. */
25826 dwarf2_mark (struct dwarf2_cu
*cu
)
25831 if (cu
->dependencies
!= NULL
)
25832 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25836 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25840 per_cu
->cu
->mark
= 0;
25841 per_cu
= per_cu
->cu
->read_in_chain
;
25845 /* Trivial hash function for partial_die_info: the hash value of a DIE
25846 is its offset in .debug_info for this objfile. */
25849 partial_die_hash (const void *item
)
25851 const struct partial_die_info
*part_die
25852 = (const struct partial_die_info
*) item
;
25854 return to_underlying (part_die
->sect_off
);
25857 /* Trivial comparison function for partial_die_info structures: two DIEs
25858 are equal if they have the same offset. */
25861 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25863 const struct partial_die_info
*part_die_lhs
25864 = (const struct partial_die_info
*) item_lhs
;
25865 const struct partial_die_info
*part_die_rhs
25866 = (const struct partial_die_info
*) item_rhs
;
25868 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25871 static struct cmd_list_element
*set_dwarf_cmdlist
;
25872 static struct cmd_list_element
*show_dwarf_cmdlist
;
25875 set_dwarf_cmd (const char *args
, int from_tty
)
25877 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25882 show_dwarf_cmd (const char *args
, int from_tty
)
25884 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25887 /* The "save gdb-index" command. */
25889 /* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
25893 file_write (FILE *file
, const void *data
, size_t size
)
25895 if (fwrite (data
, 1, size
, file
) != size
)
25896 error (_("couldn't data write to file"));
25899 /* Write the contents of VEC to FILE, with error checking. */
25901 template<typename Elem
, typename Alloc
>
25903 file_write (FILE *file
, const std::vector
<Elem
, Alloc
> &vec
)
25905 file_write (file
, vec
.data (), vec
.size () * sizeof (vec
[0]));
25908 /* In-memory buffer to prepare data to be written later to a file. */
25912 /* Copy DATA to the end of the buffer. */
25913 template<typename T
>
25914 void append_data (const T
&data
)
25916 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
25917 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
25918 grow (sizeof (data
)));
25921 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
25922 terminating zero is appended too. */
25923 void append_cstr0 (const char *cstr
)
25925 const size_t size
= strlen (cstr
) + 1;
25926 std::copy (cstr
, cstr
+ size
, grow (size
));
25929 /* Store INPUT as ULEB128 to the end of buffer. */
25930 void append_unsigned_leb128 (ULONGEST input
)
25934 gdb_byte output
= input
& 0x7f;
25938 append_data (output
);
25944 /* Accept a host-format integer in VAL and append it to the buffer
25945 as a target-format integer which is LEN bytes long. */
25946 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
25948 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
25951 /* Return the size of the buffer. */
25952 size_t size () const
25954 return m_vec
.size ();
25957 /* Return true iff the buffer is empty. */
25958 bool empty () const
25960 return m_vec
.empty ();
25963 /* Write the buffer to FILE. */
25964 void file_write (FILE *file
) const
25966 ::file_write (file
, m_vec
);
25970 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
25971 the start of the new block. */
25972 gdb_byte
*grow (size_t size
)
25974 m_vec
.resize (m_vec
.size () + size
);
25975 return &*m_vec
.end () - size
;
25978 gdb::byte_vector m_vec
;
25981 /* An entry in the symbol table. */
25982 struct symtab_index_entry
25984 /* The name of the symbol. */
25986 /* The offset of the name in the constant pool. */
25987 offset_type index_offset
;
25988 /* A sorted vector of the indices of all the CUs that hold an object
25990 std::vector
<offset_type
> cu_indices
;
25993 /* The symbol table. This is a power-of-2-sized hash table. */
25994 struct mapped_symtab
25998 data
.resize (1024);
26001 offset_type n_elements
= 0;
26002 std::vector
<symtab_index_entry
> data
;
26005 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
26008 Function is used only during write_hash_table so no index format backward
26009 compatibility is needed. */
26011 static symtab_index_entry
&
26012 find_slot (struct mapped_symtab
*symtab
, const char *name
)
26014 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
26016 index
= hash
& (symtab
->data
.size () - 1);
26017 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
26021 if (symtab
->data
[index
].name
== NULL
26022 || strcmp (name
, symtab
->data
[index
].name
) == 0)
26023 return symtab
->data
[index
];
26024 index
= (index
+ step
) & (symtab
->data
.size () - 1);
26028 /* Expand SYMTAB's hash table. */
26031 hash_expand (struct mapped_symtab
*symtab
)
26033 auto old_entries
= std::move (symtab
->data
);
26035 symtab
->data
.clear ();
26036 symtab
->data
.resize (old_entries
.size () * 2);
26038 for (auto &it
: old_entries
)
26039 if (it
.name
!= NULL
)
26041 auto &ref
= find_slot (symtab
, it
.name
);
26042 ref
= std::move (it
);
26046 /* Add an entry to SYMTAB. NAME is the name of the symbol.
26047 CU_INDEX is the index of the CU in which the symbol appears.
26048 IS_STATIC is one if the symbol is static, otherwise zero (global). */
26051 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
26052 int is_static
, gdb_index_symbol_kind kind
,
26053 offset_type cu_index
)
26055 offset_type cu_index_and_attrs
;
26057 ++symtab
->n_elements
;
26058 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
26059 hash_expand (symtab
);
26061 symtab_index_entry
&slot
= find_slot (symtab
, name
);
26062 if (slot
.name
== NULL
)
26065 /* index_offset is set later. */
26068 cu_index_and_attrs
= 0;
26069 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
26070 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
26071 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
26073 /* We don't want to record an index value twice as we want to avoid the
26075 We process all global symbols and then all static symbols
26076 (which would allow us to avoid the duplication by only having to check
26077 the last entry pushed), but a symbol could have multiple kinds in one CU.
26078 To keep things simple we don't worry about the duplication here and
26079 sort and uniqufy the list after we've processed all symbols. */
26080 slot
.cu_indices
.push_back (cu_index_and_attrs
);
26083 /* Sort and remove duplicates of all symbols' cu_indices lists. */
26086 uniquify_cu_indices (struct mapped_symtab
*symtab
)
26088 for (auto &entry
: symtab
->data
)
26090 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
26092 auto &cu_indices
= entry
.cu_indices
;
26093 std::sort (cu_indices
.begin (), cu_indices
.end ());
26094 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
26095 cu_indices
.erase (from
, cu_indices
.end ());
26100 /* A form of 'const char *' suitable for container keys. Only the
26101 pointer is stored. The strings themselves are compared, not the
26106 c_str_view (const char *cstr
)
26110 bool operator== (const c_str_view
&other
) const
26112 return strcmp (m_cstr
, other
.m_cstr
) == 0;
26115 /* Return the underlying C string. Note, the returned string is
26116 only a reference with lifetime of this object. */
26117 const char *c_str () const
26123 friend class c_str_view_hasher
;
26124 const char *const m_cstr
;
26127 /* A std::unordered_map::hasher for c_str_view that uses the right
26128 hash function for strings in a mapped index. */
26129 class c_str_view_hasher
26132 size_t operator () (const c_str_view
&x
) const
26134 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
26138 /* A std::unordered_map::hasher for std::vector<>. */
26139 template<typename T
>
26140 class vector_hasher
26143 size_t operator () (const std::vector
<T
> &key
) const
26145 return iterative_hash (key
.data (),
26146 sizeof (key
.front ()) * key
.size (), 0);
26150 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
26151 constant pool entries going into the data buffer CPOOL. */
26154 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
26157 /* Elements are sorted vectors of the indices of all the CUs that
26158 hold an object of this name. */
26159 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
26160 vector_hasher
<offset_type
>>
26163 /* We add all the index vectors to the constant pool first, to
26164 ensure alignment is ok. */
26165 for (symtab_index_entry
&entry
: symtab
->data
)
26167 if (entry
.name
== NULL
)
26169 gdb_assert (entry
.index_offset
== 0);
26171 /* Finding before inserting is faster than always trying to
26172 insert, because inserting always allocates a node, does the
26173 lookup, and then destroys the new node if another node
26174 already had the same key. C++17 try_emplace will avoid
26177 = symbol_hash_table
.find (entry
.cu_indices
);
26178 if (found
!= symbol_hash_table
.end ())
26180 entry
.index_offset
= found
->second
;
26184 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
26185 entry
.index_offset
= cpool
.size ();
26186 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
26187 for (const auto index
: entry
.cu_indices
)
26188 cpool
.append_data (MAYBE_SWAP (index
));
26192 /* Now write out the hash table. */
26193 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
26194 for (const auto &entry
: symtab
->data
)
26196 offset_type str_off
, vec_off
;
26198 if (entry
.name
!= NULL
)
26200 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
26201 if (insertpair
.second
)
26202 cpool
.append_cstr0 (entry
.name
);
26203 str_off
= insertpair
.first
->second
;
26204 vec_off
= entry
.index_offset
;
26208 /* While 0 is a valid constant pool index, it is not valid
26209 to have 0 for both offsets. */
26214 output
.append_data (MAYBE_SWAP (str_off
));
26215 output
.append_data (MAYBE_SWAP (vec_off
));
26219 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
26221 /* Helper struct for building the address table. */
26222 struct addrmap_index_data
26224 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
26225 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
26228 struct objfile
*objfile
;
26229 data_buf
&addr_vec
;
26230 psym_index_map
&cu_index_htab
;
26232 /* Non-zero if the previous_* fields are valid.
26233 We can't write an entry until we see the next entry (since it is only then
26234 that we know the end of the entry). */
26235 int previous_valid
;
26236 /* Index of the CU in the table of all CUs in the index file. */
26237 unsigned int previous_cu_index
;
26238 /* Start address of the CU. */
26239 CORE_ADDR previous_cu_start
;
26242 /* Write an address entry to ADDR_VEC. */
26245 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
26246 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
26248 CORE_ADDR baseaddr
;
26250 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
26252 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
26253 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
26254 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
26257 /* Worker function for traversing an addrmap to build the address table. */
26260 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
26262 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
26263 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
26265 if (data
->previous_valid
)
26266 add_address_entry (data
->objfile
, data
->addr_vec
,
26267 data
->previous_cu_start
, start_addr
,
26268 data
->previous_cu_index
);
26270 data
->previous_cu_start
= start_addr
;
26273 const auto it
= data
->cu_index_htab
.find (pst
);
26274 gdb_assert (it
!= data
->cu_index_htab
.cend ());
26275 data
->previous_cu_index
= it
->second
;
26276 data
->previous_valid
= 1;
26279 data
->previous_valid
= 0;
26284 /* Write OBJFILE's address map to ADDR_VEC.
26285 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
26286 in the index file. */
26289 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
26290 psym_index_map
&cu_index_htab
)
26292 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
26294 /* When writing the address table, we have to cope with the fact that
26295 the addrmap iterator only provides the start of a region; we have to
26296 wait until the next invocation to get the start of the next region. */
26298 addrmap_index_data
.objfile
= objfile
;
26299 addrmap_index_data
.previous_valid
= 0;
26301 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
26302 &addrmap_index_data
);
26304 /* It's highly unlikely the last entry (end address = 0xff...ff)
26305 is valid, but we should still handle it.
26306 The end address is recorded as the start of the next region, but that
26307 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
26309 if (addrmap_index_data
.previous_valid
)
26310 add_address_entry (objfile
, addr_vec
,
26311 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
26312 addrmap_index_data
.previous_cu_index
);
26315 /* Return the symbol kind of PSYM. */
26317 static gdb_index_symbol_kind
26318 symbol_kind (struct partial_symbol
*psym
)
26320 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26321 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26329 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
26331 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26333 case LOC_CONST_BYTES
:
26334 case LOC_OPTIMIZED_OUT
:
26336 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26338 /* Note: It's currently impossible to recognize psyms as enum values
26339 short of reading the type info. For now punt. */
26340 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26342 /* There are other LOC_FOO values that one might want to classify
26343 as variables, but dwarf2read.c doesn't currently use them. */
26344 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26346 case STRUCT_DOMAIN
:
26347 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26349 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26353 /* Add a list of partial symbols to SYMTAB. */
26356 write_psymbols (struct mapped_symtab
*symtab
,
26357 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26358 struct partial_symbol
**psymp
,
26360 offset_type cu_index
,
26363 for (; count
-- > 0; ++psymp
)
26365 struct partial_symbol
*psym
= *psymp
;
26367 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
26368 error (_("Ada is not currently supported by the index"));
26370 /* Only add a given psymbol once. */
26371 if (psyms_seen
.insert (psym
).second
)
26373 gdb_index_symbol_kind kind
= symbol_kind (psym
);
26375 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
26376 is_static
, kind
, cu_index
);
26381 /* A helper struct used when iterating over debug_types. */
26382 struct signatured_type_index_data
26384 signatured_type_index_data (data_buf
&types_list_
,
26385 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
26386 : types_list (types_list_
), psyms_seen (psyms_seen_
)
26389 struct objfile
*objfile
;
26390 struct mapped_symtab
*symtab
;
26391 data_buf
&types_list
;
26392 std::unordered_set
<partial_symbol
*> &psyms_seen
;
26396 /* A helper function that writes a single signatured_type to an
26400 write_one_signatured_type (void **slot
, void *d
)
26402 struct signatured_type_index_data
*info
26403 = (struct signatured_type_index_data
*) d
;
26404 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26405 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26407 write_psymbols (info
->symtab
,
26409 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26410 psymtab
->n_global_syms
, info
->cu_index
,
26412 write_psymbols (info
->symtab
,
26414 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26415 psymtab
->n_static_syms
, info
->cu_index
,
26418 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26419 to_underlying (entry
->per_cu
.sect_off
));
26420 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26421 to_underlying (entry
->type_offset_in_tu
));
26422 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
26429 /* Recurse into all "included" dependencies and count their symbols as
26430 if they appeared in this psymtab. */
26433 recursively_count_psymbols (struct partial_symtab
*psymtab
,
26434 size_t &psyms_seen
)
26436 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26437 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26438 recursively_count_psymbols (psymtab
->dependencies
[i
],
26441 psyms_seen
+= psymtab
->n_global_syms
;
26442 psyms_seen
+= psymtab
->n_static_syms
;
26445 /* Recurse into all "included" dependencies and write their symbols as
26446 if they appeared in this psymtab. */
26449 recursively_write_psymbols (struct objfile
*objfile
,
26450 struct partial_symtab
*psymtab
,
26451 struct mapped_symtab
*symtab
,
26452 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26453 offset_type cu_index
)
26457 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26458 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26459 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26460 symtab
, psyms_seen
, cu_index
);
26462 write_psymbols (symtab
,
26464 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26465 psymtab
->n_global_syms
, cu_index
,
26467 write_psymbols (symtab
,
26469 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26470 psymtab
->n_static_syms
, cu_index
,
26474 /* DWARF-5 .debug_names builder. */
26478 debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bool is_dwarf64
,
26479 bfd_endian dwarf5_byte_order
)
26480 : m_dwarf5_byte_order (dwarf5_byte_order
),
26481 m_dwarf32 (dwarf5_byte_order
),
26482 m_dwarf64 (dwarf5_byte_order
),
26483 m_dwarf (is_dwarf64
26484 ? static_cast<dwarf
&> (m_dwarf64
)
26485 : static_cast<dwarf
&> (m_dwarf32
)),
26486 m_name_table_string_offs (m_dwarf
.name_table_string_offs
),
26487 m_name_table_entry_offs (m_dwarf
.name_table_entry_offs
),
26488 m_debugstrlookup (dwarf2_per_objfile
)
26491 int dwarf5_offset_size () const
26493 const bool dwarf5_is_dwarf64
= &m_dwarf
== &m_dwarf64
;
26494 return dwarf5_is_dwarf64
? 8 : 4;
26497 /* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
26498 enum class unit_kind
{ cu
, tu
};
26500 /* Insert one symbol. */
26501 void insert (const partial_symbol
*psym
, int cu_index
, bool is_static
,
26504 const int dwarf_tag
= psymbol_tag (psym
);
26505 if (dwarf_tag
== 0)
26507 const char *const name
= SYMBOL_SEARCH_NAME (psym
);
26508 const auto insertpair
26509 = m_name_to_value_set
.emplace (c_str_view (name
),
26510 std::set
<symbol_value
> ());
26511 std::set
<symbol_value
> &value_set
= insertpair
.first
->second
;
26512 value_set
.emplace (symbol_value (dwarf_tag
, cu_index
, is_static
, kind
));
26515 /* Build all the tables. All symbols must be already inserted.
26516 This function does not call file_write, caller has to do it
26520 /* Verify the build method has not be called twice. */
26521 gdb_assert (m_abbrev_table
.empty ());
26522 const size_t name_count
= m_name_to_value_set
.size ();
26523 m_bucket_table
.resize
26524 (std::pow (2, std::ceil (std::log2 (name_count
* 4 / 3))));
26525 m_hash_table
.reserve (name_count
);
26526 m_name_table_string_offs
.reserve (name_count
);
26527 m_name_table_entry_offs
.reserve (name_count
);
26529 /* Map each hash of symbol to its name and value. */
26530 struct hash_it_pair
26533 decltype (m_name_to_value_set
)::const_iterator it
;
26535 std::vector
<std::forward_list
<hash_it_pair
>> bucket_hash
;
26536 bucket_hash
.resize (m_bucket_table
.size ());
26537 for (decltype (m_name_to_value_set
)::const_iterator it
26538 = m_name_to_value_set
.cbegin ();
26539 it
!= m_name_to_value_set
.cend ();
26542 const char *const name
= it
->first
.c_str ();
26543 const uint32_t hash
= dwarf5_djb_hash (name
);
26544 hash_it_pair hashitpair
;
26545 hashitpair
.hash
= hash
;
26546 hashitpair
.it
= it
;
26547 auto &slot
= bucket_hash
[hash
% bucket_hash
.size()];
26548 slot
.push_front (std::move (hashitpair
));
26550 for (size_t bucket_ix
= 0; bucket_ix
< bucket_hash
.size (); ++bucket_ix
)
26552 const std::forward_list
<hash_it_pair
> &hashitlist
26553 = bucket_hash
[bucket_ix
];
26554 if (hashitlist
.empty ())
26556 uint32_t &bucket_slot
= m_bucket_table
[bucket_ix
];
26557 /* The hashes array is indexed starting at 1. */
26558 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&bucket_slot
),
26559 sizeof (bucket_slot
), m_dwarf5_byte_order
,
26560 m_hash_table
.size () + 1);
26561 for (const hash_it_pair
&hashitpair
: hashitlist
)
26563 m_hash_table
.push_back (0);
26564 store_unsigned_integer (reinterpret_cast<gdb_byte
*>
26565 (&m_hash_table
.back ()),
26566 sizeof (m_hash_table
.back ()),
26567 m_dwarf5_byte_order
, hashitpair
.hash
);
26568 const c_str_view
&name
= hashitpair
.it
->first
;
26569 const std::set
<symbol_value
> &value_set
= hashitpair
.it
->second
;
26570 m_name_table_string_offs
.push_back_reorder
26571 (m_debugstrlookup
.lookup (name
.c_str ()));
26572 m_name_table_entry_offs
.push_back_reorder (m_entry_pool
.size ());
26573 gdb_assert (!value_set
.empty ());
26574 for (const symbol_value
&value
: value_set
)
26576 int &idx
= m_indexkey_to_idx
[index_key (value
.dwarf_tag
,
26581 idx
= m_idx_next
++;
26582 m_abbrev_table
.append_unsigned_leb128 (idx
);
26583 m_abbrev_table
.append_unsigned_leb128 (value
.dwarf_tag
);
26584 m_abbrev_table
.append_unsigned_leb128
26585 (value
.kind
== unit_kind::cu
? DW_IDX_compile_unit
26586 : DW_IDX_type_unit
);
26587 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_udata
);
26588 m_abbrev_table
.append_unsigned_leb128 (value
.is_static
26589 ? DW_IDX_GNU_internal
26590 : DW_IDX_GNU_external
);
26591 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_flag_present
);
26593 /* Terminate attributes list. */
26594 m_abbrev_table
.append_unsigned_leb128 (0);
26595 m_abbrev_table
.append_unsigned_leb128 (0);
26598 m_entry_pool
.append_unsigned_leb128 (idx
);
26599 m_entry_pool
.append_unsigned_leb128 (value
.cu_index
);
26602 /* Terminate the list of CUs. */
26603 m_entry_pool
.append_unsigned_leb128 (0);
26606 gdb_assert (m_hash_table
.size () == name_count
);
26608 /* Terminate tags list. */
26609 m_abbrev_table
.append_unsigned_leb128 (0);
26612 /* Return .debug_names bucket count. This must be called only after
26613 calling the build method. */
26614 uint32_t bucket_count () const
26616 /* Verify the build method has been already called. */
26617 gdb_assert (!m_abbrev_table
.empty ());
26618 const uint32_t retval
= m_bucket_table
.size ();
26620 /* Check for overflow. */
26621 gdb_assert (retval
== m_bucket_table
.size ());
26625 /* Return .debug_names names count. This must be called only after
26626 calling the build method. */
26627 uint32_t name_count () const
26629 /* Verify the build method has been already called. */
26630 gdb_assert (!m_abbrev_table
.empty ());
26631 const uint32_t retval
= m_hash_table
.size ();
26633 /* Check for overflow. */
26634 gdb_assert (retval
== m_hash_table
.size ());
26638 /* Return number of bytes of .debug_names abbreviation table. This
26639 must be called only after calling the build method. */
26640 uint32_t abbrev_table_bytes () const
26642 gdb_assert (!m_abbrev_table
.empty ());
26643 return m_abbrev_table
.size ();
26646 /* Recurse into all "included" dependencies and store their symbols
26647 as if they appeared in this psymtab. */
26648 void recursively_write_psymbols
26649 (struct objfile
*objfile
,
26650 struct partial_symtab
*psymtab
,
26651 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26654 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26655 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26656 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26657 psyms_seen
, cu_index
);
26659 write_psymbols (psyms_seen
,
26660 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26661 psymtab
->n_global_syms
, cu_index
, false, unit_kind::cu
);
26662 write_psymbols (psyms_seen
,
26663 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26664 psymtab
->n_static_syms
, cu_index
, true, unit_kind::cu
);
26667 /* Return number of bytes the .debug_names section will have. This
26668 must be called only after calling the build method. */
26669 size_t bytes () const
26671 /* Verify the build method has been already called. */
26672 gdb_assert (!m_abbrev_table
.empty ());
26673 size_t expected_bytes
= 0;
26674 expected_bytes
+= m_bucket_table
.size () * sizeof (m_bucket_table
[0]);
26675 expected_bytes
+= m_hash_table
.size () * sizeof (m_hash_table
[0]);
26676 expected_bytes
+= m_name_table_string_offs
.bytes ();
26677 expected_bytes
+= m_name_table_entry_offs
.bytes ();
26678 expected_bytes
+= m_abbrev_table
.size ();
26679 expected_bytes
+= m_entry_pool
.size ();
26680 return expected_bytes
;
26683 /* Write .debug_names to FILE_NAMES and .debug_str addition to
26684 FILE_STR. This must be called only after calling the build
26686 void file_write (FILE *file_names
, FILE *file_str
) const
26688 /* Verify the build method has been already called. */
26689 gdb_assert (!m_abbrev_table
.empty ());
26690 ::file_write (file_names
, m_bucket_table
);
26691 ::file_write (file_names
, m_hash_table
);
26692 m_name_table_string_offs
.file_write (file_names
);
26693 m_name_table_entry_offs
.file_write (file_names
);
26694 m_abbrev_table
.file_write (file_names
);
26695 m_entry_pool
.file_write (file_names
);
26696 m_debugstrlookup
.file_write (file_str
);
26699 /* A helper user data for write_one_signatured_type. */
26700 class write_one_signatured_type_data
26703 write_one_signatured_type_data (debug_names
&nametable_
,
26704 signatured_type_index_data
&&info_
)
26705 : nametable (nametable_
), info (std::move (info_
))
26707 debug_names
&nametable
;
26708 struct signatured_type_index_data info
;
26711 /* A helper function to pass write_one_signatured_type to
26712 htab_traverse_noresize. */
26714 write_one_signatured_type (void **slot
, void *d
)
26716 write_one_signatured_type_data
*data
= (write_one_signatured_type_data
*) d
;
26717 struct signatured_type_index_data
*info
= &data
->info
;
26718 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26720 data
->nametable
.write_one_signatured_type (entry
, info
);
26727 /* Storage for symbol names mapping them to their .debug_str section
26729 class debug_str_lookup
26733 /* Object costructor to be called for current DWARF2_PER_OBJFILE.
26734 All .debug_str section strings are automatically stored. */
26735 debug_str_lookup (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26736 : m_abfd (dwarf2_per_objfile
->objfile
->obfd
),
26737 m_dwarf2_per_objfile (dwarf2_per_objfile
)
26739 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
26740 &dwarf2_per_objfile
->str
);
26741 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
26743 for (const gdb_byte
*data
= dwarf2_per_objfile
->str
.buffer
;
26744 data
< (dwarf2_per_objfile
->str
.buffer
26745 + dwarf2_per_objfile
->str
.size
);)
26747 const char *const s
= reinterpret_cast<const char *> (data
);
26748 const auto insertpair
26749 = m_str_table
.emplace (c_str_view (s
),
26750 data
- dwarf2_per_objfile
->str
.buffer
);
26751 if (!insertpair
.second
)
26752 complaint (&symfile_complaints
,
26753 _("Duplicate string \"%s\" in "
26754 ".debug_str section [in module %s]"),
26755 s
, bfd_get_filename (m_abfd
));
26756 data
+= strlen (s
) + 1;
26760 /* Return offset of symbol name S in the .debug_str section. Add
26761 such symbol to the section's end if it does not exist there
26763 size_t lookup (const char *s
)
26765 const auto it
= m_str_table
.find (c_str_view (s
));
26766 if (it
!= m_str_table
.end ())
26768 const size_t offset
= (m_dwarf2_per_objfile
->str
.size
26769 + m_str_add_buf
.size ());
26770 m_str_table
.emplace (c_str_view (s
), offset
);
26771 m_str_add_buf
.append_cstr0 (s
);
26775 /* Append the end of the .debug_str section to FILE. */
26776 void file_write (FILE *file
) const
26778 m_str_add_buf
.file_write (file
);
26782 std::unordered_map
<c_str_view
, size_t, c_str_view_hasher
> m_str_table
;
26784 struct dwarf2_per_objfile
*m_dwarf2_per_objfile
;
26786 /* Data to add at the end of .debug_str for new needed symbol names. */
26787 data_buf m_str_add_buf
;
26790 /* Container to map used DWARF tags to their .debug_names abbreviation
26795 index_key (int dwarf_tag_
, bool is_static_
, unit_kind kind_
)
26796 : dwarf_tag (dwarf_tag_
), is_static (is_static_
), kind (kind_
)
26801 operator== (const index_key
&other
) const
26803 return (dwarf_tag
== other
.dwarf_tag
&& is_static
== other
.is_static
26804 && kind
== other
.kind
);
26807 const int dwarf_tag
;
26808 const bool is_static
;
26809 const unit_kind kind
;
26812 /* Provide std::unordered_map::hasher for index_key. */
26813 class index_key_hasher
26817 operator () (const index_key
&key
) const
26819 return (std::hash
<int>() (key
.dwarf_tag
) << 1) | key
.is_static
;
26823 /* Parameters of one symbol entry. */
26827 const int dwarf_tag
, cu_index
;
26828 const bool is_static
;
26829 const unit_kind kind
;
26831 symbol_value (int dwarf_tag_
, int cu_index_
, bool is_static_
,
26833 : dwarf_tag (dwarf_tag_
), cu_index (cu_index_
), is_static (is_static_
),
26838 operator< (const symbol_value
&other
) const
26858 /* Abstract base class to unify DWARF-32 and DWARF-64 name table
26863 const bfd_endian dwarf5_byte_order
;
26865 explicit offset_vec (bfd_endian dwarf5_byte_order_
)
26866 : dwarf5_byte_order (dwarf5_byte_order_
)
26869 /* Call std::vector::reserve for NELEM elements. */
26870 virtual void reserve (size_t nelem
) = 0;
26872 /* Call std::vector::push_back with store_unsigned_integer byte
26873 reordering for ELEM. */
26874 virtual void push_back_reorder (size_t elem
) = 0;
26876 /* Return expected output size in bytes. */
26877 virtual size_t bytes () const = 0;
26879 /* Write name table to FILE. */
26880 virtual void file_write (FILE *file
) const = 0;
26883 /* Template to unify DWARF-32 and DWARF-64 output. */
26884 template<typename OffsetSize
>
26885 class offset_vec_tmpl
: public offset_vec
26888 explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_
)
26889 : offset_vec (dwarf5_byte_order_
)
26892 /* Implement offset_vec::reserve. */
26893 void reserve (size_t nelem
) override
26895 m_vec
.reserve (nelem
);
26898 /* Implement offset_vec::push_back_reorder. */
26899 void push_back_reorder (size_t elem
) override
26901 m_vec
.push_back (elem
);
26902 /* Check for overflow. */
26903 gdb_assert (m_vec
.back () == elem
);
26904 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&m_vec
.back ()),
26905 sizeof (m_vec
.back ()), dwarf5_byte_order
, elem
);
26908 /* Implement offset_vec::bytes. */
26909 size_t bytes () const override
26911 return m_vec
.size () * sizeof (m_vec
[0]);
26914 /* Implement offset_vec::file_write. */
26915 void file_write (FILE *file
) const override
26917 ::file_write (file
, m_vec
);
26921 std::vector
<OffsetSize
> m_vec
;
26924 /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
26925 respecting name table width. */
26929 offset_vec
&name_table_string_offs
, &name_table_entry_offs
;
26931 dwarf (offset_vec
&name_table_string_offs_
,
26932 offset_vec
&name_table_entry_offs_
)
26933 : name_table_string_offs (name_table_string_offs_
),
26934 name_table_entry_offs (name_table_entry_offs_
)
26939 /* Template to unify DWARF-32 and DWARF-64 .debug_names output
26940 respecting name table width. */
26941 template<typename OffsetSize
>
26942 class dwarf_tmpl
: public dwarf
26945 explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_
)
26946 : dwarf (m_name_table_string_offs
, m_name_table_entry_offs
),
26947 m_name_table_string_offs (dwarf5_byte_order_
),
26948 m_name_table_entry_offs (dwarf5_byte_order_
)
26952 offset_vec_tmpl
<OffsetSize
> m_name_table_string_offs
;
26953 offset_vec_tmpl
<OffsetSize
> m_name_table_entry_offs
;
26956 /* Try to reconstruct original DWARF tag for given partial_symbol.
26957 This function is not DWARF-5 compliant but it is sufficient for
26958 GDB as a DWARF-5 index consumer. */
26959 static int psymbol_tag (const struct partial_symbol
*psym
)
26961 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26962 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26970 return DW_TAG_subprogram
;
26972 return DW_TAG_typedef
;
26974 case LOC_CONST_BYTES
:
26975 case LOC_OPTIMIZED_OUT
:
26977 return DW_TAG_variable
;
26979 /* Note: It's currently impossible to recognize psyms as enum values
26980 short of reading the type info. For now punt. */
26981 return DW_TAG_variable
;
26983 /* There are other LOC_FOO values that one might want to classify
26984 as variables, but dwarf2read.c doesn't currently use them. */
26985 return DW_TAG_variable
;
26987 case STRUCT_DOMAIN
:
26988 return DW_TAG_structure_type
;
26994 /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
26995 void write_psymbols (std::unordered_set
<partial_symbol
*> &psyms_seen
,
26996 struct partial_symbol
**psymp
, int count
, int cu_index
,
26997 bool is_static
, unit_kind kind
)
26999 for (; count
-- > 0; ++psymp
)
27001 struct partial_symbol
*psym
= *psymp
;
27003 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
27004 error (_("Ada is not currently supported by the index"));
27006 /* Only add a given psymbol once. */
27007 if (psyms_seen
.insert (psym
).second
)
27008 insert (psym
, cu_index
, is_static
, kind
);
27012 /* A helper function that writes a single signatured_type
27013 to a debug_names. */
27015 write_one_signatured_type (struct signatured_type
*entry
,
27016 struct signatured_type_index_data
*info
)
27018 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
27020 write_psymbols (info
->psyms_seen
,
27021 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
27022 psymtab
->n_global_syms
, info
->cu_index
, false,
27024 write_psymbols (info
->psyms_seen
,
27025 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
27026 psymtab
->n_static_syms
, info
->cu_index
, true,
27029 info
->types_list
.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order
,
27030 to_underlying (entry
->per_cu
.sect_off
));
27035 /* Store value of each symbol. */
27036 std::unordered_map
<c_str_view
, std::set
<symbol_value
>, c_str_view_hasher
>
27037 m_name_to_value_set
;
27039 /* Tables of DWARF-5 .debug_names. They are in object file byte
27041 std::vector
<uint32_t> m_bucket_table
;
27042 std::vector
<uint32_t> m_hash_table
;
27044 const bfd_endian m_dwarf5_byte_order
;
27045 dwarf_tmpl
<uint32_t> m_dwarf32
;
27046 dwarf_tmpl
<uint64_t> m_dwarf64
;
27048 offset_vec
&m_name_table_string_offs
, &m_name_table_entry_offs
;
27049 debug_str_lookup m_debugstrlookup
;
27051 /* Map each used .debug_names abbreviation tag parameter to its
27053 std::unordered_map
<index_key
, int, index_key_hasher
> m_indexkey_to_idx
;
27055 /* Next unused .debug_names abbreviation tag for
27056 m_indexkey_to_idx. */
27057 int m_idx_next
= 1;
27059 /* .debug_names abbreviation table. */
27060 data_buf m_abbrev_table
;
27062 /* .debug_names entry pool. */
27063 data_buf m_entry_pool
;
27066 /* Return iff any of the needed offsets does not fit into 32-bit
27067 .debug_names section. */
27070 check_dwarf64_offsets (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27072 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27074 const dwarf2_per_cu_data
&per_cu
= *dwarf2_per_objfile
->all_comp_units
[i
];
27076 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27079 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
27081 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
27082 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
27084 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27090 /* The psyms_seen set is potentially going to be largish (~40k
27091 elements when indexing a -g3 build of GDB itself). Estimate the
27092 number of elements in order to avoid too many rehashes, which
27093 require rebuilding buckets and thus many trips to
27097 psyms_seen_size (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27099 size_t psyms_count
= 0;
27100 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27102 struct dwarf2_per_cu_data
*per_cu
27103 = dwarf2_per_objfile
->all_comp_units
[i
];
27104 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27106 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
27107 recursively_count_psymbols (psymtab
, psyms_count
);
27109 /* Generating an index for gdb itself shows a ratio of
27110 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
27111 return psyms_count
/ 4;
27114 /* Write new .gdb_index section for OBJFILE into OUT_FILE.
27115 Return how many bytes were expected to be written into OUT_FILE. */
27118 write_gdbindex (struct dwarf2_per_objfile
*dwarf2_per_objfile
, FILE *out_file
)
27120 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27121 mapped_symtab symtab
;
27124 /* While we're scanning CU's create a table that maps a psymtab pointer
27125 (which is what addrmap records) to its index (which is what is recorded
27126 in the index file). This will later be needed to write the address
27128 psym_index_map cu_index_htab
;
27129 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
27131 /* The CU list is already sorted, so we don't need to do additional
27132 work here. Also, the debug_types entries do not appear in
27133 all_comp_units, but only in their own hash table. */
27135 std::unordered_set
<partial_symbol
*> psyms_seen
27136 (psyms_seen_size (dwarf2_per_objfile
));
27137 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27139 struct dwarf2_per_cu_data
*per_cu
27140 = dwarf2_per_objfile
->all_comp_units
[i
];
27141 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27143 /* CU of a shared file from 'dwz -m' may be unused by this main file.
27144 It may be referenced from a local scope but in such case it does not
27145 need to be present in .gdb_index. */
27146 if (psymtab
== NULL
)
27149 if (psymtab
->user
== NULL
)
27150 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
27153 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
27154 gdb_assert (insertpair
.second
);
27156 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
27157 to_underlying (per_cu
->sect_off
));
27158 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
27161 /* Dump the address map. */
27163 write_address_map (objfile
, addr_vec
, cu_index_htab
);
27165 /* Write out the .debug_type entries, if any. */
27166 data_buf types_cu_list
;
27167 if (dwarf2_per_objfile
->signatured_types
)
27169 signatured_type_index_data
sig_data (types_cu_list
,
27172 sig_data
.objfile
= objfile
;
27173 sig_data
.symtab
= &symtab
;
27174 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
27175 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27176 write_one_signatured_type
, &sig_data
);
27179 /* Now that we've processed all symbols we can shrink their cu_indices
27181 uniquify_cu_indices (&symtab
);
27183 data_buf symtab_vec
, constant_pool
;
27184 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
27187 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
27188 offset_type total_len
= size_of_contents
;
27190 /* The version number. */
27191 contents
.append_data (MAYBE_SWAP (8));
27193 /* The offset of the CU list from the start of the file. */
27194 contents
.append_data (MAYBE_SWAP (total_len
));
27195 total_len
+= cu_list
.size ();
27197 /* The offset of the types CU list from the start of the file. */
27198 contents
.append_data (MAYBE_SWAP (total_len
));
27199 total_len
+= types_cu_list
.size ();
27201 /* The offset of the address table from the start of the file. */
27202 contents
.append_data (MAYBE_SWAP (total_len
));
27203 total_len
+= addr_vec
.size ();
27205 /* The offset of the symbol table from the start of the file. */
27206 contents
.append_data (MAYBE_SWAP (total_len
));
27207 total_len
+= symtab_vec
.size ();
27209 /* The offset of the constant pool from the start of the file. */
27210 contents
.append_data (MAYBE_SWAP (total_len
));
27211 total_len
+= constant_pool
.size ();
27213 gdb_assert (contents
.size () == size_of_contents
);
27215 contents
.file_write (out_file
);
27216 cu_list
.file_write (out_file
);
27217 types_cu_list
.file_write (out_file
);
27218 addr_vec
.file_write (out_file
);
27219 symtab_vec
.file_write (out_file
);
27220 constant_pool
.file_write (out_file
);
27225 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
27226 static const gdb_byte dwarf5_gdb_augmentation
[] = { 'G', 'D', 'B', 0 };
27228 /* Write a new .debug_names section for OBJFILE into OUT_FILE, write
27229 needed addition to .debug_str section to OUT_FILE_STR. Return how
27230 many bytes were expected to be written into OUT_FILE. */
27233 write_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27234 FILE *out_file
, FILE *out_file_str
)
27236 const bool dwarf5_is_dwarf64
= check_dwarf64_offsets (dwarf2_per_objfile
);
27237 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27238 const enum bfd_endian dwarf5_byte_order
27239 = gdbarch_byte_order (get_objfile_arch (objfile
));
27241 /* The CU list is already sorted, so we don't need to do additional
27242 work here. Also, the debug_types entries do not appear in
27243 all_comp_units, but only in their own hash table. */
27245 debug_names
nametable (dwarf2_per_objfile
, dwarf5_is_dwarf64
,
27246 dwarf5_byte_order
);
27247 std::unordered_set
<partial_symbol
*>
27248 psyms_seen (psyms_seen_size (dwarf2_per_objfile
));
27249 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27251 const dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
27252 partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27254 /* CU of a shared file from 'dwz -m' may be unused by this main
27255 file. It may be referenced from a local scope but in such
27256 case it does not need to be present in .debug_names. */
27257 if (psymtab
== NULL
)
27260 if (psymtab
->user
== NULL
)
27261 nametable
.recursively_write_psymbols (objfile
, psymtab
, psyms_seen
, i
);
27263 cu_list
.append_uint (nametable
.dwarf5_offset_size (), dwarf5_byte_order
,
27264 to_underlying (per_cu
->sect_off
));
27267 /* Write out the .debug_type entries, if any. */
27268 data_buf types_cu_list
;
27269 if (dwarf2_per_objfile
->signatured_types
)
27271 debug_names::write_one_signatured_type_data
sig_data (nametable
,
27272 signatured_type_index_data (types_cu_list
, psyms_seen
));
27274 sig_data
.info
.objfile
= objfile
;
27275 /* It is used only for gdb_index. */
27276 sig_data
.info
.symtab
= nullptr;
27277 sig_data
.info
.cu_index
= 0;
27278 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27279 debug_names::write_one_signatured_type
,
27283 nametable
.build ();
27285 /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
27287 const offset_type bytes_of_header
27288 = ((dwarf5_is_dwarf64
? 12 : 4)
27290 + sizeof (dwarf5_gdb_augmentation
));
27291 size_t expected_bytes
= 0;
27292 expected_bytes
+= bytes_of_header
;
27293 expected_bytes
+= cu_list
.size ();
27294 expected_bytes
+= types_cu_list
.size ();
27295 expected_bytes
+= nametable
.bytes ();
27298 if (!dwarf5_is_dwarf64
)
27300 const uint64_t size64
= expected_bytes
- 4;
27301 gdb_assert (size64
< 0xfffffff0);
27302 header
.append_uint (4, dwarf5_byte_order
, size64
);
27306 header
.append_uint (4, dwarf5_byte_order
, 0xffffffff);
27307 header
.append_uint (8, dwarf5_byte_order
, expected_bytes
- 12);
27310 /* The version number. */
27311 header
.append_uint (2, dwarf5_byte_order
, 5);
27314 header
.append_uint (2, dwarf5_byte_order
, 0);
27316 /* comp_unit_count - The number of CUs in the CU list. */
27317 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_comp_units
);
27319 /* local_type_unit_count - The number of TUs in the local TU
27321 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_type_units
);
27323 /* foreign_type_unit_count - The number of TUs in the foreign TU
27325 header
.append_uint (4, dwarf5_byte_order
, 0);
27327 /* bucket_count - The number of hash buckets in the hash lookup
27329 header
.append_uint (4, dwarf5_byte_order
, nametable
.bucket_count ());
27331 /* name_count - The number of unique names in the index. */
27332 header
.append_uint (4, dwarf5_byte_order
, nametable
.name_count ());
27334 /* abbrev_table_size - The size in bytes of the abbreviations
27336 header
.append_uint (4, dwarf5_byte_order
, nametable
.abbrev_table_bytes ());
27338 /* augmentation_string_size - The size in bytes of the augmentation
27339 string. This value is rounded up to a multiple of 4. */
27340 static_assert (sizeof (dwarf5_gdb_augmentation
) % 4 == 0, "");
27341 header
.append_uint (4, dwarf5_byte_order
, sizeof (dwarf5_gdb_augmentation
));
27342 header
.append_data (dwarf5_gdb_augmentation
);
27344 gdb_assert (header
.size () == bytes_of_header
);
27346 header
.file_write (out_file
);
27347 cu_list
.file_write (out_file
);
27348 types_cu_list
.file_write (out_file
);
27349 nametable
.file_write (out_file
, out_file_str
);
27351 return expected_bytes
;
27354 /* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
27355 position is at the end of the file. */
27358 assert_file_size (FILE *file
, const char *filename
, size_t expected_size
)
27360 const auto file_size
= ftell (file
);
27361 if (file_size
== -1)
27362 error (_("Can't get `%s' size"), filename
);
27363 gdb_assert (file_size
== expected_size
);
27366 /* Create an index file for OBJFILE in the directory DIR. */
27369 write_psymtabs_to_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27371 dw_index_kind index_kind
)
27373 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27375 if (dwarf2_per_objfile
->using_index
)
27376 error (_("Cannot use an index to create the index"));
27378 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
27379 error (_("Cannot make an index when the file has multiple .debug_types sections"));
27381 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
27385 if (stat (objfile_name (objfile
), &st
) < 0)
27386 perror_with_name (objfile_name (objfile
));
27388 std::string
filename (std::string (dir
) + SLASH_STRING
27389 + lbasename (objfile_name (objfile
))
27390 + (index_kind
== dw_index_kind::DEBUG_NAMES
27391 ? INDEX5_SUFFIX
: INDEX4_SUFFIX
));
27393 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
27395 error (_("Can't open `%s' for writing"), filename
.c_str ());
27397 /* Order matters here; we want FILE to be closed before FILENAME is
27398 unlinked, because on MS-Windows one cannot delete a file that is
27399 still open. (Don't call anything here that might throw until
27400 file_closer is created.) */
27401 gdb::unlinker
unlink_file (filename
.c_str ());
27402 gdb_file_up
close_out_file (out_file
);
27404 if (index_kind
== dw_index_kind::DEBUG_NAMES
)
27406 std::string
filename_str (std::string (dir
) + SLASH_STRING
27407 + lbasename (objfile_name (objfile
))
27408 + DEBUG_STR_SUFFIX
);
27410 = gdb_fopen_cloexec (filename_str
.c_str (), "wb").release ();
27412 error (_("Can't open `%s' for writing"), filename_str
.c_str ());
27413 gdb::unlinker
unlink_file_str (filename_str
.c_str ());
27414 gdb_file_up
close_out_file_str (out_file_str
);
27416 const size_t total_len
27417 = write_debug_names (dwarf2_per_objfile
, out_file
, out_file_str
);
27418 assert_file_size (out_file
, filename
.c_str (), total_len
);
27420 /* We want to keep the file .debug_str file too. */
27421 unlink_file_str
.keep ();
27425 const size_t total_len
27426 = write_gdbindex (dwarf2_per_objfile
, out_file
);
27427 assert_file_size (out_file
, filename
.c_str (), total_len
);
27430 /* We want to keep the file. */
27431 unlink_file
.keep ();
27434 /* Implementation of the `save gdb-index' command.
27436 Note that the .gdb_index file format used by this command is
27437 documented in the GDB manual. Any changes here must be documented
27441 save_gdb_index_command (const char *arg
, int from_tty
)
27443 struct objfile
*objfile
;
27444 const char dwarf5space
[] = "-dwarf-5 ";
27445 dw_index_kind index_kind
= dw_index_kind::GDB_INDEX
;
27450 arg
= skip_spaces (arg
);
27451 if (strncmp (arg
, dwarf5space
, strlen (dwarf5space
)) == 0)
27453 index_kind
= dw_index_kind::DEBUG_NAMES
;
27454 arg
+= strlen (dwarf5space
);
27455 arg
= skip_spaces (arg
);
27459 error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
27461 ALL_OBJFILES (objfile
)
27465 /* If the objfile does not correspond to an actual file, skip it. */
27466 if (stat (objfile_name (objfile
), &st
) < 0)
27469 struct dwarf2_per_objfile
*dwarf2_per_objfile
27470 = get_dwarf2_per_objfile (objfile
);
27472 if (dwarf2_per_objfile
!= NULL
)
27476 write_psymtabs_to_index (dwarf2_per_objfile
, arg
, index_kind
);
27478 CATCH (except
, RETURN_MASK_ERROR
)
27480 exception_fprintf (gdb_stderr
, except
,
27481 _("Error while writing index for `%s': "),
27482 objfile_name (objfile
));
27492 int dwarf_always_disassemble
;
27495 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
27496 struct cmd_list_element
*c
, const char *value
)
27498 fprintf_filtered (file
,
27499 _("Whether to always disassemble "
27500 "DWARF expressions is %s.\n"),
27505 show_check_physname (struct ui_file
*file
, int from_tty
,
27506 struct cmd_list_element
*c
, const char *value
)
27508 fprintf_filtered (file
,
27509 _("Whether to check \"physname\" is %s.\n"),
27514 _initialize_dwarf2_read (void)
27516 struct cmd_list_element
*c
;
27518 dwarf2_objfile_data_key
= register_objfile_data ();
27520 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
27521 Set DWARF specific variables.\n\
27522 Configure DWARF variables such as the cache size"),
27523 &set_dwarf_cmdlist
, "maintenance set dwarf ",
27524 0/*allow-unknown*/, &maintenance_set_cmdlist
);
27526 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
27527 Show DWARF specific variables\n\
27528 Show DWARF variables such as the cache size"),
27529 &show_dwarf_cmdlist
, "maintenance show dwarf ",
27530 0/*allow-unknown*/, &maintenance_show_cmdlist
);
27532 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
27533 &dwarf_max_cache_age
, _("\
27534 Set the upper bound on the age of cached DWARF compilation units."), _("\
27535 Show the upper bound on the age of cached DWARF compilation units."), _("\
27536 A higher limit means that cached compilation units will be stored\n\
27537 in memory longer, and more total memory will be used. Zero disables\n\
27538 caching, which can slow down startup."),
27540 show_dwarf_max_cache_age
,
27541 &set_dwarf_cmdlist
,
27542 &show_dwarf_cmdlist
);
27544 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
27545 &dwarf_always_disassemble
, _("\
27546 Set whether `info address' always disassembles DWARF expressions."), _("\
27547 Show whether `info address' always disassembles DWARF expressions."), _("\
27548 When enabled, DWARF expressions are always printed in an assembly-like\n\
27549 syntax. When disabled, expressions will be printed in a more\n\
27550 conversational style, when possible."),
27552 show_dwarf_always_disassemble
,
27553 &set_dwarf_cmdlist
,
27554 &show_dwarf_cmdlist
);
27556 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
27557 Set debugging of the DWARF reader."), _("\
27558 Show debugging of the DWARF reader."), _("\
27559 When enabled (non-zero), debugging messages are printed during DWARF\n\
27560 reading and symtab expansion. A value of 1 (one) provides basic\n\
27561 information. A value greater than 1 provides more verbose information."),
27564 &setdebuglist
, &showdebuglist
);
27566 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
27567 Set debugging of the DWARF DIE reader."), _("\
27568 Show debugging of the DWARF DIE reader."), _("\
27569 When enabled (non-zero), DIEs are dumped after they are read in.\n\
27570 The value is the maximum depth to print."),
27573 &setdebuglist
, &showdebuglist
);
27575 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
27576 Set debugging of the dwarf line reader."), _("\
27577 Show debugging of the dwarf line reader."), _("\
27578 When enabled (non-zero), line number entries are dumped as they are read in.\n\
27579 A value of 1 (one) provides basic information.\n\
27580 A value greater than 1 provides more verbose information."),
27583 &setdebuglist
, &showdebuglist
);
27585 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
27586 Set cross-checking of \"physname\" code against demangler."), _("\
27587 Show cross-checking of \"physname\" code against demangler."), _("\
27588 When enabled, GDB's internal \"physname\" code is checked against\n\
27590 NULL
, show_check_physname
,
27591 &setdebuglist
, &showdebuglist
);
27593 add_setshow_boolean_cmd ("use-deprecated-index-sections",
27594 no_class
, &use_deprecated_index_sections
, _("\
27595 Set whether to use deprecated gdb_index sections."), _("\
27596 Show whether to use deprecated gdb_index sections."), _("\
27597 When enabled, deprecated .gdb_index sections are used anyway.\n\
27598 Normally they are ignored either because of a missing feature or\n\
27599 performance issue.\n\
27600 Warning: This option must be enabled before gdb reads the file."),
27603 &setlist
, &showlist
);
27605 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
27607 Save a gdb-index file.\n\
27608 Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
27610 No options create one file with .gdb-index extension for pre-DWARF-5\n\
27611 compatible .gdb_index section. With -dwarf-5 creates two files with\n\
27612 extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
27614 set_cmd_completer (c
, filename_completer
);
27616 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27617 &dwarf2_locexpr_funcs
);
27618 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27619 &dwarf2_loclist_funcs
);
27621 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27622 &dwarf2_block_frame_base_locexpr_funcs
);
27623 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27624 &dwarf2_block_frame_base_loclist_funcs
);
27627 selftests::register_test ("dw2_expand_symtabs_matching",
27628 selftests::dw2_expand_symtabs_matching::run_test
);