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 (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11497 /* Do nothing (do not demangle the symbol name). */
11499 else if (cu
->language
== language_go
)
11501 /* This is a lie, but we already lie to the caller new_symbol.
11502 new_symbol assumes we return the mangled name.
11503 This just undoes that lie until things are cleaned up. */
11507 /* Use DMGL_RET_DROP for C++ template functions to suppress
11508 their return type. It is easier for GDB users to search
11509 for such functions as `name(params)' than `long name(params)'.
11510 In such case the minimal symbol names do not match the full
11511 symbol names but for template functions there is never a need
11512 to look up their definition from their declaration so
11513 the only disadvantage remains the minimal symbol variant
11514 `long name(params)' does not have the proper inferior type. */
11515 demangled
.reset (gdb_demangle (mangled
,
11516 (DMGL_PARAMS
| DMGL_ANSI
11517 | DMGL_RET_DROP
)));
11520 canon
= demangled
.get ();
11528 if (canon
== NULL
|| check_physname
)
11530 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11532 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11534 /* It may not mean a bug in GDB. The compiler could also
11535 compute DW_AT_linkage_name incorrectly. But in such case
11536 GDB would need to be bug-to-bug compatible. */
11538 complaint (&symfile_complaints
,
11539 _("Computed physname <%s> does not match demangled <%s> "
11540 "(from linkage <%s>) - DIE at %s [in module %s]"),
11541 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11542 objfile_name (objfile
));
11544 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11545 is available here - over computed PHYSNAME. It is safer
11546 against both buggy GDB and buggy compilers. */
11560 retval
= ((const char *)
11561 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11562 retval
, strlen (retval
)));
11567 /* Inspect DIE in CU for a namespace alias. If one exists, record
11568 a new symbol for it.
11570 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11573 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11575 struct attribute
*attr
;
11577 /* If the die does not have a name, this is not a namespace
11579 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11583 struct die_info
*d
= die
;
11584 struct dwarf2_cu
*imported_cu
= cu
;
11586 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11587 keep inspecting DIEs until we hit the underlying import. */
11588 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11589 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11591 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11595 d
= follow_die_ref (d
, attr
, &imported_cu
);
11596 if (d
->tag
!= DW_TAG_imported_declaration
)
11600 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11602 complaint (&symfile_complaints
,
11603 _("DIE at %s has too many recursively imported "
11604 "declarations"), sect_offset_str (d
->sect_off
));
11611 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11613 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11614 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11616 /* This declaration is a global namespace alias. Add
11617 a symbol for it whose type is the aliased namespace. */
11618 new_symbol (die
, type
, cu
);
11627 /* Return the using directives repository (global or local?) to use in the
11628 current context for LANGUAGE.
11630 For Ada, imported declarations can materialize renamings, which *may* be
11631 global. However it is impossible (for now?) in DWARF to distinguish
11632 "external" imported declarations and "static" ones. As all imported
11633 declarations seem to be static in all other languages, make them all CU-wide
11634 global only in Ada. */
11636 static struct using_direct
**
11637 using_directives (enum language language
)
11639 if (language
== language_ada
&& context_stack_depth
== 0)
11640 return &global_using_directives
;
11642 return &local_using_directives
;
11645 /* Read the import statement specified by the given die and record it. */
11648 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11650 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11651 struct attribute
*import_attr
;
11652 struct die_info
*imported_die
, *child_die
;
11653 struct dwarf2_cu
*imported_cu
;
11654 const char *imported_name
;
11655 const char *imported_name_prefix
;
11656 const char *canonical_name
;
11657 const char *import_alias
;
11658 const char *imported_declaration
= NULL
;
11659 const char *import_prefix
;
11660 std::vector
<const char *> excludes
;
11662 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11663 if (import_attr
== NULL
)
11665 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11666 dwarf_tag_name (die
->tag
));
11671 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11672 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11673 if (imported_name
== NULL
)
11675 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11677 The import in the following code:
11691 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11692 <52> DW_AT_decl_file : 1
11693 <53> DW_AT_decl_line : 6
11694 <54> DW_AT_import : <0x75>
11695 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11696 <59> DW_AT_name : B
11697 <5b> DW_AT_decl_file : 1
11698 <5c> DW_AT_decl_line : 2
11699 <5d> DW_AT_type : <0x6e>
11701 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11702 <76> DW_AT_byte_size : 4
11703 <77> DW_AT_encoding : 5 (signed)
11705 imports the wrong die ( 0x75 instead of 0x58 ).
11706 This case will be ignored until the gcc bug is fixed. */
11710 /* Figure out the local name after import. */
11711 import_alias
= dwarf2_name (die
, cu
);
11713 /* Figure out where the statement is being imported to. */
11714 import_prefix
= determine_prefix (die
, cu
);
11716 /* Figure out what the scope of the imported die is and prepend it
11717 to the name of the imported die. */
11718 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11720 if (imported_die
->tag
!= DW_TAG_namespace
11721 && imported_die
->tag
!= DW_TAG_module
)
11723 imported_declaration
= imported_name
;
11724 canonical_name
= imported_name_prefix
;
11726 else if (strlen (imported_name_prefix
) > 0)
11727 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11728 imported_name_prefix
,
11729 (cu
->language
== language_d
? "." : "::"),
11730 imported_name
, (char *) NULL
);
11732 canonical_name
= imported_name
;
11734 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11735 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11736 child_die
= sibling_die (child_die
))
11738 /* DWARF-4: A Fortran use statement with a “rename list” may be
11739 represented by an imported module entry with an import attribute
11740 referring to the module and owned entries corresponding to those
11741 entities that are renamed as part of being imported. */
11743 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11745 complaint (&symfile_complaints
,
11746 _("child DW_TAG_imported_declaration expected "
11747 "- DIE at %s [in module %s]"),
11748 sect_offset_str (child_die
->sect_off
),
11749 objfile_name (objfile
));
11753 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11754 if (import_attr
== NULL
)
11756 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11757 dwarf_tag_name (child_die
->tag
));
11762 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11764 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11765 if (imported_name
== NULL
)
11767 complaint (&symfile_complaints
,
11768 _("child DW_TAG_imported_declaration has unknown "
11769 "imported name - DIE at %s [in module %s]"),
11770 sect_offset_str (child_die
->sect_off
),
11771 objfile_name (objfile
));
11775 excludes
.push_back (imported_name
);
11777 process_die (child_die
, cu
);
11780 add_using_directive (using_directives (cu
->language
),
11784 imported_declaration
,
11787 &objfile
->objfile_obstack
);
11790 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11791 types, but gives them a size of zero. Starting with version 14,
11792 ICC is compatible with GCC. */
11795 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11797 if (!cu
->checked_producer
)
11798 check_producer (cu
);
11800 return cu
->producer_is_icc_lt_14
;
11803 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11804 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11805 this, it was first present in GCC release 4.3.0. */
11808 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11810 if (!cu
->checked_producer
)
11811 check_producer (cu
);
11813 return cu
->producer_is_gcc_lt_4_3
;
11816 static file_and_directory
11817 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11819 file_and_directory res
;
11821 /* Find the filename. Do not use dwarf2_name here, since the filename
11822 is not a source language identifier. */
11823 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11824 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11826 if (res
.comp_dir
== NULL
11827 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11828 && IS_ABSOLUTE_PATH (res
.name
))
11830 res
.comp_dir_storage
= ldirname (res
.name
);
11831 if (!res
.comp_dir_storage
.empty ())
11832 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11834 if (res
.comp_dir
!= NULL
)
11836 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11837 directory, get rid of it. */
11838 const char *cp
= strchr (res
.comp_dir
, ':');
11840 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11841 res
.comp_dir
= cp
+ 1;
11844 if (res
.name
== NULL
)
11845 res
.name
= "<unknown>";
11850 /* Handle DW_AT_stmt_list for a compilation unit.
11851 DIE is the DW_TAG_compile_unit die for CU.
11852 COMP_DIR is the compilation directory. LOWPC is passed to
11853 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11856 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11857 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11859 struct dwarf2_per_objfile
*dwarf2_per_objfile
11860 = cu
->per_cu
->dwarf2_per_objfile
;
11861 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11862 struct attribute
*attr
;
11863 struct line_header line_header_local
;
11864 hashval_t line_header_local_hash
;
11866 int decode_mapping
;
11868 gdb_assert (! cu
->per_cu
->is_debug_types
);
11870 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11874 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11876 /* The line header hash table is only created if needed (it exists to
11877 prevent redundant reading of the line table for partial_units).
11878 If we're given a partial_unit, we'll need it. If we're given a
11879 compile_unit, then use the line header hash table if it's already
11880 created, but don't create one just yet. */
11882 if (dwarf2_per_objfile
->line_header_hash
== NULL
11883 && die
->tag
== DW_TAG_partial_unit
)
11885 dwarf2_per_objfile
->line_header_hash
11886 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11887 line_header_eq_voidp
,
11888 free_line_header_voidp
,
11889 &objfile
->objfile_obstack
,
11890 hashtab_obstack_allocate
,
11891 dummy_obstack_deallocate
);
11894 line_header_local
.sect_off
= line_offset
;
11895 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11896 line_header_local_hash
= line_header_hash (&line_header_local
);
11897 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11899 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11900 &line_header_local
,
11901 line_header_local_hash
, NO_INSERT
);
11903 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11904 is not present in *SLOT (since if there is something in *SLOT then
11905 it will be for a partial_unit). */
11906 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11908 gdb_assert (*slot
!= NULL
);
11909 cu
->line_header
= (struct line_header
*) *slot
;
11914 /* dwarf_decode_line_header does not yet provide sufficient information.
11915 We always have to call also dwarf_decode_lines for it. */
11916 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11920 cu
->line_header
= lh
.release ();
11921 cu
->line_header_die_owner
= die
;
11923 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11927 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11928 &line_header_local
,
11929 line_header_local_hash
, INSERT
);
11930 gdb_assert (slot
!= NULL
);
11932 if (slot
!= NULL
&& *slot
== NULL
)
11934 /* This newly decoded line number information unit will be owned
11935 by line_header_hash hash table. */
11936 *slot
= cu
->line_header
;
11937 cu
->line_header_die_owner
= NULL
;
11941 /* We cannot free any current entry in (*slot) as that struct line_header
11942 may be already used by multiple CUs. Create only temporary decoded
11943 line_header for this CU - it may happen at most once for each line
11944 number information unit. And if we're not using line_header_hash
11945 then this is what we want as well. */
11946 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11948 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11949 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11954 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11957 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11959 struct dwarf2_per_objfile
*dwarf2_per_objfile
11960 = cu
->per_cu
->dwarf2_per_objfile
;
11961 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11962 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11963 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11964 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11965 struct attribute
*attr
;
11966 struct die_info
*child_die
;
11967 CORE_ADDR baseaddr
;
11969 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11971 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11973 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11974 from finish_block. */
11975 if (lowpc
== ((CORE_ADDR
) -1))
11977 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11979 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11981 prepare_one_comp_unit (cu
, die
, cu
->language
);
11983 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11984 standardised yet. As a workaround for the language detection we fall
11985 back to the DW_AT_producer string. */
11986 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11987 cu
->language
= language_opencl
;
11989 /* Similar hack for Go. */
11990 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11991 set_cu_language (DW_LANG_Go
, cu
);
11993 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11995 /* Decode line number information if present. We do this before
11996 processing child DIEs, so that the line header table is available
11997 for DW_AT_decl_file. */
11998 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
12000 /* Process all dies in compilation unit. */
12001 if (die
->child
!= NULL
)
12003 child_die
= die
->child
;
12004 while (child_die
&& child_die
->tag
)
12006 process_die (child_die
, cu
);
12007 child_die
= sibling_die (child_die
);
12011 /* Decode macro information, if present. Dwarf 2 macro information
12012 refers to information in the line number info statement program
12013 header, so we can only read it if we've read the header
12015 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
12017 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
12018 if (attr
&& cu
->line_header
)
12020 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
12021 complaint (&symfile_complaints
,
12022 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
12024 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
12028 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
12029 if (attr
&& cu
->line_header
)
12031 unsigned int macro_offset
= DW_UNSND (attr
);
12033 dwarf_decode_macros (cu
, macro_offset
, 0);
12038 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
12039 Create the set of symtabs used by this TU, or if this TU is sharing
12040 symtabs with another TU and the symtabs have already been created
12041 then restore those symtabs in the line header.
12042 We don't need the pc/line-number mapping for type units. */
12045 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
12047 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
12048 struct type_unit_group
*tu_group
;
12050 struct attribute
*attr
;
12052 struct signatured_type
*sig_type
;
12054 gdb_assert (per_cu
->is_debug_types
);
12055 sig_type
= (struct signatured_type
*) per_cu
;
12057 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
12059 /* If we're using .gdb_index (includes -readnow) then
12060 per_cu->type_unit_group may not have been set up yet. */
12061 if (sig_type
->type_unit_group
== NULL
)
12062 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
12063 tu_group
= sig_type
->type_unit_group
;
12065 /* If we've already processed this stmt_list there's no real need to
12066 do it again, we could fake it and just recreate the part we need
12067 (file name,index -> symtab mapping). If data shows this optimization
12068 is useful we can do it then. */
12069 first_time
= tu_group
->compunit_symtab
== NULL
;
12071 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
12076 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
12077 lh
= dwarf_decode_line_header (line_offset
, cu
);
12082 dwarf2_start_symtab (cu
, "", NULL
, 0);
12085 gdb_assert (tu_group
->symtabs
== NULL
);
12086 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12091 cu
->line_header
= lh
.release ();
12092 cu
->line_header_die_owner
= die
;
12096 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
12098 /* Note: We don't assign tu_group->compunit_symtab yet because we're
12099 still initializing it, and our caller (a few levels up)
12100 process_full_type_unit still needs to know if this is the first
12103 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
12104 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
12105 cu
->line_header
->file_names
.size ());
12107 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12109 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12111 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
12113 if (current_subfile
->symtab
== NULL
)
12115 /* NOTE: start_subfile will recognize when it's been
12116 passed a file it has already seen. So we can't
12117 assume there's a simple mapping from
12118 cu->line_header->file_names to subfiles, plus
12119 cu->line_header->file_names may contain dups. */
12120 current_subfile
->symtab
12121 = allocate_symtab (cust
, current_subfile
->name
);
12124 fe
.symtab
= current_subfile
->symtab
;
12125 tu_group
->symtabs
[i
] = fe
.symtab
;
12130 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12132 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12134 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12136 fe
.symtab
= tu_group
->symtabs
[i
];
12140 /* The main symtab is allocated last. Type units don't have DW_AT_name
12141 so they don't have a "real" (so to speak) symtab anyway.
12142 There is later code that will assign the main symtab to all symbols
12143 that don't have one. We need to handle the case of a symbol with a
12144 missing symtab (DW_AT_decl_file) anyway. */
12147 /* Process DW_TAG_type_unit.
12148 For TUs we want to skip the first top level sibling if it's not the
12149 actual type being defined by this TU. In this case the first top
12150 level sibling is there to provide context only. */
12153 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12155 struct die_info
*child_die
;
12157 prepare_one_comp_unit (cu
, die
, language_minimal
);
12159 /* Initialize (or reinitialize) the machinery for building symtabs.
12160 We do this before processing child DIEs, so that the line header table
12161 is available for DW_AT_decl_file. */
12162 setup_type_unit_groups (die
, cu
);
12164 if (die
->child
!= NULL
)
12166 child_die
= die
->child
;
12167 while (child_die
&& child_die
->tag
)
12169 process_die (child_die
, cu
);
12170 child_die
= sibling_die (child_die
);
12177 http://gcc.gnu.org/wiki/DebugFission
12178 http://gcc.gnu.org/wiki/DebugFissionDWP
12180 To simplify handling of both DWO files ("object" files with the DWARF info)
12181 and DWP files (a file with the DWOs packaged up into one file), we treat
12182 DWP files as having a collection of virtual DWO files. */
12185 hash_dwo_file (const void *item
)
12187 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
12190 hash
= htab_hash_string (dwo_file
->dwo_name
);
12191 if (dwo_file
->comp_dir
!= NULL
)
12192 hash
+= htab_hash_string (dwo_file
->comp_dir
);
12197 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
12199 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
12200 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
12202 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
12204 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
12205 return lhs
->comp_dir
== rhs
->comp_dir
;
12206 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
12209 /* Allocate a hash table for DWO files. */
12212 allocate_dwo_file_hash_table (struct objfile
*objfile
)
12214 return htab_create_alloc_ex (41,
12218 &objfile
->objfile_obstack
,
12219 hashtab_obstack_allocate
,
12220 dummy_obstack_deallocate
);
12223 /* Lookup DWO file DWO_NAME. */
12226 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12227 const char *dwo_name
,
12228 const char *comp_dir
)
12230 struct dwo_file find_entry
;
12233 if (dwarf2_per_objfile
->dwo_files
== NULL
)
12234 dwarf2_per_objfile
->dwo_files
12235 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
12237 memset (&find_entry
, 0, sizeof (find_entry
));
12238 find_entry
.dwo_name
= dwo_name
;
12239 find_entry
.comp_dir
= comp_dir
;
12240 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
12246 hash_dwo_unit (const void *item
)
12248 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12250 /* This drops the top 32 bits of the id, but is ok for a hash. */
12251 return dwo_unit
->signature
;
12255 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
12257 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
12258 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
12260 /* The signature is assumed to be unique within the DWO file.
12261 So while object file CU dwo_id's always have the value zero,
12262 that's OK, assuming each object file DWO file has only one CU,
12263 and that's the rule for now. */
12264 return lhs
->signature
== rhs
->signature
;
12267 /* Allocate a hash table for DWO CUs,TUs.
12268 There is one of these tables for each of CUs,TUs for each DWO file. */
12271 allocate_dwo_unit_table (struct objfile
*objfile
)
12273 /* Start out with a pretty small number.
12274 Generally DWO files contain only one CU and maybe some TUs. */
12275 return htab_create_alloc_ex (3,
12279 &objfile
->objfile_obstack
,
12280 hashtab_obstack_allocate
,
12281 dummy_obstack_deallocate
);
12284 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
12286 struct create_dwo_cu_data
12288 struct dwo_file
*dwo_file
;
12289 struct dwo_unit dwo_unit
;
12292 /* die_reader_func for create_dwo_cu. */
12295 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
12296 const gdb_byte
*info_ptr
,
12297 struct die_info
*comp_unit_die
,
12301 struct dwarf2_cu
*cu
= reader
->cu
;
12302 sect_offset sect_off
= cu
->per_cu
->sect_off
;
12303 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
12304 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
12305 struct dwo_file
*dwo_file
= data
->dwo_file
;
12306 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
12307 struct attribute
*attr
;
12309 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
12312 complaint (&symfile_complaints
,
12313 _("Dwarf Error: debug entry at offset %s is missing"
12314 " its dwo_id [in module %s]"),
12315 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
12319 dwo_unit
->dwo_file
= dwo_file
;
12320 dwo_unit
->signature
= DW_UNSND (attr
);
12321 dwo_unit
->section
= section
;
12322 dwo_unit
->sect_off
= sect_off
;
12323 dwo_unit
->length
= cu
->per_cu
->length
;
12325 if (dwarf_read_debug
)
12326 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
12327 sect_offset_str (sect_off
),
12328 hex_string (dwo_unit
->signature
));
12331 /* Create the dwo_units for the CUs in a DWO_FILE.
12332 Note: This function processes DWO files only, not DWP files. */
12335 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12336 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
12339 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12340 const gdb_byte
*info_ptr
, *end_ptr
;
12342 dwarf2_read_section (objfile
, §ion
);
12343 info_ptr
= section
.buffer
;
12345 if (info_ptr
== NULL
)
12348 if (dwarf_read_debug
)
12350 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12351 get_section_name (§ion
),
12352 get_section_file_name (§ion
));
12355 end_ptr
= info_ptr
+ section
.size
;
12356 while (info_ptr
< end_ptr
)
12358 struct dwarf2_per_cu_data per_cu
;
12359 struct create_dwo_cu_data create_dwo_cu_data
;
12360 struct dwo_unit
*dwo_unit
;
12362 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12364 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12365 sizeof (create_dwo_cu_data
.dwo_unit
));
12366 memset (&per_cu
, 0, sizeof (per_cu
));
12367 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12368 per_cu
.is_debug_types
= 0;
12369 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12370 per_cu
.section
= §ion
;
12371 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12373 init_cutu_and_read_dies_no_follow (
12374 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12375 info_ptr
+= per_cu
.length
;
12377 // If the unit could not be parsed, skip it.
12378 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12381 if (cus_htab
== NULL
)
12382 cus_htab
= allocate_dwo_unit_table (objfile
);
12384 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12385 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12386 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12387 gdb_assert (slot
!= NULL
);
12390 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12391 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12393 complaint (&symfile_complaints
,
12394 _("debug cu entry at offset %s is duplicate to"
12395 " the entry at offset %s, signature %s"),
12396 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12397 hex_string (dwo_unit
->signature
));
12399 *slot
= (void *)dwo_unit
;
12403 /* DWP file .debug_{cu,tu}_index section format:
12404 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12408 Both index sections have the same format, and serve to map a 64-bit
12409 signature to a set of section numbers. Each section begins with a header,
12410 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12411 indexes, and a pool of 32-bit section numbers. The index sections will be
12412 aligned at 8-byte boundaries in the file.
12414 The index section header consists of:
12416 V, 32 bit version number
12418 N, 32 bit number of compilation units or type units in the index
12419 M, 32 bit number of slots in the hash table
12421 Numbers are recorded using the byte order of the application binary.
12423 The hash table begins at offset 16 in the section, and consists of an array
12424 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12425 order of the application binary). Unused slots in the hash table are 0.
12426 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12428 The parallel table begins immediately after the hash table
12429 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12430 array of 32-bit indexes (using the byte order of the application binary),
12431 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12432 table contains a 32-bit index into the pool of section numbers. For unused
12433 hash table slots, the corresponding entry in the parallel table will be 0.
12435 The pool of section numbers begins immediately following the hash table
12436 (at offset 16 + 12 * M from the beginning of the section). The pool of
12437 section numbers consists of an array of 32-bit words (using the byte order
12438 of the application binary). Each item in the array is indexed starting
12439 from 0. The hash table entry provides the index of the first section
12440 number in the set. Additional section numbers in the set follow, and the
12441 set is terminated by a 0 entry (section number 0 is not used in ELF).
12443 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12444 section must be the first entry in the set, and the .debug_abbrev.dwo must
12445 be the second entry. Other members of the set may follow in any order.
12451 DWP Version 2 combines all the .debug_info, etc. sections into one,
12452 and the entries in the index tables are now offsets into these sections.
12453 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12456 Index Section Contents:
12458 Hash Table of Signatures dwp_hash_table.hash_table
12459 Parallel Table of Indices dwp_hash_table.unit_table
12460 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12461 Table of Section Sizes dwp_hash_table.v2.sizes
12463 The index section header consists of:
12465 V, 32 bit version number
12466 L, 32 bit number of columns in the table of section offsets
12467 N, 32 bit number of compilation units or type units in the index
12468 M, 32 bit number of slots in the hash table
12470 Numbers are recorded using the byte order of the application binary.
12472 The hash table has the same format as version 1.
12473 The parallel table of indices has the same format as version 1,
12474 except that the entries are origin-1 indices into the table of sections
12475 offsets and the table of section sizes.
12477 The table of offsets begins immediately following the parallel table
12478 (at offset 16 + 12 * M from the beginning of the section). The table is
12479 a two-dimensional array of 32-bit words (using the byte order of the
12480 application binary), with L columns and N+1 rows, in row-major order.
12481 Each row in the array is indexed starting from 0. The first row provides
12482 a key to the remaining rows: each column in this row provides an identifier
12483 for a debug section, and the offsets in the same column of subsequent rows
12484 refer to that section. The section identifiers are:
12486 DW_SECT_INFO 1 .debug_info.dwo
12487 DW_SECT_TYPES 2 .debug_types.dwo
12488 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12489 DW_SECT_LINE 4 .debug_line.dwo
12490 DW_SECT_LOC 5 .debug_loc.dwo
12491 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12492 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12493 DW_SECT_MACRO 8 .debug_macro.dwo
12495 The offsets provided by the CU and TU index sections are the base offsets
12496 for the contributions made by each CU or TU to the corresponding section
12497 in the package file. Each CU and TU header contains an abbrev_offset
12498 field, used to find the abbreviations table for that CU or TU within the
12499 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12500 be interpreted as relative to the base offset given in the index section.
12501 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12502 should be interpreted as relative to the base offset for .debug_line.dwo,
12503 and offsets into other debug sections obtained from DWARF attributes should
12504 also be interpreted as relative to the corresponding base offset.
12506 The table of sizes begins immediately following the table of offsets.
12507 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12508 with L columns and N rows, in row-major order. Each row in the array is
12509 indexed starting from 1 (row 0 is shared by the two tables).
12513 Hash table lookup is handled the same in version 1 and 2:
12515 We assume that N and M will not exceed 2^32 - 1.
12516 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12518 Given a 64-bit compilation unit signature or a type signature S, an entry
12519 in the hash table is located as follows:
12521 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12522 the low-order k bits all set to 1.
12524 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12526 3) If the hash table entry at index H matches the signature, use that
12527 entry. If the hash table entry at index H is unused (all zeroes),
12528 terminate the search: the signature is not present in the table.
12530 4) Let H = (H + H') modulo M. Repeat at Step 3.
12532 Because M > N and H' and M are relatively prime, the search is guaranteed
12533 to stop at an unused slot or find the match. */
12535 /* Create a hash table to map DWO IDs to their CU/TU entry in
12536 .debug_{info,types}.dwo in DWP_FILE.
12537 Returns NULL if there isn't one.
12538 Note: This function processes DWP files only, not DWO files. */
12540 static struct dwp_hash_table
*
12541 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12542 struct dwp_file
*dwp_file
, int is_debug_types
)
12544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12545 bfd
*dbfd
= dwp_file
->dbfd
;
12546 const gdb_byte
*index_ptr
, *index_end
;
12547 struct dwarf2_section_info
*index
;
12548 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12549 struct dwp_hash_table
*htab
;
12551 if (is_debug_types
)
12552 index
= &dwp_file
->sections
.tu_index
;
12554 index
= &dwp_file
->sections
.cu_index
;
12556 if (dwarf2_section_empty_p (index
))
12558 dwarf2_read_section (objfile
, index
);
12560 index_ptr
= index
->buffer
;
12561 index_end
= index_ptr
+ index
->size
;
12563 version
= read_4_bytes (dbfd
, index_ptr
);
12566 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12570 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12572 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12575 if (version
!= 1 && version
!= 2)
12577 error (_("Dwarf Error: unsupported DWP file version (%s)"
12578 " [in module %s]"),
12579 pulongest (version
), dwp_file
->name
);
12581 if (nr_slots
!= (nr_slots
& -nr_slots
))
12583 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12584 " is not power of 2 [in module %s]"),
12585 pulongest (nr_slots
), dwp_file
->name
);
12588 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12589 htab
->version
= version
;
12590 htab
->nr_columns
= nr_columns
;
12591 htab
->nr_units
= nr_units
;
12592 htab
->nr_slots
= nr_slots
;
12593 htab
->hash_table
= index_ptr
;
12594 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12596 /* Exit early if the table is empty. */
12597 if (nr_slots
== 0 || nr_units
== 0
12598 || (version
== 2 && nr_columns
== 0))
12600 /* All must be zero. */
12601 if (nr_slots
!= 0 || nr_units
!= 0
12602 || (version
== 2 && nr_columns
!= 0))
12604 complaint (&symfile_complaints
,
12605 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12606 " all zero [in modules %s]"),
12614 htab
->section_pool
.v1
.indices
=
12615 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12616 /* It's harder to decide whether the section is too small in v1.
12617 V1 is deprecated anyway so we punt. */
12621 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12622 int *ids
= htab
->section_pool
.v2
.section_ids
;
12623 /* Reverse map for error checking. */
12624 int ids_seen
[DW_SECT_MAX
+ 1];
12627 if (nr_columns
< 2)
12629 error (_("Dwarf Error: bad DWP hash table, too few columns"
12630 " in section table [in module %s]"),
12633 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12635 error (_("Dwarf Error: bad DWP hash table, too many columns"
12636 " in section table [in module %s]"),
12639 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12640 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12641 for (i
= 0; i
< nr_columns
; ++i
)
12643 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12645 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12647 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12648 " in section table [in module %s]"),
12649 id
, dwp_file
->name
);
12651 if (ids_seen
[id
] != -1)
12653 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12654 " id %d in section table [in module %s]"),
12655 id
, dwp_file
->name
);
12660 /* Must have exactly one info or types section. */
12661 if (((ids_seen
[DW_SECT_INFO
] != -1)
12662 + (ids_seen
[DW_SECT_TYPES
] != -1))
12665 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12666 " DWO info/types section [in module %s]"),
12669 /* Must have an abbrev section. */
12670 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12672 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12673 " section [in module %s]"),
12676 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12677 htab
->section_pool
.v2
.sizes
=
12678 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12679 * nr_units
* nr_columns
);
12680 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12681 * nr_units
* nr_columns
))
12684 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12685 " [in module %s]"),
12693 /* Update SECTIONS with the data from SECTP.
12695 This function is like the other "locate" section routines that are
12696 passed to bfd_map_over_sections, but in this context the sections to
12697 read comes from the DWP V1 hash table, not the full ELF section table.
12699 The result is non-zero for success, or zero if an error was found. */
12702 locate_v1_virtual_dwo_sections (asection
*sectp
,
12703 struct virtual_v1_dwo_sections
*sections
)
12705 const struct dwop_section_names
*names
= &dwop_section_names
;
12707 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12709 /* There can be only one. */
12710 if (sections
->abbrev
.s
.section
!= NULL
)
12712 sections
->abbrev
.s
.section
= sectp
;
12713 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12715 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12716 || section_is_p (sectp
->name
, &names
->types_dwo
))
12718 /* There can be only one. */
12719 if (sections
->info_or_types
.s
.section
!= NULL
)
12721 sections
->info_or_types
.s
.section
= sectp
;
12722 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12724 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12726 /* There can be only one. */
12727 if (sections
->line
.s
.section
!= NULL
)
12729 sections
->line
.s
.section
= sectp
;
12730 sections
->line
.size
= bfd_get_section_size (sectp
);
12732 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12734 /* There can be only one. */
12735 if (sections
->loc
.s
.section
!= NULL
)
12737 sections
->loc
.s
.section
= sectp
;
12738 sections
->loc
.size
= bfd_get_section_size (sectp
);
12740 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12742 /* There can be only one. */
12743 if (sections
->macinfo
.s
.section
!= NULL
)
12745 sections
->macinfo
.s
.section
= sectp
;
12746 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12748 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12750 /* There can be only one. */
12751 if (sections
->macro
.s
.section
!= NULL
)
12753 sections
->macro
.s
.section
= sectp
;
12754 sections
->macro
.size
= bfd_get_section_size (sectp
);
12756 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12758 /* There can be only one. */
12759 if (sections
->str_offsets
.s
.section
!= NULL
)
12761 sections
->str_offsets
.s
.section
= sectp
;
12762 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12766 /* No other kind of section is valid. */
12773 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12774 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12775 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12776 This is for DWP version 1 files. */
12778 static struct dwo_unit
*
12779 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12780 struct dwp_file
*dwp_file
,
12781 uint32_t unit_index
,
12782 const char *comp_dir
,
12783 ULONGEST signature
, int is_debug_types
)
12785 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12786 const struct dwp_hash_table
*dwp_htab
=
12787 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12788 bfd
*dbfd
= dwp_file
->dbfd
;
12789 const char *kind
= is_debug_types
? "TU" : "CU";
12790 struct dwo_file
*dwo_file
;
12791 struct dwo_unit
*dwo_unit
;
12792 struct virtual_v1_dwo_sections sections
;
12793 void **dwo_file_slot
;
12796 gdb_assert (dwp_file
->version
== 1);
12798 if (dwarf_read_debug
)
12800 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12802 pulongest (unit_index
), hex_string (signature
),
12806 /* Fetch the sections of this DWO unit.
12807 Put a limit on the number of sections we look for so that bad data
12808 doesn't cause us to loop forever. */
12810 #define MAX_NR_V1_DWO_SECTIONS \
12811 (1 /* .debug_info or .debug_types */ \
12812 + 1 /* .debug_abbrev */ \
12813 + 1 /* .debug_line */ \
12814 + 1 /* .debug_loc */ \
12815 + 1 /* .debug_str_offsets */ \
12816 + 1 /* .debug_macro or .debug_macinfo */ \
12817 + 1 /* trailing zero */)
12819 memset (§ions
, 0, sizeof (sections
));
12821 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12824 uint32_t section_nr
=
12825 read_4_bytes (dbfd
,
12826 dwp_htab
->section_pool
.v1
.indices
12827 + (unit_index
+ i
) * sizeof (uint32_t));
12829 if (section_nr
== 0)
12831 if (section_nr
>= dwp_file
->num_sections
)
12833 error (_("Dwarf Error: bad DWP hash table, section number too large"
12834 " [in module %s]"),
12838 sectp
= dwp_file
->elf_sections
[section_nr
];
12839 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12841 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12842 " [in module %s]"),
12848 || dwarf2_section_empty_p (§ions
.info_or_types
)
12849 || dwarf2_section_empty_p (§ions
.abbrev
))
12851 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12852 " [in module %s]"),
12855 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12857 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12858 " [in module %s]"),
12862 /* It's easier for the rest of the code if we fake a struct dwo_file and
12863 have dwo_unit "live" in that. At least for now.
12865 The DWP file can be made up of a random collection of CUs and TUs.
12866 However, for each CU + set of TUs that came from the same original DWO
12867 file, we can combine them back into a virtual DWO file to save space
12868 (fewer struct dwo_file objects to allocate). Remember that for really
12869 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12871 std::string virtual_dwo_name
=
12872 string_printf ("virtual-dwo/%d-%d-%d-%d",
12873 get_section_id (§ions
.abbrev
),
12874 get_section_id (§ions
.line
),
12875 get_section_id (§ions
.loc
),
12876 get_section_id (§ions
.str_offsets
));
12877 /* Can we use an existing virtual DWO file? */
12878 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12879 virtual_dwo_name
.c_str (),
12881 /* Create one if necessary. */
12882 if (*dwo_file_slot
== NULL
)
12884 if (dwarf_read_debug
)
12886 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12887 virtual_dwo_name
.c_str ());
12889 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12891 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12892 virtual_dwo_name
.c_str (),
12893 virtual_dwo_name
.size ());
12894 dwo_file
->comp_dir
= comp_dir
;
12895 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12896 dwo_file
->sections
.line
= sections
.line
;
12897 dwo_file
->sections
.loc
= sections
.loc
;
12898 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12899 dwo_file
->sections
.macro
= sections
.macro
;
12900 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12901 /* The "str" section is global to the entire DWP file. */
12902 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12903 /* The info or types section is assigned below to dwo_unit,
12904 there's no need to record it in dwo_file.
12905 Also, we can't simply record type sections in dwo_file because
12906 we record a pointer into the vector in dwo_unit. As we collect more
12907 types we'll grow the vector and eventually have to reallocate space
12908 for it, invalidating all copies of pointers into the previous
12910 *dwo_file_slot
= dwo_file
;
12914 if (dwarf_read_debug
)
12916 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12917 virtual_dwo_name
.c_str ());
12919 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12922 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12923 dwo_unit
->dwo_file
= dwo_file
;
12924 dwo_unit
->signature
= signature
;
12925 dwo_unit
->section
=
12926 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12927 *dwo_unit
->section
= sections
.info_or_types
;
12928 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12933 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12934 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12935 piece within that section used by a TU/CU, return a virtual section
12936 of just that piece. */
12938 static struct dwarf2_section_info
12939 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12940 struct dwarf2_section_info
*section
,
12941 bfd_size_type offset
, bfd_size_type size
)
12943 struct dwarf2_section_info result
;
12946 gdb_assert (section
!= NULL
);
12947 gdb_assert (!section
->is_virtual
);
12949 memset (&result
, 0, sizeof (result
));
12950 result
.s
.containing_section
= section
;
12951 result
.is_virtual
= 1;
12956 sectp
= get_section_bfd_section (section
);
12958 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12959 bounds of the real section. This is a pretty-rare event, so just
12960 flag an error (easier) instead of a warning and trying to cope. */
12962 || offset
+ size
> bfd_get_section_size (sectp
))
12964 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12965 " in section %s [in module %s]"),
12966 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12967 objfile_name (dwarf2_per_objfile
->objfile
));
12970 result
.virtual_offset
= offset
;
12971 result
.size
= size
;
12975 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12976 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12977 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12978 This is for DWP version 2 files. */
12980 static struct dwo_unit
*
12981 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12982 struct dwp_file
*dwp_file
,
12983 uint32_t unit_index
,
12984 const char *comp_dir
,
12985 ULONGEST signature
, int is_debug_types
)
12987 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12988 const struct dwp_hash_table
*dwp_htab
=
12989 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12990 bfd
*dbfd
= dwp_file
->dbfd
;
12991 const char *kind
= is_debug_types
? "TU" : "CU";
12992 struct dwo_file
*dwo_file
;
12993 struct dwo_unit
*dwo_unit
;
12994 struct virtual_v2_dwo_sections sections
;
12995 void **dwo_file_slot
;
12998 gdb_assert (dwp_file
->version
== 2);
13000 if (dwarf_read_debug
)
13002 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
13004 pulongest (unit_index
), hex_string (signature
),
13008 /* Fetch the section offsets of this DWO unit. */
13010 memset (§ions
, 0, sizeof (sections
));
13012 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
13014 uint32_t offset
= read_4_bytes (dbfd
,
13015 dwp_htab
->section_pool
.v2
.offsets
13016 + (((unit_index
- 1) * dwp_htab
->nr_columns
13018 * sizeof (uint32_t)));
13019 uint32_t size
= read_4_bytes (dbfd
,
13020 dwp_htab
->section_pool
.v2
.sizes
13021 + (((unit_index
- 1) * dwp_htab
->nr_columns
13023 * sizeof (uint32_t)));
13025 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
13028 case DW_SECT_TYPES
:
13029 sections
.info_or_types_offset
= offset
;
13030 sections
.info_or_types_size
= size
;
13032 case DW_SECT_ABBREV
:
13033 sections
.abbrev_offset
= offset
;
13034 sections
.abbrev_size
= size
;
13037 sections
.line_offset
= offset
;
13038 sections
.line_size
= size
;
13041 sections
.loc_offset
= offset
;
13042 sections
.loc_size
= size
;
13044 case DW_SECT_STR_OFFSETS
:
13045 sections
.str_offsets_offset
= offset
;
13046 sections
.str_offsets_size
= size
;
13048 case DW_SECT_MACINFO
:
13049 sections
.macinfo_offset
= offset
;
13050 sections
.macinfo_size
= size
;
13052 case DW_SECT_MACRO
:
13053 sections
.macro_offset
= offset
;
13054 sections
.macro_size
= size
;
13059 /* It's easier for the rest of the code if we fake a struct dwo_file and
13060 have dwo_unit "live" in that. At least for now.
13062 The DWP file can be made up of a random collection of CUs and TUs.
13063 However, for each CU + set of TUs that came from the same original DWO
13064 file, we can combine them back into a virtual DWO file to save space
13065 (fewer struct dwo_file objects to allocate). Remember that for really
13066 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
13068 std::string virtual_dwo_name
=
13069 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
13070 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
13071 (long) (sections
.line_size
? sections
.line_offset
: 0),
13072 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
13073 (long) (sections
.str_offsets_size
13074 ? sections
.str_offsets_offset
: 0));
13075 /* Can we use an existing virtual DWO file? */
13076 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13077 virtual_dwo_name
.c_str (),
13079 /* Create one if necessary. */
13080 if (*dwo_file_slot
== NULL
)
13082 if (dwarf_read_debug
)
13084 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
13085 virtual_dwo_name
.c_str ());
13087 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13089 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
13090 virtual_dwo_name
.c_str (),
13091 virtual_dwo_name
.size ());
13092 dwo_file
->comp_dir
= comp_dir
;
13093 dwo_file
->sections
.abbrev
=
13094 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
13095 sections
.abbrev_offset
, sections
.abbrev_size
);
13096 dwo_file
->sections
.line
=
13097 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
13098 sections
.line_offset
, sections
.line_size
);
13099 dwo_file
->sections
.loc
=
13100 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
13101 sections
.loc_offset
, sections
.loc_size
);
13102 dwo_file
->sections
.macinfo
=
13103 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
13104 sections
.macinfo_offset
, sections
.macinfo_size
);
13105 dwo_file
->sections
.macro
=
13106 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
13107 sections
.macro_offset
, sections
.macro_size
);
13108 dwo_file
->sections
.str_offsets
=
13109 create_dwp_v2_section (dwarf2_per_objfile
,
13110 &dwp_file
->sections
.str_offsets
,
13111 sections
.str_offsets_offset
,
13112 sections
.str_offsets_size
);
13113 /* The "str" section is global to the entire DWP file. */
13114 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
13115 /* The info or types section is assigned below to dwo_unit,
13116 there's no need to record it in dwo_file.
13117 Also, we can't simply record type sections in dwo_file because
13118 we record a pointer into the vector in dwo_unit. As we collect more
13119 types we'll grow the vector and eventually have to reallocate space
13120 for it, invalidating all copies of pointers into the previous
13122 *dwo_file_slot
= dwo_file
;
13126 if (dwarf_read_debug
)
13128 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
13129 virtual_dwo_name
.c_str ());
13131 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13134 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
13135 dwo_unit
->dwo_file
= dwo_file
;
13136 dwo_unit
->signature
= signature
;
13137 dwo_unit
->section
=
13138 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
13139 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
13141 ? &dwp_file
->sections
.types
13142 : &dwp_file
->sections
.info
,
13143 sections
.info_or_types_offset
,
13144 sections
.info_or_types_size
);
13145 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
13150 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
13151 Returns NULL if the signature isn't found. */
13153 static struct dwo_unit
*
13154 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13155 struct dwp_file
*dwp_file
, const char *comp_dir
,
13156 ULONGEST signature
, int is_debug_types
)
13158 const struct dwp_hash_table
*dwp_htab
=
13159 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13160 bfd
*dbfd
= dwp_file
->dbfd
;
13161 uint32_t mask
= dwp_htab
->nr_slots
- 1;
13162 uint32_t hash
= signature
& mask
;
13163 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
13166 struct dwo_unit find_dwo_cu
;
13168 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
13169 find_dwo_cu
.signature
= signature
;
13170 slot
= htab_find_slot (is_debug_types
13171 ? dwp_file
->loaded_tus
13172 : dwp_file
->loaded_cus
,
13173 &find_dwo_cu
, INSERT
);
13176 return (struct dwo_unit
*) *slot
;
13178 /* Use a for loop so that we don't loop forever on bad debug info. */
13179 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
13181 ULONGEST signature_in_table
;
13183 signature_in_table
=
13184 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
13185 if (signature_in_table
== signature
)
13187 uint32_t unit_index
=
13188 read_4_bytes (dbfd
,
13189 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
13191 if (dwp_file
->version
== 1)
13193 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
13194 dwp_file
, unit_index
,
13195 comp_dir
, signature
,
13200 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
13201 dwp_file
, unit_index
,
13202 comp_dir
, signature
,
13205 return (struct dwo_unit
*) *slot
;
13207 if (signature_in_table
== 0)
13209 hash
= (hash
+ hash2
) & mask
;
13212 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
13213 " [in module %s]"),
13217 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
13218 Open the file specified by FILE_NAME and hand it off to BFD for
13219 preliminary analysis. Return a newly initialized bfd *, which
13220 includes a canonicalized copy of FILE_NAME.
13221 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
13222 SEARCH_CWD is true if the current directory is to be searched.
13223 It will be searched before debug-file-directory.
13224 If successful, the file is added to the bfd include table of the
13225 objfile's bfd (see gdb_bfd_record_inclusion).
13226 If unable to find/open the file, return NULL.
13227 NOTE: This function is derived from symfile_bfd_open. */
13229 static gdb_bfd_ref_ptr
13230 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13231 const char *file_name
, int is_dwp
, int search_cwd
)
13234 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
13235 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
13236 to debug_file_directory. */
13237 const char *search_path
;
13238 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
13240 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
13243 if (*debug_file_directory
!= '\0')
13245 search_path_holder
.reset (concat (".", dirname_separator_string
,
13246 debug_file_directory
,
13248 search_path
= search_path_holder
.get ();
13254 search_path
= debug_file_directory
;
13256 openp_flags flags
= OPF_RETURN_REALPATH
;
13258 flags
|= OPF_SEARCH_IN_PATH
;
13260 gdb::unique_xmalloc_ptr
<char> absolute_name
;
13261 desc
= openp (search_path
, flags
, file_name
,
13262 O_RDONLY
| O_BINARY
, &absolute_name
);
13266 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
13268 if (sym_bfd
== NULL
)
13270 bfd_set_cacheable (sym_bfd
.get (), 1);
13272 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
13275 /* Success. Record the bfd as having been included by the objfile's bfd.
13276 This is important because things like demangled_names_hash lives in the
13277 objfile's per_bfd space and may have references to things like symbol
13278 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
13279 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
13284 /* Try to open DWO file FILE_NAME.
13285 COMP_DIR is the DW_AT_comp_dir attribute.
13286 The result is the bfd handle of the file.
13287 If there is a problem finding or opening the file, return NULL.
13288 Upon success, the canonicalized path of the file is stored in the bfd,
13289 same as symfile_bfd_open. */
13291 static gdb_bfd_ref_ptr
13292 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13293 const char *file_name
, const char *comp_dir
)
13295 if (IS_ABSOLUTE_PATH (file_name
))
13296 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13297 0 /*is_dwp*/, 0 /*search_cwd*/);
13299 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
13301 if (comp_dir
!= NULL
)
13303 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
13304 file_name
, (char *) NULL
);
13306 /* NOTE: If comp_dir is a relative path, this will also try the
13307 search path, which seems useful. */
13308 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
13311 1 /*search_cwd*/));
13312 xfree (path_to_try
);
13317 /* That didn't work, try debug-file-directory, which, despite its name,
13318 is a list of paths. */
13320 if (*debug_file_directory
== '\0')
13323 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13324 0 /*is_dwp*/, 1 /*search_cwd*/);
13327 /* This function is mapped across the sections and remembers the offset and
13328 size of each of the DWO debugging sections we are interested in. */
13331 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
13333 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
13334 const struct dwop_section_names
*names
= &dwop_section_names
;
13336 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13338 dwo_sections
->abbrev
.s
.section
= sectp
;
13339 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
13341 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13343 dwo_sections
->info
.s
.section
= sectp
;
13344 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
13346 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13348 dwo_sections
->line
.s
.section
= sectp
;
13349 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
13351 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13353 dwo_sections
->loc
.s
.section
= sectp
;
13354 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
13356 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13358 dwo_sections
->macinfo
.s
.section
= sectp
;
13359 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
13361 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13363 dwo_sections
->macro
.s
.section
= sectp
;
13364 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
13366 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13368 dwo_sections
->str
.s
.section
= sectp
;
13369 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
13371 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13373 dwo_sections
->str_offsets
.s
.section
= sectp
;
13374 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
13376 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13378 struct dwarf2_section_info type_section
;
13380 memset (&type_section
, 0, sizeof (type_section
));
13381 type_section
.s
.section
= sectp
;
13382 type_section
.size
= bfd_get_section_size (sectp
);
13383 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
13388 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13389 by PER_CU. This is for the non-DWP case.
13390 The result is NULL if DWO_NAME can't be found. */
13392 static struct dwo_file
*
13393 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13394 const char *dwo_name
, const char *comp_dir
)
13396 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13397 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13398 struct dwo_file
*dwo_file
;
13399 struct cleanup
*cleanups
;
13401 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
13404 if (dwarf_read_debug
)
13405 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13408 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13409 dwo_file
->dwo_name
= dwo_name
;
13410 dwo_file
->comp_dir
= comp_dir
;
13411 dwo_file
->dbfd
= dbfd
.release ();
13413 free_dwo_file_cleanup_data
*cleanup_data
= XNEW (free_dwo_file_cleanup_data
);
13414 cleanup_data
->dwo_file
= dwo_file
;
13415 cleanup_data
->dwarf2_per_objfile
= dwarf2_per_objfile
;
13417 cleanups
= make_cleanup (free_dwo_file_cleanup
, cleanup_data
);
13419 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13420 &dwo_file
->sections
);
13422 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13425 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
,
13426 dwo_file
->sections
.types
, dwo_file
->tus
);
13428 discard_cleanups (cleanups
);
13430 if (dwarf_read_debug
)
13431 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13436 /* This function is mapped across the sections and remembers the offset and
13437 size of each of the DWP debugging sections common to version 1 and 2 that
13438 we are interested in. */
13441 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13442 void *dwp_file_ptr
)
13444 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13445 const struct dwop_section_names
*names
= &dwop_section_names
;
13446 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13448 /* Record the ELF section number for later lookup: this is what the
13449 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13450 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13451 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13453 /* Look for specific sections that we need. */
13454 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13456 dwp_file
->sections
.str
.s
.section
= sectp
;
13457 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13459 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13461 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13462 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13464 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13466 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13467 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13471 /* This function is mapped across the sections and remembers the offset and
13472 size of each of the DWP version 2 debugging sections that we are interested
13473 in. This is split into a separate function because we don't know if we
13474 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13477 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13479 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13480 const struct dwop_section_names
*names
= &dwop_section_names
;
13481 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13483 /* Record the ELF section number for later lookup: this is what the
13484 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13485 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13486 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13488 /* Look for specific sections that we need. */
13489 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13491 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13492 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13494 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13496 dwp_file
->sections
.info
.s
.section
= sectp
;
13497 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13499 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13501 dwp_file
->sections
.line
.s
.section
= sectp
;
13502 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13504 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13506 dwp_file
->sections
.loc
.s
.section
= sectp
;
13507 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13509 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13511 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13512 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13514 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13516 dwp_file
->sections
.macro
.s
.section
= sectp
;
13517 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13519 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13521 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13522 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13524 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13526 dwp_file
->sections
.types
.s
.section
= sectp
;
13527 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13531 /* Hash function for dwp_file loaded CUs/TUs. */
13534 hash_dwp_loaded_cutus (const void *item
)
13536 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13538 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13539 return dwo_unit
->signature
;
13542 /* Equality function for dwp_file loaded CUs/TUs. */
13545 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13547 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13548 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13550 return dua
->signature
== dub
->signature
;
13553 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13556 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13558 return htab_create_alloc_ex (3,
13559 hash_dwp_loaded_cutus
,
13560 eq_dwp_loaded_cutus
,
13562 &objfile
->objfile_obstack
,
13563 hashtab_obstack_allocate
,
13564 dummy_obstack_deallocate
);
13567 /* Try to open DWP file FILE_NAME.
13568 The result is the bfd handle of the file.
13569 If there is a problem finding or opening the file, return NULL.
13570 Upon success, the canonicalized path of the file is stored in the bfd,
13571 same as symfile_bfd_open. */
13573 static gdb_bfd_ref_ptr
13574 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13575 const char *file_name
)
13577 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13579 1 /*search_cwd*/));
13583 /* Work around upstream bug 15652.
13584 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13585 [Whether that's a "bug" is debatable, but it is getting in our way.]
13586 We have no real idea where the dwp file is, because gdb's realpath-ing
13587 of the executable's path may have discarded the needed info.
13588 [IWBN if the dwp file name was recorded in the executable, akin to
13589 .gnu_debuglink, but that doesn't exist yet.]
13590 Strip the directory from FILE_NAME and search again. */
13591 if (*debug_file_directory
!= '\0')
13593 /* Don't implicitly search the current directory here.
13594 If the user wants to search "." to handle this case,
13595 it must be added to debug-file-directory. */
13596 return try_open_dwop_file (dwarf2_per_objfile
,
13597 lbasename (file_name
), 1 /*is_dwp*/,
13604 /* Initialize the use of the DWP file for the current objfile.
13605 By convention the name of the DWP file is ${objfile}.dwp.
13606 The result is NULL if it can't be found. */
13608 static struct dwp_file
*
13609 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13611 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13612 struct dwp_file
*dwp_file
;
13614 /* Try to find first .dwp for the binary file before any symbolic links
13617 /* If the objfile is a debug file, find the name of the real binary
13618 file and get the name of dwp file from there. */
13619 std::string dwp_name
;
13620 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13622 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13623 const char *backlink_basename
= lbasename (backlink
->original_name
);
13625 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13628 dwp_name
= objfile
->original_name
;
13630 dwp_name
+= ".dwp";
13632 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13634 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13636 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13637 dwp_name
= objfile_name (objfile
);
13638 dwp_name
+= ".dwp";
13639 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13644 if (dwarf_read_debug
)
13645 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13648 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13649 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13650 dwp_file
->dbfd
= dbfd
.release ();
13652 /* +1: section 0 is unused */
13653 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13654 dwp_file
->elf_sections
=
13655 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13656 dwp_file
->num_sections
, asection
*);
13658 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13661 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13663 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13665 /* The DWP file version is stored in the hash table. Oh well. */
13666 if (dwp_file
->cus
&& dwp_file
->tus
13667 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13669 /* Technically speaking, we should try to limp along, but this is
13670 pretty bizarre. We use pulongest here because that's the established
13671 portability solution (e.g, we cannot use %u for uint32_t). */
13672 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13673 " TU version %s [in DWP file %s]"),
13674 pulongest (dwp_file
->cus
->version
),
13675 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13679 dwp_file
->version
= dwp_file
->cus
->version
;
13680 else if (dwp_file
->tus
)
13681 dwp_file
->version
= dwp_file
->tus
->version
;
13683 dwp_file
->version
= 2;
13685 if (dwp_file
->version
== 2)
13686 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13689 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13690 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13692 if (dwarf_read_debug
)
13694 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13695 fprintf_unfiltered (gdb_stdlog
,
13696 " %s CUs, %s TUs\n",
13697 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13698 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13704 /* Wrapper around open_and_init_dwp_file, only open it once. */
13706 static struct dwp_file
*
13707 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13709 if (! dwarf2_per_objfile
->dwp_checked
)
13711 dwarf2_per_objfile
->dwp_file
13712 = open_and_init_dwp_file (dwarf2_per_objfile
);
13713 dwarf2_per_objfile
->dwp_checked
= 1;
13715 return dwarf2_per_objfile
->dwp_file
;
13718 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13719 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13720 or in the DWP file for the objfile, referenced by THIS_UNIT.
13721 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13722 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13724 This is called, for example, when wanting to read a variable with a
13725 complex location. Therefore we don't want to do file i/o for every call.
13726 Therefore we don't want to look for a DWO file on every call.
13727 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13728 then we check if we've already seen DWO_NAME, and only THEN do we check
13731 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13732 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13734 static struct dwo_unit
*
13735 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13736 const char *dwo_name
, const char *comp_dir
,
13737 ULONGEST signature
, int is_debug_types
)
13739 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13740 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13741 const char *kind
= is_debug_types
? "TU" : "CU";
13742 void **dwo_file_slot
;
13743 struct dwo_file
*dwo_file
;
13744 struct dwp_file
*dwp_file
;
13746 /* First see if there's a DWP file.
13747 If we have a DWP file but didn't find the DWO inside it, don't
13748 look for the original DWO file. It makes gdb behave differently
13749 depending on whether one is debugging in the build tree. */
13751 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13752 if (dwp_file
!= NULL
)
13754 const struct dwp_hash_table
*dwp_htab
=
13755 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13757 if (dwp_htab
!= NULL
)
13759 struct dwo_unit
*dwo_cutu
=
13760 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13761 signature
, is_debug_types
);
13763 if (dwo_cutu
!= NULL
)
13765 if (dwarf_read_debug
)
13767 fprintf_unfiltered (gdb_stdlog
,
13768 "Virtual DWO %s %s found: @%s\n",
13769 kind
, hex_string (signature
),
13770 host_address_to_string (dwo_cutu
));
13778 /* No DWP file, look for the DWO file. */
13780 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13781 dwo_name
, comp_dir
);
13782 if (*dwo_file_slot
== NULL
)
13784 /* Read in the file and build a table of the CUs/TUs it contains. */
13785 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13787 /* NOTE: This will be NULL if unable to open the file. */
13788 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13790 if (dwo_file
!= NULL
)
13792 struct dwo_unit
*dwo_cutu
= NULL
;
13794 if (is_debug_types
&& dwo_file
->tus
)
13796 struct dwo_unit find_dwo_cutu
;
13798 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13799 find_dwo_cutu
.signature
= signature
;
13801 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13803 else if (!is_debug_types
&& dwo_file
->cus
)
13805 struct dwo_unit find_dwo_cutu
;
13807 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13808 find_dwo_cutu
.signature
= signature
;
13809 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13813 if (dwo_cutu
!= NULL
)
13815 if (dwarf_read_debug
)
13817 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13818 kind
, dwo_name
, hex_string (signature
),
13819 host_address_to_string (dwo_cutu
));
13826 /* We didn't find it. This could mean a dwo_id mismatch, or
13827 someone deleted the DWO/DWP file, or the search path isn't set up
13828 correctly to find the file. */
13830 if (dwarf_read_debug
)
13832 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13833 kind
, dwo_name
, hex_string (signature
));
13836 /* This is a warning and not a complaint because it can be caused by
13837 pilot error (e.g., user accidentally deleting the DWO). */
13839 /* Print the name of the DWP file if we looked there, helps the user
13840 better diagnose the problem. */
13841 std::string dwp_text
;
13843 if (dwp_file
!= NULL
)
13844 dwp_text
= string_printf (" [in DWP file %s]",
13845 lbasename (dwp_file
->name
));
13847 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13848 " [in module %s]"),
13849 kind
, dwo_name
, hex_string (signature
),
13851 this_unit
->is_debug_types
? "TU" : "CU",
13852 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13857 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13858 See lookup_dwo_cutu_unit for details. */
13860 static struct dwo_unit
*
13861 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13862 const char *dwo_name
, const char *comp_dir
,
13863 ULONGEST signature
)
13865 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13868 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13869 See lookup_dwo_cutu_unit for details. */
13871 static struct dwo_unit
*
13872 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13873 const char *dwo_name
, const char *comp_dir
)
13875 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13878 /* Traversal function for queue_and_load_all_dwo_tus. */
13881 queue_and_load_dwo_tu (void **slot
, void *info
)
13883 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13884 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13885 ULONGEST signature
= dwo_unit
->signature
;
13886 struct signatured_type
*sig_type
=
13887 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13889 if (sig_type
!= NULL
)
13891 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13893 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13894 a real dependency of PER_CU on SIG_TYPE. That is detected later
13895 while processing PER_CU. */
13896 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13897 load_full_type_unit (sig_cu
);
13898 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13904 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13905 The DWO may have the only definition of the type, though it may not be
13906 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13907 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13910 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13912 struct dwo_unit
*dwo_unit
;
13913 struct dwo_file
*dwo_file
;
13915 gdb_assert (!per_cu
->is_debug_types
);
13916 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13917 gdb_assert (per_cu
->cu
!= NULL
);
13919 dwo_unit
= per_cu
->cu
->dwo_unit
;
13920 gdb_assert (dwo_unit
!= NULL
);
13922 dwo_file
= dwo_unit
->dwo_file
;
13923 if (dwo_file
->tus
!= NULL
)
13924 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13927 /* Free all resources associated with DWO_FILE.
13928 Close the DWO file and munmap the sections.
13929 All memory should be on the objfile obstack. */
13932 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
13935 /* Note: dbfd is NULL for virtual DWO files. */
13936 gdb_bfd_unref (dwo_file
->dbfd
);
13938 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13941 /* Wrapper for free_dwo_file for use in cleanups. */
13944 free_dwo_file_cleanup (void *arg
)
13946 struct free_dwo_file_cleanup_data
*data
13947 = (struct free_dwo_file_cleanup_data
*) arg
;
13948 struct objfile
*objfile
= data
->dwarf2_per_objfile
->objfile
;
13950 free_dwo_file (data
->dwo_file
, objfile
);
13955 /* Traversal function for free_dwo_files. */
13958 free_dwo_file_from_slot (void **slot
, void *info
)
13960 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13961 struct objfile
*objfile
= (struct objfile
*) info
;
13963 free_dwo_file (dwo_file
, objfile
);
13968 /* Free all resources associated with DWO_FILES. */
13971 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13973 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13976 /* Read in various DIEs. */
13978 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13979 Inherit only the children of the DW_AT_abstract_origin DIE not being
13980 already referenced by DW_AT_abstract_origin from the children of the
13984 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13986 struct die_info
*child_die
;
13987 sect_offset
*offsetp
;
13988 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13989 struct die_info
*origin_die
;
13990 /* Iterator of the ORIGIN_DIE children. */
13991 struct die_info
*origin_child_die
;
13992 struct attribute
*attr
;
13993 struct dwarf2_cu
*origin_cu
;
13994 struct pending
**origin_previous_list_in_scope
;
13996 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14000 /* Note that following die references may follow to a die in a
14004 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
14006 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
14008 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
14009 origin_cu
->list_in_scope
= cu
->list_in_scope
;
14011 if (die
->tag
!= origin_die
->tag
14012 && !(die
->tag
== DW_TAG_inlined_subroutine
14013 && origin_die
->tag
== DW_TAG_subprogram
))
14014 complaint (&symfile_complaints
,
14015 _("DIE %s and its abstract origin %s have different tags"),
14016 sect_offset_str (die
->sect_off
),
14017 sect_offset_str (origin_die
->sect_off
));
14019 std::vector
<sect_offset
> offsets
;
14021 for (child_die
= die
->child
;
14022 child_die
&& child_die
->tag
;
14023 child_die
= sibling_die (child_die
))
14025 struct die_info
*child_origin_die
;
14026 struct dwarf2_cu
*child_origin_cu
;
14028 /* We are trying to process concrete instance entries:
14029 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
14030 it's not relevant to our analysis here. i.e. detecting DIEs that are
14031 present in the abstract instance but not referenced in the concrete
14033 if (child_die
->tag
== DW_TAG_call_site
14034 || child_die
->tag
== DW_TAG_GNU_call_site
)
14037 /* For each CHILD_DIE, find the corresponding child of
14038 ORIGIN_DIE. If there is more than one layer of
14039 DW_AT_abstract_origin, follow them all; there shouldn't be,
14040 but GCC versions at least through 4.4 generate this (GCC PR
14042 child_origin_die
= child_die
;
14043 child_origin_cu
= cu
;
14046 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
14050 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
14054 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
14055 counterpart may exist. */
14056 if (child_origin_die
!= child_die
)
14058 if (child_die
->tag
!= child_origin_die
->tag
14059 && !(child_die
->tag
== DW_TAG_inlined_subroutine
14060 && child_origin_die
->tag
== DW_TAG_subprogram
))
14061 complaint (&symfile_complaints
,
14062 _("Child DIE %s and its abstract origin %s have "
14064 sect_offset_str (child_die
->sect_off
),
14065 sect_offset_str (child_origin_die
->sect_off
));
14066 if (child_origin_die
->parent
!= origin_die
)
14067 complaint (&symfile_complaints
,
14068 _("Child DIE %s and its abstract origin %s have "
14069 "different parents"),
14070 sect_offset_str (child_die
->sect_off
),
14071 sect_offset_str (child_origin_die
->sect_off
));
14073 offsets
.push_back (child_origin_die
->sect_off
);
14076 std::sort (offsets
.begin (), offsets
.end ());
14077 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
14078 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
14079 if (offsetp
[-1] == *offsetp
)
14080 complaint (&symfile_complaints
,
14081 _("Multiple children of DIE %s refer "
14082 "to DIE %s as their abstract origin"),
14083 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
14085 offsetp
= offsets
.data ();
14086 origin_child_die
= origin_die
->child
;
14087 while (origin_child_die
&& origin_child_die
->tag
)
14089 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
14090 while (offsetp
< offsets_end
14091 && *offsetp
< origin_child_die
->sect_off
)
14093 if (offsetp
>= offsets_end
14094 || *offsetp
> origin_child_die
->sect_off
)
14096 /* Found that ORIGIN_CHILD_DIE is really not referenced.
14097 Check whether we're already processing ORIGIN_CHILD_DIE.
14098 This can happen with mutually referenced abstract_origins.
14100 if (!origin_child_die
->in_process
)
14101 process_die (origin_child_die
, origin_cu
);
14103 origin_child_die
= sibling_die (origin_child_die
);
14105 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
14109 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14111 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14112 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14113 struct context_stack
*newobj
;
14116 struct die_info
*child_die
;
14117 struct attribute
*attr
, *call_line
, *call_file
;
14119 CORE_ADDR baseaddr
;
14120 struct block
*block
;
14121 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14122 std::vector
<struct symbol
*> template_args
;
14123 struct template_symbol
*templ_func
= NULL
;
14127 /* If we do not have call site information, we can't show the
14128 caller of this inlined function. That's too confusing, so
14129 only use the scope for local variables. */
14130 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
14131 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
14132 if (call_line
== NULL
|| call_file
== NULL
)
14134 read_lexical_block_scope (die
, cu
);
14139 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14141 name
= dwarf2_name (die
, cu
);
14143 /* Ignore functions with missing or empty names. These are actually
14144 illegal according to the DWARF standard. */
14147 complaint (&symfile_complaints
,
14148 _("missing name for subprogram DIE at %s"),
14149 sect_offset_str (die
->sect_off
));
14153 /* Ignore functions with missing or invalid low and high pc attributes. */
14154 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
14155 <= PC_BOUNDS_INVALID
)
14157 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
14158 if (!attr
|| !DW_UNSND (attr
))
14159 complaint (&symfile_complaints
,
14160 _("cannot get low and high bounds "
14161 "for subprogram DIE at %s"),
14162 sect_offset_str (die
->sect_off
));
14166 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14167 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14169 /* If we have any template arguments, then we must allocate a
14170 different sort of symbol. */
14171 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
14173 if (child_die
->tag
== DW_TAG_template_type_param
14174 || child_die
->tag
== DW_TAG_template_value_param
)
14176 templ_func
= allocate_template_symbol (objfile
);
14177 templ_func
->subclass
= SYMBOL_TEMPLATE
;
14182 newobj
= push_context (0, lowpc
);
14183 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
14184 (struct symbol
*) templ_func
);
14186 /* If there is a location expression for DW_AT_frame_base, record
14188 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
14190 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
14192 /* If there is a location for the static link, record it. */
14193 newobj
->static_link
= NULL
;
14194 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
14197 newobj
->static_link
14198 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
14199 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
14202 cu
->list_in_scope
= &local_symbols
;
14204 if (die
->child
!= NULL
)
14206 child_die
= die
->child
;
14207 while (child_die
&& child_die
->tag
)
14209 if (child_die
->tag
== DW_TAG_template_type_param
14210 || child_die
->tag
== DW_TAG_template_value_param
)
14212 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
14215 template_args
.push_back (arg
);
14218 process_die (child_die
, cu
);
14219 child_die
= sibling_die (child_die
);
14223 inherit_abstract_dies (die
, cu
);
14225 /* If we have a DW_AT_specification, we might need to import using
14226 directives from the context of the specification DIE. See the
14227 comment in determine_prefix. */
14228 if (cu
->language
== language_cplus
14229 && dwarf2_attr (die
, DW_AT_specification
, cu
))
14231 struct dwarf2_cu
*spec_cu
= cu
;
14232 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
14236 child_die
= spec_die
->child
;
14237 while (child_die
&& child_die
->tag
)
14239 if (child_die
->tag
== DW_TAG_imported_module
)
14240 process_die (child_die
, spec_cu
);
14241 child_die
= sibling_die (child_die
);
14244 /* In some cases, GCC generates specification DIEs that
14245 themselves contain DW_AT_specification attributes. */
14246 spec_die
= die_specification (spec_die
, &spec_cu
);
14250 newobj
= pop_context ();
14251 /* Make a block for the local symbols within. */
14252 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
14253 newobj
->static_link
, lowpc
, highpc
);
14255 /* For C++, set the block's scope. */
14256 if ((cu
->language
== language_cplus
14257 || cu
->language
== language_fortran
14258 || cu
->language
== language_d
14259 || cu
->language
== language_rust
)
14260 && cu
->processing_has_namespace_info
)
14261 block_set_scope (block
, determine_prefix (die
, cu
),
14262 &objfile
->objfile_obstack
);
14264 /* If we have address ranges, record them. */
14265 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14267 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
14269 /* Attach template arguments to function. */
14270 if (!template_args
.empty ())
14272 gdb_assert (templ_func
!= NULL
);
14274 templ_func
->n_template_arguments
= template_args
.size ();
14275 templ_func
->template_arguments
14276 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
14277 templ_func
->n_template_arguments
);
14278 memcpy (templ_func
->template_arguments
,
14279 template_args
.data (),
14280 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
14283 /* In C++, we can have functions nested inside functions (e.g., when
14284 a function declares a class that has methods). This means that
14285 when we finish processing a function scope, we may need to go
14286 back to building a containing block's symbol lists. */
14287 local_symbols
= newobj
->locals
;
14288 local_using_directives
= newobj
->local_using_directives
;
14290 /* If we've finished processing a top-level function, subsequent
14291 symbols go in the file symbol list. */
14292 if (outermost_context_p ())
14293 cu
->list_in_scope
= &file_symbols
;
14296 /* Process all the DIES contained within a lexical block scope. Start
14297 a new scope, process the dies, and then close the scope. */
14300 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14302 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14303 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14304 struct context_stack
*newobj
;
14305 CORE_ADDR lowpc
, highpc
;
14306 struct die_info
*child_die
;
14307 CORE_ADDR baseaddr
;
14309 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14311 /* Ignore blocks with missing or invalid low and high pc attributes. */
14312 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
14313 as multiple lexical blocks? Handling children in a sane way would
14314 be nasty. Might be easier to properly extend generic blocks to
14315 describe ranges. */
14316 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
14318 case PC_BOUNDS_NOT_PRESENT
:
14319 /* DW_TAG_lexical_block has no attributes, process its children as if
14320 there was no wrapping by that DW_TAG_lexical_block.
14321 GCC does no longer produces such DWARF since GCC r224161. */
14322 for (child_die
= die
->child
;
14323 child_die
!= NULL
&& child_die
->tag
;
14324 child_die
= sibling_die (child_die
))
14325 process_die (child_die
, cu
);
14327 case PC_BOUNDS_INVALID
:
14330 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14331 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14333 push_context (0, lowpc
);
14334 if (die
->child
!= NULL
)
14336 child_die
= die
->child
;
14337 while (child_die
&& child_die
->tag
)
14339 process_die (child_die
, cu
);
14340 child_die
= sibling_die (child_die
);
14343 inherit_abstract_dies (die
, cu
);
14344 newobj
= pop_context ();
14346 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
14348 struct block
*block
14349 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
14350 newobj
->start_addr
, highpc
);
14352 /* Note that recording ranges after traversing children, as we
14353 do here, means that recording a parent's ranges entails
14354 walking across all its children's ranges as they appear in
14355 the address map, which is quadratic behavior.
14357 It would be nicer to record the parent's ranges before
14358 traversing its children, simply overriding whatever you find
14359 there. But since we don't even decide whether to create a
14360 block until after we've traversed its children, that's hard
14362 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14364 local_symbols
= newobj
->locals
;
14365 local_using_directives
= newobj
->local_using_directives
;
14368 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
14371 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14373 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14374 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14375 CORE_ADDR pc
, baseaddr
;
14376 struct attribute
*attr
;
14377 struct call_site
*call_site
, call_site_local
;
14380 struct die_info
*child_die
;
14382 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14384 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
14387 /* This was a pre-DWARF-5 GNU extension alias
14388 for DW_AT_call_return_pc. */
14389 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14393 complaint (&symfile_complaints
,
14394 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
14395 "DIE %s [in module %s]"),
14396 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14399 pc
= attr_value_as_address (attr
) + baseaddr
;
14400 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14402 if (cu
->call_site_htab
== NULL
)
14403 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14404 NULL
, &objfile
->objfile_obstack
,
14405 hashtab_obstack_allocate
, NULL
);
14406 call_site_local
.pc
= pc
;
14407 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14410 complaint (&symfile_complaints
,
14411 _("Duplicate PC %s for DW_TAG_call_site "
14412 "DIE %s [in module %s]"),
14413 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14414 objfile_name (objfile
));
14418 /* Count parameters at the caller. */
14421 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14422 child_die
= sibling_die (child_die
))
14424 if (child_die
->tag
!= DW_TAG_call_site_parameter
14425 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14427 complaint (&symfile_complaints
,
14428 _("Tag %d is not DW_TAG_call_site_parameter in "
14429 "DW_TAG_call_site child DIE %s [in module %s]"),
14430 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14431 objfile_name (objfile
));
14439 = ((struct call_site
*)
14440 obstack_alloc (&objfile
->objfile_obstack
,
14441 sizeof (*call_site
)
14442 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14444 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14445 call_site
->pc
= pc
;
14447 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14448 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14450 struct die_info
*func_die
;
14452 /* Skip also over DW_TAG_inlined_subroutine. */
14453 for (func_die
= die
->parent
;
14454 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14455 && func_die
->tag
!= DW_TAG_subroutine_type
;
14456 func_die
= func_die
->parent
);
14458 /* DW_AT_call_all_calls is a superset
14459 of DW_AT_call_all_tail_calls. */
14461 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14462 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14463 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14464 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14466 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14467 not complete. But keep CALL_SITE for look ups via call_site_htab,
14468 both the initial caller containing the real return address PC and
14469 the final callee containing the current PC of a chain of tail
14470 calls do not need to have the tail call list complete. But any
14471 function candidate for a virtual tail call frame searched via
14472 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14473 determined unambiguously. */
14477 struct type
*func_type
= NULL
;
14480 func_type
= get_die_type (func_die
, cu
);
14481 if (func_type
!= NULL
)
14483 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14485 /* Enlist this call site to the function. */
14486 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14487 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14490 complaint (&symfile_complaints
,
14491 _("Cannot find function owning DW_TAG_call_site "
14492 "DIE %s [in module %s]"),
14493 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14497 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14499 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14501 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14504 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14505 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14507 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14508 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14509 /* Keep NULL DWARF_BLOCK. */;
14510 else if (attr_form_is_block (attr
))
14512 struct dwarf2_locexpr_baton
*dlbaton
;
14514 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14515 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14516 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14517 dlbaton
->per_cu
= cu
->per_cu
;
14519 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14521 else if (attr_form_is_ref (attr
))
14523 struct dwarf2_cu
*target_cu
= cu
;
14524 struct die_info
*target_die
;
14526 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14527 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14528 if (die_is_declaration (target_die
, target_cu
))
14530 const char *target_physname
;
14532 /* Prefer the mangled name; otherwise compute the demangled one. */
14533 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14534 if (target_physname
== NULL
)
14535 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14536 if (target_physname
== NULL
)
14537 complaint (&symfile_complaints
,
14538 _("DW_AT_call_target target DIE has invalid "
14539 "physname, for referencing DIE %s [in module %s]"),
14540 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14542 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14548 /* DW_AT_entry_pc should be preferred. */
14549 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14550 <= PC_BOUNDS_INVALID
)
14551 complaint (&symfile_complaints
,
14552 _("DW_AT_call_target target DIE has invalid "
14553 "low pc, for referencing DIE %s [in module %s]"),
14554 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14557 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14558 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14563 complaint (&symfile_complaints
,
14564 _("DW_TAG_call_site DW_AT_call_target is neither "
14565 "block nor reference, for DIE %s [in module %s]"),
14566 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14568 call_site
->per_cu
= cu
->per_cu
;
14570 for (child_die
= die
->child
;
14571 child_die
&& child_die
->tag
;
14572 child_die
= sibling_die (child_die
))
14574 struct call_site_parameter
*parameter
;
14575 struct attribute
*loc
, *origin
;
14577 if (child_die
->tag
!= DW_TAG_call_site_parameter
14578 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14580 /* Already printed the complaint above. */
14584 gdb_assert (call_site
->parameter_count
< nparams
);
14585 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14587 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14588 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14589 register is contained in DW_AT_call_value. */
14591 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14592 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14593 if (origin
== NULL
)
14595 /* This was a pre-DWARF-5 GNU extension alias
14596 for DW_AT_call_parameter. */
14597 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14599 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14601 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14603 sect_offset sect_off
14604 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14605 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14607 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14608 binding can be done only inside one CU. Such referenced DIE
14609 therefore cannot be even moved to DW_TAG_partial_unit. */
14610 complaint (&symfile_complaints
,
14611 _("DW_AT_call_parameter offset is not in CU for "
14612 "DW_TAG_call_site child DIE %s [in module %s]"),
14613 sect_offset_str (child_die
->sect_off
),
14614 objfile_name (objfile
));
14617 parameter
->u
.param_cu_off
14618 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14620 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14622 complaint (&symfile_complaints
,
14623 _("No DW_FORM_block* DW_AT_location for "
14624 "DW_TAG_call_site child DIE %s [in module %s]"),
14625 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14630 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14631 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14632 if (parameter
->u
.dwarf_reg
!= -1)
14633 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14634 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14635 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14636 ¶meter
->u
.fb_offset
))
14637 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14640 complaint (&symfile_complaints
,
14641 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14642 "for DW_FORM_block* DW_AT_location is supported for "
14643 "DW_TAG_call_site child DIE %s "
14645 sect_offset_str (child_die
->sect_off
),
14646 objfile_name (objfile
));
14651 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14653 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14654 if (!attr_form_is_block (attr
))
14656 complaint (&symfile_complaints
,
14657 _("No DW_FORM_block* DW_AT_call_value for "
14658 "DW_TAG_call_site child DIE %s [in module %s]"),
14659 sect_offset_str (child_die
->sect_off
),
14660 objfile_name (objfile
));
14663 parameter
->value
= DW_BLOCK (attr
)->data
;
14664 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14666 /* Parameters are not pre-cleared by memset above. */
14667 parameter
->data_value
= NULL
;
14668 parameter
->data_value_size
= 0;
14669 call_site
->parameter_count
++;
14671 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14673 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14676 if (!attr_form_is_block (attr
))
14677 complaint (&symfile_complaints
,
14678 _("No DW_FORM_block* DW_AT_call_data_value for "
14679 "DW_TAG_call_site child DIE %s [in module %s]"),
14680 sect_offset_str (child_die
->sect_off
),
14681 objfile_name (objfile
));
14684 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14685 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14691 /* Helper function for read_variable. If DIE represents a virtual
14692 table, then return the type of the concrete object that is
14693 associated with the virtual table. Otherwise, return NULL. */
14695 static struct type
*
14696 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14698 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14702 /* Find the type DIE. */
14703 struct die_info
*type_die
= NULL
;
14704 struct dwarf2_cu
*type_cu
= cu
;
14706 if (attr_form_is_ref (attr
))
14707 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14708 if (type_die
== NULL
)
14711 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14713 return die_containing_type (type_die
, type_cu
);
14716 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14719 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14721 struct rust_vtable_symbol
*storage
= NULL
;
14723 if (cu
->language
== language_rust
)
14725 struct type
*containing_type
= rust_containing_type (die
, cu
);
14727 if (containing_type
!= NULL
)
14729 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14731 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14732 struct rust_vtable_symbol
);
14733 initialize_objfile_symbol (storage
);
14734 storage
->concrete_type
= containing_type
;
14735 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14739 new_symbol (die
, NULL
, cu
, storage
);
14742 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14743 reading .debug_rnglists.
14744 Callback's type should be:
14745 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14746 Return true if the attributes are present and valid, otherwise,
14749 template <typename Callback
>
14751 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14752 Callback
&&callback
)
14754 struct dwarf2_per_objfile
*dwarf2_per_objfile
14755 = cu
->per_cu
->dwarf2_per_objfile
;
14756 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14757 bfd
*obfd
= objfile
->obfd
;
14758 /* Base address selection entry. */
14761 const gdb_byte
*buffer
;
14762 CORE_ADDR baseaddr
;
14763 bool overflow
= false;
14765 found_base
= cu
->base_known
;
14766 base
= cu
->base_address
;
14768 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14769 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14771 complaint (&symfile_complaints
,
14772 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14776 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14778 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14782 /* Initialize it due to a false compiler warning. */
14783 CORE_ADDR range_beginning
= 0, range_end
= 0;
14784 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14785 + dwarf2_per_objfile
->rnglists
.size
);
14786 unsigned int bytes_read
;
14788 if (buffer
== buf_end
)
14793 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14796 case DW_RLE_end_of_list
:
14798 case DW_RLE_base_address
:
14799 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14804 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14806 buffer
+= bytes_read
;
14808 case DW_RLE_start_length
:
14809 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14814 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14815 buffer
+= bytes_read
;
14816 range_end
= (range_beginning
14817 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14818 buffer
+= bytes_read
;
14819 if (buffer
> buf_end
)
14825 case DW_RLE_offset_pair
:
14826 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14827 buffer
+= bytes_read
;
14828 if (buffer
> buf_end
)
14833 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14834 buffer
+= bytes_read
;
14835 if (buffer
> buf_end
)
14841 case DW_RLE_start_end
:
14842 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14847 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14848 buffer
+= bytes_read
;
14849 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14850 buffer
+= bytes_read
;
14853 complaint (&symfile_complaints
,
14854 _("Invalid .debug_rnglists data (no base address)"));
14857 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14859 if (rlet
== DW_RLE_base_address
)
14864 /* We have no valid base address for the ranges
14866 complaint (&symfile_complaints
,
14867 _("Invalid .debug_rnglists data (no base address)"));
14871 if (range_beginning
> range_end
)
14873 /* Inverted range entries are invalid. */
14874 complaint (&symfile_complaints
,
14875 _("Invalid .debug_rnglists data (inverted range)"));
14879 /* Empty range entries have no effect. */
14880 if (range_beginning
== range_end
)
14883 range_beginning
+= base
;
14886 /* A not-uncommon case of bad debug info.
14887 Don't pollute the addrmap with bad data. */
14888 if (range_beginning
+ baseaddr
== 0
14889 && !dwarf2_per_objfile
->has_section_at_zero
)
14891 complaint (&symfile_complaints
,
14892 _(".debug_rnglists entry has start address of zero"
14893 " [in module %s]"), objfile_name (objfile
));
14897 callback (range_beginning
, range_end
);
14902 complaint (&symfile_complaints
,
14903 _("Offset %d is not terminated "
14904 "for DW_AT_ranges attribute"),
14912 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14913 Callback's type should be:
14914 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14915 Return 1 if the attributes are present and valid, otherwise, return 0. */
14917 template <typename Callback
>
14919 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14920 Callback
&&callback
)
14922 struct dwarf2_per_objfile
*dwarf2_per_objfile
14923 = cu
->per_cu
->dwarf2_per_objfile
;
14924 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14925 struct comp_unit_head
*cu_header
= &cu
->header
;
14926 bfd
*obfd
= objfile
->obfd
;
14927 unsigned int addr_size
= cu_header
->addr_size
;
14928 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14929 /* Base address selection entry. */
14932 unsigned int dummy
;
14933 const gdb_byte
*buffer
;
14934 CORE_ADDR baseaddr
;
14936 if (cu_header
->version
>= 5)
14937 return dwarf2_rnglists_process (offset
, cu
, callback
);
14939 found_base
= cu
->base_known
;
14940 base
= cu
->base_address
;
14942 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14943 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14945 complaint (&symfile_complaints
,
14946 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14950 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14952 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14956 CORE_ADDR range_beginning
, range_end
;
14958 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14959 buffer
+= addr_size
;
14960 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14961 buffer
+= addr_size
;
14962 offset
+= 2 * addr_size
;
14964 /* An end of list marker is a pair of zero addresses. */
14965 if (range_beginning
== 0 && range_end
== 0)
14966 /* Found the end of list entry. */
14969 /* Each base address selection entry is a pair of 2 values.
14970 The first is the largest possible address, the second is
14971 the base address. Check for a base address here. */
14972 if ((range_beginning
& mask
) == mask
)
14974 /* If we found the largest possible address, then we already
14975 have the base address in range_end. */
14983 /* We have no valid base address for the ranges
14985 complaint (&symfile_complaints
,
14986 _("Invalid .debug_ranges data (no base address)"));
14990 if (range_beginning
> range_end
)
14992 /* Inverted range entries are invalid. */
14993 complaint (&symfile_complaints
,
14994 _("Invalid .debug_ranges data (inverted range)"));
14998 /* Empty range entries have no effect. */
14999 if (range_beginning
== range_end
)
15002 range_beginning
+= base
;
15005 /* A not-uncommon case of bad debug info.
15006 Don't pollute the addrmap with bad data. */
15007 if (range_beginning
+ baseaddr
== 0
15008 && !dwarf2_per_objfile
->has_section_at_zero
)
15010 complaint (&symfile_complaints
,
15011 _(".debug_ranges entry has start address of zero"
15012 " [in module %s]"), objfile_name (objfile
));
15016 callback (range_beginning
, range_end
);
15022 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
15023 Return 1 if the attributes are present and valid, otherwise, return 0.
15024 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
15027 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
15028 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
15029 struct partial_symtab
*ranges_pst
)
15031 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15032 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15033 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
15034 SECT_OFF_TEXT (objfile
));
15037 CORE_ADDR high
= 0;
15040 retval
= dwarf2_ranges_process (offset
, cu
,
15041 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
15043 if (ranges_pst
!= NULL
)
15048 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15049 range_beginning
+ baseaddr
);
15050 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15051 range_end
+ baseaddr
);
15052 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
15056 /* FIXME: This is recording everything as a low-high
15057 segment of consecutive addresses. We should have a
15058 data structure for discontiguous block ranges
15062 low
= range_beginning
;
15068 if (range_beginning
< low
)
15069 low
= range_beginning
;
15070 if (range_end
> high
)
15078 /* If the first entry is an end-of-list marker, the range
15079 describes an empty scope, i.e. no instructions. */
15085 *high_return
= high
;
15089 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
15090 definition for the return value. *LOWPC and *HIGHPC are set iff
15091 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
15093 static enum pc_bounds_kind
15094 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
15095 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
15096 struct partial_symtab
*pst
)
15098 struct dwarf2_per_objfile
*dwarf2_per_objfile
15099 = cu
->per_cu
->dwarf2_per_objfile
;
15100 struct attribute
*attr
;
15101 struct attribute
*attr_high
;
15103 CORE_ADDR high
= 0;
15104 enum pc_bounds_kind ret
;
15106 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15109 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15112 low
= attr_value_as_address (attr
);
15113 high
= attr_value_as_address (attr_high
);
15114 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15118 /* Found high w/o low attribute. */
15119 return PC_BOUNDS_INVALID
;
15121 /* Found consecutive range of addresses. */
15122 ret
= PC_BOUNDS_HIGH_LOW
;
15126 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15129 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15130 We take advantage of the fact that DW_AT_ranges does not appear
15131 in DW_TAG_compile_unit of DWO files. */
15132 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15133 unsigned int ranges_offset
= (DW_UNSND (attr
)
15134 + (need_ranges_base
15138 /* Value of the DW_AT_ranges attribute is the offset in the
15139 .debug_ranges section. */
15140 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
15141 return PC_BOUNDS_INVALID
;
15142 /* Found discontinuous range of addresses. */
15143 ret
= PC_BOUNDS_RANGES
;
15146 return PC_BOUNDS_NOT_PRESENT
;
15149 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
15151 return PC_BOUNDS_INVALID
;
15153 /* When using the GNU linker, .gnu.linkonce. sections are used to
15154 eliminate duplicate copies of functions and vtables and such.
15155 The linker will arbitrarily choose one and discard the others.
15156 The AT_*_pc values for such functions refer to local labels in
15157 these sections. If the section from that file was discarded, the
15158 labels are not in the output, so the relocs get a value of 0.
15159 If this is a discarded function, mark the pc bounds as invalid,
15160 so that GDB will ignore it. */
15161 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15162 return PC_BOUNDS_INVALID
;
15170 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
15171 its low and high PC addresses. Do nothing if these addresses could not
15172 be determined. Otherwise, set LOWPC to the low address if it is smaller,
15173 and HIGHPC to the high address if greater than HIGHPC. */
15176 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
15177 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15178 struct dwarf2_cu
*cu
)
15180 CORE_ADDR low
, high
;
15181 struct die_info
*child
= die
->child
;
15183 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
15185 *lowpc
= std::min (*lowpc
, low
);
15186 *highpc
= std::max (*highpc
, high
);
15189 /* If the language does not allow nested subprograms (either inside
15190 subprograms or lexical blocks), we're done. */
15191 if (cu
->language
!= language_ada
)
15194 /* Check all the children of the given DIE. If it contains nested
15195 subprograms, then check their pc bounds. Likewise, we need to
15196 check lexical blocks as well, as they may also contain subprogram
15198 while (child
&& child
->tag
)
15200 if (child
->tag
== DW_TAG_subprogram
15201 || child
->tag
== DW_TAG_lexical_block
)
15202 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
15203 child
= sibling_die (child
);
15207 /* Get the low and high pc's represented by the scope DIE, and store
15208 them in *LOWPC and *HIGHPC. If the correct values can't be
15209 determined, set *LOWPC to -1 and *HIGHPC to 0. */
15212 get_scope_pc_bounds (struct die_info
*die
,
15213 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15214 struct dwarf2_cu
*cu
)
15216 CORE_ADDR best_low
= (CORE_ADDR
) -1;
15217 CORE_ADDR best_high
= (CORE_ADDR
) 0;
15218 CORE_ADDR current_low
, current_high
;
15220 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
15221 >= PC_BOUNDS_RANGES
)
15223 best_low
= current_low
;
15224 best_high
= current_high
;
15228 struct die_info
*child
= die
->child
;
15230 while (child
&& child
->tag
)
15232 switch (child
->tag
) {
15233 case DW_TAG_subprogram
:
15234 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
15236 case DW_TAG_namespace
:
15237 case DW_TAG_module
:
15238 /* FIXME: carlton/2004-01-16: Should we do this for
15239 DW_TAG_class_type/DW_TAG_structure_type, too? I think
15240 that current GCC's always emit the DIEs corresponding
15241 to definitions of methods of classes as children of a
15242 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
15243 the DIEs giving the declarations, which could be
15244 anywhere). But I don't see any reason why the
15245 standards says that they have to be there. */
15246 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
15248 if (current_low
!= ((CORE_ADDR
) -1))
15250 best_low
= std::min (best_low
, current_low
);
15251 best_high
= std::max (best_high
, current_high
);
15259 child
= sibling_die (child
);
15264 *highpc
= best_high
;
15267 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
15271 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
15272 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
15274 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15275 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15276 struct attribute
*attr
;
15277 struct attribute
*attr_high
;
15279 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15282 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15285 CORE_ADDR low
= attr_value_as_address (attr
);
15286 CORE_ADDR high
= attr_value_as_address (attr_high
);
15288 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15291 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
15292 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
15293 record_block_range (block
, low
, high
- 1);
15297 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15300 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15301 We take advantage of the fact that DW_AT_ranges does not appear
15302 in DW_TAG_compile_unit of DWO files. */
15303 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15305 /* The value of the DW_AT_ranges attribute is the offset of the
15306 address range list in the .debug_ranges section. */
15307 unsigned long offset
= (DW_UNSND (attr
)
15308 + (need_ranges_base
? cu
->ranges_base
: 0));
15309 const gdb_byte
*buffer
;
15311 /* For some target architectures, but not others, the
15312 read_address function sign-extends the addresses it returns.
15313 To recognize base address selection entries, we need a
15315 unsigned int addr_size
= cu
->header
.addr_size
;
15316 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
15318 /* The base address, to which the next pair is relative. Note
15319 that this 'base' is a DWARF concept: most entries in a range
15320 list are relative, to reduce the number of relocs against the
15321 debugging information. This is separate from this function's
15322 'baseaddr' argument, which GDB uses to relocate debugging
15323 information from a shared library based on the address at
15324 which the library was loaded. */
15325 CORE_ADDR base
= cu
->base_address
;
15326 int base_known
= cu
->base_known
;
15328 dwarf2_ranges_process (offset
, cu
,
15329 [&] (CORE_ADDR start
, CORE_ADDR end
)
15333 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
15334 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
15335 record_block_range (block
, start
, end
- 1);
15340 /* Check whether the producer field indicates either of GCC < 4.6, or the
15341 Intel C/C++ compiler, and cache the result in CU. */
15344 check_producer (struct dwarf2_cu
*cu
)
15348 if (cu
->producer
== NULL
)
15350 /* For unknown compilers expect their behavior is DWARF version
15353 GCC started to support .debug_types sections by -gdwarf-4 since
15354 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
15355 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
15356 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
15357 interpreted incorrectly by GDB now - GCC PR debug/48229. */
15359 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
15361 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
15362 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
15364 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
15365 cu
->producer_is_icc_lt_14
= major
< 14;
15368 /* For other non-GCC compilers, expect their behavior is DWARF version
15372 cu
->checked_producer
= 1;
15375 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
15376 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
15377 during 4.6.0 experimental. */
15380 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
15382 if (!cu
->checked_producer
)
15383 check_producer (cu
);
15385 return cu
->producer_is_gxx_lt_4_6
;
15388 /* Return the default accessibility type if it is not overriden by
15389 DW_AT_accessibility. */
15391 static enum dwarf_access_attribute
15392 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15394 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15396 /* The default DWARF 2 accessibility for members is public, the default
15397 accessibility for inheritance is private. */
15399 if (die
->tag
!= DW_TAG_inheritance
)
15400 return DW_ACCESS_public
;
15402 return DW_ACCESS_private
;
15406 /* DWARF 3+ defines the default accessibility a different way. The same
15407 rules apply now for DW_TAG_inheritance as for the members and it only
15408 depends on the container kind. */
15410 if (die
->parent
->tag
== DW_TAG_class_type
)
15411 return DW_ACCESS_private
;
15413 return DW_ACCESS_public
;
15417 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15418 offset. If the attribute was not found return 0, otherwise return
15419 1. If it was found but could not properly be handled, set *OFFSET
15423 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15426 struct attribute
*attr
;
15428 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15433 /* Note that we do not check for a section offset first here.
15434 This is because DW_AT_data_member_location is new in DWARF 4,
15435 so if we see it, we can assume that a constant form is really
15436 a constant and not a section offset. */
15437 if (attr_form_is_constant (attr
))
15438 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15439 else if (attr_form_is_section_offset (attr
))
15440 dwarf2_complex_location_expr_complaint ();
15441 else if (attr_form_is_block (attr
))
15442 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15444 dwarf2_complex_location_expr_complaint ();
15452 /* Add an aggregate field to the field list. */
15455 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15456 struct dwarf2_cu
*cu
)
15458 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15459 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15460 struct nextfield
*new_field
;
15461 struct attribute
*attr
;
15463 const char *fieldname
= "";
15465 if (die
->tag
== DW_TAG_inheritance
)
15467 fip
->baseclasses
.emplace_back ();
15468 new_field
= &fip
->baseclasses
.back ();
15472 fip
->fields
.emplace_back ();
15473 new_field
= &fip
->fields
.back ();
15478 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15480 new_field
->accessibility
= DW_UNSND (attr
);
15482 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15483 if (new_field
->accessibility
!= DW_ACCESS_public
)
15484 fip
->non_public_fields
= 1;
15486 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15488 new_field
->virtuality
= DW_UNSND (attr
);
15490 new_field
->virtuality
= DW_VIRTUALITY_none
;
15492 fp
= &new_field
->field
;
15494 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15498 /* Data member other than a C++ static data member. */
15500 /* Get type of field. */
15501 fp
->type
= die_type (die
, cu
);
15503 SET_FIELD_BITPOS (*fp
, 0);
15505 /* Get bit size of field (zero if none). */
15506 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15509 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15513 FIELD_BITSIZE (*fp
) = 0;
15516 /* Get bit offset of field. */
15517 if (handle_data_member_location (die
, cu
, &offset
))
15518 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15519 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15522 if (gdbarch_bits_big_endian (gdbarch
))
15524 /* For big endian bits, the DW_AT_bit_offset gives the
15525 additional bit offset from the MSB of the containing
15526 anonymous object to the MSB of the field. We don't
15527 have to do anything special since we don't need to
15528 know the size of the anonymous object. */
15529 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15533 /* For little endian bits, compute the bit offset to the
15534 MSB of the anonymous object, subtract off the number of
15535 bits from the MSB of the field to the MSB of the
15536 object, and then subtract off the number of bits of
15537 the field itself. The result is the bit offset of
15538 the LSB of the field. */
15539 int anonymous_size
;
15540 int bit_offset
= DW_UNSND (attr
);
15542 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15545 /* The size of the anonymous object containing
15546 the bit field is explicit, so use the
15547 indicated size (in bytes). */
15548 anonymous_size
= DW_UNSND (attr
);
15552 /* The size of the anonymous object containing
15553 the bit field must be inferred from the type
15554 attribute of the data member containing the
15556 anonymous_size
= TYPE_LENGTH (fp
->type
);
15558 SET_FIELD_BITPOS (*fp
,
15559 (FIELD_BITPOS (*fp
)
15560 + anonymous_size
* bits_per_byte
15561 - bit_offset
- FIELD_BITSIZE (*fp
)));
15564 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15566 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15567 + dwarf2_get_attr_constant_value (attr
, 0)));
15569 /* Get name of field. */
15570 fieldname
= dwarf2_name (die
, cu
);
15571 if (fieldname
== NULL
)
15574 /* The name is already allocated along with this objfile, so we don't
15575 need to duplicate it for the type. */
15576 fp
->name
= fieldname
;
15578 /* Change accessibility for artificial fields (e.g. virtual table
15579 pointer or virtual base class pointer) to private. */
15580 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15582 FIELD_ARTIFICIAL (*fp
) = 1;
15583 new_field
->accessibility
= DW_ACCESS_private
;
15584 fip
->non_public_fields
= 1;
15587 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15589 /* C++ static member. */
15591 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15592 is a declaration, but all versions of G++ as of this writing
15593 (so through at least 3.2.1) incorrectly generate
15594 DW_TAG_variable tags. */
15596 const char *physname
;
15598 /* Get name of field. */
15599 fieldname
= dwarf2_name (die
, cu
);
15600 if (fieldname
== NULL
)
15603 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15605 /* Only create a symbol if this is an external value.
15606 new_symbol checks this and puts the value in the global symbol
15607 table, which we want. If it is not external, new_symbol
15608 will try to put the value in cu->list_in_scope which is wrong. */
15609 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15611 /* A static const member, not much different than an enum as far as
15612 we're concerned, except that we can support more types. */
15613 new_symbol (die
, NULL
, cu
);
15616 /* Get physical name. */
15617 physname
= dwarf2_physname (fieldname
, die
, cu
);
15619 /* The name is already allocated along with this objfile, so we don't
15620 need to duplicate it for the type. */
15621 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15622 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15623 FIELD_NAME (*fp
) = fieldname
;
15625 else if (die
->tag
== DW_TAG_inheritance
)
15629 /* C++ base class field. */
15630 if (handle_data_member_location (die
, cu
, &offset
))
15631 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15632 FIELD_BITSIZE (*fp
) = 0;
15633 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15634 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15636 else if (die
->tag
== DW_TAG_variant_part
)
15638 /* process_structure_scope will treat this DIE as a union. */
15639 process_structure_scope (die
, cu
);
15641 /* The variant part is relative to the start of the enclosing
15643 SET_FIELD_BITPOS (*fp
, 0);
15644 fp
->type
= get_die_type (die
, cu
);
15645 fp
->artificial
= 1;
15646 fp
->name
= "<<variant>>";
15649 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15652 /* Can the type given by DIE define another type? */
15655 type_can_define_types (const struct die_info
*die
)
15659 case DW_TAG_typedef
:
15660 case DW_TAG_class_type
:
15661 case DW_TAG_structure_type
:
15662 case DW_TAG_union_type
:
15663 case DW_TAG_enumeration_type
:
15671 /* Add a type definition defined in the scope of the FIP's class. */
15674 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15675 struct dwarf2_cu
*cu
)
15677 struct decl_field fp
;
15678 memset (&fp
, 0, sizeof (fp
));
15680 gdb_assert (type_can_define_types (die
));
15682 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15683 fp
.name
= dwarf2_name (die
, cu
);
15684 fp
.type
= read_type_die (die
, cu
);
15686 /* Save accessibility. */
15687 enum dwarf_access_attribute accessibility
;
15688 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15690 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15692 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15693 switch (accessibility
)
15695 case DW_ACCESS_public
:
15696 /* The assumed value if neither private nor protected. */
15698 case DW_ACCESS_private
:
15701 case DW_ACCESS_protected
:
15702 fp
.is_protected
= 1;
15705 complaint (&symfile_complaints
,
15706 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15709 if (die
->tag
== DW_TAG_typedef
)
15710 fip
->typedef_field_list
.push_back (fp
);
15712 fip
->nested_types_list
.push_back (fp
);
15715 /* Create the vector of fields, and attach it to the type. */
15718 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15719 struct dwarf2_cu
*cu
)
15721 int nfields
= fip
->nfields
;
15723 /* Record the field count, allocate space for the array of fields,
15724 and create blank accessibility bitfields if necessary. */
15725 TYPE_NFIELDS (type
) = nfields
;
15726 TYPE_FIELDS (type
) = (struct field
*)
15727 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15729 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15731 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15733 TYPE_FIELD_PRIVATE_BITS (type
) =
15734 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15735 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15737 TYPE_FIELD_PROTECTED_BITS (type
) =
15738 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15739 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15741 TYPE_FIELD_IGNORE_BITS (type
) =
15742 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15743 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15746 /* If the type has baseclasses, allocate and clear a bit vector for
15747 TYPE_FIELD_VIRTUAL_BITS. */
15748 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15750 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15751 unsigned char *pointer
;
15753 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15754 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15755 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15756 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15757 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15760 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15762 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15764 for (int index
= 0; index
< nfields
; ++index
)
15766 struct nextfield
&field
= fip
->fields
[index
];
15768 if (field
.variant
.is_discriminant
)
15769 di
->discriminant_index
= index
;
15770 else if (field
.variant
.default_branch
)
15771 di
->default_index
= index
;
15773 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15777 /* Copy the saved-up fields into the field vector. */
15778 for (int i
= 0; i
< nfields
; ++i
)
15780 struct nextfield
&field
15781 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15782 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15784 TYPE_FIELD (type
, i
) = field
.field
;
15785 switch (field
.accessibility
)
15787 case DW_ACCESS_private
:
15788 if (cu
->language
!= language_ada
)
15789 SET_TYPE_FIELD_PRIVATE (type
, i
);
15792 case DW_ACCESS_protected
:
15793 if (cu
->language
!= language_ada
)
15794 SET_TYPE_FIELD_PROTECTED (type
, i
);
15797 case DW_ACCESS_public
:
15801 /* Unknown accessibility. Complain and treat it as public. */
15803 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15804 field
.accessibility
);
15808 if (i
< fip
->baseclasses
.size ())
15810 switch (field
.virtuality
)
15812 case DW_VIRTUALITY_virtual
:
15813 case DW_VIRTUALITY_pure_virtual
:
15814 if (cu
->language
== language_ada
)
15815 error (_("unexpected virtuality in component of Ada type"));
15816 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15823 /* Return true if this member function is a constructor, false
15827 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15829 const char *fieldname
;
15830 const char *type_name
;
15833 if (die
->parent
== NULL
)
15836 if (die
->parent
->tag
!= DW_TAG_structure_type
15837 && die
->parent
->tag
!= DW_TAG_union_type
15838 && die
->parent
->tag
!= DW_TAG_class_type
)
15841 fieldname
= dwarf2_name (die
, cu
);
15842 type_name
= dwarf2_name (die
->parent
, cu
);
15843 if (fieldname
== NULL
|| type_name
== NULL
)
15846 len
= strlen (fieldname
);
15847 return (strncmp (fieldname
, type_name
, len
) == 0
15848 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15851 /* Add a member function to the proper fieldlist. */
15854 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15855 struct type
*type
, struct dwarf2_cu
*cu
)
15857 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15858 struct attribute
*attr
;
15860 struct fnfieldlist
*flp
= nullptr;
15861 struct fn_field
*fnp
;
15862 const char *fieldname
;
15863 struct type
*this_type
;
15864 enum dwarf_access_attribute accessibility
;
15866 if (cu
->language
== language_ada
)
15867 error (_("unexpected member function in Ada type"));
15869 /* Get name of member function. */
15870 fieldname
= dwarf2_name (die
, cu
);
15871 if (fieldname
== NULL
)
15874 /* Look up member function name in fieldlist. */
15875 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15877 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15879 flp
= &fip
->fnfieldlists
[i
];
15884 /* Create a new fnfieldlist if necessary. */
15885 if (flp
== nullptr)
15887 fip
->fnfieldlists
.emplace_back ();
15888 flp
= &fip
->fnfieldlists
.back ();
15889 flp
->name
= fieldname
;
15890 i
= fip
->fnfieldlists
.size () - 1;
15893 /* Create a new member function field and add it to the vector of
15895 flp
->fnfields
.emplace_back ();
15896 fnp
= &flp
->fnfields
.back ();
15898 /* Delay processing of the physname until later. */
15899 if (cu
->language
== language_cplus
)
15900 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15904 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15905 fnp
->physname
= physname
? physname
: "";
15908 fnp
->type
= alloc_type (objfile
);
15909 this_type
= read_type_die (die
, cu
);
15910 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15912 int nparams
= TYPE_NFIELDS (this_type
);
15914 /* TYPE is the domain of this method, and THIS_TYPE is the type
15915 of the method itself (TYPE_CODE_METHOD). */
15916 smash_to_method_type (fnp
->type
, type
,
15917 TYPE_TARGET_TYPE (this_type
),
15918 TYPE_FIELDS (this_type
),
15919 TYPE_NFIELDS (this_type
),
15920 TYPE_VARARGS (this_type
));
15922 /* Handle static member functions.
15923 Dwarf2 has no clean way to discern C++ static and non-static
15924 member functions. G++ helps GDB by marking the first
15925 parameter for non-static member functions (which is the this
15926 pointer) as artificial. We obtain this information from
15927 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15928 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15929 fnp
->voffset
= VOFFSET_STATIC
;
15932 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15933 dwarf2_full_name (fieldname
, die
, cu
));
15935 /* Get fcontext from DW_AT_containing_type if present. */
15936 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15937 fnp
->fcontext
= die_containing_type (die
, cu
);
15939 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15940 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15942 /* Get accessibility. */
15943 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15945 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15947 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15948 switch (accessibility
)
15950 case DW_ACCESS_private
:
15951 fnp
->is_private
= 1;
15953 case DW_ACCESS_protected
:
15954 fnp
->is_protected
= 1;
15958 /* Check for artificial methods. */
15959 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15960 if (attr
&& DW_UNSND (attr
) != 0)
15961 fnp
->is_artificial
= 1;
15963 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15965 /* Get index in virtual function table if it is a virtual member
15966 function. For older versions of GCC, this is an offset in the
15967 appropriate virtual table, as specified by DW_AT_containing_type.
15968 For everyone else, it is an expression to be evaluated relative
15969 to the object address. */
15971 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15974 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15976 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15978 /* Old-style GCC. */
15979 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15981 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15982 || (DW_BLOCK (attr
)->size
> 1
15983 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15984 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15986 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15987 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15988 dwarf2_complex_location_expr_complaint ();
15990 fnp
->voffset
/= cu
->header
.addr_size
;
15994 dwarf2_complex_location_expr_complaint ();
15996 if (!fnp
->fcontext
)
15998 /* If there is no `this' field and no DW_AT_containing_type,
15999 we cannot actually find a base class context for the
16001 if (TYPE_NFIELDS (this_type
) == 0
16002 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
16004 complaint (&symfile_complaints
,
16005 _("cannot determine context for virtual member "
16006 "function \"%s\" (offset %s)"),
16007 fieldname
, sect_offset_str (die
->sect_off
));
16012 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
16016 else if (attr_form_is_section_offset (attr
))
16018 dwarf2_complex_location_expr_complaint ();
16022 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
16028 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
16029 if (attr
&& DW_UNSND (attr
))
16031 /* GCC does this, as of 2008-08-25; PR debug/37237. */
16032 complaint (&symfile_complaints
,
16033 _("Member function \"%s\" (offset %s) is virtual "
16034 "but the vtable offset is not specified"),
16035 fieldname
, sect_offset_str (die
->sect_off
));
16036 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16037 TYPE_CPLUS_DYNAMIC (type
) = 1;
16042 /* Create the vector of member function fields, and attach it to the type. */
16045 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
16046 struct dwarf2_cu
*cu
)
16048 if (cu
->language
== language_ada
)
16049 error (_("unexpected member functions in Ada type"));
16051 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16052 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
16054 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
16056 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
16058 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
16059 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
16061 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
16062 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
16063 fn_flp
->fn_fields
= (struct fn_field
*)
16064 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
16066 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
16067 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
16070 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
16073 /* Returns non-zero if NAME is the name of a vtable member in CU's
16074 language, zero otherwise. */
16076 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
16078 static const char vptr
[] = "_vptr";
16080 /* Look for the C++ form of the vtable. */
16081 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
16087 /* GCC outputs unnamed structures that are really pointers to member
16088 functions, with the ABI-specified layout. If TYPE describes
16089 such a structure, smash it into a member function type.
16091 GCC shouldn't do this; it should just output pointer to member DIEs.
16092 This is GCC PR debug/28767. */
16095 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
16097 struct type
*pfn_type
, *self_type
, *new_type
;
16099 /* Check for a structure with no name and two children. */
16100 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
16103 /* Check for __pfn and __delta members. */
16104 if (TYPE_FIELD_NAME (type
, 0) == NULL
16105 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
16106 || TYPE_FIELD_NAME (type
, 1) == NULL
16107 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
16110 /* Find the type of the method. */
16111 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
16112 if (pfn_type
== NULL
16113 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
16114 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
16117 /* Look for the "this" argument. */
16118 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
16119 if (TYPE_NFIELDS (pfn_type
) == 0
16120 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
16121 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
16124 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
16125 new_type
= alloc_type (objfile
);
16126 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
16127 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
16128 TYPE_VARARGS (pfn_type
));
16129 smash_to_methodptr_type (type
, new_type
);
16133 /* Called when we find the DIE that starts a structure or union scope
16134 (definition) to create a type for the structure or union. Fill in
16135 the type's name and general properties; the members will not be
16136 processed until process_structure_scope. A symbol table entry for
16137 the type will also not be done until process_structure_scope (assuming
16138 the type has a name).
16140 NOTE: we need to call these functions regardless of whether or not the
16141 DIE has a DW_AT_name attribute, since it might be an anonymous
16142 structure or union. This gets the type entered into our set of
16143 user defined types. */
16145 static struct type
*
16146 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16148 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16150 struct attribute
*attr
;
16153 /* If the definition of this type lives in .debug_types, read that type.
16154 Don't follow DW_AT_specification though, that will take us back up
16155 the chain and we want to go down. */
16156 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16159 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16161 /* The type's CU may not be the same as CU.
16162 Ensure TYPE is recorded with CU in die_type_hash. */
16163 return set_die_type (die
, type
, cu
);
16166 type
= alloc_type (objfile
);
16167 INIT_CPLUS_SPECIFIC (type
);
16169 name
= dwarf2_name (die
, cu
);
16172 if (cu
->language
== language_cplus
16173 || cu
->language
== language_d
16174 || cu
->language
== language_rust
)
16176 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16178 /* dwarf2_full_name might have already finished building the DIE's
16179 type. If so, there is no need to continue. */
16180 if (get_die_type (die
, cu
) != NULL
)
16181 return get_die_type (die
, cu
);
16183 TYPE_TAG_NAME (type
) = full_name
;
16184 if (die
->tag
== DW_TAG_structure_type
16185 || die
->tag
== DW_TAG_class_type
)
16186 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16190 /* The name is already allocated along with this objfile, so
16191 we don't need to duplicate it for the type. */
16192 TYPE_TAG_NAME (type
) = name
;
16193 if (die
->tag
== DW_TAG_class_type
)
16194 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16198 if (die
->tag
== DW_TAG_structure_type
)
16200 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16202 else if (die
->tag
== DW_TAG_union_type
)
16204 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16206 else if (die
->tag
== DW_TAG_variant_part
)
16208 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16209 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
16213 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16216 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16217 TYPE_DECLARED_CLASS (type
) = 1;
16219 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16222 if (attr_form_is_constant (attr
))
16223 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16226 /* For the moment, dynamic type sizes are not supported
16227 by GDB's struct type. The actual size is determined
16228 on-demand when resolving the type of a given object,
16229 so set the type's length to zero for now. Otherwise,
16230 we record an expression as the length, and that expression
16231 could lead to a very large value, which could eventually
16232 lead to us trying to allocate that much memory when creating
16233 a value of that type. */
16234 TYPE_LENGTH (type
) = 0;
16239 TYPE_LENGTH (type
) = 0;
16242 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16244 /* ICC<14 does not output the required DW_AT_declaration on
16245 incomplete types, but gives them a size of zero. */
16246 TYPE_STUB (type
) = 1;
16249 TYPE_STUB_SUPPORTED (type
) = 1;
16251 if (die_is_declaration (die
, cu
))
16252 TYPE_STUB (type
) = 1;
16253 else if (attr
== NULL
&& die
->child
== NULL
16254 && producer_is_realview (cu
->producer
))
16255 /* RealView does not output the required DW_AT_declaration
16256 on incomplete types. */
16257 TYPE_STUB (type
) = 1;
16259 /* We need to add the type field to the die immediately so we don't
16260 infinitely recurse when dealing with pointers to the structure
16261 type within the structure itself. */
16262 set_die_type (die
, type
, cu
);
16264 /* set_die_type should be already done. */
16265 set_descriptive_type (type
, die
, cu
);
16270 /* A helper for process_structure_scope that handles a single member
16274 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16275 struct field_info
*fi
,
16276 std::vector
<struct symbol
*> *template_args
,
16277 struct dwarf2_cu
*cu
)
16279 if (child_die
->tag
== DW_TAG_member
16280 || child_die
->tag
== DW_TAG_variable
16281 || child_die
->tag
== DW_TAG_variant_part
)
16283 /* NOTE: carlton/2002-11-05: A C++ static data member
16284 should be a DW_TAG_member that is a declaration, but
16285 all versions of G++ as of this writing (so through at
16286 least 3.2.1) incorrectly generate DW_TAG_variable
16287 tags for them instead. */
16288 dwarf2_add_field (fi
, child_die
, cu
);
16290 else if (child_die
->tag
== DW_TAG_subprogram
)
16292 /* Rust doesn't have member functions in the C++ sense.
16293 However, it does emit ordinary functions as children
16294 of a struct DIE. */
16295 if (cu
->language
== language_rust
)
16296 read_func_scope (child_die
, cu
);
16299 /* C++ member function. */
16300 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16303 else if (child_die
->tag
== DW_TAG_inheritance
)
16305 /* C++ base class field. */
16306 dwarf2_add_field (fi
, child_die
, cu
);
16308 else if (type_can_define_types (child_die
))
16309 dwarf2_add_type_defn (fi
, child_die
, cu
);
16310 else if (child_die
->tag
== DW_TAG_template_type_param
16311 || child_die
->tag
== DW_TAG_template_value_param
)
16313 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16316 template_args
->push_back (arg
);
16318 else if (child_die
->tag
== DW_TAG_variant
)
16320 /* In a variant we want to get the discriminant and also add a
16321 field for our sole member child. */
16322 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16324 for (struct die_info
*variant_child
= child_die
->child
;
16325 variant_child
!= NULL
;
16326 variant_child
= sibling_die (variant_child
))
16328 if (variant_child
->tag
== DW_TAG_member
)
16330 handle_struct_member_die (variant_child
, type
, fi
,
16331 template_args
, cu
);
16332 /* Only handle the one. */
16337 /* We don't handle this but we might as well report it if we see
16339 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16340 complaint (&symfile_complaints
,
16341 _("DW_AT_discr_list is not supported yet"
16342 " - DIE at %s [in module %s]"),
16343 sect_offset_str (child_die
->sect_off
),
16344 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16346 /* The first field was just added, so we can stash the
16347 discriminant there. */
16348 gdb_assert (!fi
->fields
.empty ());
16350 fi
->fields
.back ().variant
.default_branch
= true;
16352 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16356 /* Finish creating a structure or union type, including filling in
16357 its members and creating a symbol for it. */
16360 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16362 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16363 struct die_info
*child_die
;
16366 type
= get_die_type (die
, cu
);
16368 type
= read_structure_type (die
, cu
);
16370 /* When reading a DW_TAG_variant_part, we need to notice when we
16371 read the discriminant member, so we can record it later in the
16372 discriminant_info. */
16373 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16374 sect_offset discr_offset
;
16376 if (is_variant_part
)
16378 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16381 /* Maybe it's a univariant form, an extension we support.
16382 In this case arrange not to check the offset. */
16383 is_variant_part
= false;
16385 else if (attr_form_is_ref (discr
))
16387 struct dwarf2_cu
*target_cu
= cu
;
16388 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16390 discr_offset
= target_die
->sect_off
;
16394 complaint (&symfile_complaints
,
16395 _("DW_AT_discr does not have DIE reference form"
16396 " - DIE at %s [in module %s]"),
16397 sect_offset_str (die
->sect_off
),
16398 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16399 is_variant_part
= false;
16403 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16405 struct field_info fi
;
16406 std::vector
<struct symbol
*> template_args
;
16408 child_die
= die
->child
;
16410 while (child_die
&& child_die
->tag
)
16412 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16414 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16415 fi
.fields
.back ().variant
.is_discriminant
= true;
16417 child_die
= sibling_die (child_die
);
16420 /* Attach template arguments to type. */
16421 if (!template_args
.empty ())
16423 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16424 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16425 TYPE_TEMPLATE_ARGUMENTS (type
)
16426 = XOBNEWVEC (&objfile
->objfile_obstack
,
16428 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16429 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16430 template_args
.data (),
16431 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16432 * sizeof (struct symbol
*)));
16435 /* Attach fields and member functions to the type. */
16437 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16438 if (!fi
.fnfieldlists
.empty ())
16440 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16442 /* Get the type which refers to the base class (possibly this
16443 class itself) which contains the vtable pointer for the current
16444 class from the DW_AT_containing_type attribute. This use of
16445 DW_AT_containing_type is a GNU extension. */
16447 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16449 struct type
*t
= die_containing_type (die
, cu
);
16451 set_type_vptr_basetype (type
, t
);
16456 /* Our own class provides vtbl ptr. */
16457 for (i
= TYPE_NFIELDS (t
) - 1;
16458 i
>= TYPE_N_BASECLASSES (t
);
16461 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16463 if (is_vtable_name (fieldname
, cu
))
16465 set_type_vptr_fieldno (type
, i
);
16470 /* Complain if virtual function table field not found. */
16471 if (i
< TYPE_N_BASECLASSES (t
))
16472 complaint (&symfile_complaints
,
16473 _("virtual function table pointer "
16474 "not found when defining class '%s'"),
16475 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16480 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16483 else if (cu
->producer
16484 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16486 /* The IBM XLC compiler does not provide direct indication
16487 of the containing type, but the vtable pointer is
16488 always named __vfp. */
16492 for (i
= TYPE_NFIELDS (type
) - 1;
16493 i
>= TYPE_N_BASECLASSES (type
);
16496 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16498 set_type_vptr_fieldno (type
, i
);
16499 set_type_vptr_basetype (type
, type
);
16506 /* Copy fi.typedef_field_list linked list elements content into the
16507 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16508 if (!fi
.typedef_field_list
.empty ())
16510 int count
= fi
.typedef_field_list
.size ();
16512 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16513 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16514 = ((struct decl_field
*)
16516 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16517 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16519 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16520 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16523 /* Copy fi.nested_types_list linked list elements content into the
16524 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16525 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16527 int count
= fi
.nested_types_list
.size ();
16529 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16530 TYPE_NESTED_TYPES_ARRAY (type
)
16531 = ((struct decl_field
*)
16532 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16533 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16535 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16536 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16540 quirk_gcc_member_function_pointer (type
, objfile
);
16541 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16542 cu
->rust_unions
.push_back (type
);
16544 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16545 snapshots) has been known to create a die giving a declaration
16546 for a class that has, as a child, a die giving a definition for a
16547 nested class. So we have to process our children even if the
16548 current die is a declaration. Normally, of course, a declaration
16549 won't have any children at all. */
16551 child_die
= die
->child
;
16553 while (child_die
!= NULL
&& child_die
->tag
)
16555 if (child_die
->tag
== DW_TAG_member
16556 || child_die
->tag
== DW_TAG_variable
16557 || child_die
->tag
== DW_TAG_inheritance
16558 || child_die
->tag
== DW_TAG_template_value_param
16559 || child_die
->tag
== DW_TAG_template_type_param
)
16564 process_die (child_die
, cu
);
16566 child_die
= sibling_die (child_die
);
16569 /* Do not consider external references. According to the DWARF standard,
16570 these DIEs are identified by the fact that they have no byte_size
16571 attribute, and a declaration attribute. */
16572 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16573 || !die_is_declaration (die
, cu
))
16574 new_symbol (die
, type
, cu
);
16577 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16578 update TYPE using some information only available in DIE's children. */
16581 update_enumeration_type_from_children (struct die_info
*die
,
16583 struct dwarf2_cu
*cu
)
16585 struct die_info
*child_die
;
16586 int unsigned_enum
= 1;
16590 auto_obstack obstack
;
16592 for (child_die
= die
->child
;
16593 child_die
!= NULL
&& child_die
->tag
;
16594 child_die
= sibling_die (child_die
))
16596 struct attribute
*attr
;
16598 const gdb_byte
*bytes
;
16599 struct dwarf2_locexpr_baton
*baton
;
16602 if (child_die
->tag
!= DW_TAG_enumerator
)
16605 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16609 name
= dwarf2_name (child_die
, cu
);
16611 name
= "<anonymous enumerator>";
16613 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16614 &value
, &bytes
, &baton
);
16620 else if ((mask
& value
) != 0)
16625 /* If we already know that the enum type is neither unsigned, nor
16626 a flag type, no need to look at the rest of the enumerates. */
16627 if (!unsigned_enum
&& !flag_enum
)
16632 TYPE_UNSIGNED (type
) = 1;
16634 TYPE_FLAG_ENUM (type
) = 1;
16637 /* Given a DW_AT_enumeration_type die, set its type. We do not
16638 complete the type's fields yet, or create any symbols. */
16640 static struct type
*
16641 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16643 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16645 struct attribute
*attr
;
16648 /* If the definition of this type lives in .debug_types, read that type.
16649 Don't follow DW_AT_specification though, that will take us back up
16650 the chain and we want to go down. */
16651 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16654 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16656 /* The type's CU may not be the same as CU.
16657 Ensure TYPE is recorded with CU in die_type_hash. */
16658 return set_die_type (die
, type
, cu
);
16661 type
= alloc_type (objfile
);
16663 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16664 name
= dwarf2_full_name (NULL
, die
, cu
);
16666 TYPE_TAG_NAME (type
) = name
;
16668 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16671 struct type
*underlying_type
= die_type (die
, cu
);
16673 TYPE_TARGET_TYPE (type
) = underlying_type
;
16676 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16679 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16683 TYPE_LENGTH (type
) = 0;
16686 /* The enumeration DIE can be incomplete. In Ada, any type can be
16687 declared as private in the package spec, and then defined only
16688 inside the package body. Such types are known as Taft Amendment
16689 Types. When another package uses such a type, an incomplete DIE
16690 may be generated by the compiler. */
16691 if (die_is_declaration (die
, cu
))
16692 TYPE_STUB (type
) = 1;
16694 /* Finish the creation of this type by using the enum's children.
16695 We must call this even when the underlying type has been provided
16696 so that we can determine if we're looking at a "flag" enum. */
16697 update_enumeration_type_from_children (die
, type
, cu
);
16699 /* If this type has an underlying type that is not a stub, then we
16700 may use its attributes. We always use the "unsigned" attribute
16701 in this situation, because ordinarily we guess whether the type
16702 is unsigned -- but the guess can be wrong and the underlying type
16703 can tell us the reality. However, we defer to a local size
16704 attribute if one exists, because this lets the compiler override
16705 the underlying type if needed. */
16706 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16708 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16709 if (TYPE_LENGTH (type
) == 0)
16710 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16713 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16715 return set_die_type (die
, type
, cu
);
16718 /* Given a pointer to a die which begins an enumeration, process all
16719 the dies that define the members of the enumeration, and create the
16720 symbol for the enumeration type.
16722 NOTE: We reverse the order of the element list. */
16725 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16727 struct type
*this_type
;
16729 this_type
= get_die_type (die
, cu
);
16730 if (this_type
== NULL
)
16731 this_type
= read_enumeration_type (die
, cu
);
16733 if (die
->child
!= NULL
)
16735 struct die_info
*child_die
;
16736 struct symbol
*sym
;
16737 struct field
*fields
= NULL
;
16738 int num_fields
= 0;
16741 child_die
= die
->child
;
16742 while (child_die
&& child_die
->tag
)
16744 if (child_die
->tag
!= DW_TAG_enumerator
)
16746 process_die (child_die
, cu
);
16750 name
= dwarf2_name (child_die
, cu
);
16753 sym
= new_symbol (child_die
, this_type
, cu
);
16755 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16757 fields
= (struct field
*)
16759 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16760 * sizeof (struct field
));
16763 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16764 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16765 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16766 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16772 child_die
= sibling_die (child_die
);
16777 TYPE_NFIELDS (this_type
) = num_fields
;
16778 TYPE_FIELDS (this_type
) = (struct field
*)
16779 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16780 memcpy (TYPE_FIELDS (this_type
), fields
,
16781 sizeof (struct field
) * num_fields
);
16786 /* If we are reading an enum from a .debug_types unit, and the enum
16787 is a declaration, and the enum is not the signatured type in the
16788 unit, then we do not want to add a symbol for it. Adding a
16789 symbol would in some cases obscure the true definition of the
16790 enum, giving users an incomplete type when the definition is
16791 actually available. Note that we do not want to do this for all
16792 enums which are just declarations, because C++0x allows forward
16793 enum declarations. */
16794 if (cu
->per_cu
->is_debug_types
16795 && die_is_declaration (die
, cu
))
16797 struct signatured_type
*sig_type
;
16799 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16800 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16801 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16805 new_symbol (die
, this_type
, cu
);
16808 /* Extract all information from a DW_TAG_array_type DIE and put it in
16809 the DIE's type field. For now, this only handles one dimensional
16812 static struct type
*
16813 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16815 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16816 struct die_info
*child_die
;
16818 struct type
*element_type
, *range_type
, *index_type
;
16819 struct attribute
*attr
;
16821 struct dynamic_prop
*byte_stride_prop
= NULL
;
16822 unsigned int bit_stride
= 0;
16824 element_type
= die_type (die
, cu
);
16826 /* The die_type call above may have already set the type for this DIE. */
16827 type
= get_die_type (die
, cu
);
16831 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16837 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16838 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16841 complaint (&symfile_complaints
,
16842 _("unable to read array DW_AT_byte_stride "
16843 " - DIE at %s [in module %s]"),
16844 sect_offset_str (die
->sect_off
),
16845 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16846 /* Ignore this attribute. We will likely not be able to print
16847 arrays of this type correctly, but there is little we can do
16848 to help if we cannot read the attribute's value. */
16849 byte_stride_prop
= NULL
;
16853 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16855 bit_stride
= DW_UNSND (attr
);
16857 /* Irix 6.2 native cc creates array types without children for
16858 arrays with unspecified length. */
16859 if (die
->child
== NULL
)
16861 index_type
= objfile_type (objfile
)->builtin_int
;
16862 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16863 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16864 byte_stride_prop
, bit_stride
);
16865 return set_die_type (die
, type
, cu
);
16868 std::vector
<struct type
*> range_types
;
16869 child_die
= die
->child
;
16870 while (child_die
&& child_die
->tag
)
16872 if (child_die
->tag
== DW_TAG_subrange_type
)
16874 struct type
*child_type
= read_type_die (child_die
, cu
);
16876 if (child_type
!= NULL
)
16878 /* The range type was succesfully read. Save it for the
16879 array type creation. */
16880 range_types
.push_back (child_type
);
16883 child_die
= sibling_die (child_die
);
16886 /* Dwarf2 dimensions are output from left to right, create the
16887 necessary array types in backwards order. */
16889 type
= element_type
;
16891 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16895 while (i
< range_types
.size ())
16896 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16897 byte_stride_prop
, bit_stride
);
16901 size_t ndim
= range_types
.size ();
16903 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16904 byte_stride_prop
, bit_stride
);
16907 /* Understand Dwarf2 support for vector types (like they occur on
16908 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16909 array type. This is not part of the Dwarf2/3 standard yet, but a
16910 custom vendor extension. The main difference between a regular
16911 array and the vector variant is that vectors are passed by value
16913 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16915 make_vector_type (type
);
16917 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16918 implementation may choose to implement triple vectors using this
16920 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16923 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16924 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16926 complaint (&symfile_complaints
,
16927 _("DW_AT_byte_size for array type smaller "
16928 "than the total size of elements"));
16931 name
= dwarf2_name (die
, cu
);
16933 TYPE_NAME (type
) = name
;
16935 /* Install the type in the die. */
16936 set_die_type (die
, type
, cu
);
16938 /* set_die_type should be already done. */
16939 set_descriptive_type (type
, die
, cu
);
16944 static enum dwarf_array_dim_ordering
16945 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16947 struct attribute
*attr
;
16949 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16952 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16954 /* GNU F77 is a special case, as at 08/2004 array type info is the
16955 opposite order to the dwarf2 specification, but data is still
16956 laid out as per normal fortran.
16958 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16959 version checking. */
16961 if (cu
->language
== language_fortran
16962 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16964 return DW_ORD_row_major
;
16967 switch (cu
->language_defn
->la_array_ordering
)
16969 case array_column_major
:
16970 return DW_ORD_col_major
;
16971 case array_row_major
:
16973 return DW_ORD_row_major
;
16977 /* Extract all information from a DW_TAG_set_type DIE and put it in
16978 the DIE's type field. */
16980 static struct type
*
16981 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16983 struct type
*domain_type
, *set_type
;
16984 struct attribute
*attr
;
16986 domain_type
= die_type (die
, cu
);
16988 /* The die_type call above may have already set the type for this DIE. */
16989 set_type
= get_die_type (die
, cu
);
16993 set_type
= create_set_type (NULL
, domain_type
);
16995 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16997 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16999 return set_die_type (die
, set_type
, cu
);
17002 /* A helper for read_common_block that creates a locexpr baton.
17003 SYM is the symbol which we are marking as computed.
17004 COMMON_DIE is the DIE for the common block.
17005 COMMON_LOC is the location expression attribute for the common
17007 MEMBER_LOC is the location expression attribute for the particular
17008 member of the common block that we are processing.
17009 CU is the CU from which the above come. */
17012 mark_common_block_symbol_computed (struct symbol
*sym
,
17013 struct die_info
*common_die
,
17014 struct attribute
*common_loc
,
17015 struct attribute
*member_loc
,
17016 struct dwarf2_cu
*cu
)
17018 struct dwarf2_per_objfile
*dwarf2_per_objfile
17019 = cu
->per_cu
->dwarf2_per_objfile
;
17020 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17021 struct dwarf2_locexpr_baton
*baton
;
17023 unsigned int cu_off
;
17024 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
17025 LONGEST offset
= 0;
17027 gdb_assert (common_loc
&& member_loc
);
17028 gdb_assert (attr_form_is_block (common_loc
));
17029 gdb_assert (attr_form_is_block (member_loc
)
17030 || attr_form_is_constant (member_loc
));
17032 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17033 baton
->per_cu
= cu
->per_cu
;
17034 gdb_assert (baton
->per_cu
);
17036 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17038 if (attr_form_is_constant (member_loc
))
17040 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
17041 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17044 baton
->size
+= DW_BLOCK (member_loc
)->size
;
17046 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17049 *ptr
++ = DW_OP_call4
;
17050 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17051 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17054 if (attr_form_is_constant (member_loc
))
17056 *ptr
++ = DW_OP_addr
;
17057 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17058 ptr
+= cu
->header
.addr_size
;
17062 /* We have to copy the data here, because DW_OP_call4 will only
17063 use a DW_AT_location attribute. */
17064 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
17065 ptr
+= DW_BLOCK (member_loc
)->size
;
17068 *ptr
++ = DW_OP_plus
;
17069 gdb_assert (ptr
- baton
->data
== baton
->size
);
17071 SYMBOL_LOCATION_BATON (sym
) = baton
;
17072 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17075 /* Create appropriate locally-scoped variables for all the
17076 DW_TAG_common_block entries. Also create a struct common_block
17077 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17078 is used to sepate the common blocks name namespace from regular
17082 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17084 struct attribute
*attr
;
17086 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17089 /* Support the .debug_loc offsets. */
17090 if (attr_form_is_block (attr
))
17094 else if (attr_form_is_section_offset (attr
))
17096 dwarf2_complex_location_expr_complaint ();
17101 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17102 "common block member");
17107 if (die
->child
!= NULL
)
17109 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17110 struct die_info
*child_die
;
17111 size_t n_entries
= 0, size
;
17112 struct common_block
*common_block
;
17113 struct symbol
*sym
;
17115 for (child_die
= die
->child
;
17116 child_die
&& child_die
->tag
;
17117 child_die
= sibling_die (child_die
))
17120 size
= (sizeof (struct common_block
)
17121 + (n_entries
- 1) * sizeof (struct symbol
*));
17123 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17125 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17126 common_block
->n_entries
= 0;
17128 for (child_die
= die
->child
;
17129 child_die
&& child_die
->tag
;
17130 child_die
= sibling_die (child_die
))
17132 /* Create the symbol in the DW_TAG_common_block block in the current
17134 sym
= new_symbol (child_die
, NULL
, cu
);
17137 struct attribute
*member_loc
;
17139 common_block
->contents
[common_block
->n_entries
++] = sym
;
17141 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17145 /* GDB has handled this for a long time, but it is
17146 not specified by DWARF. It seems to have been
17147 emitted by gfortran at least as recently as:
17148 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17149 complaint (&symfile_complaints
,
17150 _("Variable in common block has "
17151 "DW_AT_data_member_location "
17152 "- DIE at %s [in module %s]"),
17153 sect_offset_str (child_die
->sect_off
),
17154 objfile_name (objfile
));
17156 if (attr_form_is_section_offset (member_loc
))
17157 dwarf2_complex_location_expr_complaint ();
17158 else if (attr_form_is_constant (member_loc
)
17159 || attr_form_is_block (member_loc
))
17162 mark_common_block_symbol_computed (sym
, die
, attr
,
17166 dwarf2_complex_location_expr_complaint ();
17171 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17172 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17176 /* Create a type for a C++ namespace. */
17178 static struct type
*
17179 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17181 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17182 const char *previous_prefix
, *name
;
17186 /* For extensions, reuse the type of the original namespace. */
17187 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17189 struct die_info
*ext_die
;
17190 struct dwarf2_cu
*ext_cu
= cu
;
17192 ext_die
= dwarf2_extension (die
, &ext_cu
);
17193 type
= read_type_die (ext_die
, ext_cu
);
17195 /* EXT_CU may not be the same as CU.
17196 Ensure TYPE is recorded with CU in die_type_hash. */
17197 return set_die_type (die
, type
, cu
);
17200 name
= namespace_name (die
, &is_anonymous
, cu
);
17202 /* Now build the name of the current namespace. */
17204 previous_prefix
= determine_prefix (die
, cu
);
17205 if (previous_prefix
[0] != '\0')
17206 name
= typename_concat (&objfile
->objfile_obstack
,
17207 previous_prefix
, name
, 0, cu
);
17209 /* Create the type. */
17210 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17211 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17213 return set_die_type (die
, type
, cu
);
17216 /* Read a namespace scope. */
17219 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17221 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17224 /* Add a symbol associated to this if we haven't seen the namespace
17225 before. Also, add a using directive if it's an anonymous
17228 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17232 type
= read_type_die (die
, cu
);
17233 new_symbol (die
, type
, cu
);
17235 namespace_name (die
, &is_anonymous
, cu
);
17238 const char *previous_prefix
= determine_prefix (die
, cu
);
17240 std::vector
<const char *> excludes
;
17241 add_using_directive (using_directives (cu
->language
),
17242 previous_prefix
, TYPE_NAME (type
), NULL
,
17243 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17247 if (die
->child
!= NULL
)
17249 struct die_info
*child_die
= die
->child
;
17251 while (child_die
&& child_die
->tag
)
17253 process_die (child_die
, cu
);
17254 child_die
= sibling_die (child_die
);
17259 /* Read a Fortran module as type. This DIE can be only a declaration used for
17260 imported module. Still we need that type as local Fortran "use ... only"
17261 declaration imports depend on the created type in determine_prefix. */
17263 static struct type
*
17264 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17266 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17267 const char *module_name
;
17270 module_name
= dwarf2_name (die
, cu
);
17272 complaint (&symfile_complaints
,
17273 _("DW_TAG_module has no name, offset %s"),
17274 sect_offset_str (die
->sect_off
));
17275 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17277 /* determine_prefix uses TYPE_TAG_NAME. */
17278 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17280 return set_die_type (die
, type
, cu
);
17283 /* Read a Fortran module. */
17286 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17288 struct die_info
*child_die
= die
->child
;
17291 type
= read_type_die (die
, cu
);
17292 new_symbol (die
, type
, cu
);
17294 while (child_die
&& child_die
->tag
)
17296 process_die (child_die
, cu
);
17297 child_die
= sibling_die (child_die
);
17301 /* Return the name of the namespace represented by DIE. Set
17302 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17305 static const char *
17306 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17308 struct die_info
*current_die
;
17309 const char *name
= NULL
;
17311 /* Loop through the extensions until we find a name. */
17313 for (current_die
= die
;
17314 current_die
!= NULL
;
17315 current_die
= dwarf2_extension (die
, &cu
))
17317 /* We don't use dwarf2_name here so that we can detect the absence
17318 of a name -> anonymous namespace. */
17319 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17325 /* Is it an anonymous namespace? */
17327 *is_anonymous
= (name
== NULL
);
17329 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17334 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17335 the user defined type vector. */
17337 static struct type
*
17338 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17340 struct gdbarch
*gdbarch
17341 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17342 struct comp_unit_head
*cu_header
= &cu
->header
;
17344 struct attribute
*attr_byte_size
;
17345 struct attribute
*attr_address_class
;
17346 int byte_size
, addr_class
;
17347 struct type
*target_type
;
17349 target_type
= die_type (die
, cu
);
17351 /* The die_type call above may have already set the type for this DIE. */
17352 type
= get_die_type (die
, cu
);
17356 type
= lookup_pointer_type (target_type
);
17358 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17359 if (attr_byte_size
)
17360 byte_size
= DW_UNSND (attr_byte_size
);
17362 byte_size
= cu_header
->addr_size
;
17364 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17365 if (attr_address_class
)
17366 addr_class
= DW_UNSND (attr_address_class
);
17368 addr_class
= DW_ADDR_none
;
17370 /* If the pointer size or address class is different than the
17371 default, create a type variant marked as such and set the
17372 length accordingly. */
17373 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
17375 if (gdbarch_address_class_type_flags_p (gdbarch
))
17379 type_flags
= gdbarch_address_class_type_flags
17380 (gdbarch
, byte_size
, addr_class
);
17381 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17383 type
= make_type_with_address_space (type
, type_flags
);
17385 else if (TYPE_LENGTH (type
) != byte_size
)
17387 complaint (&symfile_complaints
,
17388 _("invalid pointer size %d"), byte_size
);
17392 /* Should we also complain about unhandled address classes? */
17396 TYPE_LENGTH (type
) = byte_size
;
17397 return set_die_type (die
, type
, cu
);
17400 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17401 the user defined type vector. */
17403 static struct type
*
17404 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17407 struct type
*to_type
;
17408 struct type
*domain
;
17410 to_type
= die_type (die
, cu
);
17411 domain
= die_containing_type (die
, cu
);
17413 /* The calls above may have already set the type for this DIE. */
17414 type
= get_die_type (die
, cu
);
17418 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17419 type
= lookup_methodptr_type (to_type
);
17420 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17422 struct type
*new_type
17423 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17425 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17426 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17427 TYPE_VARARGS (to_type
));
17428 type
= lookup_methodptr_type (new_type
);
17431 type
= lookup_memberptr_type (to_type
, domain
);
17433 return set_die_type (die
, type
, cu
);
17436 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17437 the user defined type vector. */
17439 static struct type
*
17440 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17441 enum type_code refcode
)
17443 struct comp_unit_head
*cu_header
= &cu
->header
;
17444 struct type
*type
, *target_type
;
17445 struct attribute
*attr
;
17447 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17449 target_type
= die_type (die
, cu
);
17451 /* The die_type call above may have already set the type for this DIE. */
17452 type
= get_die_type (die
, cu
);
17456 type
= lookup_reference_type (target_type
, refcode
);
17457 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17460 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17464 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17466 return set_die_type (die
, type
, cu
);
17469 /* Add the given cv-qualifiers to the element type of the array. GCC
17470 outputs DWARF type qualifiers that apply to an array, not the
17471 element type. But GDB relies on the array element type to carry
17472 the cv-qualifiers. This mimics section 6.7.3 of the C99
17475 static struct type
*
17476 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17477 struct type
*base_type
, int cnst
, int voltl
)
17479 struct type
*el_type
, *inner_array
;
17481 base_type
= copy_type (base_type
);
17482 inner_array
= base_type
;
17484 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17486 TYPE_TARGET_TYPE (inner_array
) =
17487 copy_type (TYPE_TARGET_TYPE (inner_array
));
17488 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17491 el_type
= TYPE_TARGET_TYPE (inner_array
);
17492 cnst
|= TYPE_CONST (el_type
);
17493 voltl
|= TYPE_VOLATILE (el_type
);
17494 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17496 return set_die_type (die
, base_type
, cu
);
17499 static struct type
*
17500 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17502 struct type
*base_type
, *cv_type
;
17504 base_type
= die_type (die
, cu
);
17506 /* The die_type call above may have already set the type for this DIE. */
17507 cv_type
= get_die_type (die
, cu
);
17511 /* In case the const qualifier is applied to an array type, the element type
17512 is so qualified, not the array type (section 6.7.3 of C99). */
17513 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17514 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17516 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17517 return set_die_type (die
, cv_type
, cu
);
17520 static struct type
*
17521 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17523 struct type
*base_type
, *cv_type
;
17525 base_type
= die_type (die
, cu
);
17527 /* The die_type call above may have already set the type for this DIE. */
17528 cv_type
= get_die_type (die
, cu
);
17532 /* In case the volatile qualifier is applied to an array type, the
17533 element type is so qualified, not the array type (section 6.7.3
17535 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17536 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17538 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17539 return set_die_type (die
, cv_type
, cu
);
17542 /* Handle DW_TAG_restrict_type. */
17544 static struct type
*
17545 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17547 struct type
*base_type
, *cv_type
;
17549 base_type
= die_type (die
, cu
);
17551 /* The die_type call above may have already set the type for this DIE. */
17552 cv_type
= get_die_type (die
, cu
);
17556 cv_type
= make_restrict_type (base_type
);
17557 return set_die_type (die
, cv_type
, cu
);
17560 /* Handle DW_TAG_atomic_type. */
17562 static struct type
*
17563 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17565 struct type
*base_type
, *cv_type
;
17567 base_type
= die_type (die
, cu
);
17569 /* The die_type call above may have already set the type for this DIE. */
17570 cv_type
= get_die_type (die
, cu
);
17574 cv_type
= make_atomic_type (base_type
);
17575 return set_die_type (die
, cv_type
, cu
);
17578 /* Extract all information from a DW_TAG_string_type DIE and add to
17579 the user defined type vector. It isn't really a user defined type,
17580 but it behaves like one, with other DIE's using an AT_user_def_type
17581 attribute to reference it. */
17583 static struct type
*
17584 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17586 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17587 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17588 struct type
*type
, *range_type
, *index_type
, *char_type
;
17589 struct attribute
*attr
;
17590 unsigned int length
;
17592 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17595 length
= DW_UNSND (attr
);
17599 /* Check for the DW_AT_byte_size attribute. */
17600 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17603 length
= DW_UNSND (attr
);
17611 index_type
= objfile_type (objfile
)->builtin_int
;
17612 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17613 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17614 type
= create_string_type (NULL
, char_type
, range_type
);
17616 return set_die_type (die
, type
, cu
);
17619 /* Assuming that DIE corresponds to a function, returns nonzero
17620 if the function is prototyped. */
17623 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17625 struct attribute
*attr
;
17627 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17628 if (attr
&& (DW_UNSND (attr
) != 0))
17631 /* The DWARF standard implies that the DW_AT_prototyped attribute
17632 is only meaninful for C, but the concept also extends to other
17633 languages that allow unprototyped functions (Eg: Objective C).
17634 For all other languages, assume that functions are always
17636 if (cu
->language
!= language_c
17637 && cu
->language
!= language_objc
17638 && cu
->language
!= language_opencl
)
17641 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17642 prototyped and unprototyped functions; default to prototyped,
17643 since that is more common in modern code (and RealView warns
17644 about unprototyped functions). */
17645 if (producer_is_realview (cu
->producer
))
17651 /* Handle DIES due to C code like:
17655 int (*funcp)(int a, long l);
17659 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17661 static struct type
*
17662 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17664 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17665 struct type
*type
; /* Type that this function returns. */
17666 struct type
*ftype
; /* Function that returns above type. */
17667 struct attribute
*attr
;
17669 type
= die_type (die
, cu
);
17671 /* The die_type call above may have already set the type for this DIE. */
17672 ftype
= get_die_type (die
, cu
);
17676 ftype
= lookup_function_type (type
);
17678 if (prototyped_function_p (die
, cu
))
17679 TYPE_PROTOTYPED (ftype
) = 1;
17681 /* Store the calling convention in the type if it's available in
17682 the subroutine die. Otherwise set the calling convention to
17683 the default value DW_CC_normal. */
17684 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17686 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17687 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17688 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17690 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17692 /* Record whether the function returns normally to its caller or not
17693 if the DWARF producer set that information. */
17694 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17695 if (attr
&& (DW_UNSND (attr
) != 0))
17696 TYPE_NO_RETURN (ftype
) = 1;
17698 /* We need to add the subroutine type to the die immediately so
17699 we don't infinitely recurse when dealing with parameters
17700 declared as the same subroutine type. */
17701 set_die_type (die
, ftype
, cu
);
17703 if (die
->child
!= NULL
)
17705 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17706 struct die_info
*child_die
;
17707 int nparams
, iparams
;
17709 /* Count the number of parameters.
17710 FIXME: GDB currently ignores vararg functions, but knows about
17711 vararg member functions. */
17713 child_die
= die
->child
;
17714 while (child_die
&& child_die
->tag
)
17716 if (child_die
->tag
== DW_TAG_formal_parameter
)
17718 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17719 TYPE_VARARGS (ftype
) = 1;
17720 child_die
= sibling_die (child_die
);
17723 /* Allocate storage for parameters and fill them in. */
17724 TYPE_NFIELDS (ftype
) = nparams
;
17725 TYPE_FIELDS (ftype
) = (struct field
*)
17726 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17728 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17729 even if we error out during the parameters reading below. */
17730 for (iparams
= 0; iparams
< nparams
; iparams
++)
17731 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17734 child_die
= die
->child
;
17735 while (child_die
&& child_die
->tag
)
17737 if (child_die
->tag
== DW_TAG_formal_parameter
)
17739 struct type
*arg_type
;
17741 /* DWARF version 2 has no clean way to discern C++
17742 static and non-static member functions. G++ helps
17743 GDB by marking the first parameter for non-static
17744 member functions (which is the this pointer) as
17745 artificial. We pass this information to
17746 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17748 DWARF version 3 added DW_AT_object_pointer, which GCC
17749 4.5 does not yet generate. */
17750 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17752 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17754 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17755 arg_type
= die_type (child_die
, cu
);
17757 /* RealView does not mark THIS as const, which the testsuite
17758 expects. GCC marks THIS as const in method definitions,
17759 but not in the class specifications (GCC PR 43053). */
17760 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17761 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17764 struct dwarf2_cu
*arg_cu
= cu
;
17765 const char *name
= dwarf2_name (child_die
, cu
);
17767 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17770 /* If the compiler emits this, use it. */
17771 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17774 else if (name
&& strcmp (name
, "this") == 0)
17775 /* Function definitions will have the argument names. */
17777 else if (name
== NULL
&& iparams
== 0)
17778 /* Declarations may not have the names, so like
17779 elsewhere in GDB, assume an artificial first
17780 argument is "this". */
17784 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17788 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17791 child_die
= sibling_die (child_die
);
17798 static struct type
*
17799 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17801 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17802 const char *name
= NULL
;
17803 struct type
*this_type
, *target_type
;
17805 name
= dwarf2_full_name (NULL
, die
, cu
);
17806 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17807 TYPE_TARGET_STUB (this_type
) = 1;
17808 set_die_type (die
, this_type
, cu
);
17809 target_type
= die_type (die
, cu
);
17810 if (target_type
!= this_type
)
17811 TYPE_TARGET_TYPE (this_type
) = target_type
;
17814 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17815 spec and cause infinite loops in GDB. */
17816 complaint (&symfile_complaints
,
17817 _("Self-referential DW_TAG_typedef "
17818 "- DIE at %s [in module %s]"),
17819 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17820 TYPE_TARGET_TYPE (this_type
) = NULL
;
17825 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17826 (which may be different from NAME) to the architecture back-end to allow
17827 it to guess the correct format if necessary. */
17829 static struct type
*
17830 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17831 const char *name_hint
)
17833 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17834 const struct floatformat
**format
;
17837 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17839 type
= init_float_type (objfile
, bits
, name
, format
);
17841 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17846 /* Find a representation of a given base type and install
17847 it in the TYPE field of the die. */
17849 static struct type
*
17850 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17852 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17854 struct attribute
*attr
;
17855 int encoding
= 0, bits
= 0;
17858 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17861 encoding
= DW_UNSND (attr
);
17863 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17866 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17868 name
= dwarf2_name (die
, cu
);
17871 complaint (&symfile_complaints
,
17872 _("DW_AT_name missing from DW_TAG_base_type"));
17877 case DW_ATE_address
:
17878 /* Turn DW_ATE_address into a void * pointer. */
17879 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17880 type
= init_pointer_type (objfile
, bits
, name
, type
);
17882 case DW_ATE_boolean
:
17883 type
= init_boolean_type (objfile
, bits
, 1, name
);
17885 case DW_ATE_complex_float
:
17886 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17887 type
= init_complex_type (objfile
, name
, type
);
17889 case DW_ATE_decimal_float
:
17890 type
= init_decfloat_type (objfile
, bits
, name
);
17893 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17895 case DW_ATE_signed
:
17896 type
= init_integer_type (objfile
, bits
, 0, name
);
17898 case DW_ATE_unsigned
:
17899 if (cu
->language
== language_fortran
17901 && startswith (name
, "character("))
17902 type
= init_character_type (objfile
, bits
, 1, name
);
17904 type
= init_integer_type (objfile
, bits
, 1, name
);
17906 case DW_ATE_signed_char
:
17907 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17908 || cu
->language
== language_pascal
17909 || cu
->language
== language_fortran
)
17910 type
= init_character_type (objfile
, bits
, 0, name
);
17912 type
= init_integer_type (objfile
, bits
, 0, name
);
17914 case DW_ATE_unsigned_char
:
17915 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17916 || cu
->language
== language_pascal
17917 || cu
->language
== language_fortran
17918 || cu
->language
== language_rust
)
17919 type
= init_character_type (objfile
, bits
, 1, name
);
17921 type
= init_integer_type (objfile
, bits
, 1, name
);
17925 gdbarch
*arch
= get_objfile_arch (objfile
);
17928 type
= builtin_type (arch
)->builtin_char16
;
17929 else if (bits
== 32)
17930 type
= builtin_type (arch
)->builtin_char32
;
17933 complaint (&symfile_complaints
,
17934 _("unsupported DW_ATE_UTF bit size: '%d'"),
17936 type
= init_integer_type (objfile
, bits
, 1, name
);
17938 return set_die_type (die
, type
, cu
);
17943 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17944 dwarf_type_encoding_name (encoding
));
17945 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17949 if (name
&& strcmp (name
, "char") == 0)
17950 TYPE_NOSIGN (type
) = 1;
17952 return set_die_type (die
, type
, cu
);
17955 /* Parse dwarf attribute if it's a block, reference or constant and put the
17956 resulting value of the attribute into struct bound_prop.
17957 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17960 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17961 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17963 struct dwarf2_property_baton
*baton
;
17964 struct obstack
*obstack
17965 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17967 if (attr
== NULL
|| prop
== NULL
)
17970 if (attr_form_is_block (attr
))
17972 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17973 baton
->referenced_type
= NULL
;
17974 baton
->locexpr
.per_cu
= cu
->per_cu
;
17975 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17976 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17977 prop
->data
.baton
= baton
;
17978 prop
->kind
= PROP_LOCEXPR
;
17979 gdb_assert (prop
->data
.baton
!= NULL
);
17981 else if (attr_form_is_ref (attr
))
17983 struct dwarf2_cu
*target_cu
= cu
;
17984 struct die_info
*target_die
;
17985 struct attribute
*target_attr
;
17987 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17988 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17989 if (target_attr
== NULL
)
17990 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17992 if (target_attr
== NULL
)
17995 switch (target_attr
->name
)
17997 case DW_AT_location
:
17998 if (attr_form_is_section_offset (target_attr
))
18000 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18001 baton
->referenced_type
= die_type (target_die
, target_cu
);
18002 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18003 prop
->data
.baton
= baton
;
18004 prop
->kind
= PROP_LOCLIST
;
18005 gdb_assert (prop
->data
.baton
!= NULL
);
18007 else if (attr_form_is_block (target_attr
))
18009 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18010 baton
->referenced_type
= die_type (target_die
, target_cu
);
18011 baton
->locexpr
.per_cu
= cu
->per_cu
;
18012 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
18013 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
18014 prop
->data
.baton
= baton
;
18015 prop
->kind
= PROP_LOCEXPR
;
18016 gdb_assert (prop
->data
.baton
!= NULL
);
18020 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18021 "dynamic property");
18025 case DW_AT_data_member_location
:
18029 if (!handle_data_member_location (target_die
, target_cu
,
18033 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18034 baton
->referenced_type
= read_type_die (target_die
->parent
,
18036 baton
->offset_info
.offset
= offset
;
18037 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18038 prop
->data
.baton
= baton
;
18039 prop
->kind
= PROP_ADDR_OFFSET
;
18044 else if (attr_form_is_constant (attr
))
18046 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18047 prop
->kind
= PROP_CONST
;
18051 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18052 dwarf2_name (die
, cu
));
18059 /* Read the given DW_AT_subrange DIE. */
18061 static struct type
*
18062 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18064 struct type
*base_type
, *orig_base_type
;
18065 struct type
*range_type
;
18066 struct attribute
*attr
;
18067 struct dynamic_prop low
, high
;
18068 int low_default_is_valid
;
18069 int high_bound_is_count
= 0;
18071 LONGEST negative_mask
;
18073 orig_base_type
= die_type (die
, cu
);
18074 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18075 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18076 creating the range type, but we use the result of check_typedef
18077 when examining properties of the type. */
18078 base_type
= check_typedef (orig_base_type
);
18080 /* The die_type call above may have already set the type for this DIE. */
18081 range_type
= get_die_type (die
, cu
);
18085 low
.kind
= PROP_CONST
;
18086 high
.kind
= PROP_CONST
;
18087 high
.data
.const_val
= 0;
18089 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18090 omitting DW_AT_lower_bound. */
18091 switch (cu
->language
)
18094 case language_cplus
:
18095 low
.data
.const_val
= 0;
18096 low_default_is_valid
= 1;
18098 case language_fortran
:
18099 low
.data
.const_val
= 1;
18100 low_default_is_valid
= 1;
18103 case language_objc
:
18104 case language_rust
:
18105 low
.data
.const_val
= 0;
18106 low_default_is_valid
= (cu
->header
.version
>= 4);
18110 case language_pascal
:
18111 low
.data
.const_val
= 1;
18112 low_default_is_valid
= (cu
->header
.version
>= 4);
18115 low
.data
.const_val
= 0;
18116 low_default_is_valid
= 0;
18120 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18122 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
18123 else if (!low_default_is_valid
)
18124 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
18125 "- DIE at %s [in module %s]"),
18126 sect_offset_str (die
->sect_off
),
18127 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18129 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18130 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18132 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
18133 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18135 /* If bounds are constant do the final calculation here. */
18136 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18137 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18139 high_bound_is_count
= 1;
18143 /* Dwarf-2 specifications explicitly allows to create subrange types
18144 without specifying a base type.
18145 In that case, the base type must be set to the type of
18146 the lower bound, upper bound or count, in that order, if any of these
18147 three attributes references an object that has a type.
18148 If no base type is found, the Dwarf-2 specifications say that
18149 a signed integer type of size equal to the size of an address should
18151 For the following C code: `extern char gdb_int [];'
18152 GCC produces an empty range DIE.
18153 FIXME: muller/2010-05-28: Possible references to object for low bound,
18154 high bound or count are not yet handled by this code. */
18155 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
18157 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18158 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18159 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
18160 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
18162 /* Test "int", "long int", and "long long int" objfile types,
18163 and select the first one having a size above or equal to the
18164 architecture address size. */
18165 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18166 base_type
= int_type
;
18169 int_type
= objfile_type (objfile
)->builtin_long
;
18170 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18171 base_type
= int_type
;
18174 int_type
= objfile_type (objfile
)->builtin_long_long
;
18175 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18176 base_type
= int_type
;
18181 /* Normally, the DWARF producers are expected to use a signed
18182 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18183 But this is unfortunately not always the case, as witnessed
18184 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18185 is used instead. To work around that ambiguity, we treat
18186 the bounds as signed, and thus sign-extend their values, when
18187 the base type is signed. */
18189 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18190 if (low
.kind
== PROP_CONST
18191 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18192 low
.data
.const_val
|= negative_mask
;
18193 if (high
.kind
== PROP_CONST
18194 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18195 high
.data
.const_val
|= negative_mask
;
18197 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
18199 if (high_bound_is_count
)
18200 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18202 /* Ada expects an empty array on no boundary attributes. */
18203 if (attr
== NULL
&& cu
->language
!= language_ada
)
18204 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18206 name
= dwarf2_name (die
, cu
);
18208 TYPE_NAME (range_type
) = name
;
18210 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18212 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18214 set_die_type (die
, range_type
, cu
);
18216 /* set_die_type should be already done. */
18217 set_descriptive_type (range_type
, die
, cu
);
18222 static struct type
*
18223 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18227 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18229 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18231 /* In Ada, an unspecified type is typically used when the description
18232 of the type is defered to a different unit. When encountering
18233 such a type, we treat it as a stub, and try to resolve it later on,
18235 if (cu
->language
== language_ada
)
18236 TYPE_STUB (type
) = 1;
18238 return set_die_type (die
, type
, cu
);
18241 /* Read a single die and all its descendents. Set the die's sibling
18242 field to NULL; set other fields in the die correctly, and set all
18243 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18244 location of the info_ptr after reading all of those dies. PARENT
18245 is the parent of the die in question. */
18247 static struct die_info
*
18248 read_die_and_children (const struct die_reader_specs
*reader
,
18249 const gdb_byte
*info_ptr
,
18250 const gdb_byte
**new_info_ptr
,
18251 struct die_info
*parent
)
18253 struct die_info
*die
;
18254 const gdb_byte
*cur_ptr
;
18257 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18260 *new_info_ptr
= cur_ptr
;
18263 store_in_ref_table (die
, reader
->cu
);
18266 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18270 *new_info_ptr
= cur_ptr
;
18273 die
->sibling
= NULL
;
18274 die
->parent
= parent
;
18278 /* Read a die, all of its descendents, and all of its siblings; set
18279 all of the fields of all of the dies correctly. Arguments are as
18280 in read_die_and_children. */
18282 static struct die_info
*
18283 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18284 const gdb_byte
*info_ptr
,
18285 const gdb_byte
**new_info_ptr
,
18286 struct die_info
*parent
)
18288 struct die_info
*first_die
, *last_sibling
;
18289 const gdb_byte
*cur_ptr
;
18291 cur_ptr
= info_ptr
;
18292 first_die
= last_sibling
= NULL
;
18296 struct die_info
*die
18297 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18301 *new_info_ptr
= cur_ptr
;
18308 last_sibling
->sibling
= die
;
18310 last_sibling
= die
;
18314 /* Read a die, all of its descendents, and all of its siblings; set
18315 all of the fields of all of the dies correctly. Arguments are as
18316 in read_die_and_children.
18317 This the main entry point for reading a DIE and all its children. */
18319 static struct die_info
*
18320 read_die_and_siblings (const struct die_reader_specs
*reader
,
18321 const gdb_byte
*info_ptr
,
18322 const gdb_byte
**new_info_ptr
,
18323 struct die_info
*parent
)
18325 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18326 new_info_ptr
, parent
);
18328 if (dwarf_die_debug
)
18330 fprintf_unfiltered (gdb_stdlog
,
18331 "Read die from %s@0x%x of %s:\n",
18332 get_section_name (reader
->die_section
),
18333 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18334 bfd_get_filename (reader
->abfd
));
18335 dump_die (die
, dwarf_die_debug
);
18341 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18343 The caller is responsible for filling in the extra attributes
18344 and updating (*DIEP)->num_attrs.
18345 Set DIEP to point to a newly allocated die with its information,
18346 except for its child, sibling, and parent fields.
18347 Set HAS_CHILDREN to tell whether the die has children or not. */
18349 static const gdb_byte
*
18350 read_full_die_1 (const struct die_reader_specs
*reader
,
18351 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18352 int *has_children
, int num_extra_attrs
)
18354 unsigned int abbrev_number
, bytes_read
, i
;
18355 struct abbrev_info
*abbrev
;
18356 struct die_info
*die
;
18357 struct dwarf2_cu
*cu
= reader
->cu
;
18358 bfd
*abfd
= reader
->abfd
;
18360 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18361 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18362 info_ptr
+= bytes_read
;
18363 if (!abbrev_number
)
18370 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18372 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18374 bfd_get_filename (abfd
));
18376 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18377 die
->sect_off
= sect_off
;
18378 die
->tag
= abbrev
->tag
;
18379 die
->abbrev
= abbrev_number
;
18381 /* Make the result usable.
18382 The caller needs to update num_attrs after adding the extra
18384 die
->num_attrs
= abbrev
->num_attrs
;
18386 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18387 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18391 *has_children
= abbrev
->has_children
;
18395 /* Read a die and all its attributes.
18396 Set DIEP to point to a newly allocated die with its information,
18397 except for its child, sibling, and parent fields.
18398 Set HAS_CHILDREN to tell whether the die has children or not. */
18400 static const gdb_byte
*
18401 read_full_die (const struct die_reader_specs
*reader
,
18402 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18405 const gdb_byte
*result
;
18407 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18409 if (dwarf_die_debug
)
18411 fprintf_unfiltered (gdb_stdlog
,
18412 "Read die from %s@0x%x of %s:\n",
18413 get_section_name (reader
->die_section
),
18414 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18415 bfd_get_filename (reader
->abfd
));
18416 dump_die (*diep
, dwarf_die_debug
);
18422 /* Abbreviation tables.
18424 In DWARF version 2, the description of the debugging information is
18425 stored in a separate .debug_abbrev section. Before we read any
18426 dies from a section we read in all abbreviations and install them
18427 in a hash table. */
18429 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18431 struct abbrev_info
*
18432 abbrev_table::alloc_abbrev ()
18434 struct abbrev_info
*abbrev
;
18436 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18437 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18442 /* Add an abbreviation to the table. */
18445 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18446 struct abbrev_info
*abbrev
)
18448 unsigned int hash_number
;
18450 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18451 abbrev
->next
= m_abbrevs
[hash_number
];
18452 m_abbrevs
[hash_number
] = abbrev
;
18455 /* Look up an abbrev in the table.
18456 Returns NULL if the abbrev is not found. */
18458 struct abbrev_info
*
18459 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18461 unsigned int hash_number
;
18462 struct abbrev_info
*abbrev
;
18464 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18465 abbrev
= m_abbrevs
[hash_number
];
18469 if (abbrev
->number
== abbrev_number
)
18471 abbrev
= abbrev
->next
;
18476 /* Read in an abbrev table. */
18478 static abbrev_table_up
18479 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18480 struct dwarf2_section_info
*section
,
18481 sect_offset sect_off
)
18483 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18484 bfd
*abfd
= get_section_bfd_owner (section
);
18485 const gdb_byte
*abbrev_ptr
;
18486 struct abbrev_info
*cur_abbrev
;
18487 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18488 unsigned int abbrev_form
;
18489 struct attr_abbrev
*cur_attrs
;
18490 unsigned int allocated_attrs
;
18492 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18494 dwarf2_read_section (objfile
, section
);
18495 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18496 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18497 abbrev_ptr
+= bytes_read
;
18499 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18500 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18502 /* Loop until we reach an abbrev number of 0. */
18503 while (abbrev_number
)
18505 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18507 /* read in abbrev header */
18508 cur_abbrev
->number
= abbrev_number
;
18510 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18511 abbrev_ptr
+= bytes_read
;
18512 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18515 /* now read in declarations */
18518 LONGEST implicit_const
;
18520 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18521 abbrev_ptr
+= bytes_read
;
18522 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18523 abbrev_ptr
+= bytes_read
;
18524 if (abbrev_form
== DW_FORM_implicit_const
)
18526 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18528 abbrev_ptr
+= bytes_read
;
18532 /* Initialize it due to a false compiler warning. */
18533 implicit_const
= -1;
18536 if (abbrev_name
== 0)
18539 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18541 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18543 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18546 cur_attrs
[cur_abbrev
->num_attrs
].name
18547 = (enum dwarf_attribute
) abbrev_name
;
18548 cur_attrs
[cur_abbrev
->num_attrs
].form
18549 = (enum dwarf_form
) abbrev_form
;
18550 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18551 ++cur_abbrev
->num_attrs
;
18554 cur_abbrev
->attrs
=
18555 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18556 cur_abbrev
->num_attrs
);
18557 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18558 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18560 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18562 /* Get next abbreviation.
18563 Under Irix6 the abbreviations for a compilation unit are not
18564 always properly terminated with an abbrev number of 0.
18565 Exit loop if we encounter an abbreviation which we have
18566 already read (which means we are about to read the abbreviations
18567 for the next compile unit) or if the end of the abbreviation
18568 table is reached. */
18569 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18571 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18572 abbrev_ptr
+= bytes_read
;
18573 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18578 return abbrev_table
;
18581 /* Returns nonzero if TAG represents a type that we might generate a partial
18585 is_type_tag_for_partial (int tag
)
18590 /* Some types that would be reasonable to generate partial symbols for,
18591 that we don't at present. */
18592 case DW_TAG_array_type
:
18593 case DW_TAG_file_type
:
18594 case DW_TAG_ptr_to_member_type
:
18595 case DW_TAG_set_type
:
18596 case DW_TAG_string_type
:
18597 case DW_TAG_subroutine_type
:
18599 case DW_TAG_base_type
:
18600 case DW_TAG_class_type
:
18601 case DW_TAG_interface_type
:
18602 case DW_TAG_enumeration_type
:
18603 case DW_TAG_structure_type
:
18604 case DW_TAG_subrange_type
:
18605 case DW_TAG_typedef
:
18606 case DW_TAG_union_type
:
18613 /* Load all DIEs that are interesting for partial symbols into memory. */
18615 static struct partial_die_info
*
18616 load_partial_dies (const struct die_reader_specs
*reader
,
18617 const gdb_byte
*info_ptr
, int building_psymtab
)
18619 struct dwarf2_cu
*cu
= reader
->cu
;
18620 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18621 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18622 unsigned int bytes_read
;
18623 unsigned int load_all
= 0;
18624 int nesting_level
= 1;
18629 gdb_assert (cu
->per_cu
!= NULL
);
18630 if (cu
->per_cu
->load_all_dies
)
18634 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18638 &cu
->comp_unit_obstack
,
18639 hashtab_obstack_allocate
,
18640 dummy_obstack_deallocate
);
18644 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18646 /* A NULL abbrev means the end of a series of children. */
18647 if (abbrev
== NULL
)
18649 if (--nesting_level
== 0)
18652 info_ptr
+= bytes_read
;
18653 last_die
= parent_die
;
18654 parent_die
= parent_die
->die_parent
;
18658 /* Check for template arguments. We never save these; if
18659 they're seen, we just mark the parent, and go on our way. */
18660 if (parent_die
!= NULL
18661 && cu
->language
== language_cplus
18662 && (abbrev
->tag
== DW_TAG_template_type_param
18663 || abbrev
->tag
== DW_TAG_template_value_param
))
18665 parent_die
->has_template_arguments
= 1;
18669 /* We don't need a partial DIE for the template argument. */
18670 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18675 /* We only recurse into c++ subprograms looking for template arguments.
18676 Skip their other children. */
18678 && cu
->language
== language_cplus
18679 && parent_die
!= NULL
18680 && parent_die
->tag
== DW_TAG_subprogram
)
18682 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18686 /* Check whether this DIE is interesting enough to save. Normally
18687 we would not be interested in members here, but there may be
18688 later variables referencing them via DW_AT_specification (for
18689 static members). */
18691 && !is_type_tag_for_partial (abbrev
->tag
)
18692 && abbrev
->tag
!= DW_TAG_constant
18693 && abbrev
->tag
!= DW_TAG_enumerator
18694 && abbrev
->tag
!= DW_TAG_subprogram
18695 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18696 && abbrev
->tag
!= DW_TAG_lexical_block
18697 && abbrev
->tag
!= DW_TAG_variable
18698 && abbrev
->tag
!= DW_TAG_namespace
18699 && abbrev
->tag
!= DW_TAG_module
18700 && abbrev
->tag
!= DW_TAG_member
18701 && abbrev
->tag
!= DW_TAG_imported_unit
18702 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18704 /* Otherwise we skip to the next sibling, if any. */
18705 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18709 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18712 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18714 /* This two-pass algorithm for processing partial symbols has a
18715 high cost in cache pressure. Thus, handle some simple cases
18716 here which cover the majority of C partial symbols. DIEs
18717 which neither have specification tags in them, nor could have
18718 specification tags elsewhere pointing at them, can simply be
18719 processed and discarded.
18721 This segment is also optional; scan_partial_symbols and
18722 add_partial_symbol will handle these DIEs if we chain
18723 them in normally. When compilers which do not emit large
18724 quantities of duplicate debug information are more common,
18725 this code can probably be removed. */
18727 /* Any complete simple types at the top level (pretty much all
18728 of them, for a language without namespaces), can be processed
18730 if (parent_die
== NULL
18731 && pdi
.has_specification
== 0
18732 && pdi
.is_declaration
== 0
18733 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18734 || pdi
.tag
== DW_TAG_base_type
18735 || pdi
.tag
== DW_TAG_subrange_type
))
18737 if (building_psymtab
&& pdi
.name
!= NULL
)
18738 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18739 VAR_DOMAIN
, LOC_TYPEDEF
,
18740 &objfile
->static_psymbols
,
18741 0, cu
->language
, objfile
);
18742 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18746 /* The exception for DW_TAG_typedef with has_children above is
18747 a workaround of GCC PR debug/47510. In the case of this complaint
18748 type_name_no_tag_or_error will error on such types later.
18750 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18751 it could not find the child DIEs referenced later, this is checked
18752 above. In correct DWARF DW_TAG_typedef should have no children. */
18754 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18755 complaint (&symfile_complaints
,
18756 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18757 "- DIE at %s [in module %s]"),
18758 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18760 /* If we're at the second level, and we're an enumerator, and
18761 our parent has no specification (meaning possibly lives in a
18762 namespace elsewhere), then we can add the partial symbol now
18763 instead of queueing it. */
18764 if (pdi
.tag
== DW_TAG_enumerator
18765 && parent_die
!= NULL
18766 && parent_die
->die_parent
== NULL
18767 && parent_die
->tag
== DW_TAG_enumeration_type
18768 && parent_die
->has_specification
== 0)
18770 if (pdi
.name
== NULL
)
18771 complaint (&symfile_complaints
,
18772 _("malformed enumerator DIE ignored"));
18773 else if (building_psymtab
)
18774 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18775 VAR_DOMAIN
, LOC_CONST
,
18776 cu
->language
== language_cplus
18777 ? &objfile
->global_psymbols
18778 : &objfile
->static_psymbols
,
18779 0, cu
->language
, objfile
);
18781 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18785 struct partial_die_info
*part_die
18786 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18788 /* We'll save this DIE so link it in. */
18789 part_die
->die_parent
= parent_die
;
18790 part_die
->die_sibling
= NULL
;
18791 part_die
->die_child
= NULL
;
18793 if (last_die
&& last_die
== parent_die
)
18794 last_die
->die_child
= part_die
;
18796 last_die
->die_sibling
= part_die
;
18798 last_die
= part_die
;
18800 if (first_die
== NULL
)
18801 first_die
= part_die
;
18803 /* Maybe add the DIE to the hash table. Not all DIEs that we
18804 find interesting need to be in the hash table, because we
18805 also have the parent/sibling/child chains; only those that we
18806 might refer to by offset later during partial symbol reading.
18808 For now this means things that might have be the target of a
18809 DW_AT_specification, DW_AT_abstract_origin, or
18810 DW_AT_extension. DW_AT_extension will refer only to
18811 namespaces; DW_AT_abstract_origin refers to functions (and
18812 many things under the function DIE, but we do not recurse
18813 into function DIEs during partial symbol reading) and
18814 possibly variables as well; DW_AT_specification refers to
18815 declarations. Declarations ought to have the DW_AT_declaration
18816 flag. It happens that GCC forgets to put it in sometimes, but
18817 only for functions, not for types.
18819 Adding more things than necessary to the hash table is harmless
18820 except for the performance cost. Adding too few will result in
18821 wasted time in find_partial_die, when we reread the compilation
18822 unit with load_all_dies set. */
18825 || abbrev
->tag
== DW_TAG_constant
18826 || abbrev
->tag
== DW_TAG_subprogram
18827 || abbrev
->tag
== DW_TAG_variable
18828 || abbrev
->tag
== DW_TAG_namespace
18829 || part_die
->is_declaration
)
18833 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18834 to_underlying (part_die
->sect_off
),
18839 /* For some DIEs we want to follow their children (if any). For C
18840 we have no reason to follow the children of structures; for other
18841 languages we have to, so that we can get at method physnames
18842 to infer fully qualified class names, for DW_AT_specification,
18843 and for C++ template arguments. For C++, we also look one level
18844 inside functions to find template arguments (if the name of the
18845 function does not already contain the template arguments).
18847 For Ada, we need to scan the children of subprograms and lexical
18848 blocks as well because Ada allows the definition of nested
18849 entities that could be interesting for the debugger, such as
18850 nested subprograms for instance. */
18851 if (last_die
->has_children
18853 || last_die
->tag
== DW_TAG_namespace
18854 || last_die
->tag
== DW_TAG_module
18855 || last_die
->tag
== DW_TAG_enumeration_type
18856 || (cu
->language
== language_cplus
18857 && last_die
->tag
== DW_TAG_subprogram
18858 && (last_die
->name
== NULL
18859 || strchr (last_die
->name
, '<') == NULL
))
18860 || (cu
->language
!= language_c
18861 && (last_die
->tag
== DW_TAG_class_type
18862 || last_die
->tag
== DW_TAG_interface_type
18863 || last_die
->tag
== DW_TAG_structure_type
18864 || last_die
->tag
== DW_TAG_union_type
))
18865 || (cu
->language
== language_ada
18866 && (last_die
->tag
== DW_TAG_subprogram
18867 || last_die
->tag
== DW_TAG_lexical_block
))))
18870 parent_die
= last_die
;
18874 /* Otherwise we skip to the next sibling, if any. */
18875 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18877 /* Back to the top, do it again. */
18881 partial_die_info::partial_die_info (sect_offset sect_off_
,
18882 struct abbrev_info
*abbrev
)
18883 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18887 /* Read a minimal amount of information into the minimal die structure.
18888 INFO_PTR should point just after the initial uleb128 of a DIE. */
18891 partial_die_info::read (const struct die_reader_specs
*reader
,
18892 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18894 struct dwarf2_cu
*cu
= reader
->cu
;
18895 struct dwarf2_per_objfile
*dwarf2_per_objfile
18896 = cu
->per_cu
->dwarf2_per_objfile
;
18898 int has_low_pc_attr
= 0;
18899 int has_high_pc_attr
= 0;
18900 int high_pc_relative
= 0;
18902 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18904 struct attribute attr
;
18906 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18908 /* Store the data if it is of an attribute we want to keep in a
18909 partial symbol table. */
18915 case DW_TAG_compile_unit
:
18916 case DW_TAG_partial_unit
:
18917 case DW_TAG_type_unit
:
18918 /* Compilation units have a DW_AT_name that is a filename, not
18919 a source language identifier. */
18920 case DW_TAG_enumeration_type
:
18921 case DW_TAG_enumerator
:
18922 /* These tags always have simple identifiers already; no need
18923 to canonicalize them. */
18924 name
= DW_STRING (&attr
);
18928 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18931 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18932 &objfile
->per_bfd
->storage_obstack
);
18937 case DW_AT_linkage_name
:
18938 case DW_AT_MIPS_linkage_name
:
18939 /* Note that both forms of linkage name might appear. We
18940 assume they will be the same, and we only store the last
18942 if (cu
->language
== language_ada
)
18943 name
= DW_STRING (&attr
);
18944 linkage_name
= DW_STRING (&attr
);
18947 has_low_pc_attr
= 1;
18948 lowpc
= attr_value_as_address (&attr
);
18950 case DW_AT_high_pc
:
18951 has_high_pc_attr
= 1;
18952 highpc
= attr_value_as_address (&attr
);
18953 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18954 high_pc_relative
= 1;
18956 case DW_AT_location
:
18957 /* Support the .debug_loc offsets. */
18958 if (attr_form_is_block (&attr
))
18960 d
.locdesc
= DW_BLOCK (&attr
);
18962 else if (attr_form_is_section_offset (&attr
))
18964 dwarf2_complex_location_expr_complaint ();
18968 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18969 "partial symbol information");
18972 case DW_AT_external
:
18973 is_external
= DW_UNSND (&attr
);
18975 case DW_AT_declaration
:
18976 is_declaration
= DW_UNSND (&attr
);
18981 case DW_AT_abstract_origin
:
18982 case DW_AT_specification
:
18983 case DW_AT_extension
:
18984 has_specification
= 1;
18985 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18986 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18987 || cu
->per_cu
->is_dwz
);
18989 case DW_AT_sibling
:
18990 /* Ignore absolute siblings, they might point outside of
18991 the current compile unit. */
18992 if (attr
.form
== DW_FORM_ref_addr
)
18993 complaint (&symfile_complaints
,
18994 _("ignoring absolute DW_AT_sibling"));
18997 const gdb_byte
*buffer
= reader
->buffer
;
18998 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18999 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19001 if (sibling_ptr
< info_ptr
)
19002 complaint (&symfile_complaints
,
19003 _("DW_AT_sibling points backwards"));
19004 else if (sibling_ptr
> reader
->buffer_end
)
19005 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19007 sibling
= sibling_ptr
;
19010 case DW_AT_byte_size
:
19013 case DW_AT_const_value
:
19014 has_const_value
= 1;
19016 case DW_AT_calling_convention
:
19017 /* DWARF doesn't provide a way to identify a program's source-level
19018 entry point. DW_AT_calling_convention attributes are only meant
19019 to describe functions' calling conventions.
19021 However, because it's a necessary piece of information in
19022 Fortran, and before DWARF 4 DW_CC_program was the only
19023 piece of debugging information whose definition refers to
19024 a 'main program' at all, several compilers marked Fortran
19025 main programs with DW_CC_program --- even when those
19026 functions use the standard calling conventions.
19028 Although DWARF now specifies a way to provide this
19029 information, we support this practice for backward
19031 if (DW_UNSND (&attr
) == DW_CC_program
19032 && cu
->language
== language_fortran
)
19033 main_subprogram
= 1;
19036 if (DW_UNSND (&attr
) == DW_INL_inlined
19037 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19038 may_be_inlined
= 1;
19042 if (tag
== DW_TAG_imported_unit
)
19044 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19045 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19046 || cu
->per_cu
->is_dwz
);
19050 case DW_AT_main_subprogram
:
19051 main_subprogram
= DW_UNSND (&attr
);
19059 if (high_pc_relative
)
19062 if (has_low_pc_attr
&& has_high_pc_attr
)
19064 /* When using the GNU linker, .gnu.linkonce. sections are used to
19065 eliminate duplicate copies of functions and vtables and such.
19066 The linker will arbitrarily choose one and discard the others.
19067 The AT_*_pc values for such functions refer to local labels in
19068 these sections. If the section from that file was discarded, the
19069 labels are not in the output, so the relocs get a value of 0.
19070 If this is a discarded function, mark the pc bounds as invalid,
19071 so that GDB will ignore it. */
19072 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19074 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19075 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19077 complaint (&symfile_complaints
,
19078 _("DW_AT_low_pc %s is zero "
19079 "for DIE at %s [in module %s]"),
19080 paddress (gdbarch
, lowpc
),
19081 sect_offset_str (sect_off
),
19082 objfile_name (objfile
));
19084 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19085 else if (lowpc
>= highpc
)
19087 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19088 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19090 complaint (&symfile_complaints
,
19091 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19092 "for DIE at %s [in module %s]"),
19093 paddress (gdbarch
, lowpc
),
19094 paddress (gdbarch
, highpc
),
19095 sect_offset_str (sect_off
),
19096 objfile_name (objfile
));
19105 /* Find a cached partial DIE at OFFSET in CU. */
19107 struct partial_die_info
*
19108 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19110 struct partial_die_info
*lookup_die
= NULL
;
19111 struct partial_die_info
part_die (sect_off
);
19113 lookup_die
= ((struct partial_die_info
*)
19114 htab_find_with_hash (partial_dies
, &part_die
,
19115 to_underlying (sect_off
)));
19120 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19121 except in the case of .debug_types DIEs which do not reference
19122 outside their CU (they do however referencing other types via
19123 DW_FORM_ref_sig8). */
19125 static struct partial_die_info
*
19126 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19128 struct dwarf2_per_objfile
*dwarf2_per_objfile
19129 = cu
->per_cu
->dwarf2_per_objfile
;
19130 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19131 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19132 struct partial_die_info
*pd
= NULL
;
19134 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19135 && offset_in_cu_p (&cu
->header
, sect_off
))
19137 pd
= cu
->find_partial_die (sect_off
);
19140 /* We missed recording what we needed.
19141 Load all dies and try again. */
19142 per_cu
= cu
->per_cu
;
19146 /* TUs don't reference other CUs/TUs (except via type signatures). */
19147 if (cu
->per_cu
->is_debug_types
)
19149 error (_("Dwarf Error: Type Unit at offset %s contains"
19150 " external reference to offset %s [in module %s].\n"),
19151 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19152 bfd_get_filename (objfile
->obfd
));
19154 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19155 dwarf2_per_objfile
);
19157 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19158 load_partial_comp_unit (per_cu
);
19160 per_cu
->cu
->last_used
= 0;
19161 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19164 /* If we didn't find it, and not all dies have been loaded,
19165 load them all and try again. */
19167 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19169 per_cu
->load_all_dies
= 1;
19171 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19172 THIS_CU->cu may already be in use. So we can't just free it and
19173 replace its DIEs with the ones we read in. Instead, we leave those
19174 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19175 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19177 load_partial_comp_unit (per_cu
);
19179 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19183 internal_error (__FILE__
, __LINE__
,
19184 _("could not find partial DIE %s "
19185 "in cache [from module %s]\n"),
19186 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19190 /* See if we can figure out if the class lives in a namespace. We do
19191 this by looking for a member function; its demangled name will
19192 contain namespace info, if there is any. */
19195 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19196 struct dwarf2_cu
*cu
)
19198 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19199 what template types look like, because the demangler
19200 frequently doesn't give the same name as the debug info. We
19201 could fix this by only using the demangled name to get the
19202 prefix (but see comment in read_structure_type). */
19204 struct partial_die_info
*real_pdi
;
19205 struct partial_die_info
*child_pdi
;
19207 /* If this DIE (this DIE's specification, if any) has a parent, then
19208 we should not do this. We'll prepend the parent's fully qualified
19209 name when we create the partial symbol. */
19211 real_pdi
= struct_pdi
;
19212 while (real_pdi
->has_specification
)
19213 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
19214 real_pdi
->spec_is_dwz
, cu
);
19216 if (real_pdi
->die_parent
!= NULL
)
19219 for (child_pdi
= struct_pdi
->die_child
;
19221 child_pdi
= child_pdi
->die_sibling
)
19223 if (child_pdi
->tag
== DW_TAG_subprogram
19224 && child_pdi
->linkage_name
!= NULL
)
19226 char *actual_class_name
19227 = language_class_name_from_physname (cu
->language_defn
,
19228 child_pdi
->linkage_name
);
19229 if (actual_class_name
!= NULL
)
19231 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19234 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19236 strlen (actual_class_name
)));
19237 xfree (actual_class_name
);
19245 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19247 /* Once we've fixed up a die, there's no point in doing so again.
19248 This also avoids a memory leak if we were to call
19249 guess_partial_die_structure_name multiple times. */
19253 /* If we found a reference attribute and the DIE has no name, try
19254 to find a name in the referred to DIE. */
19256 if (name
== NULL
&& has_specification
)
19258 struct partial_die_info
*spec_die
;
19260 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19262 spec_die
->fixup (cu
);
19264 if (spec_die
->name
)
19266 name
= spec_die
->name
;
19268 /* Copy DW_AT_external attribute if it is set. */
19269 if (spec_die
->is_external
)
19270 is_external
= spec_die
->is_external
;
19274 /* Set default names for some unnamed DIEs. */
19276 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19277 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19279 /* If there is no parent die to provide a namespace, and there are
19280 children, see if we can determine the namespace from their linkage
19282 if (cu
->language
== language_cplus
19283 && !VEC_empty (dwarf2_section_info_def
,
19284 cu
->per_cu
->dwarf2_per_objfile
->types
)
19285 && die_parent
== NULL
19287 && (tag
== DW_TAG_class_type
19288 || tag
== DW_TAG_structure_type
19289 || tag
== DW_TAG_union_type
))
19290 guess_partial_die_structure_name (this, cu
);
19292 /* GCC might emit a nameless struct or union that has a linkage
19293 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19295 && (tag
== DW_TAG_class_type
19296 || tag
== DW_TAG_interface_type
19297 || tag
== DW_TAG_structure_type
19298 || tag
== DW_TAG_union_type
)
19299 && linkage_name
!= NULL
)
19303 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19308 /* Strip any leading namespaces/classes, keep only the base name.
19309 DW_AT_name for named DIEs does not contain the prefixes. */
19310 base
= strrchr (demangled
, ':');
19311 if (base
&& base
> demangled
&& base
[-1] == ':')
19316 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19319 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19320 base
, strlen (base
)));
19328 /* Read an attribute value described by an attribute form. */
19330 static const gdb_byte
*
19331 read_attribute_value (const struct die_reader_specs
*reader
,
19332 struct attribute
*attr
, unsigned form
,
19333 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19335 struct dwarf2_cu
*cu
= reader
->cu
;
19336 struct dwarf2_per_objfile
*dwarf2_per_objfile
19337 = cu
->per_cu
->dwarf2_per_objfile
;
19338 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19339 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19340 bfd
*abfd
= reader
->abfd
;
19341 struct comp_unit_head
*cu_header
= &cu
->header
;
19342 unsigned int bytes_read
;
19343 struct dwarf_block
*blk
;
19345 attr
->form
= (enum dwarf_form
) form
;
19348 case DW_FORM_ref_addr
:
19349 if (cu
->header
.version
== 2)
19350 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19352 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19353 &cu
->header
, &bytes_read
);
19354 info_ptr
+= bytes_read
;
19356 case DW_FORM_GNU_ref_alt
:
19357 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19358 info_ptr
+= bytes_read
;
19361 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19362 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19363 info_ptr
+= bytes_read
;
19365 case DW_FORM_block2
:
19366 blk
= dwarf_alloc_block (cu
);
19367 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19369 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19370 info_ptr
+= blk
->size
;
19371 DW_BLOCK (attr
) = blk
;
19373 case DW_FORM_block4
:
19374 blk
= dwarf_alloc_block (cu
);
19375 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19377 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19378 info_ptr
+= blk
->size
;
19379 DW_BLOCK (attr
) = blk
;
19381 case DW_FORM_data2
:
19382 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19385 case DW_FORM_data4
:
19386 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19389 case DW_FORM_data8
:
19390 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19393 case DW_FORM_data16
:
19394 blk
= dwarf_alloc_block (cu
);
19396 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19398 DW_BLOCK (attr
) = blk
;
19400 case DW_FORM_sec_offset
:
19401 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19402 info_ptr
+= bytes_read
;
19404 case DW_FORM_string
:
19405 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19406 DW_STRING_IS_CANONICAL (attr
) = 0;
19407 info_ptr
+= bytes_read
;
19410 if (!cu
->per_cu
->is_dwz
)
19412 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19413 abfd
, info_ptr
, cu_header
,
19415 DW_STRING_IS_CANONICAL (attr
) = 0;
19416 info_ptr
+= bytes_read
;
19420 case DW_FORM_line_strp
:
19421 if (!cu
->per_cu
->is_dwz
)
19423 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19425 cu_header
, &bytes_read
);
19426 DW_STRING_IS_CANONICAL (attr
) = 0;
19427 info_ptr
+= bytes_read
;
19431 case DW_FORM_GNU_strp_alt
:
19433 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19434 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19437 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19439 DW_STRING_IS_CANONICAL (attr
) = 0;
19440 info_ptr
+= bytes_read
;
19443 case DW_FORM_exprloc
:
19444 case DW_FORM_block
:
19445 blk
= dwarf_alloc_block (cu
);
19446 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19447 info_ptr
+= bytes_read
;
19448 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19449 info_ptr
+= blk
->size
;
19450 DW_BLOCK (attr
) = blk
;
19452 case DW_FORM_block1
:
19453 blk
= dwarf_alloc_block (cu
);
19454 blk
->size
= read_1_byte (abfd
, info_ptr
);
19456 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19457 info_ptr
+= blk
->size
;
19458 DW_BLOCK (attr
) = blk
;
19460 case DW_FORM_data1
:
19461 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19465 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19468 case DW_FORM_flag_present
:
19469 DW_UNSND (attr
) = 1;
19471 case DW_FORM_sdata
:
19472 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19473 info_ptr
+= bytes_read
;
19475 case DW_FORM_udata
:
19476 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19477 info_ptr
+= bytes_read
;
19480 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19481 + read_1_byte (abfd
, info_ptr
));
19485 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19486 + read_2_bytes (abfd
, info_ptr
));
19490 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19491 + read_4_bytes (abfd
, info_ptr
));
19495 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19496 + read_8_bytes (abfd
, info_ptr
));
19499 case DW_FORM_ref_sig8
:
19500 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19503 case DW_FORM_ref_udata
:
19504 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19505 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19506 info_ptr
+= bytes_read
;
19508 case DW_FORM_indirect
:
19509 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19510 info_ptr
+= bytes_read
;
19511 if (form
== DW_FORM_implicit_const
)
19513 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19514 info_ptr
+= bytes_read
;
19516 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19519 case DW_FORM_implicit_const
:
19520 DW_SND (attr
) = implicit_const
;
19522 case DW_FORM_GNU_addr_index
:
19523 if (reader
->dwo_file
== NULL
)
19525 /* For now flag a hard error.
19526 Later we can turn this into a complaint. */
19527 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19528 dwarf_form_name (form
),
19529 bfd_get_filename (abfd
));
19531 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19532 info_ptr
+= bytes_read
;
19534 case DW_FORM_GNU_str_index
:
19535 if (reader
->dwo_file
== NULL
)
19537 /* For now flag a hard error.
19538 Later we can turn this into a complaint if warranted. */
19539 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19540 dwarf_form_name (form
),
19541 bfd_get_filename (abfd
));
19544 ULONGEST str_index
=
19545 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19547 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19548 DW_STRING_IS_CANONICAL (attr
) = 0;
19549 info_ptr
+= bytes_read
;
19553 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19554 dwarf_form_name (form
),
19555 bfd_get_filename (abfd
));
19559 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19560 attr
->form
= DW_FORM_GNU_ref_alt
;
19562 /* We have seen instances where the compiler tried to emit a byte
19563 size attribute of -1 which ended up being encoded as an unsigned
19564 0xffffffff. Although 0xffffffff is technically a valid size value,
19565 an object of this size seems pretty unlikely so we can relatively
19566 safely treat these cases as if the size attribute was invalid and
19567 treat them as zero by default. */
19568 if (attr
->name
== DW_AT_byte_size
19569 && form
== DW_FORM_data4
19570 && DW_UNSND (attr
) >= 0xffffffff)
19573 (&symfile_complaints
,
19574 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19575 hex_string (DW_UNSND (attr
)));
19576 DW_UNSND (attr
) = 0;
19582 /* Read an attribute described by an abbreviated attribute. */
19584 static const gdb_byte
*
19585 read_attribute (const struct die_reader_specs
*reader
,
19586 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19587 const gdb_byte
*info_ptr
)
19589 attr
->name
= abbrev
->name
;
19590 return read_attribute_value (reader
, attr
, abbrev
->form
,
19591 abbrev
->implicit_const
, info_ptr
);
19594 /* Read dwarf information from a buffer. */
19596 static unsigned int
19597 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19599 return bfd_get_8 (abfd
, buf
);
19603 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19605 return bfd_get_signed_8 (abfd
, buf
);
19608 static unsigned int
19609 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19611 return bfd_get_16 (abfd
, buf
);
19615 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19617 return bfd_get_signed_16 (abfd
, buf
);
19620 static unsigned int
19621 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19623 return bfd_get_32 (abfd
, buf
);
19627 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19629 return bfd_get_signed_32 (abfd
, buf
);
19633 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19635 return bfd_get_64 (abfd
, buf
);
19639 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19640 unsigned int *bytes_read
)
19642 struct comp_unit_head
*cu_header
= &cu
->header
;
19643 CORE_ADDR retval
= 0;
19645 if (cu_header
->signed_addr_p
)
19647 switch (cu_header
->addr_size
)
19650 retval
= bfd_get_signed_16 (abfd
, buf
);
19653 retval
= bfd_get_signed_32 (abfd
, buf
);
19656 retval
= bfd_get_signed_64 (abfd
, buf
);
19659 internal_error (__FILE__
, __LINE__
,
19660 _("read_address: bad switch, signed [in module %s]"),
19661 bfd_get_filename (abfd
));
19666 switch (cu_header
->addr_size
)
19669 retval
= bfd_get_16 (abfd
, buf
);
19672 retval
= bfd_get_32 (abfd
, buf
);
19675 retval
= bfd_get_64 (abfd
, buf
);
19678 internal_error (__FILE__
, __LINE__
,
19679 _("read_address: bad switch, "
19680 "unsigned [in module %s]"),
19681 bfd_get_filename (abfd
));
19685 *bytes_read
= cu_header
->addr_size
;
19689 /* Read the initial length from a section. The (draft) DWARF 3
19690 specification allows the initial length to take up either 4 bytes
19691 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19692 bytes describe the length and all offsets will be 8 bytes in length
19695 An older, non-standard 64-bit format is also handled by this
19696 function. The older format in question stores the initial length
19697 as an 8-byte quantity without an escape value. Lengths greater
19698 than 2^32 aren't very common which means that the initial 4 bytes
19699 is almost always zero. Since a length value of zero doesn't make
19700 sense for the 32-bit format, this initial zero can be considered to
19701 be an escape value which indicates the presence of the older 64-bit
19702 format. As written, the code can't detect (old format) lengths
19703 greater than 4GB. If it becomes necessary to handle lengths
19704 somewhat larger than 4GB, we could allow other small values (such
19705 as the non-sensical values of 1, 2, and 3) to also be used as
19706 escape values indicating the presence of the old format.
19708 The value returned via bytes_read should be used to increment the
19709 relevant pointer after calling read_initial_length().
19711 [ Note: read_initial_length() and read_offset() are based on the
19712 document entitled "DWARF Debugging Information Format", revision
19713 3, draft 8, dated November 19, 2001. This document was obtained
19716 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19718 This document is only a draft and is subject to change. (So beware.)
19720 Details regarding the older, non-standard 64-bit format were
19721 determined empirically by examining 64-bit ELF files produced by
19722 the SGI toolchain on an IRIX 6.5 machine.
19724 - Kevin, July 16, 2002
19728 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19730 LONGEST length
= bfd_get_32 (abfd
, buf
);
19732 if (length
== 0xffffffff)
19734 length
= bfd_get_64 (abfd
, buf
+ 4);
19737 else if (length
== 0)
19739 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19740 length
= bfd_get_64 (abfd
, buf
);
19751 /* Cover function for read_initial_length.
19752 Returns the length of the object at BUF, and stores the size of the
19753 initial length in *BYTES_READ and stores the size that offsets will be in
19755 If the initial length size is not equivalent to that specified in
19756 CU_HEADER then issue a complaint.
19757 This is useful when reading non-comp-unit headers. */
19760 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19761 const struct comp_unit_head
*cu_header
,
19762 unsigned int *bytes_read
,
19763 unsigned int *offset_size
)
19765 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19767 gdb_assert (cu_header
->initial_length_size
== 4
19768 || cu_header
->initial_length_size
== 8
19769 || cu_header
->initial_length_size
== 12);
19771 if (cu_header
->initial_length_size
!= *bytes_read
)
19772 complaint (&symfile_complaints
,
19773 _("intermixed 32-bit and 64-bit DWARF sections"));
19775 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19779 /* Read an offset from the data stream. The size of the offset is
19780 given by cu_header->offset_size. */
19783 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19784 const struct comp_unit_head
*cu_header
,
19785 unsigned int *bytes_read
)
19787 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19789 *bytes_read
= cu_header
->offset_size
;
19793 /* Read an offset from the data stream. */
19796 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19798 LONGEST retval
= 0;
19800 switch (offset_size
)
19803 retval
= bfd_get_32 (abfd
, buf
);
19806 retval
= bfd_get_64 (abfd
, buf
);
19809 internal_error (__FILE__
, __LINE__
,
19810 _("read_offset_1: bad switch [in module %s]"),
19811 bfd_get_filename (abfd
));
19817 static const gdb_byte
*
19818 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19820 /* If the size of a host char is 8 bits, we can return a pointer
19821 to the buffer, otherwise we have to copy the data to a buffer
19822 allocated on the temporary obstack. */
19823 gdb_assert (HOST_CHAR_BIT
== 8);
19827 static const char *
19828 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19829 unsigned int *bytes_read_ptr
)
19831 /* If the size of a host char is 8 bits, we can return a pointer
19832 to the string, otherwise we have to copy the string to a buffer
19833 allocated on the temporary obstack. */
19834 gdb_assert (HOST_CHAR_BIT
== 8);
19837 *bytes_read_ptr
= 1;
19840 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19841 return (const char *) buf
;
19844 /* Return pointer to string at section SECT offset STR_OFFSET with error
19845 reporting strings FORM_NAME and SECT_NAME. */
19847 static const char *
19848 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19849 bfd
*abfd
, LONGEST str_offset
,
19850 struct dwarf2_section_info
*sect
,
19851 const char *form_name
,
19852 const char *sect_name
)
19854 dwarf2_read_section (objfile
, sect
);
19855 if (sect
->buffer
== NULL
)
19856 error (_("%s used without %s section [in module %s]"),
19857 form_name
, sect_name
, bfd_get_filename (abfd
));
19858 if (str_offset
>= sect
->size
)
19859 error (_("%s pointing outside of %s section [in module %s]"),
19860 form_name
, sect_name
, bfd_get_filename (abfd
));
19861 gdb_assert (HOST_CHAR_BIT
== 8);
19862 if (sect
->buffer
[str_offset
] == '\0')
19864 return (const char *) (sect
->buffer
+ str_offset
);
19867 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19869 static const char *
19870 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19871 bfd
*abfd
, LONGEST str_offset
)
19873 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19875 &dwarf2_per_objfile
->str
,
19876 "DW_FORM_strp", ".debug_str");
19879 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19881 static const char *
19882 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19883 bfd
*abfd
, LONGEST str_offset
)
19885 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19887 &dwarf2_per_objfile
->line_str
,
19888 "DW_FORM_line_strp",
19889 ".debug_line_str");
19892 /* Read a string at offset STR_OFFSET in the .debug_str section from
19893 the .dwz file DWZ. Throw an error if the offset is too large. If
19894 the string consists of a single NUL byte, return NULL; otherwise
19895 return a pointer to the string. */
19897 static const char *
19898 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19899 LONGEST str_offset
)
19901 dwarf2_read_section (objfile
, &dwz
->str
);
19903 if (dwz
->str
.buffer
== NULL
)
19904 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19905 "section [in module %s]"),
19906 bfd_get_filename (dwz
->dwz_bfd
));
19907 if (str_offset
>= dwz
->str
.size
)
19908 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19909 ".debug_str section [in module %s]"),
19910 bfd_get_filename (dwz
->dwz_bfd
));
19911 gdb_assert (HOST_CHAR_BIT
== 8);
19912 if (dwz
->str
.buffer
[str_offset
] == '\0')
19914 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19917 /* Return pointer to string at .debug_str offset as read from BUF.
19918 BUF is assumed to be in a compilation unit described by CU_HEADER.
19919 Return *BYTES_READ_PTR count of bytes read from BUF. */
19921 static const char *
19922 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19923 const gdb_byte
*buf
,
19924 const struct comp_unit_head
*cu_header
,
19925 unsigned int *bytes_read_ptr
)
19927 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19929 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19932 /* Return pointer to string at .debug_line_str offset as read from BUF.
19933 BUF is assumed to be in a compilation unit described by CU_HEADER.
19934 Return *BYTES_READ_PTR count of bytes read from BUF. */
19936 static const char *
19937 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19938 bfd
*abfd
, const gdb_byte
*buf
,
19939 const struct comp_unit_head
*cu_header
,
19940 unsigned int *bytes_read_ptr
)
19942 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19944 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19949 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19950 unsigned int *bytes_read_ptr
)
19953 unsigned int num_read
;
19955 unsigned char byte
;
19962 byte
= bfd_get_8 (abfd
, buf
);
19965 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19966 if ((byte
& 128) == 0)
19972 *bytes_read_ptr
= num_read
;
19977 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19978 unsigned int *bytes_read_ptr
)
19981 int shift
, num_read
;
19982 unsigned char byte
;
19989 byte
= bfd_get_8 (abfd
, buf
);
19992 result
|= ((LONGEST
) (byte
& 127) << shift
);
19994 if ((byte
& 128) == 0)
19999 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20000 result
|= -(((LONGEST
) 1) << shift
);
20001 *bytes_read_ptr
= num_read
;
20005 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20006 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20007 ADDR_SIZE is the size of addresses from the CU header. */
20010 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20011 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20013 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20014 bfd
*abfd
= objfile
->obfd
;
20015 const gdb_byte
*info_ptr
;
20017 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20018 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20019 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20020 objfile_name (objfile
));
20021 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20022 error (_("DW_FORM_addr_index pointing outside of "
20023 ".debug_addr section [in module %s]"),
20024 objfile_name (objfile
));
20025 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20026 + addr_base
+ addr_index
* addr_size
);
20027 if (addr_size
== 4)
20028 return bfd_get_32 (abfd
, info_ptr
);
20030 return bfd_get_64 (abfd
, info_ptr
);
20033 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20036 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20038 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20039 cu
->addr_base
, cu
->header
.addr_size
);
20042 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20045 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20046 unsigned int *bytes_read
)
20048 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20049 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20051 return read_addr_index (cu
, addr_index
);
20054 /* Data structure to pass results from dwarf2_read_addr_index_reader
20055 back to dwarf2_read_addr_index. */
20057 struct dwarf2_read_addr_index_data
20059 ULONGEST addr_base
;
20063 /* die_reader_func for dwarf2_read_addr_index. */
20066 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20067 const gdb_byte
*info_ptr
,
20068 struct die_info
*comp_unit_die
,
20072 struct dwarf2_cu
*cu
= reader
->cu
;
20073 struct dwarf2_read_addr_index_data
*aidata
=
20074 (struct dwarf2_read_addr_index_data
*) data
;
20076 aidata
->addr_base
= cu
->addr_base
;
20077 aidata
->addr_size
= cu
->header
.addr_size
;
20080 /* Given an index in .debug_addr, fetch the value.
20081 NOTE: This can be called during dwarf expression evaluation,
20082 long after the debug information has been read, and thus per_cu->cu
20083 may no longer exist. */
20086 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20087 unsigned int addr_index
)
20089 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20090 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20091 struct dwarf2_cu
*cu
= per_cu
->cu
;
20092 ULONGEST addr_base
;
20095 /* We need addr_base and addr_size.
20096 If we don't have PER_CU->cu, we have to get it.
20097 Nasty, but the alternative is storing the needed info in PER_CU,
20098 which at this point doesn't seem justified: it's not clear how frequently
20099 it would get used and it would increase the size of every PER_CU.
20100 Entry points like dwarf2_per_cu_addr_size do a similar thing
20101 so we're not in uncharted territory here.
20102 Alas we need to be a bit more complicated as addr_base is contained
20105 We don't need to read the entire CU(/TU).
20106 We just need the header and top level die.
20108 IWBN to use the aging mechanism to let us lazily later discard the CU.
20109 For now we skip this optimization. */
20113 addr_base
= cu
->addr_base
;
20114 addr_size
= cu
->header
.addr_size
;
20118 struct dwarf2_read_addr_index_data aidata
;
20120 /* Note: We can't use init_cutu_and_read_dies_simple here,
20121 we need addr_base. */
20122 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
20123 dwarf2_read_addr_index_reader
, &aidata
);
20124 addr_base
= aidata
.addr_base
;
20125 addr_size
= aidata
.addr_size
;
20128 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20132 /* Given a DW_FORM_GNU_str_index, fetch the string.
20133 This is only used by the Fission support. */
20135 static const char *
20136 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20138 struct dwarf2_cu
*cu
= reader
->cu
;
20139 struct dwarf2_per_objfile
*dwarf2_per_objfile
20140 = cu
->per_cu
->dwarf2_per_objfile
;
20141 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20142 const char *objf_name
= objfile_name (objfile
);
20143 bfd
*abfd
= objfile
->obfd
;
20144 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20145 struct dwarf2_section_info
*str_offsets_section
=
20146 &reader
->dwo_file
->sections
.str_offsets
;
20147 const gdb_byte
*info_ptr
;
20148 ULONGEST str_offset
;
20149 static const char form_name
[] = "DW_FORM_GNU_str_index";
20151 dwarf2_read_section (objfile
, str_section
);
20152 dwarf2_read_section (objfile
, str_offsets_section
);
20153 if (str_section
->buffer
== NULL
)
20154 error (_("%s used without .debug_str.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_offsets_section
->buffer
== NULL
)
20158 error (_("%s used without .debug_str_offsets.dwo section"
20159 " in CU at offset %s [in module %s]"),
20160 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20161 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20162 error (_("%s pointing outside of .debug_str_offsets.dwo"
20163 " section in CU at offset %s [in module %s]"),
20164 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20165 info_ptr
= (str_offsets_section
->buffer
20166 + str_index
* cu
->header
.offset_size
);
20167 if (cu
->header
.offset_size
== 4)
20168 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20170 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20171 if (str_offset
>= str_section
->size
)
20172 error (_("Offset from %s pointing outside of"
20173 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20174 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20175 return (const char *) (str_section
->buffer
+ str_offset
);
20178 /* Return the length of an LEB128 number in BUF. */
20181 leb128_size (const gdb_byte
*buf
)
20183 const gdb_byte
*begin
= buf
;
20189 if ((byte
& 128) == 0)
20190 return buf
- begin
;
20195 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20204 cu
->language
= language_c
;
20207 case DW_LANG_C_plus_plus
:
20208 case DW_LANG_C_plus_plus_11
:
20209 case DW_LANG_C_plus_plus_14
:
20210 cu
->language
= language_cplus
;
20213 cu
->language
= language_d
;
20215 case DW_LANG_Fortran77
:
20216 case DW_LANG_Fortran90
:
20217 case DW_LANG_Fortran95
:
20218 case DW_LANG_Fortran03
:
20219 case DW_LANG_Fortran08
:
20220 cu
->language
= language_fortran
;
20223 cu
->language
= language_go
;
20225 case DW_LANG_Mips_Assembler
:
20226 cu
->language
= language_asm
;
20228 case DW_LANG_Ada83
:
20229 case DW_LANG_Ada95
:
20230 cu
->language
= language_ada
;
20232 case DW_LANG_Modula2
:
20233 cu
->language
= language_m2
;
20235 case DW_LANG_Pascal83
:
20236 cu
->language
= language_pascal
;
20239 cu
->language
= language_objc
;
20242 case DW_LANG_Rust_old
:
20243 cu
->language
= language_rust
;
20245 case DW_LANG_Cobol74
:
20246 case DW_LANG_Cobol85
:
20248 cu
->language
= language_minimal
;
20251 cu
->language_defn
= language_def (cu
->language
);
20254 /* Return the named attribute or NULL if not there. */
20256 static struct attribute
*
20257 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20262 struct attribute
*spec
= NULL
;
20264 for (i
= 0; i
< die
->num_attrs
; ++i
)
20266 if (die
->attrs
[i
].name
== name
)
20267 return &die
->attrs
[i
];
20268 if (die
->attrs
[i
].name
== DW_AT_specification
20269 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20270 spec
= &die
->attrs
[i
];
20276 die
= follow_die_ref (die
, spec
, &cu
);
20282 /* Return the named attribute or NULL if not there,
20283 but do not follow DW_AT_specification, etc.
20284 This is for use in contexts where we're reading .debug_types dies.
20285 Following DW_AT_specification, DW_AT_abstract_origin will take us
20286 back up the chain, and we want to go down. */
20288 static struct attribute
*
20289 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20293 for (i
= 0; i
< die
->num_attrs
; ++i
)
20294 if (die
->attrs
[i
].name
== name
)
20295 return &die
->attrs
[i
];
20300 /* Return the string associated with a string-typed attribute, or NULL if it
20301 is either not found or is of an incorrect type. */
20303 static const char *
20304 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20306 struct attribute
*attr
;
20307 const char *str
= NULL
;
20309 attr
= dwarf2_attr (die
, name
, cu
);
20313 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20314 || attr
->form
== DW_FORM_string
20315 || attr
->form
== DW_FORM_GNU_str_index
20316 || attr
->form
== DW_FORM_GNU_strp_alt
)
20317 str
= DW_STRING (attr
);
20319 complaint (&symfile_complaints
,
20320 _("string type expected for attribute %s for "
20321 "DIE at %s in module %s"),
20322 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20323 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20329 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20330 and holds a non-zero value. This function should only be used for
20331 DW_FORM_flag or DW_FORM_flag_present attributes. */
20334 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20336 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20338 return (attr
&& DW_UNSND (attr
));
20342 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20344 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20345 which value is non-zero. However, we have to be careful with
20346 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20347 (via dwarf2_flag_true_p) follows this attribute. So we may
20348 end up accidently finding a declaration attribute that belongs
20349 to a different DIE referenced by the specification attribute,
20350 even though the given DIE does not have a declaration attribute. */
20351 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20352 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20355 /* Return the die giving the specification for DIE, if there is
20356 one. *SPEC_CU is the CU containing DIE on input, and the CU
20357 containing the return value on output. If there is no
20358 specification, but there is an abstract origin, that is
20361 static struct die_info
*
20362 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20364 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20367 if (spec_attr
== NULL
)
20368 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20370 if (spec_attr
== NULL
)
20373 return follow_die_ref (die
, spec_attr
, spec_cu
);
20376 /* Stub for free_line_header to match void * callback types. */
20379 free_line_header_voidp (void *arg
)
20381 struct line_header
*lh
= (struct line_header
*) arg
;
20387 line_header::add_include_dir (const char *include_dir
)
20389 if (dwarf_line_debug
>= 2)
20390 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20391 include_dirs
.size () + 1, include_dir
);
20393 include_dirs
.push_back (include_dir
);
20397 line_header::add_file_name (const char *name
,
20399 unsigned int mod_time
,
20400 unsigned int length
)
20402 if (dwarf_line_debug
>= 2)
20403 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20404 (unsigned) file_names
.size () + 1, name
);
20406 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20409 /* A convenience function to find the proper .debug_line section for a CU. */
20411 static struct dwarf2_section_info
*
20412 get_debug_line_section (struct dwarf2_cu
*cu
)
20414 struct dwarf2_section_info
*section
;
20415 struct dwarf2_per_objfile
*dwarf2_per_objfile
20416 = cu
->per_cu
->dwarf2_per_objfile
;
20418 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20420 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20421 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20422 else if (cu
->per_cu
->is_dwz
)
20424 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20426 section
= &dwz
->line
;
20429 section
= &dwarf2_per_objfile
->line
;
20434 /* Read directory or file name entry format, starting with byte of
20435 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20436 entries count and the entries themselves in the described entry
20440 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20441 bfd
*abfd
, const gdb_byte
**bufp
,
20442 struct line_header
*lh
,
20443 const struct comp_unit_head
*cu_header
,
20444 void (*callback
) (struct line_header
*lh
,
20447 unsigned int mod_time
,
20448 unsigned int length
))
20450 gdb_byte format_count
, formati
;
20451 ULONGEST data_count
, datai
;
20452 const gdb_byte
*buf
= *bufp
;
20453 const gdb_byte
*format_header_data
;
20454 unsigned int bytes_read
;
20456 format_count
= read_1_byte (abfd
, buf
);
20458 format_header_data
= buf
;
20459 for (formati
= 0; formati
< format_count
; formati
++)
20461 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20463 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20467 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20469 for (datai
= 0; datai
< data_count
; datai
++)
20471 const gdb_byte
*format
= format_header_data
;
20472 struct file_entry fe
;
20474 for (formati
= 0; formati
< format_count
; formati
++)
20476 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20477 format
+= bytes_read
;
20479 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20480 format
+= bytes_read
;
20482 gdb::optional
<const char *> string
;
20483 gdb::optional
<unsigned int> uint
;
20487 case DW_FORM_string
:
20488 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20492 case DW_FORM_line_strp
:
20493 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20500 case DW_FORM_data1
:
20501 uint
.emplace (read_1_byte (abfd
, buf
));
20505 case DW_FORM_data2
:
20506 uint
.emplace (read_2_bytes (abfd
, buf
));
20510 case DW_FORM_data4
:
20511 uint
.emplace (read_4_bytes (abfd
, buf
));
20515 case DW_FORM_data8
:
20516 uint
.emplace (read_8_bytes (abfd
, buf
));
20520 case DW_FORM_udata
:
20521 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20525 case DW_FORM_block
:
20526 /* It is valid only for DW_LNCT_timestamp which is ignored by
20531 switch (content_type
)
20534 if (string
.has_value ())
20537 case DW_LNCT_directory_index
:
20538 if (uint
.has_value ())
20539 fe
.d_index
= (dir_index
) *uint
;
20541 case DW_LNCT_timestamp
:
20542 if (uint
.has_value ())
20543 fe
.mod_time
= *uint
;
20546 if (uint
.has_value ())
20552 complaint (&symfile_complaints
,
20553 _("Unknown format content type %s"),
20554 pulongest (content_type
));
20558 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20564 /* Read the statement program header starting at OFFSET in
20565 .debug_line, or .debug_line.dwo. Return a pointer
20566 to a struct line_header, allocated using xmalloc.
20567 Returns NULL if there is a problem reading the header, e.g., if it
20568 has a version we don't understand.
20570 NOTE: the strings in the include directory and file name tables of
20571 the returned object point into the dwarf line section buffer,
20572 and must not be freed. */
20574 static line_header_up
20575 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20577 const gdb_byte
*line_ptr
;
20578 unsigned int bytes_read
, offset_size
;
20580 const char *cur_dir
, *cur_file
;
20581 struct dwarf2_section_info
*section
;
20583 struct dwarf2_per_objfile
*dwarf2_per_objfile
20584 = cu
->per_cu
->dwarf2_per_objfile
;
20586 section
= get_debug_line_section (cu
);
20587 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20588 if (section
->buffer
== NULL
)
20590 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20591 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20593 complaint (&symfile_complaints
, _("missing .debug_line section"));
20597 /* We can't do this until we know the section is non-empty.
20598 Only then do we know we have such a section. */
20599 abfd
= get_section_bfd_owner (section
);
20601 /* Make sure that at least there's room for the total_length field.
20602 That could be 12 bytes long, but we're just going to fudge that. */
20603 if (to_underlying (sect_off
) + 4 >= section
->size
)
20605 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20609 line_header_up
lh (new line_header ());
20611 lh
->sect_off
= sect_off
;
20612 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20614 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20616 /* Read in the header. */
20618 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20619 &bytes_read
, &offset_size
);
20620 line_ptr
+= bytes_read
;
20621 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20623 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20626 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20627 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20629 if (lh
->version
> 5)
20631 /* This is a version we don't understand. The format could have
20632 changed in ways we don't handle properly so just punt. */
20633 complaint (&symfile_complaints
,
20634 _("unsupported version in .debug_line section"));
20637 if (lh
->version
>= 5)
20639 gdb_byte segment_selector_size
;
20641 /* Skip address size. */
20642 read_1_byte (abfd
, line_ptr
);
20645 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20647 if (segment_selector_size
!= 0)
20649 complaint (&symfile_complaints
,
20650 _("unsupported segment selector size %u "
20651 "in .debug_line section"),
20652 segment_selector_size
);
20656 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20657 line_ptr
+= offset_size
;
20658 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20660 if (lh
->version
>= 4)
20662 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20666 lh
->maximum_ops_per_instruction
= 1;
20668 if (lh
->maximum_ops_per_instruction
== 0)
20670 lh
->maximum_ops_per_instruction
= 1;
20671 complaint (&symfile_complaints
,
20672 _("invalid maximum_ops_per_instruction "
20673 "in `.debug_line' section"));
20676 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20678 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20680 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20682 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20684 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20686 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20687 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20689 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20693 if (lh
->version
>= 5)
20695 /* Read directory table. */
20696 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20698 [] (struct line_header
*lh
, const char *name
,
20699 dir_index d_index
, unsigned int mod_time
,
20700 unsigned int length
)
20702 lh
->add_include_dir (name
);
20705 /* Read file name table. */
20706 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20708 [] (struct line_header
*lh
, const char *name
,
20709 dir_index d_index
, unsigned int mod_time
,
20710 unsigned int length
)
20712 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20717 /* Read directory table. */
20718 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20720 line_ptr
+= bytes_read
;
20721 lh
->add_include_dir (cur_dir
);
20723 line_ptr
+= bytes_read
;
20725 /* Read file name table. */
20726 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20728 unsigned int mod_time
, length
;
20731 line_ptr
+= bytes_read
;
20732 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20733 line_ptr
+= bytes_read
;
20734 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20735 line_ptr
+= bytes_read
;
20736 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20737 line_ptr
+= bytes_read
;
20739 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20741 line_ptr
+= bytes_read
;
20743 lh
->statement_program_start
= line_ptr
;
20745 if (line_ptr
> (section
->buffer
+ section
->size
))
20746 complaint (&symfile_complaints
,
20747 _("line number info header doesn't "
20748 "fit in `.debug_line' section"));
20753 /* Subroutine of dwarf_decode_lines to simplify it.
20754 Return the file name of the psymtab for included file FILE_INDEX
20755 in line header LH of PST.
20756 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20757 If space for the result is malloc'd, *NAME_HOLDER will be set.
20758 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20760 static const char *
20761 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20762 const struct partial_symtab
*pst
,
20763 const char *comp_dir
,
20764 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20766 const file_entry
&fe
= lh
->file_names
[file_index
];
20767 const char *include_name
= fe
.name
;
20768 const char *include_name_to_compare
= include_name
;
20769 const char *pst_filename
;
20772 const char *dir_name
= fe
.include_dir (lh
);
20774 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20775 if (!IS_ABSOLUTE_PATH (include_name
)
20776 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20778 /* Avoid creating a duplicate psymtab for PST.
20779 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20780 Before we do the comparison, however, we need to account
20781 for DIR_NAME and COMP_DIR.
20782 First prepend dir_name (if non-NULL). If we still don't
20783 have an absolute path prepend comp_dir (if non-NULL).
20784 However, the directory we record in the include-file's
20785 psymtab does not contain COMP_DIR (to match the
20786 corresponding symtab(s)).
20791 bash$ gcc -g ./hello.c
20792 include_name = "hello.c"
20794 DW_AT_comp_dir = comp_dir = "/tmp"
20795 DW_AT_name = "./hello.c"
20799 if (dir_name
!= NULL
)
20801 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20802 include_name
, (char *) NULL
));
20803 include_name
= name_holder
->get ();
20804 include_name_to_compare
= include_name
;
20806 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20808 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20809 include_name
, (char *) NULL
));
20810 include_name_to_compare
= hold_compare
.get ();
20814 pst_filename
= pst
->filename
;
20815 gdb::unique_xmalloc_ptr
<char> copied_name
;
20816 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20818 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20819 pst_filename
, (char *) NULL
));
20820 pst_filename
= copied_name
.get ();
20823 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20827 return include_name
;
20830 /* State machine to track the state of the line number program. */
20832 class lnp_state_machine
20835 /* Initialize a machine state for the start of a line number
20837 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20839 file_entry
*current_file ()
20841 /* lh->file_names is 0-based, but the file name numbers in the
20842 statement program are 1-based. */
20843 return m_line_header
->file_name_at (m_file
);
20846 /* Record the line in the state machine. END_SEQUENCE is true if
20847 we're processing the end of a sequence. */
20848 void record_line (bool end_sequence
);
20850 /* Check address and if invalid nop-out the rest of the lines in this
20852 void check_line_address (struct dwarf2_cu
*cu
,
20853 const gdb_byte
*line_ptr
,
20854 CORE_ADDR lowpc
, CORE_ADDR address
);
20856 void handle_set_discriminator (unsigned int discriminator
)
20858 m_discriminator
= discriminator
;
20859 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20862 /* Handle DW_LNE_set_address. */
20863 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20866 address
+= baseaddr
;
20867 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20870 /* Handle DW_LNS_advance_pc. */
20871 void handle_advance_pc (CORE_ADDR adjust
);
20873 /* Handle a special opcode. */
20874 void handle_special_opcode (unsigned char op_code
);
20876 /* Handle DW_LNS_advance_line. */
20877 void handle_advance_line (int line_delta
)
20879 advance_line (line_delta
);
20882 /* Handle DW_LNS_set_file. */
20883 void handle_set_file (file_name_index file
);
20885 /* Handle DW_LNS_negate_stmt. */
20886 void handle_negate_stmt ()
20888 m_is_stmt
= !m_is_stmt
;
20891 /* Handle DW_LNS_const_add_pc. */
20892 void handle_const_add_pc ();
20894 /* Handle DW_LNS_fixed_advance_pc. */
20895 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20897 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20901 /* Handle DW_LNS_copy. */
20902 void handle_copy ()
20904 record_line (false);
20905 m_discriminator
= 0;
20908 /* Handle DW_LNE_end_sequence. */
20909 void handle_end_sequence ()
20911 m_record_line_callback
= ::record_line
;
20915 /* Advance the line by LINE_DELTA. */
20916 void advance_line (int line_delta
)
20918 m_line
+= line_delta
;
20920 if (line_delta
!= 0)
20921 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20924 gdbarch
*m_gdbarch
;
20926 /* True if we're recording lines.
20927 Otherwise we're building partial symtabs and are just interested in
20928 finding include files mentioned by the line number program. */
20929 bool m_record_lines_p
;
20931 /* The line number header. */
20932 line_header
*m_line_header
;
20934 /* These are part of the standard DWARF line number state machine,
20935 and initialized according to the DWARF spec. */
20937 unsigned char m_op_index
= 0;
20938 /* The line table index (1-based) of the current file. */
20939 file_name_index m_file
= (file_name_index
) 1;
20940 unsigned int m_line
= 1;
20942 /* These are initialized in the constructor. */
20944 CORE_ADDR m_address
;
20946 unsigned int m_discriminator
;
20948 /* Additional bits of state we need to track. */
20950 /* The last file that we called dwarf2_start_subfile for.
20951 This is only used for TLLs. */
20952 unsigned int m_last_file
= 0;
20953 /* The last file a line number was recorded for. */
20954 struct subfile
*m_last_subfile
= NULL
;
20956 /* The function to call to record a line. */
20957 record_line_ftype
*m_record_line_callback
= NULL
;
20959 /* The last line number that was recorded, used to coalesce
20960 consecutive entries for the same line. This can happen, for
20961 example, when discriminators are present. PR 17276. */
20962 unsigned int m_last_line
= 0;
20963 bool m_line_has_non_zero_discriminator
= false;
20967 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20969 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20970 / m_line_header
->maximum_ops_per_instruction
)
20971 * m_line_header
->minimum_instruction_length
);
20972 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20973 m_op_index
= ((m_op_index
+ adjust
)
20974 % m_line_header
->maximum_ops_per_instruction
);
20978 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20980 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20981 CORE_ADDR addr_adj
= (((m_op_index
20982 + (adj_opcode
/ m_line_header
->line_range
))
20983 / m_line_header
->maximum_ops_per_instruction
)
20984 * m_line_header
->minimum_instruction_length
);
20985 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20986 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20987 % m_line_header
->maximum_ops_per_instruction
);
20989 int line_delta
= (m_line_header
->line_base
20990 + (adj_opcode
% m_line_header
->line_range
));
20991 advance_line (line_delta
);
20992 record_line (false);
20993 m_discriminator
= 0;
20997 lnp_state_machine::handle_set_file (file_name_index file
)
21001 const file_entry
*fe
= current_file ();
21003 dwarf2_debug_line_missing_file_complaint ();
21004 else if (m_record_lines_p
)
21006 const char *dir
= fe
->include_dir (m_line_header
);
21008 m_last_subfile
= current_subfile
;
21009 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21010 dwarf2_start_subfile (fe
->name
, dir
);
21015 lnp_state_machine::handle_const_add_pc ()
21018 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21021 = (((m_op_index
+ adjust
)
21022 / m_line_header
->maximum_ops_per_instruction
)
21023 * m_line_header
->minimum_instruction_length
);
21025 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21026 m_op_index
= ((m_op_index
+ adjust
)
21027 % m_line_header
->maximum_ops_per_instruction
);
21030 /* Ignore this record_line request. */
21033 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
21038 /* Return non-zero if we should add LINE to the line number table.
21039 LINE is the line to add, LAST_LINE is the last line that was added,
21040 LAST_SUBFILE is the subfile for LAST_LINE.
21041 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21042 had a non-zero discriminator.
21044 We have to be careful in the presence of discriminators.
21045 E.g., for this line:
21047 for (i = 0; i < 100000; i++);
21049 clang can emit four line number entries for that one line,
21050 each with a different discriminator.
21051 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21053 However, we want gdb to coalesce all four entries into one.
21054 Otherwise the user could stepi into the middle of the line and
21055 gdb would get confused about whether the pc really was in the
21056 middle of the line.
21058 Things are further complicated by the fact that two consecutive
21059 line number entries for the same line is a heuristic used by gcc
21060 to denote the end of the prologue. So we can't just discard duplicate
21061 entries, we have to be selective about it. The heuristic we use is
21062 that we only collapse consecutive entries for the same line if at least
21063 one of those entries has a non-zero discriminator. PR 17276.
21065 Note: Addresses in the line number state machine can never go backwards
21066 within one sequence, thus this coalescing is ok. */
21069 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
21070 int line_has_non_zero_discriminator
,
21071 struct subfile
*last_subfile
)
21073 if (current_subfile
!= last_subfile
)
21075 if (line
!= last_line
)
21077 /* Same line for the same file that we've seen already.
21078 As a last check, for pr 17276, only record the line if the line
21079 has never had a non-zero discriminator. */
21080 if (!line_has_non_zero_discriminator
)
21085 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
21086 in the line table of subfile SUBFILE. */
21089 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21090 unsigned int line
, CORE_ADDR address
,
21091 record_line_ftype p_record_line
)
21093 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21095 if (dwarf_line_debug
)
21097 fprintf_unfiltered (gdb_stdlog
,
21098 "Recording line %u, file %s, address %s\n",
21099 line
, lbasename (subfile
->name
),
21100 paddress (gdbarch
, address
));
21103 (*p_record_line
) (subfile
, line
, addr
);
21106 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21107 Mark the end of a set of line number records.
21108 The arguments are the same as for dwarf_record_line_1.
21109 If SUBFILE is NULL the request is ignored. */
21112 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21113 CORE_ADDR address
, record_line_ftype p_record_line
)
21115 if (subfile
== NULL
)
21118 if (dwarf_line_debug
)
21120 fprintf_unfiltered (gdb_stdlog
,
21121 "Finishing current line, file %s, address %s\n",
21122 lbasename (subfile
->name
),
21123 paddress (gdbarch
, address
));
21126 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
21130 lnp_state_machine::record_line (bool end_sequence
)
21132 if (dwarf_line_debug
)
21134 fprintf_unfiltered (gdb_stdlog
,
21135 "Processing actual line %u: file %u,"
21136 " address %s, is_stmt %u, discrim %u\n",
21137 m_line
, to_underlying (m_file
),
21138 paddress (m_gdbarch
, m_address
),
21139 m_is_stmt
, m_discriminator
);
21142 file_entry
*fe
= current_file ();
21145 dwarf2_debug_line_missing_file_complaint ();
21146 /* For now we ignore lines not starting on an instruction boundary.
21147 But not when processing end_sequence for compatibility with the
21148 previous version of the code. */
21149 else if (m_op_index
== 0 || end_sequence
)
21151 fe
->included_p
= 1;
21152 if (m_record_lines_p
&& m_is_stmt
)
21154 if (m_last_subfile
!= current_subfile
|| end_sequence
)
21156 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
21157 m_address
, m_record_line_callback
);
21162 if (dwarf_record_line_p (m_line
, m_last_line
,
21163 m_line_has_non_zero_discriminator
,
21166 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
21168 m_record_line_callback
);
21170 m_last_subfile
= current_subfile
;
21171 m_last_line
= m_line
;
21177 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
21178 bool record_lines_p
)
21181 m_record_lines_p
= record_lines_p
;
21182 m_line_header
= lh
;
21184 m_record_line_callback
= ::record_line
;
21186 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21187 was a line entry for it so that the backend has a chance to adjust it
21188 and also record it in case it needs it. This is currently used by MIPS
21189 code, cf. `mips_adjust_dwarf2_line'. */
21190 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21191 m_is_stmt
= lh
->default_is_stmt
;
21192 m_discriminator
= 0;
21196 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21197 const gdb_byte
*line_ptr
,
21198 CORE_ADDR lowpc
, CORE_ADDR address
)
21200 /* If address < lowpc then it's not a usable value, it's outside the
21201 pc range of the CU. However, we restrict the test to only address
21202 values of zero to preserve GDB's previous behaviour which is to
21203 handle the specific case of a function being GC'd by the linker. */
21205 if (address
== 0 && address
< lowpc
)
21207 /* This line table is for a function which has been
21208 GCd by the linker. Ignore it. PR gdb/12528 */
21210 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21211 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21213 complaint (&symfile_complaints
,
21214 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21215 line_offset
, objfile_name (objfile
));
21216 m_record_line_callback
= noop_record_line
;
21217 /* Note: record_line_callback is left as noop_record_line until
21218 we see DW_LNE_end_sequence. */
21222 /* Subroutine of dwarf_decode_lines to simplify it.
21223 Process the line number information in LH.
21224 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21225 program in order to set included_p for every referenced header. */
21228 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21229 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21231 const gdb_byte
*line_ptr
, *extended_end
;
21232 const gdb_byte
*line_end
;
21233 unsigned int bytes_read
, extended_len
;
21234 unsigned char op_code
, extended_op
;
21235 CORE_ADDR baseaddr
;
21236 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21237 bfd
*abfd
= objfile
->obfd
;
21238 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21239 /* True if we're recording line info (as opposed to building partial
21240 symtabs and just interested in finding include files mentioned by
21241 the line number program). */
21242 bool record_lines_p
= !decode_for_pst_p
;
21244 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21246 line_ptr
= lh
->statement_program_start
;
21247 line_end
= lh
->statement_program_end
;
21249 /* Read the statement sequences until there's nothing left. */
21250 while (line_ptr
< line_end
)
21252 /* The DWARF line number program state machine. Reset the state
21253 machine at the start of each sequence. */
21254 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
21255 bool end_sequence
= false;
21257 if (record_lines_p
)
21259 /* Start a subfile for the current file of the state
21261 const file_entry
*fe
= state_machine
.current_file ();
21264 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
21267 /* Decode the table. */
21268 while (line_ptr
< line_end
&& !end_sequence
)
21270 op_code
= read_1_byte (abfd
, line_ptr
);
21273 if (op_code
>= lh
->opcode_base
)
21275 /* Special opcode. */
21276 state_machine
.handle_special_opcode (op_code
);
21278 else switch (op_code
)
21280 case DW_LNS_extended_op
:
21281 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21283 line_ptr
+= bytes_read
;
21284 extended_end
= line_ptr
+ extended_len
;
21285 extended_op
= read_1_byte (abfd
, line_ptr
);
21287 switch (extended_op
)
21289 case DW_LNE_end_sequence
:
21290 state_machine
.handle_end_sequence ();
21291 end_sequence
= true;
21293 case DW_LNE_set_address
:
21296 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21297 line_ptr
+= bytes_read
;
21299 state_machine
.check_line_address (cu
, line_ptr
,
21301 state_machine
.handle_set_address (baseaddr
, address
);
21304 case DW_LNE_define_file
:
21306 const char *cur_file
;
21307 unsigned int mod_time
, length
;
21310 cur_file
= read_direct_string (abfd
, line_ptr
,
21312 line_ptr
+= bytes_read
;
21313 dindex
= (dir_index
)
21314 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21315 line_ptr
+= bytes_read
;
21317 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21318 line_ptr
+= bytes_read
;
21320 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21321 line_ptr
+= bytes_read
;
21322 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21325 case DW_LNE_set_discriminator
:
21327 /* The discriminator is not interesting to the
21328 debugger; just ignore it. We still need to
21329 check its value though:
21330 if there are consecutive entries for the same
21331 (non-prologue) line we want to coalesce them.
21334 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21335 line_ptr
+= bytes_read
;
21337 state_machine
.handle_set_discriminator (discr
);
21341 complaint (&symfile_complaints
,
21342 _("mangled .debug_line section"));
21345 /* Make sure that we parsed the extended op correctly. If e.g.
21346 we expected a different address size than the producer used,
21347 we may have read the wrong number of bytes. */
21348 if (line_ptr
!= extended_end
)
21350 complaint (&symfile_complaints
,
21351 _("mangled .debug_line section"));
21356 state_machine
.handle_copy ();
21358 case DW_LNS_advance_pc
:
21361 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21362 line_ptr
+= bytes_read
;
21364 state_machine
.handle_advance_pc (adjust
);
21367 case DW_LNS_advance_line
:
21370 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21371 line_ptr
+= bytes_read
;
21373 state_machine
.handle_advance_line (line_delta
);
21376 case DW_LNS_set_file
:
21378 file_name_index file
21379 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21381 line_ptr
+= bytes_read
;
21383 state_machine
.handle_set_file (file
);
21386 case DW_LNS_set_column
:
21387 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21388 line_ptr
+= bytes_read
;
21390 case DW_LNS_negate_stmt
:
21391 state_machine
.handle_negate_stmt ();
21393 case DW_LNS_set_basic_block
:
21395 /* Add to the address register of the state machine the
21396 address increment value corresponding to special opcode
21397 255. I.e., this value is scaled by the minimum
21398 instruction length since special opcode 255 would have
21399 scaled the increment. */
21400 case DW_LNS_const_add_pc
:
21401 state_machine
.handle_const_add_pc ();
21403 case DW_LNS_fixed_advance_pc
:
21405 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21408 state_machine
.handle_fixed_advance_pc (addr_adj
);
21413 /* Unknown standard opcode, ignore it. */
21416 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21418 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21419 line_ptr
+= bytes_read
;
21426 dwarf2_debug_line_missing_end_sequence_complaint ();
21428 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21429 in which case we still finish recording the last line). */
21430 state_machine
.record_line (true);
21434 /* Decode the Line Number Program (LNP) for the given line_header
21435 structure and CU. The actual information extracted and the type
21436 of structures created from the LNP depends on the value of PST.
21438 1. If PST is NULL, then this procedure uses the data from the program
21439 to create all necessary symbol tables, and their linetables.
21441 2. If PST is not NULL, this procedure reads the program to determine
21442 the list of files included by the unit represented by PST, and
21443 builds all the associated partial symbol tables.
21445 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21446 It is used for relative paths in the line table.
21447 NOTE: When processing partial symtabs (pst != NULL),
21448 comp_dir == pst->dirname.
21450 NOTE: It is important that psymtabs have the same file name (via strcmp)
21451 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21452 symtab we don't use it in the name of the psymtabs we create.
21453 E.g. expand_line_sal requires this when finding psymtabs to expand.
21454 A good testcase for this is mb-inline.exp.
21456 LOWPC is the lowest address in CU (or 0 if not known).
21458 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21459 for its PC<->lines mapping information. Otherwise only the filename
21460 table is read in. */
21463 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21464 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21465 CORE_ADDR lowpc
, int decode_mapping
)
21467 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21468 const int decode_for_pst_p
= (pst
!= NULL
);
21470 if (decode_mapping
)
21471 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21473 if (decode_for_pst_p
)
21477 /* Now that we're done scanning the Line Header Program, we can
21478 create the psymtab of each included file. */
21479 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21480 if (lh
->file_names
[file_index
].included_p
== 1)
21482 gdb::unique_xmalloc_ptr
<char> name_holder
;
21483 const char *include_name
=
21484 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21486 if (include_name
!= NULL
)
21487 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21492 /* Make sure a symtab is created for every file, even files
21493 which contain only variables (i.e. no code with associated
21495 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21498 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21500 file_entry
&fe
= lh
->file_names
[i
];
21502 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21504 if (current_subfile
->symtab
== NULL
)
21506 current_subfile
->symtab
21507 = allocate_symtab (cust
, current_subfile
->name
);
21509 fe
.symtab
= current_subfile
->symtab
;
21514 /* Start a subfile for DWARF. FILENAME is the name of the file and
21515 DIRNAME the name of the source directory which contains FILENAME
21516 or NULL if not known.
21517 This routine tries to keep line numbers from identical absolute and
21518 relative file names in a common subfile.
21520 Using the `list' example from the GDB testsuite, which resides in
21521 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21522 of /srcdir/list0.c yields the following debugging information for list0.c:
21524 DW_AT_name: /srcdir/list0.c
21525 DW_AT_comp_dir: /compdir
21526 files.files[0].name: list0.h
21527 files.files[0].dir: /srcdir
21528 files.files[1].name: list0.c
21529 files.files[1].dir: /srcdir
21531 The line number information for list0.c has to end up in a single
21532 subfile, so that `break /srcdir/list0.c:1' works as expected.
21533 start_subfile will ensure that this happens provided that we pass the
21534 concatenation of files.files[1].dir and files.files[1].name as the
21538 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21542 /* In order not to lose the line information directory,
21543 we concatenate it to the filename when it makes sense.
21544 Note that the Dwarf3 standard says (speaking of filenames in line
21545 information): ``The directory index is ignored for file names
21546 that represent full path names''. Thus ignoring dirname in the
21547 `else' branch below isn't an issue. */
21549 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21551 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21555 start_subfile (filename
);
21561 /* Start a symtab for DWARF.
21562 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21564 static struct compunit_symtab
*
21565 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21566 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21568 struct compunit_symtab
*cust
21569 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21570 low_pc
, cu
->language
);
21572 record_debugformat ("DWARF 2");
21573 record_producer (cu
->producer
);
21575 /* We assume that we're processing GCC output. */
21576 processing_gcc_compilation
= 2;
21578 cu
->processing_has_namespace_info
= 0;
21584 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21585 struct dwarf2_cu
*cu
)
21587 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21588 struct comp_unit_head
*cu_header
= &cu
->header
;
21590 /* NOTE drow/2003-01-30: There used to be a comment and some special
21591 code here to turn a symbol with DW_AT_external and a
21592 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21593 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21594 with some versions of binutils) where shared libraries could have
21595 relocations against symbols in their debug information - the
21596 minimal symbol would have the right address, but the debug info
21597 would not. It's no longer necessary, because we will explicitly
21598 apply relocations when we read in the debug information now. */
21600 /* A DW_AT_location attribute with no contents indicates that a
21601 variable has been optimized away. */
21602 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21604 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21608 /* Handle one degenerate form of location expression specially, to
21609 preserve GDB's previous behavior when section offsets are
21610 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21611 then mark this symbol as LOC_STATIC. */
21613 if (attr_form_is_block (attr
)
21614 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21615 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21616 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21617 && (DW_BLOCK (attr
)->size
21618 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21620 unsigned int dummy
;
21622 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21623 SYMBOL_VALUE_ADDRESS (sym
) =
21624 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21626 SYMBOL_VALUE_ADDRESS (sym
) =
21627 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21628 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21629 fixup_symbol_section (sym
, objfile
);
21630 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21631 SYMBOL_SECTION (sym
));
21635 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21636 expression evaluator, and use LOC_COMPUTED only when necessary
21637 (i.e. when the value of a register or memory location is
21638 referenced, or a thread-local block, etc.). Then again, it might
21639 not be worthwhile. I'm assuming that it isn't unless performance
21640 or memory numbers show me otherwise. */
21642 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21644 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21645 cu
->has_loclist
= 1;
21648 /* Given a pointer to a DWARF information entry, figure out if we need
21649 to make a symbol table entry for it, and if so, create a new entry
21650 and return a pointer to it.
21651 If TYPE is NULL, determine symbol type from the die, otherwise
21652 used the passed type.
21653 If SPACE is not NULL, use it to hold the new symbol. If it is
21654 NULL, allocate a new symbol on the objfile's obstack. */
21656 static struct symbol
*
21657 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21658 struct symbol
*space
)
21660 struct dwarf2_per_objfile
*dwarf2_per_objfile
21661 = cu
->per_cu
->dwarf2_per_objfile
;
21662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21663 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21664 struct symbol
*sym
= NULL
;
21666 struct attribute
*attr
= NULL
;
21667 struct attribute
*attr2
= NULL
;
21668 CORE_ADDR baseaddr
;
21669 struct pending
**list_to_add
= NULL
;
21671 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21673 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21675 name
= dwarf2_name (die
, cu
);
21678 const char *linkagename
;
21679 int suppress_add
= 0;
21684 sym
= allocate_symbol (objfile
);
21685 OBJSTAT (objfile
, n_syms
++);
21687 /* Cache this symbol's name and the name's demangled form (if any). */
21688 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21689 linkagename
= dwarf2_physname (name
, die
, cu
);
21690 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21692 /* Fortran does not have mangling standard and the mangling does differ
21693 between gfortran, iFort etc. */
21694 if (cu
->language
== language_fortran
21695 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21696 symbol_set_demangled_name (&(sym
->ginfo
),
21697 dwarf2_full_name (name
, die
, cu
),
21700 /* Default assumptions.
21701 Use the passed type or decode it from the die. */
21702 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21703 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21705 SYMBOL_TYPE (sym
) = type
;
21707 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21708 attr
= dwarf2_attr (die
,
21709 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21713 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21716 attr
= dwarf2_attr (die
,
21717 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21721 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21722 struct file_entry
*fe
;
21724 if (cu
->line_header
!= NULL
)
21725 fe
= cu
->line_header
->file_name_at (file_index
);
21730 complaint (&symfile_complaints
,
21731 _("file index out of range"));
21733 symbol_set_symtab (sym
, fe
->symtab
);
21739 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21744 addr
= attr_value_as_address (attr
);
21745 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21746 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21748 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21749 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21750 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21751 add_symbol_to_list (sym
, cu
->list_in_scope
);
21753 case DW_TAG_subprogram
:
21754 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21756 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21757 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21758 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21759 || cu
->language
== language_ada
)
21761 /* Subprograms marked external are stored as a global symbol.
21762 Ada subprograms, whether marked external or not, are always
21763 stored as a global symbol, because we want to be able to
21764 access them globally. For instance, we want to be able
21765 to break on a nested subprogram without having to
21766 specify the context. */
21767 list_to_add
= &global_symbols
;
21771 list_to_add
= cu
->list_in_scope
;
21774 case DW_TAG_inlined_subroutine
:
21775 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21777 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21778 SYMBOL_INLINED (sym
) = 1;
21779 list_to_add
= cu
->list_in_scope
;
21781 case DW_TAG_template_value_param
:
21783 /* Fall through. */
21784 case DW_TAG_constant
:
21785 case DW_TAG_variable
:
21786 case DW_TAG_member
:
21787 /* Compilation with minimal debug info may result in
21788 variables with missing type entries. Change the
21789 misleading `void' type to something sensible. */
21790 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21791 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21793 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21794 /* In the case of DW_TAG_member, we should only be called for
21795 static const members. */
21796 if (die
->tag
== DW_TAG_member
)
21798 /* dwarf2_add_field uses die_is_declaration,
21799 so we do the same. */
21800 gdb_assert (die_is_declaration (die
, cu
));
21805 dwarf2_const_value (attr
, sym
, cu
);
21806 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21809 if (attr2
&& (DW_UNSND (attr2
) != 0))
21810 list_to_add
= &global_symbols
;
21812 list_to_add
= cu
->list_in_scope
;
21816 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21819 var_decode_location (attr
, sym
, cu
);
21820 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21822 /* Fortran explicitly imports any global symbols to the local
21823 scope by DW_TAG_common_block. */
21824 if (cu
->language
== language_fortran
&& die
->parent
21825 && die
->parent
->tag
== DW_TAG_common_block
)
21828 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21829 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21830 && !dwarf2_per_objfile
->has_section_at_zero
)
21832 /* When a static variable is eliminated by the linker,
21833 the corresponding debug information is not stripped
21834 out, but the variable address is set to null;
21835 do not add such variables into symbol table. */
21837 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21839 /* Workaround gfortran PR debug/40040 - it uses
21840 DW_AT_location for variables in -fPIC libraries which may
21841 get overriden by other libraries/executable and get
21842 a different address. Resolve it by the minimal symbol
21843 which may come from inferior's executable using copy
21844 relocation. Make this workaround only for gfortran as for
21845 other compilers GDB cannot guess the minimal symbol
21846 Fortran mangling kind. */
21847 if (cu
->language
== language_fortran
&& die
->parent
21848 && die
->parent
->tag
== DW_TAG_module
21850 && startswith (cu
->producer
, "GNU Fortran"))
21851 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21853 /* A variable with DW_AT_external is never static,
21854 but it may be block-scoped. */
21855 list_to_add
= (cu
->list_in_scope
== &file_symbols
21856 ? &global_symbols
: cu
->list_in_scope
);
21859 list_to_add
= cu
->list_in_scope
;
21863 /* We do not know the address of this symbol.
21864 If it is an external symbol and we have type information
21865 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21866 The address of the variable will then be determined from
21867 the minimal symbol table whenever the variable is
21869 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21871 /* Fortran explicitly imports any global symbols to the local
21872 scope by DW_TAG_common_block. */
21873 if (cu
->language
== language_fortran
&& die
->parent
21874 && die
->parent
->tag
== DW_TAG_common_block
)
21876 /* SYMBOL_CLASS doesn't matter here because
21877 read_common_block is going to reset it. */
21879 list_to_add
= cu
->list_in_scope
;
21881 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21882 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21884 /* A variable with DW_AT_external is never static, but it
21885 may be block-scoped. */
21886 list_to_add
= (cu
->list_in_scope
== &file_symbols
21887 ? &global_symbols
: cu
->list_in_scope
);
21889 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21891 else if (!die_is_declaration (die
, cu
))
21893 /* Use the default LOC_OPTIMIZED_OUT class. */
21894 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21896 list_to_add
= cu
->list_in_scope
;
21900 case DW_TAG_formal_parameter
:
21901 /* If we are inside a function, mark this as an argument. If
21902 not, we might be looking at an argument to an inlined function
21903 when we do not have enough information to show inlined frames;
21904 pretend it's a local variable in that case so that the user can
21906 if (context_stack_depth
> 0
21907 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21908 SYMBOL_IS_ARGUMENT (sym
) = 1;
21909 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21912 var_decode_location (attr
, sym
, cu
);
21914 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21917 dwarf2_const_value (attr
, sym
, cu
);
21920 list_to_add
= cu
->list_in_scope
;
21922 case DW_TAG_unspecified_parameters
:
21923 /* From varargs functions; gdb doesn't seem to have any
21924 interest in this information, so just ignore it for now.
21927 case DW_TAG_template_type_param
:
21929 /* Fall through. */
21930 case DW_TAG_class_type
:
21931 case DW_TAG_interface_type
:
21932 case DW_TAG_structure_type
:
21933 case DW_TAG_union_type
:
21934 case DW_TAG_set_type
:
21935 case DW_TAG_enumeration_type
:
21936 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21937 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21940 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21941 really ever be static objects: otherwise, if you try
21942 to, say, break of a class's method and you're in a file
21943 which doesn't mention that class, it won't work unless
21944 the check for all static symbols in lookup_symbol_aux
21945 saves you. See the OtherFileClass tests in
21946 gdb.c++/namespace.exp. */
21950 list_to_add
= (cu
->list_in_scope
== &file_symbols
21951 && cu
->language
== language_cplus
21952 ? &global_symbols
: cu
->list_in_scope
);
21954 /* The semantics of C++ state that "struct foo {
21955 ... }" also defines a typedef for "foo". */
21956 if (cu
->language
== language_cplus
21957 || cu
->language
== language_ada
21958 || cu
->language
== language_d
21959 || cu
->language
== language_rust
)
21961 /* The symbol's name is already allocated along
21962 with this objfile, so we don't need to
21963 duplicate it for the type. */
21964 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21965 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21970 case DW_TAG_typedef
:
21971 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21972 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21973 list_to_add
= cu
->list_in_scope
;
21975 case DW_TAG_base_type
:
21976 case DW_TAG_subrange_type
:
21977 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21978 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21979 list_to_add
= cu
->list_in_scope
;
21981 case DW_TAG_enumerator
:
21982 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21985 dwarf2_const_value (attr
, sym
, cu
);
21988 /* NOTE: carlton/2003-11-10: See comment above in the
21989 DW_TAG_class_type, etc. block. */
21991 list_to_add
= (cu
->list_in_scope
== &file_symbols
21992 && cu
->language
== language_cplus
21993 ? &global_symbols
: cu
->list_in_scope
);
21996 case DW_TAG_imported_declaration
:
21997 case DW_TAG_namespace
:
21998 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21999 list_to_add
= &global_symbols
;
22001 case DW_TAG_module
:
22002 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22003 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22004 list_to_add
= &global_symbols
;
22006 case DW_TAG_common_block
:
22007 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22008 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22009 add_symbol_to_list (sym
, cu
->list_in_scope
);
22012 /* Not a tag we recognize. Hopefully we aren't processing
22013 trash data, but since we must specifically ignore things
22014 we don't recognize, there is nothing else we should do at
22016 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
22017 dwarf_tag_name (die
->tag
));
22023 sym
->hash_next
= objfile
->template_symbols
;
22024 objfile
->template_symbols
= sym
;
22025 list_to_add
= NULL
;
22028 if (list_to_add
!= NULL
)
22029 add_symbol_to_list (sym
, list_to_add
);
22031 /* For the benefit of old versions of GCC, check for anonymous
22032 namespaces based on the demangled name. */
22033 if (!cu
->processing_has_namespace_info
22034 && cu
->language
== language_cplus
)
22035 cp_scan_for_anonymous_namespaces (sym
, objfile
);
22040 /* Given an attr with a DW_FORM_dataN value in host byte order,
22041 zero-extend it as appropriate for the symbol's type. The DWARF
22042 standard (v4) is not entirely clear about the meaning of using
22043 DW_FORM_dataN for a constant with a signed type, where the type is
22044 wider than the data. The conclusion of a discussion on the DWARF
22045 list was that this is unspecified. We choose to always zero-extend
22046 because that is the interpretation long in use by GCC. */
22049 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22050 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22052 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22053 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22054 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22055 LONGEST l
= DW_UNSND (attr
);
22057 if (bits
< sizeof (*value
) * 8)
22059 l
&= ((LONGEST
) 1 << bits
) - 1;
22062 else if (bits
== sizeof (*value
) * 8)
22066 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22067 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22074 /* Read a constant value from an attribute. Either set *VALUE, or if
22075 the value does not fit in *VALUE, set *BYTES - either already
22076 allocated on the objfile obstack, or newly allocated on OBSTACK,
22077 or, set *BATON, if we translated the constant to a location
22081 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22082 const char *name
, struct obstack
*obstack
,
22083 struct dwarf2_cu
*cu
,
22084 LONGEST
*value
, const gdb_byte
**bytes
,
22085 struct dwarf2_locexpr_baton
**baton
)
22087 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22088 struct comp_unit_head
*cu_header
= &cu
->header
;
22089 struct dwarf_block
*blk
;
22090 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22091 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22097 switch (attr
->form
)
22100 case DW_FORM_GNU_addr_index
:
22104 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22105 dwarf2_const_value_length_mismatch_complaint (name
,
22106 cu_header
->addr_size
,
22107 TYPE_LENGTH (type
));
22108 /* Symbols of this form are reasonably rare, so we just
22109 piggyback on the existing location code rather than writing
22110 a new implementation of symbol_computed_ops. */
22111 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22112 (*baton
)->per_cu
= cu
->per_cu
;
22113 gdb_assert ((*baton
)->per_cu
);
22115 (*baton
)->size
= 2 + cu_header
->addr_size
;
22116 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22117 (*baton
)->data
= data
;
22119 data
[0] = DW_OP_addr
;
22120 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22121 byte_order
, DW_ADDR (attr
));
22122 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22125 case DW_FORM_string
:
22127 case DW_FORM_GNU_str_index
:
22128 case DW_FORM_GNU_strp_alt
:
22129 /* DW_STRING is already allocated on the objfile obstack, point
22131 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22133 case DW_FORM_block1
:
22134 case DW_FORM_block2
:
22135 case DW_FORM_block4
:
22136 case DW_FORM_block
:
22137 case DW_FORM_exprloc
:
22138 case DW_FORM_data16
:
22139 blk
= DW_BLOCK (attr
);
22140 if (TYPE_LENGTH (type
) != blk
->size
)
22141 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22142 TYPE_LENGTH (type
));
22143 *bytes
= blk
->data
;
22146 /* The DW_AT_const_value attributes are supposed to carry the
22147 symbol's value "represented as it would be on the target
22148 architecture." By the time we get here, it's already been
22149 converted to host endianness, so we just need to sign- or
22150 zero-extend it as appropriate. */
22151 case DW_FORM_data1
:
22152 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22154 case DW_FORM_data2
:
22155 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22157 case DW_FORM_data4
:
22158 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22160 case DW_FORM_data8
:
22161 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22164 case DW_FORM_sdata
:
22165 case DW_FORM_implicit_const
:
22166 *value
= DW_SND (attr
);
22169 case DW_FORM_udata
:
22170 *value
= DW_UNSND (attr
);
22174 complaint (&symfile_complaints
,
22175 _("unsupported const value attribute form: '%s'"),
22176 dwarf_form_name (attr
->form
));
22183 /* Copy constant value from an attribute to a symbol. */
22186 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22187 struct dwarf2_cu
*cu
)
22189 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22191 const gdb_byte
*bytes
;
22192 struct dwarf2_locexpr_baton
*baton
;
22194 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22195 SYMBOL_PRINT_NAME (sym
),
22196 &objfile
->objfile_obstack
, cu
,
22197 &value
, &bytes
, &baton
);
22201 SYMBOL_LOCATION_BATON (sym
) = baton
;
22202 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22204 else if (bytes
!= NULL
)
22206 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22207 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22211 SYMBOL_VALUE (sym
) = value
;
22212 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22216 /* Return the type of the die in question using its DW_AT_type attribute. */
22218 static struct type
*
22219 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22221 struct attribute
*type_attr
;
22223 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22226 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22227 /* A missing DW_AT_type represents a void type. */
22228 return objfile_type (objfile
)->builtin_void
;
22231 return lookup_die_type (die
, type_attr
, cu
);
22234 /* True iff CU's producer generates GNAT Ada auxiliary information
22235 that allows to find parallel types through that information instead
22236 of having to do expensive parallel lookups by type name. */
22239 need_gnat_info (struct dwarf2_cu
*cu
)
22241 /* Assume that the Ada compiler was GNAT, which always produces
22242 the auxiliary information. */
22243 return (cu
->language
== language_ada
);
22246 /* Return the auxiliary type of the die in question using its
22247 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22248 attribute is not present. */
22250 static struct type
*
22251 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22253 struct attribute
*type_attr
;
22255 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22259 return lookup_die_type (die
, type_attr
, cu
);
22262 /* If DIE has a descriptive_type attribute, then set the TYPE's
22263 descriptive type accordingly. */
22266 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22267 struct dwarf2_cu
*cu
)
22269 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22271 if (descriptive_type
)
22273 ALLOCATE_GNAT_AUX_TYPE (type
);
22274 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22278 /* Return the containing type of the die in question using its
22279 DW_AT_containing_type attribute. */
22281 static struct type
*
22282 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22284 struct attribute
*type_attr
;
22285 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22287 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22289 error (_("Dwarf Error: Problem turning containing type into gdb type "
22290 "[in module %s]"), objfile_name (objfile
));
22292 return lookup_die_type (die
, type_attr
, cu
);
22295 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22297 static struct type
*
22298 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22300 struct dwarf2_per_objfile
*dwarf2_per_objfile
22301 = cu
->per_cu
->dwarf2_per_objfile
;
22302 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22303 char *message
, *saved
;
22305 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
22306 objfile_name (objfile
),
22307 sect_offset_str (cu
->header
.sect_off
),
22308 sect_offset_str (die
->sect_off
));
22309 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
22310 message
, strlen (message
));
22313 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22316 /* Look up the type of DIE in CU using its type attribute ATTR.
22317 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22318 DW_AT_containing_type.
22319 If there is no type substitute an error marker. */
22321 static struct type
*
22322 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22323 struct dwarf2_cu
*cu
)
22325 struct dwarf2_per_objfile
*dwarf2_per_objfile
22326 = cu
->per_cu
->dwarf2_per_objfile
;
22327 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22328 struct type
*this_type
;
22330 gdb_assert (attr
->name
== DW_AT_type
22331 || attr
->name
== DW_AT_GNAT_descriptive_type
22332 || attr
->name
== DW_AT_containing_type
);
22334 /* First see if we have it cached. */
22336 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22338 struct dwarf2_per_cu_data
*per_cu
;
22339 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22341 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22342 dwarf2_per_objfile
);
22343 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22345 else if (attr_form_is_ref (attr
))
22347 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22349 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22351 else if (attr
->form
== DW_FORM_ref_sig8
)
22353 ULONGEST signature
= DW_SIGNATURE (attr
);
22355 return get_signatured_type (die
, signature
, cu
);
22359 complaint (&symfile_complaints
,
22360 _("Dwarf Error: Bad type attribute %s in DIE"
22361 " at %s [in module %s]"),
22362 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22363 objfile_name (objfile
));
22364 return build_error_marker_type (cu
, die
);
22367 /* If not cached we need to read it in. */
22369 if (this_type
== NULL
)
22371 struct die_info
*type_die
= NULL
;
22372 struct dwarf2_cu
*type_cu
= cu
;
22374 if (attr_form_is_ref (attr
))
22375 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22376 if (type_die
== NULL
)
22377 return build_error_marker_type (cu
, die
);
22378 /* If we find the type now, it's probably because the type came
22379 from an inter-CU reference and the type's CU got expanded before
22381 this_type
= read_type_die (type_die
, type_cu
);
22384 /* If we still don't have a type use an error marker. */
22386 if (this_type
== NULL
)
22387 return build_error_marker_type (cu
, die
);
22392 /* Return the type in DIE, CU.
22393 Returns NULL for invalid types.
22395 This first does a lookup in die_type_hash,
22396 and only reads the die in if necessary.
22398 NOTE: This can be called when reading in partial or full symbols. */
22400 static struct type
*
22401 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22403 struct type
*this_type
;
22405 this_type
= get_die_type (die
, cu
);
22409 return read_type_die_1 (die
, cu
);
22412 /* Read the type in DIE, CU.
22413 Returns NULL for invalid types. */
22415 static struct type
*
22416 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22418 struct type
*this_type
= NULL
;
22422 case DW_TAG_class_type
:
22423 case DW_TAG_interface_type
:
22424 case DW_TAG_structure_type
:
22425 case DW_TAG_union_type
:
22426 this_type
= read_structure_type (die
, cu
);
22428 case DW_TAG_enumeration_type
:
22429 this_type
= read_enumeration_type (die
, cu
);
22431 case DW_TAG_subprogram
:
22432 case DW_TAG_subroutine_type
:
22433 case DW_TAG_inlined_subroutine
:
22434 this_type
= read_subroutine_type (die
, cu
);
22436 case DW_TAG_array_type
:
22437 this_type
= read_array_type (die
, cu
);
22439 case DW_TAG_set_type
:
22440 this_type
= read_set_type (die
, cu
);
22442 case DW_TAG_pointer_type
:
22443 this_type
= read_tag_pointer_type (die
, cu
);
22445 case DW_TAG_ptr_to_member_type
:
22446 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22448 case DW_TAG_reference_type
:
22449 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22451 case DW_TAG_rvalue_reference_type
:
22452 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22454 case DW_TAG_const_type
:
22455 this_type
= read_tag_const_type (die
, cu
);
22457 case DW_TAG_volatile_type
:
22458 this_type
= read_tag_volatile_type (die
, cu
);
22460 case DW_TAG_restrict_type
:
22461 this_type
= read_tag_restrict_type (die
, cu
);
22463 case DW_TAG_string_type
:
22464 this_type
= read_tag_string_type (die
, cu
);
22466 case DW_TAG_typedef
:
22467 this_type
= read_typedef (die
, cu
);
22469 case DW_TAG_subrange_type
:
22470 this_type
= read_subrange_type (die
, cu
);
22472 case DW_TAG_base_type
:
22473 this_type
= read_base_type (die
, cu
);
22475 case DW_TAG_unspecified_type
:
22476 this_type
= read_unspecified_type (die
, cu
);
22478 case DW_TAG_namespace
:
22479 this_type
= read_namespace_type (die
, cu
);
22481 case DW_TAG_module
:
22482 this_type
= read_module_type (die
, cu
);
22484 case DW_TAG_atomic_type
:
22485 this_type
= read_tag_atomic_type (die
, cu
);
22488 complaint (&symfile_complaints
,
22489 _("unexpected tag in read_type_die: '%s'"),
22490 dwarf_tag_name (die
->tag
));
22497 /* See if we can figure out if the class lives in a namespace. We do
22498 this by looking for a member function; its demangled name will
22499 contain namespace info, if there is any.
22500 Return the computed name or NULL.
22501 Space for the result is allocated on the objfile's obstack.
22502 This is the full-die version of guess_partial_die_structure_name.
22503 In this case we know DIE has no useful parent. */
22506 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22508 struct die_info
*spec_die
;
22509 struct dwarf2_cu
*spec_cu
;
22510 struct die_info
*child
;
22511 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22514 spec_die
= die_specification (die
, &spec_cu
);
22515 if (spec_die
!= NULL
)
22521 for (child
= die
->child
;
22523 child
= child
->sibling
)
22525 if (child
->tag
== DW_TAG_subprogram
)
22527 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22529 if (linkage_name
!= NULL
)
22532 = language_class_name_from_physname (cu
->language_defn
,
22536 if (actual_name
!= NULL
)
22538 const char *die_name
= dwarf2_name (die
, cu
);
22540 if (die_name
!= NULL
22541 && strcmp (die_name
, actual_name
) != 0)
22543 /* Strip off the class name from the full name.
22544 We want the prefix. */
22545 int die_name_len
= strlen (die_name
);
22546 int actual_name_len
= strlen (actual_name
);
22548 /* Test for '::' as a sanity check. */
22549 if (actual_name_len
> die_name_len
+ 2
22550 && actual_name
[actual_name_len
22551 - die_name_len
- 1] == ':')
22552 name
= (char *) obstack_copy0 (
22553 &objfile
->per_bfd
->storage_obstack
,
22554 actual_name
, actual_name_len
- die_name_len
- 2);
22557 xfree (actual_name
);
22566 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22567 prefix part in such case. See
22568 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22570 static const char *
22571 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22573 struct attribute
*attr
;
22576 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22577 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22580 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22583 attr
= dw2_linkage_name_attr (die
, cu
);
22584 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22587 /* dwarf2_name had to be already called. */
22588 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22590 /* Strip the base name, keep any leading namespaces/classes. */
22591 base
= strrchr (DW_STRING (attr
), ':');
22592 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22595 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22596 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22598 &base
[-1] - DW_STRING (attr
));
22601 /* Return the name of the namespace/class that DIE is defined within,
22602 or "" if we can't tell. The caller should not xfree the result.
22604 For example, if we're within the method foo() in the following
22614 then determine_prefix on foo's die will return "N::C". */
22616 static const char *
22617 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22619 struct dwarf2_per_objfile
*dwarf2_per_objfile
22620 = cu
->per_cu
->dwarf2_per_objfile
;
22621 struct die_info
*parent
, *spec_die
;
22622 struct dwarf2_cu
*spec_cu
;
22623 struct type
*parent_type
;
22624 const char *retval
;
22626 if (cu
->language
!= language_cplus
22627 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22628 && cu
->language
!= language_rust
)
22631 retval
= anonymous_struct_prefix (die
, cu
);
22635 /* We have to be careful in the presence of DW_AT_specification.
22636 For example, with GCC 3.4, given the code
22640 // Definition of N::foo.
22644 then we'll have a tree of DIEs like this:
22646 1: DW_TAG_compile_unit
22647 2: DW_TAG_namespace // N
22648 3: DW_TAG_subprogram // declaration of N::foo
22649 4: DW_TAG_subprogram // definition of N::foo
22650 DW_AT_specification // refers to die #3
22652 Thus, when processing die #4, we have to pretend that we're in
22653 the context of its DW_AT_specification, namely the contex of die
22656 spec_die
= die_specification (die
, &spec_cu
);
22657 if (spec_die
== NULL
)
22658 parent
= die
->parent
;
22661 parent
= spec_die
->parent
;
22665 if (parent
== NULL
)
22667 else if (parent
->building_fullname
)
22670 const char *parent_name
;
22672 /* It has been seen on RealView 2.2 built binaries,
22673 DW_TAG_template_type_param types actually _defined_ as
22674 children of the parent class:
22677 template class <class Enum> Class{};
22678 Class<enum E> class_e;
22680 1: DW_TAG_class_type (Class)
22681 2: DW_TAG_enumeration_type (E)
22682 3: DW_TAG_enumerator (enum1:0)
22683 3: DW_TAG_enumerator (enum2:1)
22685 2: DW_TAG_template_type_param
22686 DW_AT_type DW_FORM_ref_udata (E)
22688 Besides being broken debug info, it can put GDB into an
22689 infinite loop. Consider:
22691 When we're building the full name for Class<E>, we'll start
22692 at Class, and go look over its template type parameters,
22693 finding E. We'll then try to build the full name of E, and
22694 reach here. We're now trying to build the full name of E,
22695 and look over the parent DIE for containing scope. In the
22696 broken case, if we followed the parent DIE of E, we'd again
22697 find Class, and once again go look at its template type
22698 arguments, etc., etc. Simply don't consider such parent die
22699 as source-level parent of this die (it can't be, the language
22700 doesn't allow it), and break the loop here. */
22701 name
= dwarf2_name (die
, cu
);
22702 parent_name
= dwarf2_name (parent
, cu
);
22703 complaint (&symfile_complaints
,
22704 _("template param type '%s' defined within parent '%s'"),
22705 name
? name
: "<unknown>",
22706 parent_name
? parent_name
: "<unknown>");
22710 switch (parent
->tag
)
22712 case DW_TAG_namespace
:
22713 parent_type
= read_type_die (parent
, cu
);
22714 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22715 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22716 Work around this problem here. */
22717 if (cu
->language
== language_cplus
22718 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22720 /* We give a name to even anonymous namespaces. */
22721 return TYPE_TAG_NAME (parent_type
);
22722 case DW_TAG_class_type
:
22723 case DW_TAG_interface_type
:
22724 case DW_TAG_structure_type
:
22725 case DW_TAG_union_type
:
22726 case DW_TAG_module
:
22727 parent_type
= read_type_die (parent
, cu
);
22728 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22729 return TYPE_TAG_NAME (parent_type
);
22731 /* An anonymous structure is only allowed non-static data
22732 members; no typedefs, no member functions, et cetera.
22733 So it does not need a prefix. */
22735 case DW_TAG_compile_unit
:
22736 case DW_TAG_partial_unit
:
22737 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22738 if (cu
->language
== language_cplus
22739 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22740 && die
->child
!= NULL
22741 && (die
->tag
== DW_TAG_class_type
22742 || die
->tag
== DW_TAG_structure_type
22743 || die
->tag
== DW_TAG_union_type
))
22745 char *name
= guess_full_die_structure_name (die
, cu
);
22750 case DW_TAG_enumeration_type
:
22751 parent_type
= read_type_die (parent
, cu
);
22752 if (TYPE_DECLARED_CLASS (parent_type
))
22754 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22755 return TYPE_TAG_NAME (parent_type
);
22758 /* Fall through. */
22760 return determine_prefix (parent
, cu
);
22764 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22765 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22766 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22767 an obconcat, otherwise allocate storage for the result. The CU argument is
22768 used to determine the language and hence, the appropriate separator. */
22770 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22773 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22774 int physname
, struct dwarf2_cu
*cu
)
22776 const char *lead
= "";
22779 if (suffix
== NULL
|| suffix
[0] == '\0'
22780 || prefix
== NULL
|| prefix
[0] == '\0')
22782 else if (cu
->language
== language_d
)
22784 /* For D, the 'main' function could be defined in any module, but it
22785 should never be prefixed. */
22786 if (strcmp (suffix
, "D main") == 0)
22794 else if (cu
->language
== language_fortran
&& physname
)
22796 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22797 DW_AT_MIPS_linkage_name is preferred and used instead. */
22805 if (prefix
== NULL
)
22807 if (suffix
== NULL
)
22814 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22816 strcpy (retval
, lead
);
22817 strcat (retval
, prefix
);
22818 strcat (retval
, sep
);
22819 strcat (retval
, suffix
);
22824 /* We have an obstack. */
22825 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22829 /* Return sibling of die, NULL if no sibling. */
22831 static struct die_info
*
22832 sibling_die (struct die_info
*die
)
22834 return die
->sibling
;
22837 /* Get name of a die, return NULL if not found. */
22839 static const char *
22840 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22841 struct obstack
*obstack
)
22843 if (name
&& cu
->language
== language_cplus
)
22845 std::string canon_name
= cp_canonicalize_string (name
);
22847 if (!canon_name
.empty ())
22849 if (canon_name
!= name
)
22850 name
= (const char *) obstack_copy0 (obstack
,
22851 canon_name
.c_str (),
22852 canon_name
.length ());
22859 /* Get name of a die, return NULL if not found.
22860 Anonymous namespaces are converted to their magic string. */
22862 static const char *
22863 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22865 struct attribute
*attr
;
22866 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22868 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22869 if ((!attr
|| !DW_STRING (attr
))
22870 && die
->tag
!= DW_TAG_namespace
22871 && die
->tag
!= DW_TAG_class_type
22872 && die
->tag
!= DW_TAG_interface_type
22873 && die
->tag
!= DW_TAG_structure_type
22874 && die
->tag
!= DW_TAG_union_type
)
22879 case DW_TAG_compile_unit
:
22880 case DW_TAG_partial_unit
:
22881 /* Compilation units have a DW_AT_name that is a filename, not
22882 a source language identifier. */
22883 case DW_TAG_enumeration_type
:
22884 case DW_TAG_enumerator
:
22885 /* These tags always have simple identifiers already; no need
22886 to canonicalize them. */
22887 return DW_STRING (attr
);
22889 case DW_TAG_namespace
:
22890 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22891 return DW_STRING (attr
);
22892 return CP_ANONYMOUS_NAMESPACE_STR
;
22894 case DW_TAG_class_type
:
22895 case DW_TAG_interface_type
:
22896 case DW_TAG_structure_type
:
22897 case DW_TAG_union_type
:
22898 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22899 structures or unions. These were of the form "._%d" in GCC 4.1,
22900 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22901 and GCC 4.4. We work around this problem by ignoring these. */
22902 if (attr
&& DW_STRING (attr
)
22903 && (startswith (DW_STRING (attr
), "._")
22904 || startswith (DW_STRING (attr
), "<anonymous")))
22907 /* GCC might emit a nameless typedef that has a linkage name. See
22908 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22909 if (!attr
|| DW_STRING (attr
) == NULL
)
22911 char *demangled
= NULL
;
22913 attr
= dw2_linkage_name_attr (die
, cu
);
22914 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22917 /* Avoid demangling DW_STRING (attr) the second time on a second
22918 call for the same DIE. */
22919 if (!DW_STRING_IS_CANONICAL (attr
))
22920 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22926 /* FIXME: we already did this for the partial symbol... */
22929 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22930 demangled
, strlen (demangled
)));
22931 DW_STRING_IS_CANONICAL (attr
) = 1;
22934 /* Strip any leading namespaces/classes, keep only the base name.
22935 DW_AT_name for named DIEs does not contain the prefixes. */
22936 base
= strrchr (DW_STRING (attr
), ':');
22937 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22940 return DW_STRING (attr
);
22949 if (!DW_STRING_IS_CANONICAL (attr
))
22952 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22953 &objfile
->per_bfd
->storage_obstack
);
22954 DW_STRING_IS_CANONICAL (attr
) = 1;
22956 return DW_STRING (attr
);
22959 /* Return the die that this die in an extension of, or NULL if there
22960 is none. *EXT_CU is the CU containing DIE on input, and the CU
22961 containing the return value on output. */
22963 static struct die_info
*
22964 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22966 struct attribute
*attr
;
22968 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22972 return follow_die_ref (die
, attr
, ext_cu
);
22975 /* Convert a DIE tag into its string name. */
22977 static const char *
22978 dwarf_tag_name (unsigned tag
)
22980 const char *name
= get_DW_TAG_name (tag
);
22983 return "DW_TAG_<unknown>";
22988 /* Convert a DWARF attribute code into its string name. */
22990 static const char *
22991 dwarf_attr_name (unsigned attr
)
22995 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22996 if (attr
== DW_AT_MIPS_fde
)
22997 return "DW_AT_MIPS_fde";
22999 if (attr
== DW_AT_HP_block_index
)
23000 return "DW_AT_HP_block_index";
23003 name
= get_DW_AT_name (attr
);
23006 return "DW_AT_<unknown>";
23011 /* Convert a DWARF value form code into its string name. */
23013 static const char *
23014 dwarf_form_name (unsigned form
)
23016 const char *name
= get_DW_FORM_name (form
);
23019 return "DW_FORM_<unknown>";
23024 static const char *
23025 dwarf_bool_name (unsigned mybool
)
23033 /* Convert a DWARF type code into its string name. */
23035 static const char *
23036 dwarf_type_encoding_name (unsigned enc
)
23038 const char *name
= get_DW_ATE_name (enc
);
23041 return "DW_ATE_<unknown>";
23047 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23051 print_spaces (indent
, f
);
23052 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23053 dwarf_tag_name (die
->tag
), die
->abbrev
,
23054 sect_offset_str (die
->sect_off
));
23056 if (die
->parent
!= NULL
)
23058 print_spaces (indent
, f
);
23059 fprintf_unfiltered (f
, " parent at offset: %s\n",
23060 sect_offset_str (die
->parent
->sect_off
));
23063 print_spaces (indent
, f
);
23064 fprintf_unfiltered (f
, " has children: %s\n",
23065 dwarf_bool_name (die
->child
!= NULL
));
23067 print_spaces (indent
, f
);
23068 fprintf_unfiltered (f
, " attributes:\n");
23070 for (i
= 0; i
< die
->num_attrs
; ++i
)
23072 print_spaces (indent
, f
);
23073 fprintf_unfiltered (f
, " %s (%s) ",
23074 dwarf_attr_name (die
->attrs
[i
].name
),
23075 dwarf_form_name (die
->attrs
[i
].form
));
23077 switch (die
->attrs
[i
].form
)
23080 case DW_FORM_GNU_addr_index
:
23081 fprintf_unfiltered (f
, "address: ");
23082 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23084 case DW_FORM_block2
:
23085 case DW_FORM_block4
:
23086 case DW_FORM_block
:
23087 case DW_FORM_block1
:
23088 fprintf_unfiltered (f
, "block: size %s",
23089 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23091 case DW_FORM_exprloc
:
23092 fprintf_unfiltered (f
, "expression: size %s",
23093 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23095 case DW_FORM_data16
:
23096 fprintf_unfiltered (f
, "constant of 16 bytes");
23098 case DW_FORM_ref_addr
:
23099 fprintf_unfiltered (f
, "ref address: ");
23100 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23102 case DW_FORM_GNU_ref_alt
:
23103 fprintf_unfiltered (f
, "alt ref address: ");
23104 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23110 case DW_FORM_ref_udata
:
23111 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23112 (long) (DW_UNSND (&die
->attrs
[i
])));
23114 case DW_FORM_data1
:
23115 case DW_FORM_data2
:
23116 case DW_FORM_data4
:
23117 case DW_FORM_data8
:
23118 case DW_FORM_udata
:
23119 case DW_FORM_sdata
:
23120 fprintf_unfiltered (f
, "constant: %s",
23121 pulongest (DW_UNSND (&die
->attrs
[i
])));
23123 case DW_FORM_sec_offset
:
23124 fprintf_unfiltered (f
, "section offset: %s",
23125 pulongest (DW_UNSND (&die
->attrs
[i
])));
23127 case DW_FORM_ref_sig8
:
23128 fprintf_unfiltered (f
, "signature: %s",
23129 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23131 case DW_FORM_string
:
23133 case DW_FORM_line_strp
:
23134 case DW_FORM_GNU_str_index
:
23135 case DW_FORM_GNU_strp_alt
:
23136 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23137 DW_STRING (&die
->attrs
[i
])
23138 ? DW_STRING (&die
->attrs
[i
]) : "",
23139 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23142 if (DW_UNSND (&die
->attrs
[i
]))
23143 fprintf_unfiltered (f
, "flag: TRUE");
23145 fprintf_unfiltered (f
, "flag: FALSE");
23147 case DW_FORM_flag_present
:
23148 fprintf_unfiltered (f
, "flag: TRUE");
23150 case DW_FORM_indirect
:
23151 /* The reader will have reduced the indirect form to
23152 the "base form" so this form should not occur. */
23153 fprintf_unfiltered (f
,
23154 "unexpected attribute form: DW_FORM_indirect");
23156 case DW_FORM_implicit_const
:
23157 fprintf_unfiltered (f
, "constant: %s",
23158 plongest (DW_SND (&die
->attrs
[i
])));
23161 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23162 die
->attrs
[i
].form
);
23165 fprintf_unfiltered (f
, "\n");
23170 dump_die_for_error (struct die_info
*die
)
23172 dump_die_shallow (gdb_stderr
, 0, die
);
23176 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23178 int indent
= level
* 4;
23180 gdb_assert (die
!= NULL
);
23182 if (level
>= max_level
)
23185 dump_die_shallow (f
, indent
, die
);
23187 if (die
->child
!= NULL
)
23189 print_spaces (indent
, f
);
23190 fprintf_unfiltered (f
, " Children:");
23191 if (level
+ 1 < max_level
)
23193 fprintf_unfiltered (f
, "\n");
23194 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23198 fprintf_unfiltered (f
,
23199 " [not printed, max nesting level reached]\n");
23203 if (die
->sibling
!= NULL
&& level
> 0)
23205 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23209 /* This is called from the pdie macro in gdbinit.in.
23210 It's not static so gcc will keep a copy callable from gdb. */
23213 dump_die (struct die_info
*die
, int max_level
)
23215 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23219 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23223 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23224 to_underlying (die
->sect_off
),
23230 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23234 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23236 if (attr_form_is_ref (attr
))
23237 return (sect_offset
) DW_UNSND (attr
);
23239 complaint (&symfile_complaints
,
23240 _("unsupported die ref attribute form: '%s'"),
23241 dwarf_form_name (attr
->form
));
23245 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23246 * the value held by the attribute is not constant. */
23249 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23251 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23252 return DW_SND (attr
);
23253 else if (attr
->form
== DW_FORM_udata
23254 || attr
->form
== DW_FORM_data1
23255 || attr
->form
== DW_FORM_data2
23256 || attr
->form
== DW_FORM_data4
23257 || attr
->form
== DW_FORM_data8
)
23258 return DW_UNSND (attr
);
23261 /* For DW_FORM_data16 see attr_form_is_constant. */
23262 complaint (&symfile_complaints
,
23263 _("Attribute value is not a constant (%s)"),
23264 dwarf_form_name (attr
->form
));
23265 return default_value
;
23269 /* Follow reference or signature attribute ATTR of SRC_DIE.
23270 On entry *REF_CU is the CU of SRC_DIE.
23271 On exit *REF_CU is the CU of the result. */
23273 static struct die_info
*
23274 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23275 struct dwarf2_cu
**ref_cu
)
23277 struct die_info
*die
;
23279 if (attr_form_is_ref (attr
))
23280 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23281 else if (attr
->form
== DW_FORM_ref_sig8
)
23282 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23285 dump_die_for_error (src_die
);
23286 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23287 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23293 /* Follow reference OFFSET.
23294 On entry *REF_CU is the CU of the source die referencing OFFSET.
23295 On exit *REF_CU is the CU of the result.
23296 Returns NULL if OFFSET is invalid. */
23298 static struct die_info
*
23299 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23300 struct dwarf2_cu
**ref_cu
)
23302 struct die_info temp_die
;
23303 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23304 struct dwarf2_per_objfile
*dwarf2_per_objfile
23305 = cu
->per_cu
->dwarf2_per_objfile
;
23306 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23308 gdb_assert (cu
->per_cu
!= NULL
);
23312 if (cu
->per_cu
->is_debug_types
)
23314 /* .debug_types CUs cannot reference anything outside their CU.
23315 If they need to, they have to reference a signatured type via
23316 DW_FORM_ref_sig8. */
23317 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23320 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23321 || !offset_in_cu_p (&cu
->header
, sect_off
))
23323 struct dwarf2_per_cu_data
*per_cu
;
23325 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23326 dwarf2_per_objfile
);
23328 /* If necessary, add it to the queue and load its DIEs. */
23329 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23330 load_full_comp_unit (per_cu
, cu
->language
);
23332 target_cu
= per_cu
->cu
;
23334 else if (cu
->dies
== NULL
)
23336 /* We're loading full DIEs during partial symbol reading. */
23337 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23338 load_full_comp_unit (cu
->per_cu
, language_minimal
);
23341 *ref_cu
= target_cu
;
23342 temp_die
.sect_off
= sect_off
;
23343 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23345 to_underlying (sect_off
));
23348 /* Follow reference attribute ATTR of SRC_DIE.
23349 On entry *REF_CU is the CU of SRC_DIE.
23350 On exit *REF_CU is the CU of the result. */
23352 static struct die_info
*
23353 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23354 struct dwarf2_cu
**ref_cu
)
23356 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23357 struct dwarf2_cu
*cu
= *ref_cu
;
23358 struct die_info
*die
;
23360 die
= follow_die_offset (sect_off
,
23361 (attr
->form
== DW_FORM_GNU_ref_alt
23362 || cu
->per_cu
->is_dwz
),
23365 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23366 "at %s [in module %s]"),
23367 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23368 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23373 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23374 Returned value is intended for DW_OP_call*. Returned
23375 dwarf2_locexpr_baton->data has lifetime of
23376 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23378 struct dwarf2_locexpr_baton
23379 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23380 struct dwarf2_per_cu_data
*per_cu
,
23381 CORE_ADDR (*get_frame_pc
) (void *baton
),
23384 struct dwarf2_cu
*cu
;
23385 struct die_info
*die
;
23386 struct attribute
*attr
;
23387 struct dwarf2_locexpr_baton retval
;
23388 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23389 struct dwarf2_per_objfile
*dwarf2_per_objfile
23390 = get_dwarf2_per_objfile (objfile
);
23392 if (per_cu
->cu
== NULL
)
23397 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23398 Instead just throw an error, not much else we can do. */
23399 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23400 sect_offset_str (sect_off
), objfile_name (objfile
));
23403 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23405 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23406 sect_offset_str (sect_off
), objfile_name (objfile
));
23408 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23411 /* DWARF: "If there is no such attribute, then there is no effect.".
23412 DATA is ignored if SIZE is 0. */
23414 retval
.data
= NULL
;
23417 else if (attr_form_is_section_offset (attr
))
23419 struct dwarf2_loclist_baton loclist_baton
;
23420 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23423 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23425 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23427 retval
.size
= size
;
23431 if (!attr_form_is_block (attr
))
23432 error (_("Dwarf Error: DIE at %s referenced in module %s "
23433 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23434 sect_offset_str (sect_off
), objfile_name (objfile
));
23436 retval
.data
= DW_BLOCK (attr
)->data
;
23437 retval
.size
= DW_BLOCK (attr
)->size
;
23439 retval
.per_cu
= cu
->per_cu
;
23441 age_cached_comp_units (dwarf2_per_objfile
);
23446 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23449 struct dwarf2_locexpr_baton
23450 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23451 struct dwarf2_per_cu_data
*per_cu
,
23452 CORE_ADDR (*get_frame_pc
) (void *baton
),
23455 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23457 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23460 /* Write a constant of a given type as target-ordered bytes into
23463 static const gdb_byte
*
23464 write_constant_as_bytes (struct obstack
*obstack
,
23465 enum bfd_endian byte_order
,
23472 *len
= TYPE_LENGTH (type
);
23473 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23474 store_unsigned_integer (result
, *len
, byte_order
, value
);
23479 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23480 pointer to the constant bytes and set LEN to the length of the
23481 data. If memory is needed, allocate it on OBSTACK. If the DIE
23482 does not have a DW_AT_const_value, return NULL. */
23485 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23486 struct dwarf2_per_cu_data
*per_cu
,
23487 struct obstack
*obstack
,
23490 struct dwarf2_cu
*cu
;
23491 struct die_info
*die
;
23492 struct attribute
*attr
;
23493 const gdb_byte
*result
= NULL
;
23496 enum bfd_endian byte_order
;
23497 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23499 if (per_cu
->cu
== NULL
)
23504 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23505 Instead just throw an error, not much else we can do. */
23506 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23507 sect_offset_str (sect_off
), objfile_name (objfile
));
23510 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23512 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23513 sect_offset_str (sect_off
), objfile_name (objfile
));
23515 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23519 byte_order
= (bfd_big_endian (objfile
->obfd
)
23520 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23522 switch (attr
->form
)
23525 case DW_FORM_GNU_addr_index
:
23529 *len
= cu
->header
.addr_size
;
23530 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23531 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23535 case DW_FORM_string
:
23537 case DW_FORM_GNU_str_index
:
23538 case DW_FORM_GNU_strp_alt
:
23539 /* DW_STRING is already allocated on the objfile obstack, point
23541 result
= (const gdb_byte
*) DW_STRING (attr
);
23542 *len
= strlen (DW_STRING (attr
));
23544 case DW_FORM_block1
:
23545 case DW_FORM_block2
:
23546 case DW_FORM_block4
:
23547 case DW_FORM_block
:
23548 case DW_FORM_exprloc
:
23549 case DW_FORM_data16
:
23550 result
= DW_BLOCK (attr
)->data
;
23551 *len
= DW_BLOCK (attr
)->size
;
23554 /* The DW_AT_const_value attributes are supposed to carry the
23555 symbol's value "represented as it would be on the target
23556 architecture." By the time we get here, it's already been
23557 converted to host endianness, so we just need to sign- or
23558 zero-extend it as appropriate. */
23559 case DW_FORM_data1
:
23560 type
= die_type (die
, cu
);
23561 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23562 if (result
== NULL
)
23563 result
= write_constant_as_bytes (obstack
, byte_order
,
23566 case DW_FORM_data2
:
23567 type
= die_type (die
, cu
);
23568 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23569 if (result
== NULL
)
23570 result
= write_constant_as_bytes (obstack
, byte_order
,
23573 case DW_FORM_data4
:
23574 type
= die_type (die
, cu
);
23575 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23576 if (result
== NULL
)
23577 result
= write_constant_as_bytes (obstack
, byte_order
,
23580 case DW_FORM_data8
:
23581 type
= die_type (die
, cu
);
23582 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23583 if (result
== NULL
)
23584 result
= write_constant_as_bytes (obstack
, byte_order
,
23588 case DW_FORM_sdata
:
23589 case DW_FORM_implicit_const
:
23590 type
= die_type (die
, cu
);
23591 result
= write_constant_as_bytes (obstack
, byte_order
,
23592 type
, DW_SND (attr
), len
);
23595 case DW_FORM_udata
:
23596 type
= die_type (die
, cu
);
23597 result
= write_constant_as_bytes (obstack
, byte_order
,
23598 type
, DW_UNSND (attr
), len
);
23602 complaint (&symfile_complaints
,
23603 _("unsupported const value attribute form: '%s'"),
23604 dwarf_form_name (attr
->form
));
23611 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23612 valid type for this die is found. */
23615 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23616 struct dwarf2_per_cu_data
*per_cu
)
23618 struct dwarf2_cu
*cu
;
23619 struct die_info
*die
;
23621 if (per_cu
->cu
== NULL
)
23627 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23631 return die_type (die
, cu
);
23634 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23638 dwarf2_get_die_type (cu_offset die_offset
,
23639 struct dwarf2_per_cu_data
*per_cu
)
23641 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23642 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23645 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23646 On entry *REF_CU is the CU of SRC_DIE.
23647 On exit *REF_CU is the CU of the result.
23648 Returns NULL if the referenced DIE isn't found. */
23650 static struct die_info
*
23651 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23652 struct dwarf2_cu
**ref_cu
)
23654 struct die_info temp_die
;
23655 struct dwarf2_cu
*sig_cu
;
23656 struct die_info
*die
;
23658 /* While it might be nice to assert sig_type->type == NULL here,
23659 we can get here for DW_AT_imported_declaration where we need
23660 the DIE not the type. */
23662 /* If necessary, add it to the queue and load its DIEs. */
23664 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23665 read_signatured_type (sig_type
);
23667 sig_cu
= sig_type
->per_cu
.cu
;
23668 gdb_assert (sig_cu
!= NULL
);
23669 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23670 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23671 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23672 to_underlying (temp_die
.sect_off
));
23675 struct dwarf2_per_objfile
*dwarf2_per_objfile
23676 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23678 /* For .gdb_index version 7 keep track of included TUs.
23679 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23680 if (dwarf2_per_objfile
->index_table
!= NULL
23681 && dwarf2_per_objfile
->index_table
->version
<= 7)
23683 VEC_safe_push (dwarf2_per_cu_ptr
,
23684 (*ref_cu
)->per_cu
->imported_symtabs
,
23695 /* Follow signatured type referenced by ATTR in SRC_DIE.
23696 On entry *REF_CU is the CU of SRC_DIE.
23697 On exit *REF_CU is the CU of the result.
23698 The result is the DIE of the type.
23699 If the referenced type cannot be found an error is thrown. */
23701 static struct die_info
*
23702 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23703 struct dwarf2_cu
**ref_cu
)
23705 ULONGEST signature
= DW_SIGNATURE (attr
);
23706 struct signatured_type
*sig_type
;
23707 struct die_info
*die
;
23709 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23711 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23712 /* sig_type will be NULL if the signatured type is missing from
23714 if (sig_type
== NULL
)
23716 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23717 " from DIE at %s [in module %s]"),
23718 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23719 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23722 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23725 dump_die_for_error (src_die
);
23726 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23727 " from DIE at %s [in module %s]"),
23728 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23729 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23735 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23736 reading in and processing the type unit if necessary. */
23738 static struct type
*
23739 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23740 struct dwarf2_cu
*cu
)
23742 struct dwarf2_per_objfile
*dwarf2_per_objfile
23743 = cu
->per_cu
->dwarf2_per_objfile
;
23744 struct signatured_type
*sig_type
;
23745 struct dwarf2_cu
*type_cu
;
23746 struct die_info
*type_die
;
23749 sig_type
= lookup_signatured_type (cu
, signature
);
23750 /* sig_type will be NULL if the signatured type is missing from
23752 if (sig_type
== NULL
)
23754 complaint (&symfile_complaints
,
23755 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23756 " from DIE at %s [in module %s]"),
23757 hex_string (signature
), sect_offset_str (die
->sect_off
),
23758 objfile_name (dwarf2_per_objfile
->objfile
));
23759 return build_error_marker_type (cu
, die
);
23762 /* If we already know the type we're done. */
23763 if (sig_type
->type
!= NULL
)
23764 return sig_type
->type
;
23767 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23768 if (type_die
!= NULL
)
23770 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23771 is created. This is important, for example, because for c++ classes
23772 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23773 type
= read_type_die (type_die
, type_cu
);
23776 complaint (&symfile_complaints
,
23777 _("Dwarf Error: Cannot build signatured type %s"
23778 " referenced from DIE at %s [in module %s]"),
23779 hex_string (signature
), sect_offset_str (die
->sect_off
),
23780 objfile_name (dwarf2_per_objfile
->objfile
));
23781 type
= build_error_marker_type (cu
, die
);
23786 complaint (&symfile_complaints
,
23787 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23788 " from DIE at %s [in module %s]"),
23789 hex_string (signature
), sect_offset_str (die
->sect_off
),
23790 objfile_name (dwarf2_per_objfile
->objfile
));
23791 type
= build_error_marker_type (cu
, die
);
23793 sig_type
->type
= type
;
23798 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23799 reading in and processing the type unit if necessary. */
23801 static struct type
*
23802 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23803 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23805 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23806 if (attr_form_is_ref (attr
))
23808 struct dwarf2_cu
*type_cu
= cu
;
23809 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23811 return read_type_die (type_die
, type_cu
);
23813 else if (attr
->form
== DW_FORM_ref_sig8
)
23815 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23819 struct dwarf2_per_objfile
*dwarf2_per_objfile
23820 = cu
->per_cu
->dwarf2_per_objfile
;
23822 complaint (&symfile_complaints
,
23823 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23824 " at %s [in module %s]"),
23825 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23826 objfile_name (dwarf2_per_objfile
->objfile
));
23827 return build_error_marker_type (cu
, die
);
23831 /* Load the DIEs associated with type unit PER_CU into memory. */
23834 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23836 struct signatured_type
*sig_type
;
23838 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23839 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23841 /* We have the per_cu, but we need the signatured_type.
23842 Fortunately this is an easy translation. */
23843 gdb_assert (per_cu
->is_debug_types
);
23844 sig_type
= (struct signatured_type
*) per_cu
;
23846 gdb_assert (per_cu
->cu
== NULL
);
23848 read_signatured_type (sig_type
);
23850 gdb_assert (per_cu
->cu
!= NULL
);
23853 /* die_reader_func for read_signatured_type.
23854 This is identical to load_full_comp_unit_reader,
23855 but is kept separate for now. */
23858 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23859 const gdb_byte
*info_ptr
,
23860 struct die_info
*comp_unit_die
,
23864 struct dwarf2_cu
*cu
= reader
->cu
;
23866 gdb_assert (cu
->die_hash
== NULL
);
23868 htab_create_alloc_ex (cu
->header
.length
/ 12,
23872 &cu
->comp_unit_obstack
,
23873 hashtab_obstack_allocate
,
23874 dummy_obstack_deallocate
);
23877 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23878 &info_ptr
, comp_unit_die
);
23879 cu
->dies
= comp_unit_die
;
23880 /* comp_unit_die is not stored in die_hash, no need. */
23882 /* We try not to read any attributes in this function, because not
23883 all CUs needed for references have been loaded yet, and symbol
23884 table processing isn't initialized. But we have to set the CU language,
23885 or we won't be able to build types correctly.
23886 Similarly, if we do not read the producer, we can not apply
23887 producer-specific interpretation. */
23888 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23891 /* Read in a signatured type and build its CU and DIEs.
23892 If the type is a stub for the real type in a DWO file,
23893 read in the real type from the DWO file as well. */
23896 read_signatured_type (struct signatured_type
*sig_type
)
23898 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23900 gdb_assert (per_cu
->is_debug_types
);
23901 gdb_assert (per_cu
->cu
== NULL
);
23903 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23904 read_signatured_type_reader
, NULL
);
23905 sig_type
->per_cu
.tu_read
= 1;
23908 /* Decode simple location descriptions.
23909 Given a pointer to a dwarf block that defines a location, compute
23910 the location and return the value.
23912 NOTE drow/2003-11-18: This function is called in two situations
23913 now: for the address of static or global variables (partial symbols
23914 only) and for offsets into structures which are expected to be
23915 (more or less) constant. The partial symbol case should go away,
23916 and only the constant case should remain. That will let this
23917 function complain more accurately. A few special modes are allowed
23918 without complaint for global variables (for instance, global
23919 register values and thread-local values).
23921 A location description containing no operations indicates that the
23922 object is optimized out. The return value is 0 for that case.
23923 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23924 callers will only want a very basic result and this can become a
23927 Note that stack[0] is unused except as a default error return. */
23930 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23932 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23934 size_t size
= blk
->size
;
23935 const gdb_byte
*data
= blk
->data
;
23936 CORE_ADDR stack
[64];
23938 unsigned int bytes_read
, unsnd
;
23944 stack
[++stacki
] = 0;
23983 stack
[++stacki
] = op
- DW_OP_lit0
;
24018 stack
[++stacki
] = op
- DW_OP_reg0
;
24020 dwarf2_complex_location_expr_complaint ();
24024 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24026 stack
[++stacki
] = unsnd
;
24028 dwarf2_complex_location_expr_complaint ();
24032 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24037 case DW_OP_const1u
:
24038 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24042 case DW_OP_const1s
:
24043 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24047 case DW_OP_const2u
:
24048 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24052 case DW_OP_const2s
:
24053 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24057 case DW_OP_const4u
:
24058 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24062 case DW_OP_const4s
:
24063 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24067 case DW_OP_const8u
:
24068 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24073 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24079 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24084 stack
[stacki
+ 1] = stack
[stacki
];
24089 stack
[stacki
- 1] += stack
[stacki
];
24093 case DW_OP_plus_uconst
:
24094 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24100 stack
[stacki
- 1] -= stack
[stacki
];
24105 /* If we're not the last op, then we definitely can't encode
24106 this using GDB's address_class enum. This is valid for partial
24107 global symbols, although the variable's address will be bogus
24110 dwarf2_complex_location_expr_complaint ();
24113 case DW_OP_GNU_push_tls_address
:
24114 case DW_OP_form_tls_address
:
24115 /* The top of the stack has the offset from the beginning
24116 of the thread control block at which the variable is located. */
24117 /* Nothing should follow this operator, so the top of stack would
24119 /* This is valid for partial global symbols, but the variable's
24120 address will be bogus in the psymtab. Make it always at least
24121 non-zero to not look as a variable garbage collected by linker
24122 which have DW_OP_addr 0. */
24124 dwarf2_complex_location_expr_complaint ();
24128 case DW_OP_GNU_uninit
:
24131 case DW_OP_GNU_addr_index
:
24132 case DW_OP_GNU_const_index
:
24133 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24140 const char *name
= get_DW_OP_name (op
);
24143 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
24146 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
24150 return (stack
[stacki
]);
24153 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24154 outside of the allocated space. Also enforce minimum>0. */
24155 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24157 complaint (&symfile_complaints
,
24158 _("location description stack overflow"));
24164 complaint (&symfile_complaints
,
24165 _("location description stack underflow"));
24169 return (stack
[stacki
]);
24172 /* memory allocation interface */
24174 static struct dwarf_block
*
24175 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24177 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24180 static struct die_info
*
24181 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24183 struct die_info
*die
;
24184 size_t size
= sizeof (struct die_info
);
24187 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24189 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24190 memset (die
, 0, sizeof (struct die_info
));
24195 /* Macro support. */
24197 /* Return file name relative to the compilation directory of file number I in
24198 *LH's file name table. The result is allocated using xmalloc; the caller is
24199 responsible for freeing it. */
24202 file_file_name (int file
, struct line_header
*lh
)
24204 /* Is the file number a valid index into the line header's file name
24205 table? Remember that file numbers start with one, not zero. */
24206 if (1 <= file
&& file
<= lh
->file_names
.size ())
24208 const file_entry
&fe
= lh
->file_names
[file
- 1];
24210 if (!IS_ABSOLUTE_PATH (fe
.name
))
24212 const char *dir
= fe
.include_dir (lh
);
24214 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24216 return xstrdup (fe
.name
);
24220 /* The compiler produced a bogus file number. We can at least
24221 record the macro definitions made in the file, even if we
24222 won't be able to find the file by name. */
24223 char fake_name
[80];
24225 xsnprintf (fake_name
, sizeof (fake_name
),
24226 "<bad macro file number %d>", file
);
24228 complaint (&symfile_complaints
,
24229 _("bad file number in macro information (%d)"),
24232 return xstrdup (fake_name
);
24236 /* Return the full name of file number I in *LH's file name table.
24237 Use COMP_DIR as the name of the current directory of the
24238 compilation. The result is allocated using xmalloc; the caller is
24239 responsible for freeing it. */
24241 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24243 /* Is the file number a valid index into the line header's file name
24244 table? Remember that file numbers start with one, not zero. */
24245 if (1 <= file
&& file
<= lh
->file_names
.size ())
24247 char *relative
= file_file_name (file
, lh
);
24249 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24251 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24252 relative
, (char *) NULL
);
24255 return file_file_name (file
, lh
);
24259 static struct macro_source_file
*
24260 macro_start_file (int file
, int line
,
24261 struct macro_source_file
*current_file
,
24262 struct line_header
*lh
)
24264 /* File name relative to the compilation directory of this source file. */
24265 char *file_name
= file_file_name (file
, lh
);
24267 if (! current_file
)
24269 /* Note: We don't create a macro table for this compilation unit
24270 at all until we actually get a filename. */
24271 struct macro_table
*macro_table
= get_macro_table ();
24273 /* If we have no current file, then this must be the start_file
24274 directive for the compilation unit's main source file. */
24275 current_file
= macro_set_main (macro_table
, file_name
);
24276 macro_define_special (macro_table
);
24279 current_file
= macro_include (current_file
, line
, file_name
);
24283 return current_file
;
24286 static const char *
24287 consume_improper_spaces (const char *p
, const char *body
)
24291 complaint (&symfile_complaints
,
24292 _("macro definition contains spaces "
24293 "in formal argument list:\n`%s'"),
24305 parse_macro_definition (struct macro_source_file
*file
, int line
,
24310 /* The body string takes one of two forms. For object-like macro
24311 definitions, it should be:
24313 <macro name> " " <definition>
24315 For function-like macro definitions, it should be:
24317 <macro name> "() " <definition>
24319 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24321 Spaces may appear only where explicitly indicated, and in the
24324 The Dwarf 2 spec says that an object-like macro's name is always
24325 followed by a space, but versions of GCC around March 2002 omit
24326 the space when the macro's definition is the empty string.
24328 The Dwarf 2 spec says that there should be no spaces between the
24329 formal arguments in a function-like macro's formal argument list,
24330 but versions of GCC around March 2002 include spaces after the
24334 /* Find the extent of the macro name. The macro name is terminated
24335 by either a space or null character (for an object-like macro) or
24336 an opening paren (for a function-like macro). */
24337 for (p
= body
; *p
; p
++)
24338 if (*p
== ' ' || *p
== '(')
24341 if (*p
== ' ' || *p
== '\0')
24343 /* It's an object-like macro. */
24344 int name_len
= p
- body
;
24345 char *name
= savestring (body
, name_len
);
24346 const char *replacement
;
24349 replacement
= body
+ name_len
+ 1;
24352 dwarf2_macro_malformed_definition_complaint (body
);
24353 replacement
= body
+ name_len
;
24356 macro_define_object (file
, line
, name
, replacement
);
24360 else if (*p
== '(')
24362 /* It's a function-like macro. */
24363 char *name
= savestring (body
, p
- body
);
24366 char **argv
= XNEWVEC (char *, argv_size
);
24370 p
= consume_improper_spaces (p
, body
);
24372 /* Parse the formal argument list. */
24373 while (*p
&& *p
!= ')')
24375 /* Find the extent of the current argument name. */
24376 const char *arg_start
= p
;
24378 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24381 if (! *p
|| p
== arg_start
)
24382 dwarf2_macro_malformed_definition_complaint (body
);
24385 /* Make sure argv has room for the new argument. */
24386 if (argc
>= argv_size
)
24389 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24392 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24395 p
= consume_improper_spaces (p
, body
);
24397 /* Consume the comma, if present. */
24402 p
= consume_improper_spaces (p
, body
);
24411 /* Perfectly formed definition, no complaints. */
24412 macro_define_function (file
, line
, name
,
24413 argc
, (const char **) argv
,
24415 else if (*p
== '\0')
24417 /* Complain, but do define it. */
24418 dwarf2_macro_malformed_definition_complaint (body
);
24419 macro_define_function (file
, line
, name
,
24420 argc
, (const char **) argv
,
24424 /* Just complain. */
24425 dwarf2_macro_malformed_definition_complaint (body
);
24428 /* Just complain. */
24429 dwarf2_macro_malformed_definition_complaint (body
);
24435 for (i
= 0; i
< argc
; i
++)
24441 dwarf2_macro_malformed_definition_complaint (body
);
24444 /* Skip some bytes from BYTES according to the form given in FORM.
24445 Returns the new pointer. */
24447 static const gdb_byte
*
24448 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24449 enum dwarf_form form
,
24450 unsigned int offset_size
,
24451 struct dwarf2_section_info
*section
)
24453 unsigned int bytes_read
;
24457 case DW_FORM_data1
:
24462 case DW_FORM_data2
:
24466 case DW_FORM_data4
:
24470 case DW_FORM_data8
:
24474 case DW_FORM_data16
:
24478 case DW_FORM_string
:
24479 read_direct_string (abfd
, bytes
, &bytes_read
);
24480 bytes
+= bytes_read
;
24483 case DW_FORM_sec_offset
:
24485 case DW_FORM_GNU_strp_alt
:
24486 bytes
+= offset_size
;
24489 case DW_FORM_block
:
24490 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24491 bytes
+= bytes_read
;
24494 case DW_FORM_block1
:
24495 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24497 case DW_FORM_block2
:
24498 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24500 case DW_FORM_block4
:
24501 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24504 case DW_FORM_sdata
:
24505 case DW_FORM_udata
:
24506 case DW_FORM_GNU_addr_index
:
24507 case DW_FORM_GNU_str_index
:
24508 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24511 dwarf2_section_buffer_overflow_complaint (section
);
24516 case DW_FORM_implicit_const
:
24521 complaint (&symfile_complaints
,
24522 _("invalid form 0x%x in `%s'"),
24523 form
, get_section_name (section
));
24531 /* A helper for dwarf_decode_macros that handles skipping an unknown
24532 opcode. Returns an updated pointer to the macro data buffer; or,
24533 on error, issues a complaint and returns NULL. */
24535 static const gdb_byte
*
24536 skip_unknown_opcode (unsigned int opcode
,
24537 const gdb_byte
**opcode_definitions
,
24538 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24540 unsigned int offset_size
,
24541 struct dwarf2_section_info
*section
)
24543 unsigned int bytes_read
, i
;
24545 const gdb_byte
*defn
;
24547 if (opcode_definitions
[opcode
] == NULL
)
24549 complaint (&symfile_complaints
,
24550 _("unrecognized DW_MACFINO opcode 0x%x"),
24555 defn
= opcode_definitions
[opcode
];
24556 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24557 defn
+= bytes_read
;
24559 for (i
= 0; i
< arg
; ++i
)
24561 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24562 (enum dwarf_form
) defn
[i
], offset_size
,
24564 if (mac_ptr
== NULL
)
24566 /* skip_form_bytes already issued the complaint. */
24574 /* A helper function which parses the header of a macro section.
24575 If the macro section is the extended (for now called "GNU") type,
24576 then this updates *OFFSET_SIZE. Returns a pointer to just after
24577 the header, or issues a complaint and returns NULL on error. */
24579 static const gdb_byte
*
24580 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24582 const gdb_byte
*mac_ptr
,
24583 unsigned int *offset_size
,
24584 int section_is_gnu
)
24586 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24588 if (section_is_gnu
)
24590 unsigned int version
, flags
;
24592 version
= read_2_bytes (abfd
, mac_ptr
);
24593 if (version
!= 4 && version
!= 5)
24595 complaint (&symfile_complaints
,
24596 _("unrecognized version `%d' in .debug_macro section"),
24602 flags
= read_1_byte (abfd
, mac_ptr
);
24604 *offset_size
= (flags
& 1) ? 8 : 4;
24606 if ((flags
& 2) != 0)
24607 /* We don't need the line table offset. */
24608 mac_ptr
+= *offset_size
;
24610 /* Vendor opcode descriptions. */
24611 if ((flags
& 4) != 0)
24613 unsigned int i
, count
;
24615 count
= read_1_byte (abfd
, mac_ptr
);
24617 for (i
= 0; i
< count
; ++i
)
24619 unsigned int opcode
, bytes_read
;
24622 opcode
= read_1_byte (abfd
, mac_ptr
);
24624 opcode_definitions
[opcode
] = mac_ptr
;
24625 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24626 mac_ptr
+= bytes_read
;
24635 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24636 including DW_MACRO_import. */
24639 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24641 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24642 struct macro_source_file
*current_file
,
24643 struct line_header
*lh
,
24644 struct dwarf2_section_info
*section
,
24645 int section_is_gnu
, int section_is_dwz
,
24646 unsigned int offset_size
,
24647 htab_t include_hash
)
24649 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24650 enum dwarf_macro_record_type macinfo_type
;
24651 int at_commandline
;
24652 const gdb_byte
*opcode_definitions
[256];
24654 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24655 &offset_size
, section_is_gnu
);
24656 if (mac_ptr
== NULL
)
24658 /* We already issued a complaint. */
24662 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24663 GDB is still reading the definitions from command line. First
24664 DW_MACINFO_start_file will need to be ignored as it was already executed
24665 to create CURRENT_FILE for the main source holding also the command line
24666 definitions. On first met DW_MACINFO_start_file this flag is reset to
24667 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24669 at_commandline
= 1;
24673 /* Do we at least have room for a macinfo type byte? */
24674 if (mac_ptr
>= mac_end
)
24676 dwarf2_section_buffer_overflow_complaint (section
);
24680 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24683 /* Note that we rely on the fact that the corresponding GNU and
24684 DWARF constants are the same. */
24686 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24687 switch (macinfo_type
)
24689 /* A zero macinfo type indicates the end of the macro
24694 case DW_MACRO_define
:
24695 case DW_MACRO_undef
:
24696 case DW_MACRO_define_strp
:
24697 case DW_MACRO_undef_strp
:
24698 case DW_MACRO_define_sup
:
24699 case DW_MACRO_undef_sup
:
24701 unsigned int bytes_read
;
24706 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24707 mac_ptr
+= bytes_read
;
24709 if (macinfo_type
== DW_MACRO_define
24710 || macinfo_type
== DW_MACRO_undef
)
24712 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24713 mac_ptr
+= bytes_read
;
24717 LONGEST str_offset
;
24719 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24720 mac_ptr
+= offset_size
;
24722 if (macinfo_type
== DW_MACRO_define_sup
24723 || macinfo_type
== DW_MACRO_undef_sup
24726 struct dwz_file
*dwz
24727 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24729 body
= read_indirect_string_from_dwz (objfile
,
24733 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24737 is_define
= (macinfo_type
== DW_MACRO_define
24738 || macinfo_type
== DW_MACRO_define_strp
24739 || macinfo_type
== DW_MACRO_define_sup
);
24740 if (! current_file
)
24742 /* DWARF violation as no main source is present. */
24743 complaint (&symfile_complaints
,
24744 _("debug info with no main source gives macro %s "
24746 is_define
? _("definition") : _("undefinition"),
24750 if ((line
== 0 && !at_commandline
)
24751 || (line
!= 0 && at_commandline
))
24752 complaint (&symfile_complaints
,
24753 _("debug info gives %s macro %s with %s line %d: %s"),
24754 at_commandline
? _("command-line") : _("in-file"),
24755 is_define
? _("definition") : _("undefinition"),
24756 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24759 parse_macro_definition (current_file
, line
, body
);
24762 gdb_assert (macinfo_type
== DW_MACRO_undef
24763 || macinfo_type
== DW_MACRO_undef_strp
24764 || macinfo_type
== DW_MACRO_undef_sup
);
24765 macro_undef (current_file
, line
, body
);
24770 case DW_MACRO_start_file
:
24772 unsigned int bytes_read
;
24775 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24776 mac_ptr
+= bytes_read
;
24777 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24778 mac_ptr
+= bytes_read
;
24780 if ((line
== 0 && !at_commandline
)
24781 || (line
!= 0 && at_commandline
))
24782 complaint (&symfile_complaints
,
24783 _("debug info gives source %d included "
24784 "from %s at %s line %d"),
24785 file
, at_commandline
? _("command-line") : _("file"),
24786 line
== 0 ? _("zero") : _("non-zero"), line
);
24788 if (at_commandline
)
24790 /* This DW_MACRO_start_file was executed in the
24792 at_commandline
= 0;
24795 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24799 case DW_MACRO_end_file
:
24800 if (! current_file
)
24801 complaint (&symfile_complaints
,
24802 _("macro debug info has an unmatched "
24803 "`close_file' directive"));
24806 current_file
= current_file
->included_by
;
24807 if (! current_file
)
24809 enum dwarf_macro_record_type next_type
;
24811 /* GCC circa March 2002 doesn't produce the zero
24812 type byte marking the end of the compilation
24813 unit. Complain if it's not there, but exit no
24816 /* Do we at least have room for a macinfo type byte? */
24817 if (mac_ptr
>= mac_end
)
24819 dwarf2_section_buffer_overflow_complaint (section
);
24823 /* We don't increment mac_ptr here, so this is just
24826 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24828 if (next_type
!= 0)
24829 complaint (&symfile_complaints
,
24830 _("no terminating 0-type entry for "
24831 "macros in `.debug_macinfo' section"));
24838 case DW_MACRO_import
:
24839 case DW_MACRO_import_sup
:
24843 bfd
*include_bfd
= abfd
;
24844 struct dwarf2_section_info
*include_section
= section
;
24845 const gdb_byte
*include_mac_end
= mac_end
;
24846 int is_dwz
= section_is_dwz
;
24847 const gdb_byte
*new_mac_ptr
;
24849 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24850 mac_ptr
+= offset_size
;
24852 if (macinfo_type
== DW_MACRO_import_sup
)
24854 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24856 dwarf2_read_section (objfile
, &dwz
->macro
);
24858 include_section
= &dwz
->macro
;
24859 include_bfd
= get_section_bfd_owner (include_section
);
24860 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24864 new_mac_ptr
= include_section
->buffer
+ offset
;
24865 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24869 /* This has actually happened; see
24870 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24871 complaint (&symfile_complaints
,
24872 _("recursive DW_MACRO_import in "
24873 ".debug_macro section"));
24877 *slot
= (void *) new_mac_ptr
;
24879 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24880 include_bfd
, new_mac_ptr
,
24881 include_mac_end
, current_file
, lh
,
24882 section
, section_is_gnu
, is_dwz
,
24883 offset_size
, include_hash
);
24885 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24890 case DW_MACINFO_vendor_ext
:
24891 if (!section_is_gnu
)
24893 unsigned int bytes_read
;
24895 /* This reads the constant, but since we don't recognize
24896 any vendor extensions, we ignore it. */
24897 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24898 mac_ptr
+= bytes_read
;
24899 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24900 mac_ptr
+= bytes_read
;
24902 /* We don't recognize any vendor extensions. */
24908 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24909 mac_ptr
, mac_end
, abfd
, offset_size
,
24911 if (mac_ptr
== NULL
)
24916 } while (macinfo_type
!= 0);
24920 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24921 int section_is_gnu
)
24923 struct dwarf2_per_objfile
*dwarf2_per_objfile
24924 = cu
->per_cu
->dwarf2_per_objfile
;
24925 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24926 struct line_header
*lh
= cu
->line_header
;
24928 const gdb_byte
*mac_ptr
, *mac_end
;
24929 struct macro_source_file
*current_file
= 0;
24930 enum dwarf_macro_record_type macinfo_type
;
24931 unsigned int offset_size
= cu
->header
.offset_size
;
24932 const gdb_byte
*opcode_definitions
[256];
24934 struct dwarf2_section_info
*section
;
24935 const char *section_name
;
24937 if (cu
->dwo_unit
!= NULL
)
24939 if (section_is_gnu
)
24941 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24942 section_name
= ".debug_macro.dwo";
24946 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24947 section_name
= ".debug_macinfo.dwo";
24952 if (section_is_gnu
)
24954 section
= &dwarf2_per_objfile
->macro
;
24955 section_name
= ".debug_macro";
24959 section
= &dwarf2_per_objfile
->macinfo
;
24960 section_name
= ".debug_macinfo";
24964 dwarf2_read_section (objfile
, section
);
24965 if (section
->buffer
== NULL
)
24967 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24970 abfd
= get_section_bfd_owner (section
);
24972 /* First pass: Find the name of the base filename.
24973 This filename is needed in order to process all macros whose definition
24974 (or undefinition) comes from the command line. These macros are defined
24975 before the first DW_MACINFO_start_file entry, and yet still need to be
24976 associated to the base file.
24978 To determine the base file name, we scan the macro definitions until we
24979 reach the first DW_MACINFO_start_file entry. We then initialize
24980 CURRENT_FILE accordingly so that any macro definition found before the
24981 first DW_MACINFO_start_file can still be associated to the base file. */
24983 mac_ptr
= section
->buffer
+ offset
;
24984 mac_end
= section
->buffer
+ section
->size
;
24986 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24987 &offset_size
, section_is_gnu
);
24988 if (mac_ptr
== NULL
)
24990 /* We already issued a complaint. */
24996 /* Do we at least have room for a macinfo type byte? */
24997 if (mac_ptr
>= mac_end
)
24999 /* Complaint is printed during the second pass as GDB will probably
25000 stop the first pass earlier upon finding
25001 DW_MACINFO_start_file. */
25005 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25008 /* Note that we rely on the fact that the corresponding GNU and
25009 DWARF constants are the same. */
25011 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25012 switch (macinfo_type
)
25014 /* A zero macinfo type indicates the end of the macro
25019 case DW_MACRO_define
:
25020 case DW_MACRO_undef
:
25021 /* Only skip the data by MAC_PTR. */
25023 unsigned int bytes_read
;
25025 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25026 mac_ptr
+= bytes_read
;
25027 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25028 mac_ptr
+= bytes_read
;
25032 case DW_MACRO_start_file
:
25034 unsigned int bytes_read
;
25037 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25038 mac_ptr
+= bytes_read
;
25039 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25040 mac_ptr
+= bytes_read
;
25042 current_file
= macro_start_file (file
, line
, current_file
, lh
);
25046 case DW_MACRO_end_file
:
25047 /* No data to skip by MAC_PTR. */
25050 case DW_MACRO_define_strp
:
25051 case DW_MACRO_undef_strp
:
25052 case DW_MACRO_define_sup
:
25053 case DW_MACRO_undef_sup
:
25055 unsigned int bytes_read
;
25057 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25058 mac_ptr
+= bytes_read
;
25059 mac_ptr
+= offset_size
;
25063 case DW_MACRO_import
:
25064 case DW_MACRO_import_sup
:
25065 /* Note that, according to the spec, a transparent include
25066 chain cannot call DW_MACRO_start_file. So, we can just
25067 skip this opcode. */
25068 mac_ptr
+= offset_size
;
25071 case DW_MACINFO_vendor_ext
:
25072 /* Only skip the data by MAC_PTR. */
25073 if (!section_is_gnu
)
25075 unsigned int bytes_read
;
25077 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25078 mac_ptr
+= bytes_read
;
25079 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25080 mac_ptr
+= bytes_read
;
25085 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25086 mac_ptr
, mac_end
, abfd
, offset_size
,
25088 if (mac_ptr
== NULL
)
25093 } while (macinfo_type
!= 0 && current_file
== NULL
);
25095 /* Second pass: Process all entries.
25097 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25098 command-line macro definitions/undefinitions. This flag is unset when we
25099 reach the first DW_MACINFO_start_file entry. */
25101 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25103 NULL
, xcalloc
, xfree
));
25104 mac_ptr
= section
->buffer
+ offset
;
25105 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25106 *slot
= (void *) mac_ptr
;
25107 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
25108 abfd
, mac_ptr
, mac_end
,
25109 current_file
, lh
, section
,
25110 section_is_gnu
, 0, offset_size
,
25111 include_hash
.get ());
25114 /* Check if the attribute's form is a DW_FORM_block*
25115 if so return true else false. */
25118 attr_form_is_block (const struct attribute
*attr
)
25120 return (attr
== NULL
? 0 :
25121 attr
->form
== DW_FORM_block1
25122 || attr
->form
== DW_FORM_block2
25123 || attr
->form
== DW_FORM_block4
25124 || attr
->form
== DW_FORM_block
25125 || attr
->form
== DW_FORM_exprloc
);
25128 /* Return non-zero if ATTR's value is a section offset --- classes
25129 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25130 You may use DW_UNSND (attr) to retrieve such offsets.
25132 Section 7.5.4, "Attribute Encodings", explains that no attribute
25133 may have a value that belongs to more than one of these classes; it
25134 would be ambiguous if we did, because we use the same forms for all
25138 attr_form_is_section_offset (const struct attribute
*attr
)
25140 return (attr
->form
== DW_FORM_data4
25141 || attr
->form
== DW_FORM_data8
25142 || attr
->form
== DW_FORM_sec_offset
);
25145 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25146 zero otherwise. When this function returns true, you can apply
25147 dwarf2_get_attr_constant_value to it.
25149 However, note that for some attributes you must check
25150 attr_form_is_section_offset before using this test. DW_FORM_data4
25151 and DW_FORM_data8 are members of both the constant class, and of
25152 the classes that contain offsets into other debug sections
25153 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25154 that, if an attribute's can be either a constant or one of the
25155 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25156 taken as section offsets, not constants.
25158 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25159 cannot handle that. */
25162 attr_form_is_constant (const struct attribute
*attr
)
25164 switch (attr
->form
)
25166 case DW_FORM_sdata
:
25167 case DW_FORM_udata
:
25168 case DW_FORM_data1
:
25169 case DW_FORM_data2
:
25170 case DW_FORM_data4
:
25171 case DW_FORM_data8
:
25172 case DW_FORM_implicit_const
:
25180 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25181 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25184 attr_form_is_ref (const struct attribute
*attr
)
25186 switch (attr
->form
)
25188 case DW_FORM_ref_addr
:
25193 case DW_FORM_ref_udata
:
25194 case DW_FORM_GNU_ref_alt
:
25201 /* Return the .debug_loc section to use for CU.
25202 For DWO files use .debug_loc.dwo. */
25204 static struct dwarf2_section_info
*
25205 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25207 struct dwarf2_per_objfile
*dwarf2_per_objfile
25208 = cu
->per_cu
->dwarf2_per_objfile
;
25212 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25214 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25216 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25217 : &dwarf2_per_objfile
->loc
);
25220 /* A helper function that fills in a dwarf2_loclist_baton. */
25223 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25224 struct dwarf2_loclist_baton
*baton
,
25225 const struct attribute
*attr
)
25227 struct dwarf2_per_objfile
*dwarf2_per_objfile
25228 = cu
->per_cu
->dwarf2_per_objfile
;
25229 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25231 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25233 baton
->per_cu
= cu
->per_cu
;
25234 gdb_assert (baton
->per_cu
);
25235 /* We don't know how long the location list is, but make sure we
25236 don't run off the edge of the section. */
25237 baton
->size
= section
->size
- DW_UNSND (attr
);
25238 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25239 baton
->base_address
= cu
->base_address
;
25240 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25244 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25245 struct dwarf2_cu
*cu
, int is_block
)
25247 struct dwarf2_per_objfile
*dwarf2_per_objfile
25248 = cu
->per_cu
->dwarf2_per_objfile
;
25249 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25250 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25252 if (attr_form_is_section_offset (attr
)
25253 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25254 the section. If so, fall through to the complaint in the
25256 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25258 struct dwarf2_loclist_baton
*baton
;
25260 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25262 fill_in_loclist_baton (cu
, baton
, attr
);
25264 if (cu
->base_known
== 0)
25265 complaint (&symfile_complaints
,
25266 _("Location list used without "
25267 "specifying the CU base address."));
25269 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25270 ? dwarf2_loclist_block_index
25271 : dwarf2_loclist_index
);
25272 SYMBOL_LOCATION_BATON (sym
) = baton
;
25276 struct dwarf2_locexpr_baton
*baton
;
25278 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25279 baton
->per_cu
= cu
->per_cu
;
25280 gdb_assert (baton
->per_cu
);
25282 if (attr_form_is_block (attr
))
25284 /* Note that we're just copying the block's data pointer
25285 here, not the actual data. We're still pointing into the
25286 info_buffer for SYM's objfile; right now we never release
25287 that buffer, but when we do clean up properly this may
25289 baton
->size
= DW_BLOCK (attr
)->size
;
25290 baton
->data
= DW_BLOCK (attr
)->data
;
25294 dwarf2_invalid_attrib_class_complaint ("location description",
25295 SYMBOL_NATURAL_NAME (sym
));
25299 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25300 ? dwarf2_locexpr_block_index
25301 : dwarf2_locexpr_index
);
25302 SYMBOL_LOCATION_BATON (sym
) = baton
;
25306 /* Return the OBJFILE associated with the compilation unit CU. If CU
25307 came from a separate debuginfo file, then the master objfile is
25311 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25313 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25315 /* Return the master objfile, so that we can report and look up the
25316 correct file containing this variable. */
25317 if (objfile
->separate_debug_objfile_backlink
)
25318 objfile
= objfile
->separate_debug_objfile_backlink
;
25323 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25324 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25325 CU_HEADERP first. */
25327 static const struct comp_unit_head
*
25328 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25329 struct dwarf2_per_cu_data
*per_cu
)
25331 const gdb_byte
*info_ptr
;
25334 return &per_cu
->cu
->header
;
25336 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25338 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25339 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25340 rcuh_kind::COMPILE
);
25345 /* Return the address size given in the compilation unit header for CU. */
25348 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25350 struct comp_unit_head cu_header_local
;
25351 const struct comp_unit_head
*cu_headerp
;
25353 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25355 return cu_headerp
->addr_size
;
25358 /* Return the offset size given in the compilation unit header for CU. */
25361 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25363 struct comp_unit_head cu_header_local
;
25364 const struct comp_unit_head
*cu_headerp
;
25366 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25368 return cu_headerp
->offset_size
;
25371 /* See its dwarf2loc.h declaration. */
25374 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25376 struct comp_unit_head cu_header_local
;
25377 const struct comp_unit_head
*cu_headerp
;
25379 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25381 if (cu_headerp
->version
== 2)
25382 return cu_headerp
->addr_size
;
25384 return cu_headerp
->offset_size
;
25387 /* Return the text offset of the CU. The returned offset comes from
25388 this CU's objfile. If this objfile came from a separate debuginfo
25389 file, then the offset may be different from the corresponding
25390 offset in the parent objfile. */
25393 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25395 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25397 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25400 /* Return DWARF version number of PER_CU. */
25403 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25405 return per_cu
->dwarf_version
;
25408 /* Locate the .debug_info compilation unit from CU's objfile which contains
25409 the DIE at OFFSET. Raises an error on failure. */
25411 static struct dwarf2_per_cu_data
*
25412 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25413 unsigned int offset_in_dwz
,
25414 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25416 struct dwarf2_per_cu_data
*this_cu
;
25418 const sect_offset
*cu_off
;
25421 high
= dwarf2_per_objfile
->n_comp_units
- 1;
25424 struct dwarf2_per_cu_data
*mid_cu
;
25425 int mid
= low
+ (high
- low
) / 2;
25427 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25428 cu_off
= &mid_cu
->sect_off
;
25429 if (mid_cu
->is_dwz
> offset_in_dwz
25430 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25435 gdb_assert (low
== high
);
25436 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25437 cu_off
= &this_cu
->sect_off
;
25438 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25440 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25441 error (_("Dwarf Error: could not find partial DIE containing "
25442 "offset %s [in module %s]"),
25443 sect_offset_str (sect_off
),
25444 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25446 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25448 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25452 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25453 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25454 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25455 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25456 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25461 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25463 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25464 : per_cu (per_cu_
),
25467 checked_producer (0),
25468 producer_is_gxx_lt_4_6 (0),
25469 producer_is_gcc_lt_4_3 (0),
25470 producer_is_icc_lt_14 (0),
25471 processing_has_namespace_info (0)
25476 /* Destroy a dwarf2_cu. */
25478 dwarf2_cu::~dwarf2_cu ()
25483 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25486 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25487 enum language pretend_language
)
25489 struct attribute
*attr
;
25491 /* Set the language we're debugging. */
25492 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25494 set_cu_language (DW_UNSND (attr
), cu
);
25497 cu
->language
= pretend_language
;
25498 cu
->language_defn
= language_def (cu
->language
);
25501 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25504 /* Free all cached compilation units. */
25507 free_cached_comp_units (void *data
)
25509 struct dwarf2_per_objfile
*dwarf2_per_objfile
25510 = (struct dwarf2_per_objfile
*) data
;
25512 dwarf2_per_objfile
->free_cached_comp_units ();
25515 /* Increase the age counter on each cached compilation unit, and free
25516 any that are too old. */
25519 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25521 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25523 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25524 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25525 while (per_cu
!= NULL
)
25527 per_cu
->cu
->last_used
++;
25528 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25529 dwarf2_mark (per_cu
->cu
);
25530 per_cu
= per_cu
->cu
->read_in_chain
;
25533 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25534 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25535 while (per_cu
!= NULL
)
25537 struct dwarf2_per_cu_data
*next_cu
;
25539 next_cu
= per_cu
->cu
->read_in_chain
;
25541 if (!per_cu
->cu
->mark
)
25544 *last_chain
= next_cu
;
25547 last_chain
= &per_cu
->cu
->read_in_chain
;
25553 /* Remove a single compilation unit from the cache. */
25556 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25558 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25559 struct dwarf2_per_objfile
*dwarf2_per_objfile
25560 = target_per_cu
->dwarf2_per_objfile
;
25562 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25563 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25564 while (per_cu
!= NULL
)
25566 struct dwarf2_per_cu_data
*next_cu
;
25568 next_cu
= per_cu
->cu
->read_in_chain
;
25570 if (per_cu
== target_per_cu
)
25574 *last_chain
= next_cu
;
25578 last_chain
= &per_cu
->cu
->read_in_chain
;
25584 /* Release all extra memory associated with OBJFILE. */
25587 dwarf2_free_objfile (struct objfile
*objfile
)
25589 struct dwarf2_per_objfile
*dwarf2_per_objfile
25590 = get_dwarf2_per_objfile (objfile
);
25592 delete dwarf2_per_objfile
;
25595 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25596 We store these in a hash table separate from the DIEs, and preserve them
25597 when the DIEs are flushed out of cache.
25599 The CU "per_cu" pointer is needed because offset alone is not enough to
25600 uniquely identify the type. A file may have multiple .debug_types sections,
25601 or the type may come from a DWO file. Furthermore, while it's more logical
25602 to use per_cu->section+offset, with Fission the section with the data is in
25603 the DWO file but we don't know that section at the point we need it.
25604 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25605 because we can enter the lookup routine, get_die_type_at_offset, from
25606 outside this file, and thus won't necessarily have PER_CU->cu.
25607 Fortunately, PER_CU is stable for the life of the objfile. */
25609 struct dwarf2_per_cu_offset_and_type
25611 const struct dwarf2_per_cu_data
*per_cu
;
25612 sect_offset sect_off
;
25616 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25619 per_cu_offset_and_type_hash (const void *item
)
25621 const struct dwarf2_per_cu_offset_and_type
*ofs
25622 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25624 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25627 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25630 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25632 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25633 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25634 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25635 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25637 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25638 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25641 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25642 table if necessary. For convenience, return TYPE.
25644 The DIEs reading must have careful ordering to:
25645 * Not cause infite loops trying to read in DIEs as a prerequisite for
25646 reading current DIE.
25647 * Not trying to dereference contents of still incompletely read in types
25648 while reading in other DIEs.
25649 * Enable referencing still incompletely read in types just by a pointer to
25650 the type without accessing its fields.
25652 Therefore caller should follow these rules:
25653 * Try to fetch any prerequisite types we may need to build this DIE type
25654 before building the type and calling set_die_type.
25655 * After building type call set_die_type for current DIE as soon as
25656 possible before fetching more types to complete the current type.
25657 * Make the type as complete as possible before fetching more types. */
25659 static struct type
*
25660 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25662 struct dwarf2_per_objfile
*dwarf2_per_objfile
25663 = cu
->per_cu
->dwarf2_per_objfile
;
25664 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25665 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25666 struct attribute
*attr
;
25667 struct dynamic_prop prop
;
25669 /* For Ada types, make sure that the gnat-specific data is always
25670 initialized (if not already set). There are a few types where
25671 we should not be doing so, because the type-specific area is
25672 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25673 where the type-specific area is used to store the floatformat).
25674 But this is not a problem, because the gnat-specific information
25675 is actually not needed for these types. */
25676 if (need_gnat_info (cu
)
25677 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25678 && TYPE_CODE (type
) != TYPE_CODE_FLT
25679 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25680 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25681 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25682 && !HAVE_GNAT_AUX_INFO (type
))
25683 INIT_GNAT_SPECIFIC (type
);
25685 /* Read DW_AT_allocated and set in type. */
25686 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25687 if (attr_form_is_block (attr
))
25689 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25690 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25692 else if (attr
!= NULL
)
25694 complaint (&symfile_complaints
,
25695 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25696 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25697 sect_offset_str (die
->sect_off
));
25700 /* Read DW_AT_associated and set in type. */
25701 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25702 if (attr_form_is_block (attr
))
25704 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25705 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25707 else if (attr
!= NULL
)
25709 complaint (&symfile_complaints
,
25710 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25711 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25712 sect_offset_str (die
->sect_off
));
25715 /* Read DW_AT_data_location and set in type. */
25716 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25717 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25718 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25720 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25722 dwarf2_per_objfile
->die_type_hash
=
25723 htab_create_alloc_ex (127,
25724 per_cu_offset_and_type_hash
,
25725 per_cu_offset_and_type_eq
,
25727 &objfile
->objfile_obstack
,
25728 hashtab_obstack_allocate
,
25729 dummy_obstack_deallocate
);
25732 ofs
.per_cu
= cu
->per_cu
;
25733 ofs
.sect_off
= die
->sect_off
;
25735 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25736 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25738 complaint (&symfile_complaints
,
25739 _("A problem internal to GDB: DIE %s has type already set"),
25740 sect_offset_str (die
->sect_off
));
25741 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25742 struct dwarf2_per_cu_offset_and_type
);
25747 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25748 or return NULL if the die does not have a saved type. */
25750 static struct type
*
25751 get_die_type_at_offset (sect_offset sect_off
,
25752 struct dwarf2_per_cu_data
*per_cu
)
25754 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25755 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25757 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25760 ofs
.per_cu
= per_cu
;
25761 ofs
.sect_off
= sect_off
;
25762 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25763 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25770 /* Look up the type for DIE in CU in die_type_hash,
25771 or return NULL if DIE does not have a saved type. */
25773 static struct type
*
25774 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25776 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25779 /* Add a dependence relationship from CU to REF_PER_CU. */
25782 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25783 struct dwarf2_per_cu_data
*ref_per_cu
)
25787 if (cu
->dependencies
== NULL
)
25789 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25790 NULL
, &cu
->comp_unit_obstack
,
25791 hashtab_obstack_allocate
,
25792 dummy_obstack_deallocate
);
25794 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25796 *slot
= ref_per_cu
;
25799 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25800 Set the mark field in every compilation unit in the
25801 cache that we must keep because we are keeping CU. */
25804 dwarf2_mark_helper (void **slot
, void *data
)
25806 struct dwarf2_per_cu_data
*per_cu
;
25808 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25810 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25811 reading of the chain. As such dependencies remain valid it is not much
25812 useful to track and undo them during QUIT cleanups. */
25813 if (per_cu
->cu
== NULL
)
25816 if (per_cu
->cu
->mark
)
25818 per_cu
->cu
->mark
= 1;
25820 if (per_cu
->cu
->dependencies
!= NULL
)
25821 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25826 /* Set the mark field in CU and in every other compilation unit in the
25827 cache that we must keep because we are keeping CU. */
25830 dwarf2_mark (struct dwarf2_cu
*cu
)
25835 if (cu
->dependencies
!= NULL
)
25836 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25840 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25844 per_cu
->cu
->mark
= 0;
25845 per_cu
= per_cu
->cu
->read_in_chain
;
25849 /* Trivial hash function for partial_die_info: the hash value of a DIE
25850 is its offset in .debug_info for this objfile. */
25853 partial_die_hash (const void *item
)
25855 const struct partial_die_info
*part_die
25856 = (const struct partial_die_info
*) item
;
25858 return to_underlying (part_die
->sect_off
);
25861 /* Trivial comparison function for partial_die_info structures: two DIEs
25862 are equal if they have the same offset. */
25865 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25867 const struct partial_die_info
*part_die_lhs
25868 = (const struct partial_die_info
*) item_lhs
;
25869 const struct partial_die_info
*part_die_rhs
25870 = (const struct partial_die_info
*) item_rhs
;
25872 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25875 static struct cmd_list_element
*set_dwarf_cmdlist
;
25876 static struct cmd_list_element
*show_dwarf_cmdlist
;
25879 set_dwarf_cmd (const char *args
, int from_tty
)
25881 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25886 show_dwarf_cmd (const char *args
, int from_tty
)
25888 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25891 /* The "save gdb-index" command. */
25893 /* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
25897 file_write (FILE *file
, const void *data
, size_t size
)
25899 if (fwrite (data
, 1, size
, file
) != size
)
25900 error (_("couldn't data write to file"));
25903 /* Write the contents of VEC to FILE, with error checking. */
25905 template<typename Elem
, typename Alloc
>
25907 file_write (FILE *file
, const std::vector
<Elem
, Alloc
> &vec
)
25909 file_write (file
, vec
.data (), vec
.size () * sizeof (vec
[0]));
25912 /* In-memory buffer to prepare data to be written later to a file. */
25916 /* Copy DATA to the end of the buffer. */
25917 template<typename T
>
25918 void append_data (const T
&data
)
25920 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
25921 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
25922 grow (sizeof (data
)));
25925 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
25926 terminating zero is appended too. */
25927 void append_cstr0 (const char *cstr
)
25929 const size_t size
= strlen (cstr
) + 1;
25930 std::copy (cstr
, cstr
+ size
, grow (size
));
25933 /* Store INPUT as ULEB128 to the end of buffer. */
25934 void append_unsigned_leb128 (ULONGEST input
)
25938 gdb_byte output
= input
& 0x7f;
25942 append_data (output
);
25948 /* Accept a host-format integer in VAL and append it to the buffer
25949 as a target-format integer which is LEN bytes long. */
25950 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
25952 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
25955 /* Return the size of the buffer. */
25956 size_t size () const
25958 return m_vec
.size ();
25961 /* Return true iff the buffer is empty. */
25962 bool empty () const
25964 return m_vec
.empty ();
25967 /* Write the buffer to FILE. */
25968 void file_write (FILE *file
) const
25970 ::file_write (file
, m_vec
);
25974 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
25975 the start of the new block. */
25976 gdb_byte
*grow (size_t size
)
25978 m_vec
.resize (m_vec
.size () + size
);
25979 return &*m_vec
.end () - size
;
25982 gdb::byte_vector m_vec
;
25985 /* An entry in the symbol table. */
25986 struct symtab_index_entry
25988 /* The name of the symbol. */
25990 /* The offset of the name in the constant pool. */
25991 offset_type index_offset
;
25992 /* A sorted vector of the indices of all the CUs that hold an object
25994 std::vector
<offset_type
> cu_indices
;
25997 /* The symbol table. This is a power-of-2-sized hash table. */
25998 struct mapped_symtab
26002 data
.resize (1024);
26005 offset_type n_elements
= 0;
26006 std::vector
<symtab_index_entry
> data
;
26009 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
26012 Function is used only during write_hash_table so no index format backward
26013 compatibility is needed. */
26015 static symtab_index_entry
&
26016 find_slot (struct mapped_symtab
*symtab
, const char *name
)
26018 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
26020 index
= hash
& (symtab
->data
.size () - 1);
26021 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
26025 if (symtab
->data
[index
].name
== NULL
26026 || strcmp (name
, symtab
->data
[index
].name
) == 0)
26027 return symtab
->data
[index
];
26028 index
= (index
+ step
) & (symtab
->data
.size () - 1);
26032 /* Expand SYMTAB's hash table. */
26035 hash_expand (struct mapped_symtab
*symtab
)
26037 auto old_entries
= std::move (symtab
->data
);
26039 symtab
->data
.clear ();
26040 symtab
->data
.resize (old_entries
.size () * 2);
26042 for (auto &it
: old_entries
)
26043 if (it
.name
!= NULL
)
26045 auto &ref
= find_slot (symtab
, it
.name
);
26046 ref
= std::move (it
);
26050 /* Add an entry to SYMTAB. NAME is the name of the symbol.
26051 CU_INDEX is the index of the CU in which the symbol appears.
26052 IS_STATIC is one if the symbol is static, otherwise zero (global). */
26055 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
26056 int is_static
, gdb_index_symbol_kind kind
,
26057 offset_type cu_index
)
26059 offset_type cu_index_and_attrs
;
26061 ++symtab
->n_elements
;
26062 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
26063 hash_expand (symtab
);
26065 symtab_index_entry
&slot
= find_slot (symtab
, name
);
26066 if (slot
.name
== NULL
)
26069 /* index_offset is set later. */
26072 cu_index_and_attrs
= 0;
26073 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
26074 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
26075 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
26077 /* We don't want to record an index value twice as we want to avoid the
26079 We process all global symbols and then all static symbols
26080 (which would allow us to avoid the duplication by only having to check
26081 the last entry pushed), but a symbol could have multiple kinds in one CU.
26082 To keep things simple we don't worry about the duplication here and
26083 sort and uniqufy the list after we've processed all symbols. */
26084 slot
.cu_indices
.push_back (cu_index_and_attrs
);
26087 /* Sort and remove duplicates of all symbols' cu_indices lists. */
26090 uniquify_cu_indices (struct mapped_symtab
*symtab
)
26092 for (auto &entry
: symtab
->data
)
26094 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
26096 auto &cu_indices
= entry
.cu_indices
;
26097 std::sort (cu_indices
.begin (), cu_indices
.end ());
26098 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
26099 cu_indices
.erase (from
, cu_indices
.end ());
26104 /* A form of 'const char *' suitable for container keys. Only the
26105 pointer is stored. The strings themselves are compared, not the
26110 c_str_view (const char *cstr
)
26114 bool operator== (const c_str_view
&other
) const
26116 return strcmp (m_cstr
, other
.m_cstr
) == 0;
26119 /* Return the underlying C string. Note, the returned string is
26120 only a reference with lifetime of this object. */
26121 const char *c_str () const
26127 friend class c_str_view_hasher
;
26128 const char *const m_cstr
;
26131 /* A std::unordered_map::hasher for c_str_view that uses the right
26132 hash function for strings in a mapped index. */
26133 class c_str_view_hasher
26136 size_t operator () (const c_str_view
&x
) const
26138 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
26142 /* A std::unordered_map::hasher for std::vector<>. */
26143 template<typename T
>
26144 class vector_hasher
26147 size_t operator () (const std::vector
<T
> &key
) const
26149 return iterative_hash (key
.data (),
26150 sizeof (key
.front ()) * key
.size (), 0);
26154 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
26155 constant pool entries going into the data buffer CPOOL. */
26158 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
26161 /* Elements are sorted vectors of the indices of all the CUs that
26162 hold an object of this name. */
26163 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
26164 vector_hasher
<offset_type
>>
26167 /* We add all the index vectors to the constant pool first, to
26168 ensure alignment is ok. */
26169 for (symtab_index_entry
&entry
: symtab
->data
)
26171 if (entry
.name
== NULL
)
26173 gdb_assert (entry
.index_offset
== 0);
26175 /* Finding before inserting is faster than always trying to
26176 insert, because inserting always allocates a node, does the
26177 lookup, and then destroys the new node if another node
26178 already had the same key. C++17 try_emplace will avoid
26181 = symbol_hash_table
.find (entry
.cu_indices
);
26182 if (found
!= symbol_hash_table
.end ())
26184 entry
.index_offset
= found
->second
;
26188 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
26189 entry
.index_offset
= cpool
.size ();
26190 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
26191 for (const auto index
: entry
.cu_indices
)
26192 cpool
.append_data (MAYBE_SWAP (index
));
26196 /* Now write out the hash table. */
26197 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
26198 for (const auto &entry
: symtab
->data
)
26200 offset_type str_off
, vec_off
;
26202 if (entry
.name
!= NULL
)
26204 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
26205 if (insertpair
.second
)
26206 cpool
.append_cstr0 (entry
.name
);
26207 str_off
= insertpair
.first
->second
;
26208 vec_off
= entry
.index_offset
;
26212 /* While 0 is a valid constant pool index, it is not valid
26213 to have 0 for both offsets. */
26218 output
.append_data (MAYBE_SWAP (str_off
));
26219 output
.append_data (MAYBE_SWAP (vec_off
));
26223 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
26225 /* Helper struct for building the address table. */
26226 struct addrmap_index_data
26228 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
26229 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
26232 struct objfile
*objfile
;
26233 data_buf
&addr_vec
;
26234 psym_index_map
&cu_index_htab
;
26236 /* Non-zero if the previous_* fields are valid.
26237 We can't write an entry until we see the next entry (since it is only then
26238 that we know the end of the entry). */
26239 int previous_valid
;
26240 /* Index of the CU in the table of all CUs in the index file. */
26241 unsigned int previous_cu_index
;
26242 /* Start address of the CU. */
26243 CORE_ADDR previous_cu_start
;
26246 /* Write an address entry to ADDR_VEC. */
26249 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
26250 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
26252 CORE_ADDR baseaddr
;
26254 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
26256 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
26257 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
26258 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
26261 /* Worker function for traversing an addrmap to build the address table. */
26264 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
26266 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
26267 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
26269 if (data
->previous_valid
)
26270 add_address_entry (data
->objfile
, data
->addr_vec
,
26271 data
->previous_cu_start
, start_addr
,
26272 data
->previous_cu_index
);
26274 data
->previous_cu_start
= start_addr
;
26277 const auto it
= data
->cu_index_htab
.find (pst
);
26278 gdb_assert (it
!= data
->cu_index_htab
.cend ());
26279 data
->previous_cu_index
= it
->second
;
26280 data
->previous_valid
= 1;
26283 data
->previous_valid
= 0;
26288 /* Write OBJFILE's address map to ADDR_VEC.
26289 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
26290 in the index file. */
26293 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
26294 psym_index_map
&cu_index_htab
)
26296 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
26298 /* When writing the address table, we have to cope with the fact that
26299 the addrmap iterator only provides the start of a region; we have to
26300 wait until the next invocation to get the start of the next region. */
26302 addrmap_index_data
.objfile
= objfile
;
26303 addrmap_index_data
.previous_valid
= 0;
26305 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
26306 &addrmap_index_data
);
26308 /* It's highly unlikely the last entry (end address = 0xff...ff)
26309 is valid, but we should still handle it.
26310 The end address is recorded as the start of the next region, but that
26311 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
26313 if (addrmap_index_data
.previous_valid
)
26314 add_address_entry (objfile
, addr_vec
,
26315 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
26316 addrmap_index_data
.previous_cu_index
);
26319 /* Return the symbol kind of PSYM. */
26321 static gdb_index_symbol_kind
26322 symbol_kind (struct partial_symbol
*psym
)
26324 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26325 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26333 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
26335 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26337 case LOC_CONST_BYTES
:
26338 case LOC_OPTIMIZED_OUT
:
26340 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26342 /* Note: It's currently impossible to recognize psyms as enum values
26343 short of reading the type info. For now punt. */
26344 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26346 /* There are other LOC_FOO values that one might want to classify
26347 as variables, but dwarf2read.c doesn't currently use them. */
26348 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26350 case STRUCT_DOMAIN
:
26351 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26353 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26357 /* Add a list of partial symbols to SYMTAB. */
26360 write_psymbols (struct mapped_symtab
*symtab
,
26361 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26362 struct partial_symbol
**psymp
,
26364 offset_type cu_index
,
26367 for (; count
-- > 0; ++psymp
)
26369 struct partial_symbol
*psym
= *psymp
;
26371 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
26372 error (_("Ada is not currently supported by the index"));
26374 /* Only add a given psymbol once. */
26375 if (psyms_seen
.insert (psym
).second
)
26377 gdb_index_symbol_kind kind
= symbol_kind (psym
);
26379 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
26380 is_static
, kind
, cu_index
);
26385 /* A helper struct used when iterating over debug_types. */
26386 struct signatured_type_index_data
26388 signatured_type_index_data (data_buf
&types_list_
,
26389 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
26390 : types_list (types_list_
), psyms_seen (psyms_seen_
)
26393 struct objfile
*objfile
;
26394 struct mapped_symtab
*symtab
;
26395 data_buf
&types_list
;
26396 std::unordered_set
<partial_symbol
*> &psyms_seen
;
26400 /* A helper function that writes a single signatured_type to an
26404 write_one_signatured_type (void **slot
, void *d
)
26406 struct signatured_type_index_data
*info
26407 = (struct signatured_type_index_data
*) d
;
26408 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26409 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26411 write_psymbols (info
->symtab
,
26413 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26414 psymtab
->n_global_syms
, info
->cu_index
,
26416 write_psymbols (info
->symtab
,
26418 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26419 psymtab
->n_static_syms
, info
->cu_index
,
26422 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26423 to_underlying (entry
->per_cu
.sect_off
));
26424 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26425 to_underlying (entry
->type_offset_in_tu
));
26426 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
26433 /* Recurse into all "included" dependencies and count their symbols as
26434 if they appeared in this psymtab. */
26437 recursively_count_psymbols (struct partial_symtab
*psymtab
,
26438 size_t &psyms_seen
)
26440 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26441 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26442 recursively_count_psymbols (psymtab
->dependencies
[i
],
26445 psyms_seen
+= psymtab
->n_global_syms
;
26446 psyms_seen
+= psymtab
->n_static_syms
;
26449 /* Recurse into all "included" dependencies and write their symbols as
26450 if they appeared in this psymtab. */
26453 recursively_write_psymbols (struct objfile
*objfile
,
26454 struct partial_symtab
*psymtab
,
26455 struct mapped_symtab
*symtab
,
26456 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26457 offset_type cu_index
)
26461 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26462 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26463 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26464 symtab
, psyms_seen
, cu_index
);
26466 write_psymbols (symtab
,
26468 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26469 psymtab
->n_global_syms
, cu_index
,
26471 write_psymbols (symtab
,
26473 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26474 psymtab
->n_static_syms
, cu_index
,
26478 /* DWARF-5 .debug_names builder. */
26482 debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bool is_dwarf64
,
26483 bfd_endian dwarf5_byte_order
)
26484 : m_dwarf5_byte_order (dwarf5_byte_order
),
26485 m_dwarf32 (dwarf5_byte_order
),
26486 m_dwarf64 (dwarf5_byte_order
),
26487 m_dwarf (is_dwarf64
26488 ? static_cast<dwarf
&> (m_dwarf64
)
26489 : static_cast<dwarf
&> (m_dwarf32
)),
26490 m_name_table_string_offs (m_dwarf
.name_table_string_offs
),
26491 m_name_table_entry_offs (m_dwarf
.name_table_entry_offs
),
26492 m_debugstrlookup (dwarf2_per_objfile
)
26495 int dwarf5_offset_size () const
26497 const bool dwarf5_is_dwarf64
= &m_dwarf
== &m_dwarf64
;
26498 return dwarf5_is_dwarf64
? 8 : 4;
26501 /* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
26502 enum class unit_kind
{ cu
, tu
};
26504 /* Insert one symbol. */
26505 void insert (const partial_symbol
*psym
, int cu_index
, bool is_static
,
26508 const int dwarf_tag
= psymbol_tag (psym
);
26509 if (dwarf_tag
== 0)
26511 const char *const name
= SYMBOL_SEARCH_NAME (psym
);
26512 const auto insertpair
26513 = m_name_to_value_set
.emplace (c_str_view (name
),
26514 std::set
<symbol_value
> ());
26515 std::set
<symbol_value
> &value_set
= insertpair
.first
->second
;
26516 value_set
.emplace (symbol_value (dwarf_tag
, cu_index
, is_static
, kind
));
26519 /* Build all the tables. All symbols must be already inserted.
26520 This function does not call file_write, caller has to do it
26524 /* Verify the build method has not be called twice. */
26525 gdb_assert (m_abbrev_table
.empty ());
26526 const size_t name_count
= m_name_to_value_set
.size ();
26527 m_bucket_table
.resize
26528 (std::pow (2, std::ceil (std::log2 (name_count
* 4 / 3))));
26529 m_hash_table
.reserve (name_count
);
26530 m_name_table_string_offs
.reserve (name_count
);
26531 m_name_table_entry_offs
.reserve (name_count
);
26533 /* Map each hash of symbol to its name and value. */
26534 struct hash_it_pair
26537 decltype (m_name_to_value_set
)::const_iterator it
;
26539 std::vector
<std::forward_list
<hash_it_pair
>> bucket_hash
;
26540 bucket_hash
.resize (m_bucket_table
.size ());
26541 for (decltype (m_name_to_value_set
)::const_iterator it
26542 = m_name_to_value_set
.cbegin ();
26543 it
!= m_name_to_value_set
.cend ();
26546 const char *const name
= it
->first
.c_str ();
26547 const uint32_t hash
= dwarf5_djb_hash (name
);
26548 hash_it_pair hashitpair
;
26549 hashitpair
.hash
= hash
;
26550 hashitpair
.it
= it
;
26551 auto &slot
= bucket_hash
[hash
% bucket_hash
.size()];
26552 slot
.push_front (std::move (hashitpair
));
26554 for (size_t bucket_ix
= 0; bucket_ix
< bucket_hash
.size (); ++bucket_ix
)
26556 const std::forward_list
<hash_it_pair
> &hashitlist
26557 = bucket_hash
[bucket_ix
];
26558 if (hashitlist
.empty ())
26560 uint32_t &bucket_slot
= m_bucket_table
[bucket_ix
];
26561 /* The hashes array is indexed starting at 1. */
26562 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&bucket_slot
),
26563 sizeof (bucket_slot
), m_dwarf5_byte_order
,
26564 m_hash_table
.size () + 1);
26565 for (const hash_it_pair
&hashitpair
: hashitlist
)
26567 m_hash_table
.push_back (0);
26568 store_unsigned_integer (reinterpret_cast<gdb_byte
*>
26569 (&m_hash_table
.back ()),
26570 sizeof (m_hash_table
.back ()),
26571 m_dwarf5_byte_order
, hashitpair
.hash
);
26572 const c_str_view
&name
= hashitpair
.it
->first
;
26573 const std::set
<symbol_value
> &value_set
= hashitpair
.it
->second
;
26574 m_name_table_string_offs
.push_back_reorder
26575 (m_debugstrlookup
.lookup (name
.c_str ()));
26576 m_name_table_entry_offs
.push_back_reorder (m_entry_pool
.size ());
26577 gdb_assert (!value_set
.empty ());
26578 for (const symbol_value
&value
: value_set
)
26580 int &idx
= m_indexkey_to_idx
[index_key (value
.dwarf_tag
,
26585 idx
= m_idx_next
++;
26586 m_abbrev_table
.append_unsigned_leb128 (idx
);
26587 m_abbrev_table
.append_unsigned_leb128 (value
.dwarf_tag
);
26588 m_abbrev_table
.append_unsigned_leb128
26589 (value
.kind
== unit_kind::cu
? DW_IDX_compile_unit
26590 : DW_IDX_type_unit
);
26591 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_udata
);
26592 m_abbrev_table
.append_unsigned_leb128 (value
.is_static
26593 ? DW_IDX_GNU_internal
26594 : DW_IDX_GNU_external
);
26595 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_flag_present
);
26597 /* Terminate attributes list. */
26598 m_abbrev_table
.append_unsigned_leb128 (0);
26599 m_abbrev_table
.append_unsigned_leb128 (0);
26602 m_entry_pool
.append_unsigned_leb128 (idx
);
26603 m_entry_pool
.append_unsigned_leb128 (value
.cu_index
);
26606 /* Terminate the list of CUs. */
26607 m_entry_pool
.append_unsigned_leb128 (0);
26610 gdb_assert (m_hash_table
.size () == name_count
);
26612 /* Terminate tags list. */
26613 m_abbrev_table
.append_unsigned_leb128 (0);
26616 /* Return .debug_names bucket count. This must be called only after
26617 calling the build method. */
26618 uint32_t bucket_count () const
26620 /* Verify the build method has been already called. */
26621 gdb_assert (!m_abbrev_table
.empty ());
26622 const uint32_t retval
= m_bucket_table
.size ();
26624 /* Check for overflow. */
26625 gdb_assert (retval
== m_bucket_table
.size ());
26629 /* Return .debug_names names count. This must be called only after
26630 calling the build method. */
26631 uint32_t name_count () const
26633 /* Verify the build method has been already called. */
26634 gdb_assert (!m_abbrev_table
.empty ());
26635 const uint32_t retval
= m_hash_table
.size ();
26637 /* Check for overflow. */
26638 gdb_assert (retval
== m_hash_table
.size ());
26642 /* Return number of bytes of .debug_names abbreviation table. This
26643 must be called only after calling the build method. */
26644 uint32_t abbrev_table_bytes () const
26646 gdb_assert (!m_abbrev_table
.empty ());
26647 return m_abbrev_table
.size ();
26650 /* Recurse into all "included" dependencies and store their symbols
26651 as if they appeared in this psymtab. */
26652 void recursively_write_psymbols
26653 (struct objfile
*objfile
,
26654 struct partial_symtab
*psymtab
,
26655 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26658 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26659 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26660 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26661 psyms_seen
, cu_index
);
26663 write_psymbols (psyms_seen
,
26664 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26665 psymtab
->n_global_syms
, cu_index
, false, unit_kind::cu
);
26666 write_psymbols (psyms_seen
,
26667 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26668 psymtab
->n_static_syms
, cu_index
, true, unit_kind::cu
);
26671 /* Return number of bytes the .debug_names section will have. This
26672 must be called only after calling the build method. */
26673 size_t bytes () const
26675 /* Verify the build method has been already called. */
26676 gdb_assert (!m_abbrev_table
.empty ());
26677 size_t expected_bytes
= 0;
26678 expected_bytes
+= m_bucket_table
.size () * sizeof (m_bucket_table
[0]);
26679 expected_bytes
+= m_hash_table
.size () * sizeof (m_hash_table
[0]);
26680 expected_bytes
+= m_name_table_string_offs
.bytes ();
26681 expected_bytes
+= m_name_table_entry_offs
.bytes ();
26682 expected_bytes
+= m_abbrev_table
.size ();
26683 expected_bytes
+= m_entry_pool
.size ();
26684 return expected_bytes
;
26687 /* Write .debug_names to FILE_NAMES and .debug_str addition to
26688 FILE_STR. This must be called only after calling the build
26690 void file_write (FILE *file_names
, FILE *file_str
) const
26692 /* Verify the build method has been already called. */
26693 gdb_assert (!m_abbrev_table
.empty ());
26694 ::file_write (file_names
, m_bucket_table
);
26695 ::file_write (file_names
, m_hash_table
);
26696 m_name_table_string_offs
.file_write (file_names
);
26697 m_name_table_entry_offs
.file_write (file_names
);
26698 m_abbrev_table
.file_write (file_names
);
26699 m_entry_pool
.file_write (file_names
);
26700 m_debugstrlookup
.file_write (file_str
);
26703 /* A helper user data for write_one_signatured_type. */
26704 class write_one_signatured_type_data
26707 write_one_signatured_type_data (debug_names
&nametable_
,
26708 signatured_type_index_data
&&info_
)
26709 : nametable (nametable_
), info (std::move (info_
))
26711 debug_names
&nametable
;
26712 struct signatured_type_index_data info
;
26715 /* A helper function to pass write_one_signatured_type to
26716 htab_traverse_noresize. */
26718 write_one_signatured_type (void **slot
, void *d
)
26720 write_one_signatured_type_data
*data
= (write_one_signatured_type_data
*) d
;
26721 struct signatured_type_index_data
*info
= &data
->info
;
26722 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26724 data
->nametable
.write_one_signatured_type (entry
, info
);
26731 /* Storage for symbol names mapping them to their .debug_str section
26733 class debug_str_lookup
26737 /* Object costructor to be called for current DWARF2_PER_OBJFILE.
26738 All .debug_str section strings are automatically stored. */
26739 debug_str_lookup (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26740 : m_abfd (dwarf2_per_objfile
->objfile
->obfd
),
26741 m_dwarf2_per_objfile (dwarf2_per_objfile
)
26743 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
26744 &dwarf2_per_objfile
->str
);
26745 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
26747 for (const gdb_byte
*data
= dwarf2_per_objfile
->str
.buffer
;
26748 data
< (dwarf2_per_objfile
->str
.buffer
26749 + dwarf2_per_objfile
->str
.size
);)
26751 const char *const s
= reinterpret_cast<const char *> (data
);
26752 const auto insertpair
26753 = m_str_table
.emplace (c_str_view (s
),
26754 data
- dwarf2_per_objfile
->str
.buffer
);
26755 if (!insertpair
.second
)
26756 complaint (&symfile_complaints
,
26757 _("Duplicate string \"%s\" in "
26758 ".debug_str section [in module %s]"),
26759 s
, bfd_get_filename (m_abfd
));
26760 data
+= strlen (s
) + 1;
26764 /* Return offset of symbol name S in the .debug_str section. Add
26765 such symbol to the section's end if it does not exist there
26767 size_t lookup (const char *s
)
26769 const auto it
= m_str_table
.find (c_str_view (s
));
26770 if (it
!= m_str_table
.end ())
26772 const size_t offset
= (m_dwarf2_per_objfile
->str
.size
26773 + m_str_add_buf
.size ());
26774 m_str_table
.emplace (c_str_view (s
), offset
);
26775 m_str_add_buf
.append_cstr0 (s
);
26779 /* Append the end of the .debug_str section to FILE. */
26780 void file_write (FILE *file
) const
26782 m_str_add_buf
.file_write (file
);
26786 std::unordered_map
<c_str_view
, size_t, c_str_view_hasher
> m_str_table
;
26788 struct dwarf2_per_objfile
*m_dwarf2_per_objfile
;
26790 /* Data to add at the end of .debug_str for new needed symbol names. */
26791 data_buf m_str_add_buf
;
26794 /* Container to map used DWARF tags to their .debug_names abbreviation
26799 index_key (int dwarf_tag_
, bool is_static_
, unit_kind kind_
)
26800 : dwarf_tag (dwarf_tag_
), is_static (is_static_
), kind (kind_
)
26805 operator== (const index_key
&other
) const
26807 return (dwarf_tag
== other
.dwarf_tag
&& is_static
== other
.is_static
26808 && kind
== other
.kind
);
26811 const int dwarf_tag
;
26812 const bool is_static
;
26813 const unit_kind kind
;
26816 /* Provide std::unordered_map::hasher for index_key. */
26817 class index_key_hasher
26821 operator () (const index_key
&key
) const
26823 return (std::hash
<int>() (key
.dwarf_tag
) << 1) | key
.is_static
;
26827 /* Parameters of one symbol entry. */
26831 const int dwarf_tag
, cu_index
;
26832 const bool is_static
;
26833 const unit_kind kind
;
26835 symbol_value (int dwarf_tag_
, int cu_index_
, bool is_static_
,
26837 : dwarf_tag (dwarf_tag_
), cu_index (cu_index_
), is_static (is_static_
),
26842 operator< (const symbol_value
&other
) const
26862 /* Abstract base class to unify DWARF-32 and DWARF-64 name table
26867 const bfd_endian dwarf5_byte_order
;
26869 explicit offset_vec (bfd_endian dwarf5_byte_order_
)
26870 : dwarf5_byte_order (dwarf5_byte_order_
)
26873 /* Call std::vector::reserve for NELEM elements. */
26874 virtual void reserve (size_t nelem
) = 0;
26876 /* Call std::vector::push_back with store_unsigned_integer byte
26877 reordering for ELEM. */
26878 virtual void push_back_reorder (size_t elem
) = 0;
26880 /* Return expected output size in bytes. */
26881 virtual size_t bytes () const = 0;
26883 /* Write name table to FILE. */
26884 virtual void file_write (FILE *file
) const = 0;
26887 /* Template to unify DWARF-32 and DWARF-64 output. */
26888 template<typename OffsetSize
>
26889 class offset_vec_tmpl
: public offset_vec
26892 explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_
)
26893 : offset_vec (dwarf5_byte_order_
)
26896 /* Implement offset_vec::reserve. */
26897 void reserve (size_t nelem
) override
26899 m_vec
.reserve (nelem
);
26902 /* Implement offset_vec::push_back_reorder. */
26903 void push_back_reorder (size_t elem
) override
26905 m_vec
.push_back (elem
);
26906 /* Check for overflow. */
26907 gdb_assert (m_vec
.back () == elem
);
26908 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&m_vec
.back ()),
26909 sizeof (m_vec
.back ()), dwarf5_byte_order
, elem
);
26912 /* Implement offset_vec::bytes. */
26913 size_t bytes () const override
26915 return m_vec
.size () * sizeof (m_vec
[0]);
26918 /* Implement offset_vec::file_write. */
26919 void file_write (FILE *file
) const override
26921 ::file_write (file
, m_vec
);
26925 std::vector
<OffsetSize
> m_vec
;
26928 /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
26929 respecting name table width. */
26933 offset_vec
&name_table_string_offs
, &name_table_entry_offs
;
26935 dwarf (offset_vec
&name_table_string_offs_
,
26936 offset_vec
&name_table_entry_offs_
)
26937 : name_table_string_offs (name_table_string_offs_
),
26938 name_table_entry_offs (name_table_entry_offs_
)
26943 /* Template to unify DWARF-32 and DWARF-64 .debug_names output
26944 respecting name table width. */
26945 template<typename OffsetSize
>
26946 class dwarf_tmpl
: public dwarf
26949 explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_
)
26950 : dwarf (m_name_table_string_offs
, m_name_table_entry_offs
),
26951 m_name_table_string_offs (dwarf5_byte_order_
),
26952 m_name_table_entry_offs (dwarf5_byte_order_
)
26956 offset_vec_tmpl
<OffsetSize
> m_name_table_string_offs
;
26957 offset_vec_tmpl
<OffsetSize
> m_name_table_entry_offs
;
26960 /* Try to reconstruct original DWARF tag for given partial_symbol.
26961 This function is not DWARF-5 compliant but it is sufficient for
26962 GDB as a DWARF-5 index consumer. */
26963 static int psymbol_tag (const struct partial_symbol
*psym
)
26965 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26966 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26974 return DW_TAG_subprogram
;
26976 return DW_TAG_typedef
;
26978 case LOC_CONST_BYTES
:
26979 case LOC_OPTIMIZED_OUT
:
26981 return DW_TAG_variable
;
26983 /* Note: It's currently impossible to recognize psyms as enum values
26984 short of reading the type info. For now punt. */
26985 return DW_TAG_variable
;
26987 /* There are other LOC_FOO values that one might want to classify
26988 as variables, but dwarf2read.c doesn't currently use them. */
26989 return DW_TAG_variable
;
26991 case STRUCT_DOMAIN
:
26992 return DW_TAG_structure_type
;
26998 /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
26999 void write_psymbols (std::unordered_set
<partial_symbol
*> &psyms_seen
,
27000 struct partial_symbol
**psymp
, int count
, int cu_index
,
27001 bool is_static
, unit_kind kind
)
27003 for (; count
-- > 0; ++psymp
)
27005 struct partial_symbol
*psym
= *psymp
;
27007 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
27008 error (_("Ada is not currently supported by the index"));
27010 /* Only add a given psymbol once. */
27011 if (psyms_seen
.insert (psym
).second
)
27012 insert (psym
, cu_index
, is_static
, kind
);
27016 /* A helper function that writes a single signatured_type
27017 to a debug_names. */
27019 write_one_signatured_type (struct signatured_type
*entry
,
27020 struct signatured_type_index_data
*info
)
27022 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
27024 write_psymbols (info
->psyms_seen
,
27025 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
27026 psymtab
->n_global_syms
, info
->cu_index
, false,
27028 write_psymbols (info
->psyms_seen
,
27029 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
27030 psymtab
->n_static_syms
, info
->cu_index
, true,
27033 info
->types_list
.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order
,
27034 to_underlying (entry
->per_cu
.sect_off
));
27039 /* Store value of each symbol. */
27040 std::unordered_map
<c_str_view
, std::set
<symbol_value
>, c_str_view_hasher
>
27041 m_name_to_value_set
;
27043 /* Tables of DWARF-5 .debug_names. They are in object file byte
27045 std::vector
<uint32_t> m_bucket_table
;
27046 std::vector
<uint32_t> m_hash_table
;
27048 const bfd_endian m_dwarf5_byte_order
;
27049 dwarf_tmpl
<uint32_t> m_dwarf32
;
27050 dwarf_tmpl
<uint64_t> m_dwarf64
;
27052 offset_vec
&m_name_table_string_offs
, &m_name_table_entry_offs
;
27053 debug_str_lookup m_debugstrlookup
;
27055 /* Map each used .debug_names abbreviation tag parameter to its
27057 std::unordered_map
<index_key
, int, index_key_hasher
> m_indexkey_to_idx
;
27059 /* Next unused .debug_names abbreviation tag for
27060 m_indexkey_to_idx. */
27061 int m_idx_next
= 1;
27063 /* .debug_names abbreviation table. */
27064 data_buf m_abbrev_table
;
27066 /* .debug_names entry pool. */
27067 data_buf m_entry_pool
;
27070 /* Return iff any of the needed offsets does not fit into 32-bit
27071 .debug_names section. */
27074 check_dwarf64_offsets (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27076 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27078 const dwarf2_per_cu_data
&per_cu
= *dwarf2_per_objfile
->all_comp_units
[i
];
27080 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27083 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
27085 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
27086 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
27088 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27094 /* The psyms_seen set is potentially going to be largish (~40k
27095 elements when indexing a -g3 build of GDB itself). Estimate the
27096 number of elements in order to avoid too many rehashes, which
27097 require rebuilding buckets and thus many trips to
27101 psyms_seen_size (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27103 size_t psyms_count
= 0;
27104 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27106 struct dwarf2_per_cu_data
*per_cu
27107 = dwarf2_per_objfile
->all_comp_units
[i
];
27108 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27110 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
27111 recursively_count_psymbols (psymtab
, psyms_count
);
27113 /* Generating an index for gdb itself shows a ratio of
27114 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
27115 return psyms_count
/ 4;
27118 /* Write new .gdb_index section for OBJFILE into OUT_FILE.
27119 Return how many bytes were expected to be written into OUT_FILE. */
27122 write_gdbindex (struct dwarf2_per_objfile
*dwarf2_per_objfile
, FILE *out_file
)
27124 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27125 mapped_symtab symtab
;
27128 /* While we're scanning CU's create a table that maps a psymtab pointer
27129 (which is what addrmap records) to its index (which is what is recorded
27130 in the index file). This will later be needed to write the address
27132 psym_index_map cu_index_htab
;
27133 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
27135 /* The CU list is already sorted, so we don't need to do additional
27136 work here. Also, the debug_types entries do not appear in
27137 all_comp_units, but only in their own hash table. */
27139 std::unordered_set
<partial_symbol
*> psyms_seen
27140 (psyms_seen_size (dwarf2_per_objfile
));
27141 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27143 struct dwarf2_per_cu_data
*per_cu
27144 = dwarf2_per_objfile
->all_comp_units
[i
];
27145 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27147 /* CU of a shared file from 'dwz -m' may be unused by this main file.
27148 It may be referenced from a local scope but in such case it does not
27149 need to be present in .gdb_index. */
27150 if (psymtab
== NULL
)
27153 if (psymtab
->user
== NULL
)
27154 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
27157 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
27158 gdb_assert (insertpair
.second
);
27160 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
27161 to_underlying (per_cu
->sect_off
));
27162 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
27165 /* Dump the address map. */
27167 write_address_map (objfile
, addr_vec
, cu_index_htab
);
27169 /* Write out the .debug_type entries, if any. */
27170 data_buf types_cu_list
;
27171 if (dwarf2_per_objfile
->signatured_types
)
27173 signatured_type_index_data
sig_data (types_cu_list
,
27176 sig_data
.objfile
= objfile
;
27177 sig_data
.symtab
= &symtab
;
27178 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
27179 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27180 write_one_signatured_type
, &sig_data
);
27183 /* Now that we've processed all symbols we can shrink their cu_indices
27185 uniquify_cu_indices (&symtab
);
27187 data_buf symtab_vec
, constant_pool
;
27188 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
27191 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
27192 offset_type total_len
= size_of_contents
;
27194 /* The version number. */
27195 contents
.append_data (MAYBE_SWAP (8));
27197 /* The offset of the CU list from the start of the file. */
27198 contents
.append_data (MAYBE_SWAP (total_len
));
27199 total_len
+= cu_list
.size ();
27201 /* The offset of the types CU list from the start of the file. */
27202 contents
.append_data (MAYBE_SWAP (total_len
));
27203 total_len
+= types_cu_list
.size ();
27205 /* The offset of the address table from the start of the file. */
27206 contents
.append_data (MAYBE_SWAP (total_len
));
27207 total_len
+= addr_vec
.size ();
27209 /* The offset of the symbol table from the start of the file. */
27210 contents
.append_data (MAYBE_SWAP (total_len
));
27211 total_len
+= symtab_vec
.size ();
27213 /* The offset of the constant pool from the start of the file. */
27214 contents
.append_data (MAYBE_SWAP (total_len
));
27215 total_len
+= constant_pool
.size ();
27217 gdb_assert (contents
.size () == size_of_contents
);
27219 contents
.file_write (out_file
);
27220 cu_list
.file_write (out_file
);
27221 types_cu_list
.file_write (out_file
);
27222 addr_vec
.file_write (out_file
);
27223 symtab_vec
.file_write (out_file
);
27224 constant_pool
.file_write (out_file
);
27229 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
27230 static const gdb_byte dwarf5_gdb_augmentation
[] = { 'G', 'D', 'B', 0 };
27232 /* Write a new .debug_names section for OBJFILE into OUT_FILE, write
27233 needed addition to .debug_str section to OUT_FILE_STR. Return how
27234 many bytes were expected to be written into OUT_FILE. */
27237 write_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27238 FILE *out_file
, FILE *out_file_str
)
27240 const bool dwarf5_is_dwarf64
= check_dwarf64_offsets (dwarf2_per_objfile
);
27241 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27242 const enum bfd_endian dwarf5_byte_order
27243 = gdbarch_byte_order (get_objfile_arch (objfile
));
27245 /* The CU list is already sorted, so we don't need to do additional
27246 work here. Also, the debug_types entries do not appear in
27247 all_comp_units, but only in their own hash table. */
27249 debug_names
nametable (dwarf2_per_objfile
, dwarf5_is_dwarf64
,
27250 dwarf5_byte_order
);
27251 std::unordered_set
<partial_symbol
*>
27252 psyms_seen (psyms_seen_size (dwarf2_per_objfile
));
27253 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27255 const dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
27256 partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27258 /* CU of a shared file from 'dwz -m' may be unused by this main
27259 file. It may be referenced from a local scope but in such
27260 case it does not need to be present in .debug_names. */
27261 if (psymtab
== NULL
)
27264 if (psymtab
->user
== NULL
)
27265 nametable
.recursively_write_psymbols (objfile
, psymtab
, psyms_seen
, i
);
27267 cu_list
.append_uint (nametable
.dwarf5_offset_size (), dwarf5_byte_order
,
27268 to_underlying (per_cu
->sect_off
));
27271 /* Write out the .debug_type entries, if any. */
27272 data_buf types_cu_list
;
27273 if (dwarf2_per_objfile
->signatured_types
)
27275 debug_names::write_one_signatured_type_data
sig_data (nametable
,
27276 signatured_type_index_data (types_cu_list
, psyms_seen
));
27278 sig_data
.info
.objfile
= objfile
;
27279 /* It is used only for gdb_index. */
27280 sig_data
.info
.symtab
= nullptr;
27281 sig_data
.info
.cu_index
= 0;
27282 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27283 debug_names::write_one_signatured_type
,
27287 nametable
.build ();
27289 /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
27291 const offset_type bytes_of_header
27292 = ((dwarf5_is_dwarf64
? 12 : 4)
27294 + sizeof (dwarf5_gdb_augmentation
));
27295 size_t expected_bytes
= 0;
27296 expected_bytes
+= bytes_of_header
;
27297 expected_bytes
+= cu_list
.size ();
27298 expected_bytes
+= types_cu_list
.size ();
27299 expected_bytes
+= nametable
.bytes ();
27302 if (!dwarf5_is_dwarf64
)
27304 const uint64_t size64
= expected_bytes
- 4;
27305 gdb_assert (size64
< 0xfffffff0);
27306 header
.append_uint (4, dwarf5_byte_order
, size64
);
27310 header
.append_uint (4, dwarf5_byte_order
, 0xffffffff);
27311 header
.append_uint (8, dwarf5_byte_order
, expected_bytes
- 12);
27314 /* The version number. */
27315 header
.append_uint (2, dwarf5_byte_order
, 5);
27318 header
.append_uint (2, dwarf5_byte_order
, 0);
27320 /* comp_unit_count - The number of CUs in the CU list. */
27321 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_comp_units
);
27323 /* local_type_unit_count - The number of TUs in the local TU
27325 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_type_units
);
27327 /* foreign_type_unit_count - The number of TUs in the foreign TU
27329 header
.append_uint (4, dwarf5_byte_order
, 0);
27331 /* bucket_count - The number of hash buckets in the hash lookup
27333 header
.append_uint (4, dwarf5_byte_order
, nametable
.bucket_count ());
27335 /* name_count - The number of unique names in the index. */
27336 header
.append_uint (4, dwarf5_byte_order
, nametable
.name_count ());
27338 /* abbrev_table_size - The size in bytes of the abbreviations
27340 header
.append_uint (4, dwarf5_byte_order
, nametable
.abbrev_table_bytes ());
27342 /* augmentation_string_size - The size in bytes of the augmentation
27343 string. This value is rounded up to a multiple of 4. */
27344 static_assert (sizeof (dwarf5_gdb_augmentation
) % 4 == 0, "");
27345 header
.append_uint (4, dwarf5_byte_order
, sizeof (dwarf5_gdb_augmentation
));
27346 header
.append_data (dwarf5_gdb_augmentation
);
27348 gdb_assert (header
.size () == bytes_of_header
);
27350 header
.file_write (out_file
);
27351 cu_list
.file_write (out_file
);
27352 types_cu_list
.file_write (out_file
);
27353 nametable
.file_write (out_file
, out_file_str
);
27355 return expected_bytes
;
27358 /* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
27359 position is at the end of the file. */
27362 assert_file_size (FILE *file
, const char *filename
, size_t expected_size
)
27364 const auto file_size
= ftell (file
);
27365 if (file_size
== -1)
27366 error (_("Can't get `%s' size"), filename
);
27367 gdb_assert (file_size
== expected_size
);
27370 /* Create an index file for OBJFILE in the directory DIR. */
27373 write_psymtabs_to_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27375 dw_index_kind index_kind
)
27377 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27379 if (dwarf2_per_objfile
->using_index
)
27380 error (_("Cannot use an index to create the index"));
27382 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
27383 error (_("Cannot make an index when the file has multiple .debug_types sections"));
27385 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
27389 if (stat (objfile_name (objfile
), &st
) < 0)
27390 perror_with_name (objfile_name (objfile
));
27392 std::string
filename (std::string (dir
) + SLASH_STRING
27393 + lbasename (objfile_name (objfile
))
27394 + (index_kind
== dw_index_kind::DEBUG_NAMES
27395 ? INDEX5_SUFFIX
: INDEX4_SUFFIX
));
27397 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
27399 error (_("Can't open `%s' for writing"), filename
.c_str ());
27401 /* Order matters here; we want FILE to be closed before FILENAME is
27402 unlinked, because on MS-Windows one cannot delete a file that is
27403 still open. (Don't call anything here that might throw until
27404 file_closer is created.) */
27405 gdb::unlinker
unlink_file (filename
.c_str ());
27406 gdb_file_up
close_out_file (out_file
);
27408 if (index_kind
== dw_index_kind::DEBUG_NAMES
)
27410 std::string
filename_str (std::string (dir
) + SLASH_STRING
27411 + lbasename (objfile_name (objfile
))
27412 + DEBUG_STR_SUFFIX
);
27414 = gdb_fopen_cloexec (filename_str
.c_str (), "wb").release ();
27416 error (_("Can't open `%s' for writing"), filename_str
.c_str ());
27417 gdb::unlinker
unlink_file_str (filename_str
.c_str ());
27418 gdb_file_up
close_out_file_str (out_file_str
);
27420 const size_t total_len
27421 = write_debug_names (dwarf2_per_objfile
, out_file
, out_file_str
);
27422 assert_file_size (out_file
, filename
.c_str (), total_len
);
27424 /* We want to keep the file .debug_str file too. */
27425 unlink_file_str
.keep ();
27429 const size_t total_len
27430 = write_gdbindex (dwarf2_per_objfile
, out_file
);
27431 assert_file_size (out_file
, filename
.c_str (), total_len
);
27434 /* We want to keep the file. */
27435 unlink_file
.keep ();
27438 /* Implementation of the `save gdb-index' command.
27440 Note that the .gdb_index file format used by this command is
27441 documented in the GDB manual. Any changes here must be documented
27445 save_gdb_index_command (const char *arg
, int from_tty
)
27447 struct objfile
*objfile
;
27448 const char dwarf5space
[] = "-dwarf-5 ";
27449 dw_index_kind index_kind
= dw_index_kind::GDB_INDEX
;
27454 arg
= skip_spaces (arg
);
27455 if (strncmp (arg
, dwarf5space
, strlen (dwarf5space
)) == 0)
27457 index_kind
= dw_index_kind::DEBUG_NAMES
;
27458 arg
+= strlen (dwarf5space
);
27459 arg
= skip_spaces (arg
);
27463 error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
27465 ALL_OBJFILES (objfile
)
27469 /* If the objfile does not correspond to an actual file, skip it. */
27470 if (stat (objfile_name (objfile
), &st
) < 0)
27473 struct dwarf2_per_objfile
*dwarf2_per_objfile
27474 = get_dwarf2_per_objfile (objfile
);
27476 if (dwarf2_per_objfile
!= NULL
)
27480 write_psymtabs_to_index (dwarf2_per_objfile
, arg
, index_kind
);
27482 CATCH (except
, RETURN_MASK_ERROR
)
27484 exception_fprintf (gdb_stderr
, except
,
27485 _("Error while writing index for `%s': "),
27486 objfile_name (objfile
));
27496 int dwarf_always_disassemble
;
27499 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
27500 struct cmd_list_element
*c
, const char *value
)
27502 fprintf_filtered (file
,
27503 _("Whether to always disassemble "
27504 "DWARF expressions is %s.\n"),
27509 show_check_physname (struct ui_file
*file
, int from_tty
,
27510 struct cmd_list_element
*c
, const char *value
)
27512 fprintf_filtered (file
,
27513 _("Whether to check \"physname\" is %s.\n"),
27518 _initialize_dwarf2_read (void)
27520 struct cmd_list_element
*c
;
27522 dwarf2_objfile_data_key
= register_objfile_data ();
27524 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
27525 Set DWARF specific variables.\n\
27526 Configure DWARF variables such as the cache size"),
27527 &set_dwarf_cmdlist
, "maintenance set dwarf ",
27528 0/*allow-unknown*/, &maintenance_set_cmdlist
);
27530 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
27531 Show DWARF specific variables\n\
27532 Show DWARF variables such as the cache size"),
27533 &show_dwarf_cmdlist
, "maintenance show dwarf ",
27534 0/*allow-unknown*/, &maintenance_show_cmdlist
);
27536 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
27537 &dwarf_max_cache_age
, _("\
27538 Set the upper bound on the age of cached DWARF compilation units."), _("\
27539 Show the upper bound on the age of cached DWARF compilation units."), _("\
27540 A higher limit means that cached compilation units will be stored\n\
27541 in memory longer, and more total memory will be used. Zero disables\n\
27542 caching, which can slow down startup."),
27544 show_dwarf_max_cache_age
,
27545 &set_dwarf_cmdlist
,
27546 &show_dwarf_cmdlist
);
27548 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
27549 &dwarf_always_disassemble
, _("\
27550 Set whether `info address' always disassembles DWARF expressions."), _("\
27551 Show whether `info address' always disassembles DWARF expressions."), _("\
27552 When enabled, DWARF expressions are always printed in an assembly-like\n\
27553 syntax. When disabled, expressions will be printed in a more\n\
27554 conversational style, when possible."),
27556 show_dwarf_always_disassemble
,
27557 &set_dwarf_cmdlist
,
27558 &show_dwarf_cmdlist
);
27560 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
27561 Set debugging of the DWARF reader."), _("\
27562 Show debugging of the DWARF reader."), _("\
27563 When enabled (non-zero), debugging messages are printed during DWARF\n\
27564 reading and symtab expansion. A value of 1 (one) provides basic\n\
27565 information. A value greater than 1 provides more verbose information."),
27568 &setdebuglist
, &showdebuglist
);
27570 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
27571 Set debugging of the DWARF DIE reader."), _("\
27572 Show debugging of the DWARF DIE reader."), _("\
27573 When enabled (non-zero), DIEs are dumped after they are read in.\n\
27574 The value is the maximum depth to print."),
27577 &setdebuglist
, &showdebuglist
);
27579 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
27580 Set debugging of the dwarf line reader."), _("\
27581 Show debugging of the dwarf line reader."), _("\
27582 When enabled (non-zero), line number entries are dumped as they are read in.\n\
27583 A value of 1 (one) provides basic information.\n\
27584 A value greater than 1 provides more verbose information."),
27587 &setdebuglist
, &showdebuglist
);
27589 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
27590 Set cross-checking of \"physname\" code against demangler."), _("\
27591 Show cross-checking of \"physname\" code against demangler."), _("\
27592 When enabled, GDB's internal \"physname\" code is checked against\n\
27594 NULL
, show_check_physname
,
27595 &setdebuglist
, &showdebuglist
);
27597 add_setshow_boolean_cmd ("use-deprecated-index-sections",
27598 no_class
, &use_deprecated_index_sections
, _("\
27599 Set whether to use deprecated gdb_index sections."), _("\
27600 Show whether to use deprecated gdb_index sections."), _("\
27601 When enabled, deprecated .gdb_index sections are used anyway.\n\
27602 Normally they are ignored either because of a missing feature or\n\
27603 performance issue.\n\
27604 Warning: This option must be enabled before gdb reads the file."),
27607 &setlist
, &showlist
);
27609 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
27611 Save a gdb-index file.\n\
27612 Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
27614 No options create one file with .gdb-index extension for pre-DWARF-5\n\
27615 compatible .gdb_index section. With -dwarf-5 creates two files with\n\
27616 extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
27618 set_cmd_completer (c
, filename_completer
);
27620 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27621 &dwarf2_locexpr_funcs
);
27622 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27623 &dwarf2_loclist_funcs
);
27625 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27626 &dwarf2_block_frame_base_locexpr_funcs
);
27627 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27628 &dwarf2_block_frame_base_loclist_funcs
);
27631 selftests::register_test ("dw2_expand_symtabs_matching",
27632 selftests::dw2_expand_symtabs_matching::run_test
);