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>
90 /* When == 1, print basic high level tracing messages.
91 When > 1, be more verbose.
92 This is in contrast to the low level DIE reading of dwarf_die_debug. */
93 static unsigned int dwarf_read_debug
= 0;
95 /* When non-zero, dump DIEs after they are read in. */
96 static unsigned int dwarf_die_debug
= 0;
98 /* When non-zero, dump line number entries as they are read in. */
99 static unsigned int dwarf_line_debug
= 0;
101 /* When non-zero, cross-check physname against demangler. */
102 static int check_physname
= 0;
104 /* When non-zero, do not reject deprecated .gdb_index sections. */
105 static int use_deprecated_index_sections
= 0;
107 static const struct objfile_data
*dwarf2_objfile_data_key
;
109 /* The "aclass" indices for various kinds of computed DWARF symbols. */
111 static int dwarf2_locexpr_index
;
112 static int dwarf2_loclist_index
;
113 static int dwarf2_locexpr_block_index
;
114 static int dwarf2_loclist_block_index
;
116 /* A descriptor for dwarf sections.
118 S.ASECTION, SIZE are typically initialized when the objfile is first
119 scanned. BUFFER, READIN are filled in later when the section is read.
120 If the section contained compressed data then SIZE is updated to record
121 the uncompressed size of the section.
123 DWP file format V2 introduces a wrinkle that is easiest to handle by
124 creating the concept of virtual sections contained within a real section.
125 In DWP V2 the sections of the input DWO files are concatenated together
126 into one section, but section offsets are kept relative to the original
128 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
129 the real section this "virtual" section is contained in, and BUFFER,SIZE
130 describe the virtual section. */
132 struct dwarf2_section_info
136 /* If this is a real section, the bfd section. */
138 /* If this is a virtual section, pointer to the containing ("real")
140 struct dwarf2_section_info
*containing_section
;
142 /* Pointer to section data, only valid if readin. */
143 const gdb_byte
*buffer
;
144 /* The size of the section, real or virtual. */
146 /* If this is a virtual section, the offset in the real section.
147 Only valid if is_virtual. */
148 bfd_size_type virtual_offset
;
149 /* True if we have tried to read this section. */
151 /* True if this is a virtual section, False otherwise.
152 This specifies which of s.section and s.containing_section to use. */
156 typedef struct dwarf2_section_info dwarf2_section_info_def
;
157 DEF_VEC_O (dwarf2_section_info_def
);
159 /* All offsets in the index are of this type. It must be
160 architecture-independent. */
161 typedef uint32_t offset_type
;
163 DEF_VEC_I (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 /* Mark used when releasing cached dies. */
766 unsigned int mark
: 1;
768 /* This CU references .debug_loc. See the symtab->locations_valid field.
769 This test is imperfect as there may exist optimized debug code not using
770 any location list and still facing inlining issues if handled as
771 unoptimized code. For a future better test see GCC PR other/32998. */
772 unsigned int has_loclist
: 1;
774 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
775 if all the producer_is_* fields are valid. This information is cached
776 because profiling CU expansion showed excessive time spent in
777 producer_is_gxx_lt_4_6. */
778 unsigned int checked_producer
: 1;
779 unsigned int producer_is_gxx_lt_4_6
: 1;
780 unsigned int producer_is_gcc_lt_4_3
: 1;
781 unsigned int producer_is_icc_lt_14
: 1;
783 /* When set, the file that we're processing is known to have
784 debugging info for C++ namespaces. GCC 3.3.x did not produce
785 this information, but later versions do. */
787 unsigned int processing_has_namespace_info
: 1;
789 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
792 /* Persistent data held for a compilation unit, even when not
793 processing it. We put a pointer to this structure in the
794 read_symtab_private field of the psymtab. */
796 struct dwarf2_per_cu_data
798 /* The start offset and length of this compilation unit.
799 NOTE: Unlike comp_unit_head.length, this length includes
801 If the DIE refers to a DWO file, this is always of the original die,
803 sect_offset sect_off
;
806 /* DWARF standard version this data has been read from (such as 4 or 5). */
809 /* Flag indicating this compilation unit will be read in before
810 any of the current compilation units are processed. */
811 unsigned int queued
: 1;
813 /* This flag will be set when reading partial DIEs if we need to load
814 absolutely all DIEs for this compilation unit, instead of just the ones
815 we think are interesting. It gets set if we look for a DIE in the
816 hash table and don't find it. */
817 unsigned int load_all_dies
: 1;
819 /* Non-zero if this CU is from .debug_types.
820 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
822 unsigned int is_debug_types
: 1;
824 /* Non-zero if this CU is from the .dwz file. */
825 unsigned int is_dwz
: 1;
827 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
828 This flag is only valid if is_debug_types is true.
829 We can't read a CU directly from a DWO file: There are required
830 attributes in the stub. */
831 unsigned int reading_dwo_directly
: 1;
833 /* Non-zero if the TU has been read.
834 This is used to assist the "Stay in DWO Optimization" for Fission:
835 When reading a DWO, it's faster to read TUs from the DWO instead of
836 fetching them from random other DWOs (due to comdat folding).
837 If the TU has already been read, the optimization is unnecessary
838 (and unwise - we don't want to change where gdb thinks the TU lives
840 This flag is only valid if is_debug_types is true. */
841 unsigned int tu_read
: 1;
843 /* The section this CU/TU lives in.
844 If the DIE refers to a DWO file, this is always the original die,
846 struct dwarf2_section_info
*section
;
848 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
849 of the CU cache it gets reset to NULL again. This is left as NULL for
850 dummy CUs (a CU header, but nothing else). */
851 struct dwarf2_cu
*cu
;
853 /* The corresponding dwarf2_per_objfile. */
854 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
856 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
857 is active. Otherwise, the 'psymtab' field is active. */
860 /* The partial symbol table associated with this compilation unit,
861 or NULL for unread partial units. */
862 struct partial_symtab
*psymtab
;
864 /* Data needed by the "quick" functions. */
865 struct dwarf2_per_cu_quick_data
*quick
;
868 /* The CUs we import using DW_TAG_imported_unit. This is filled in
869 while reading psymtabs, used to compute the psymtab dependencies,
870 and then cleared. Then it is filled in again while reading full
871 symbols, and only deleted when the objfile is destroyed.
873 This is also used to work around a difference between the way gold
874 generates .gdb_index version <=7 and the way gdb does. Arguably this
875 is a gold bug. For symbols coming from TUs, gold records in the index
876 the CU that includes the TU instead of the TU itself. This breaks
877 dw2_lookup_symbol: It assumes that if the index says symbol X lives
878 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
879 will find X. Alas TUs live in their own symtab, so after expanding CU Y
880 we need to look in TU Z to find X. Fortunately, this is akin to
881 DW_TAG_imported_unit, so we just use the same mechanism: For
882 .gdb_index version <=7 this also records the TUs that the CU referred
883 to. Concurrently with this change gdb was modified to emit version 8
884 indices so we only pay a price for gold generated indices.
885 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
886 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
889 /* Entry in the signatured_types hash table. */
891 struct signatured_type
893 /* The "per_cu" object of this type.
894 This struct is used iff per_cu.is_debug_types.
895 N.B.: This is the first member so that it's easy to convert pointers
897 struct dwarf2_per_cu_data per_cu
;
899 /* The type's signature. */
902 /* Offset in the TU of the type's DIE, as read from the TU header.
903 If this TU is a DWO stub and the definition lives in a DWO file
904 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
905 cu_offset type_offset_in_tu
;
907 /* Offset in the section of the type's DIE.
908 If the definition lives in a DWO file, this is the offset in the
909 .debug_types.dwo section.
910 The value is zero until the actual value is known.
911 Zero is otherwise not a valid section offset. */
912 sect_offset type_offset_in_section
;
914 /* Type units are grouped by their DW_AT_stmt_list entry so that they
915 can share them. This points to the containing symtab. */
916 struct type_unit_group
*type_unit_group
;
919 The first time we encounter this type we fully read it in and install it
920 in the symbol tables. Subsequent times we only need the type. */
923 /* Containing DWO unit.
924 This field is valid iff per_cu.reading_dwo_directly. */
925 struct dwo_unit
*dwo_unit
;
928 typedef struct signatured_type
*sig_type_ptr
;
929 DEF_VEC_P (sig_type_ptr
);
931 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
932 This includes type_unit_group and quick_file_names. */
934 struct stmt_list_hash
936 /* The DWO unit this table is from or NULL if there is none. */
937 struct dwo_unit
*dwo_unit
;
939 /* Offset in .debug_line or .debug_line.dwo. */
940 sect_offset line_sect_off
;
943 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
944 an object of this type. */
946 struct type_unit_group
948 /* dwarf2read.c's main "handle" on a TU symtab.
949 To simplify things we create an artificial CU that "includes" all the
950 type units using this stmt_list so that the rest of the code still has
951 a "per_cu" handle on the symtab.
952 This PER_CU is recognized by having no section. */
953 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
954 struct dwarf2_per_cu_data per_cu
;
956 /* The TUs that share this DW_AT_stmt_list entry.
957 This is added to while parsing type units to build partial symtabs,
958 and is deleted afterwards and not used again. */
959 VEC (sig_type_ptr
) *tus
;
961 /* The compunit symtab.
962 Type units in a group needn't all be defined in the same source file,
963 so we create an essentially anonymous symtab as the compunit symtab. */
964 struct compunit_symtab
*compunit_symtab
;
966 /* The data used to construct the hash key. */
967 struct stmt_list_hash hash
;
969 /* The number of symtabs from the line header.
970 The value here must match line_header.num_file_names. */
971 unsigned int num_symtabs
;
973 /* The symbol tables for this TU (obtained from the files listed in
975 WARNING: The order of entries here must match the order of entries
976 in the line header. After the first TU using this type_unit_group, the
977 line header for the subsequent TUs is recreated from this. This is done
978 because we need to use the same symtabs for each TU using the same
979 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
980 there's no guarantee the line header doesn't have duplicate entries. */
981 struct symtab
**symtabs
;
984 /* These sections are what may appear in a (real or virtual) DWO file. */
988 struct dwarf2_section_info abbrev
;
989 struct dwarf2_section_info line
;
990 struct dwarf2_section_info loc
;
991 struct dwarf2_section_info loclists
;
992 struct dwarf2_section_info macinfo
;
993 struct dwarf2_section_info macro
;
994 struct dwarf2_section_info str
;
995 struct dwarf2_section_info str_offsets
;
996 /* In the case of a virtual DWO file, these two are unused. */
997 struct dwarf2_section_info info
;
998 VEC (dwarf2_section_info_def
) *types
;
1001 /* CUs/TUs in DWP/DWO files. */
1005 /* Backlink to the containing struct dwo_file. */
1006 struct dwo_file
*dwo_file
;
1008 /* The "id" that distinguishes this CU/TU.
1009 .debug_info calls this "dwo_id", .debug_types calls this "signature".
1010 Since signatures came first, we stick with it for consistency. */
1013 /* The section this CU/TU lives in, in the DWO file. */
1014 struct dwarf2_section_info
*section
;
1016 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
1017 sect_offset sect_off
;
1018 unsigned int length
;
1020 /* For types, offset in the type's DIE of the type defined by this TU. */
1021 cu_offset type_offset_in_tu
;
1024 /* include/dwarf2.h defines the DWP section codes.
1025 It defines a max value but it doesn't define a min value, which we
1026 use for error checking, so provide one. */
1028 enum dwp_v2_section_ids
1033 /* Data for one DWO file.
1035 This includes virtual DWO files (a virtual DWO file is a DWO file as it
1036 appears in a DWP file). DWP files don't really have DWO files per se -
1037 comdat folding of types "loses" the DWO file they came from, and from
1038 a high level view DWP files appear to contain a mass of random types.
1039 However, to maintain consistency with the non-DWP case we pretend DWP
1040 files contain virtual DWO files, and we assign each TU with one virtual
1041 DWO file (generally based on the line and abbrev section offsets -
1042 a heuristic that seems to work in practice). */
1046 /* The DW_AT_GNU_dwo_name attribute.
1047 For virtual DWO files the name is constructed from the section offsets
1048 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
1049 from related CU+TUs. */
1050 const char *dwo_name
;
1052 /* The DW_AT_comp_dir attribute. */
1053 const char *comp_dir
;
1055 /* The bfd, when the file is open. Otherwise this is NULL.
1056 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
1059 /* The sections that make up this DWO file.
1060 Remember that for virtual DWO files in DWP V2, these are virtual
1061 sections (for lack of a better name). */
1062 struct dwo_sections sections
;
1064 /* The CUs in the file.
1065 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
1066 an extension to handle LLVM's Link Time Optimization output (where
1067 multiple source files may be compiled into a single object/dwo pair). */
1070 /* Table of TUs in the file.
1071 Each element is a struct dwo_unit. */
1075 /* These sections are what may appear in a DWP file. */
1079 /* These are used by both DWP version 1 and 2. */
1080 struct dwarf2_section_info str
;
1081 struct dwarf2_section_info cu_index
;
1082 struct dwarf2_section_info tu_index
;
1084 /* These are only used by DWP version 2 files.
1085 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
1086 sections are referenced by section number, and are not recorded here.
1087 In DWP version 2 there is at most one copy of all these sections, each
1088 section being (effectively) comprised of the concatenation of all of the
1089 individual sections that exist in the version 1 format.
1090 To keep the code simple we treat each of these concatenated pieces as a
1091 section itself (a virtual section?). */
1092 struct dwarf2_section_info abbrev
;
1093 struct dwarf2_section_info info
;
1094 struct dwarf2_section_info line
;
1095 struct dwarf2_section_info loc
;
1096 struct dwarf2_section_info macinfo
;
1097 struct dwarf2_section_info macro
;
1098 struct dwarf2_section_info str_offsets
;
1099 struct dwarf2_section_info types
;
1102 /* These sections are what may appear in a virtual DWO file in DWP version 1.
1103 A virtual DWO file is a DWO file as it appears in a DWP file. */
1105 struct virtual_v1_dwo_sections
1107 struct dwarf2_section_info abbrev
;
1108 struct dwarf2_section_info line
;
1109 struct dwarf2_section_info loc
;
1110 struct dwarf2_section_info macinfo
;
1111 struct dwarf2_section_info macro
;
1112 struct dwarf2_section_info str_offsets
;
1113 /* Each DWP hash table entry records one CU or one TU.
1114 That is recorded here, and copied to dwo_unit.section. */
1115 struct dwarf2_section_info info_or_types
;
1118 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
1119 In version 2, the sections of the DWO files are concatenated together
1120 and stored in one section of that name. Thus each ELF section contains
1121 several "virtual" sections. */
1123 struct virtual_v2_dwo_sections
1125 bfd_size_type abbrev_offset
;
1126 bfd_size_type abbrev_size
;
1128 bfd_size_type line_offset
;
1129 bfd_size_type line_size
;
1131 bfd_size_type loc_offset
;
1132 bfd_size_type loc_size
;
1134 bfd_size_type macinfo_offset
;
1135 bfd_size_type macinfo_size
;
1137 bfd_size_type macro_offset
;
1138 bfd_size_type macro_size
;
1140 bfd_size_type str_offsets_offset
;
1141 bfd_size_type str_offsets_size
;
1143 /* Each DWP hash table entry records one CU or one TU.
1144 That is recorded here, and copied to dwo_unit.section. */
1145 bfd_size_type info_or_types_offset
;
1146 bfd_size_type info_or_types_size
;
1149 /* Contents of DWP hash tables. */
1151 struct dwp_hash_table
1153 uint32_t version
, nr_columns
;
1154 uint32_t nr_units
, nr_slots
;
1155 const gdb_byte
*hash_table
, *unit_table
;
1160 const gdb_byte
*indices
;
1164 /* This is indexed by column number and gives the id of the section
1166 #define MAX_NR_V2_DWO_SECTIONS \
1167 (1 /* .debug_info or .debug_types */ \
1168 + 1 /* .debug_abbrev */ \
1169 + 1 /* .debug_line */ \
1170 + 1 /* .debug_loc */ \
1171 + 1 /* .debug_str_offsets */ \
1172 + 1 /* .debug_macro or .debug_macinfo */)
1173 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1174 const gdb_byte
*offsets
;
1175 const gdb_byte
*sizes
;
1180 /* Data for one DWP file. */
1184 /* Name of the file. */
1187 /* File format version. */
1193 /* Section info for this file. */
1194 struct dwp_sections sections
;
1196 /* Table of CUs in the file. */
1197 const struct dwp_hash_table
*cus
;
1199 /* Table of TUs in the file. */
1200 const struct dwp_hash_table
*tus
;
1202 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1206 /* Table to map ELF section numbers to their sections.
1207 This is only needed for the DWP V1 file format. */
1208 unsigned int num_sections
;
1209 asection
**elf_sections
;
1212 /* This represents a '.dwz' file. */
1216 /* A dwz file can only contain a few sections. */
1217 struct dwarf2_section_info abbrev
;
1218 struct dwarf2_section_info info
;
1219 struct dwarf2_section_info str
;
1220 struct dwarf2_section_info line
;
1221 struct dwarf2_section_info macro
;
1222 struct dwarf2_section_info gdb_index
;
1223 struct dwarf2_section_info debug_names
;
1225 /* The dwz's BFD. */
1229 /* Struct used to pass misc. parameters to read_die_and_children, et
1230 al. which are used for both .debug_info and .debug_types dies.
1231 All parameters here are unchanging for the life of the call. This
1232 struct exists to abstract away the constant parameters of die reading. */
1234 struct die_reader_specs
1236 /* The bfd of die_section. */
1239 /* The CU of the DIE we are parsing. */
1240 struct dwarf2_cu
*cu
;
1242 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1243 struct dwo_file
*dwo_file
;
1245 /* The section the die comes from.
1246 This is either .debug_info or .debug_types, or the .dwo variants. */
1247 struct dwarf2_section_info
*die_section
;
1249 /* die_section->buffer. */
1250 const gdb_byte
*buffer
;
1252 /* The end of the buffer. */
1253 const gdb_byte
*buffer_end
;
1255 /* The value of the DW_AT_comp_dir attribute. */
1256 const char *comp_dir
;
1258 /* The abbreviation table to use when reading the DIEs. */
1259 struct abbrev_table
*abbrev_table
;
1262 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1263 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1264 const gdb_byte
*info_ptr
,
1265 struct die_info
*comp_unit_die
,
1269 /* A 1-based directory index. This is a strong typedef to prevent
1270 accidentally using a directory index as a 0-based index into an
1272 enum class dir_index
: unsigned int {};
1274 /* Likewise, a 1-based file name index. */
1275 enum class file_name_index
: unsigned int {};
1279 file_entry () = default;
1281 file_entry (const char *name_
, dir_index d_index_
,
1282 unsigned int mod_time_
, unsigned int length_
)
1285 mod_time (mod_time_
),
1289 /* Return the include directory at D_INDEX stored in LH. Returns
1290 NULL if D_INDEX is out of bounds. */
1291 const char *include_dir (const line_header
*lh
) const;
1293 /* The file name. Note this is an observing pointer. The memory is
1294 owned by debug_line_buffer. */
1295 const char *name
{};
1297 /* The directory index (1-based). */
1298 dir_index d_index
{};
1300 unsigned int mod_time
{};
1302 unsigned int length
{};
1304 /* True if referenced by the Line Number Program. */
1307 /* The associated symbol table, if any. */
1308 struct symtab
*symtab
{};
1311 /* The line number information for a compilation unit (found in the
1312 .debug_line section) begins with a "statement program header",
1313 which contains the following information. */
1320 /* Add an entry to the include directory table. */
1321 void add_include_dir (const char *include_dir
);
1323 /* Add an entry to the file name table. */
1324 void add_file_name (const char *name
, dir_index d_index
,
1325 unsigned int mod_time
, unsigned int length
);
1327 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1328 is out of bounds. */
1329 const char *include_dir_at (dir_index index
) const
1331 /* Convert directory index number (1-based) to vector index
1333 size_t vec_index
= to_underlying (index
) - 1;
1335 if (vec_index
>= include_dirs
.size ())
1337 return include_dirs
[vec_index
];
1340 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1341 is out of bounds. */
1342 file_entry
*file_name_at (file_name_index index
)
1344 /* Convert file name index number (1-based) to vector index
1346 size_t vec_index
= to_underlying (index
) - 1;
1348 if (vec_index
>= file_names
.size ())
1350 return &file_names
[vec_index
];
1353 /* Const version of the above. */
1354 const file_entry
*file_name_at (unsigned int index
) const
1356 if (index
>= file_names
.size ())
1358 return &file_names
[index
];
1361 /* Offset of line number information in .debug_line section. */
1362 sect_offset sect_off
{};
1364 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1365 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1367 unsigned int total_length
{};
1368 unsigned short version
{};
1369 unsigned int header_length
{};
1370 unsigned char minimum_instruction_length
{};
1371 unsigned char maximum_ops_per_instruction
{};
1372 unsigned char default_is_stmt
{};
1374 unsigned char line_range
{};
1375 unsigned char opcode_base
{};
1377 /* standard_opcode_lengths[i] is the number of operands for the
1378 standard opcode whose value is i. This means that
1379 standard_opcode_lengths[0] is unused, and the last meaningful
1380 element is standard_opcode_lengths[opcode_base - 1]. */
1381 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1383 /* The include_directories table. Note these are observing
1384 pointers. The memory is owned by debug_line_buffer. */
1385 std::vector
<const char *> include_dirs
;
1387 /* The file_names table. */
1388 std::vector
<file_entry
> file_names
;
1390 /* The start and end of the statement program following this
1391 header. These point into dwarf2_per_objfile->line_buffer. */
1392 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1395 typedef std::unique_ptr
<line_header
> line_header_up
;
1398 file_entry::include_dir (const line_header
*lh
) const
1400 return lh
->include_dir_at (d_index
);
1403 /* When we construct a partial symbol table entry we only
1404 need this much information. */
1405 struct partial_die_info
1407 /* Offset of this DIE. */
1408 sect_offset sect_off
;
1410 /* DWARF-2 tag for this DIE. */
1411 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1413 /* Assorted flags describing the data found in this DIE. */
1414 unsigned int has_children
: 1;
1415 unsigned int is_external
: 1;
1416 unsigned int is_declaration
: 1;
1417 unsigned int has_type
: 1;
1418 unsigned int has_specification
: 1;
1419 unsigned int has_pc_info
: 1;
1420 unsigned int may_be_inlined
: 1;
1422 /* This DIE has been marked DW_AT_main_subprogram. */
1423 unsigned int main_subprogram
: 1;
1425 /* Flag set if the SCOPE field of this structure has been
1427 unsigned int scope_set
: 1;
1429 /* Flag set if the DIE has a byte_size attribute. */
1430 unsigned int has_byte_size
: 1;
1432 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1433 unsigned int has_const_value
: 1;
1435 /* Flag set if any of the DIE's children are template arguments. */
1436 unsigned int has_template_arguments
: 1;
1438 /* Flag set if fixup_partial_die has been called on this die. */
1439 unsigned int fixup_called
: 1;
1441 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1442 unsigned int is_dwz
: 1;
1444 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1445 unsigned int spec_is_dwz
: 1;
1447 /* The name of this DIE. Normally the value of DW_AT_name, but
1448 sometimes a default name for unnamed DIEs. */
1451 /* The linkage name, if present. */
1452 const char *linkage_name
;
1454 /* The scope to prepend to our children. This is generally
1455 allocated on the comp_unit_obstack, so will disappear
1456 when this compilation unit leaves the cache. */
1459 /* Some data associated with the partial DIE. The tag determines
1460 which field is live. */
1463 /* The location description associated with this DIE, if any. */
1464 struct dwarf_block
*locdesc
;
1465 /* The offset of an import, for DW_TAG_imported_unit. */
1466 sect_offset sect_off
;
1469 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1473 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1474 DW_AT_sibling, if any. */
1475 /* NOTE: This member isn't strictly necessary, read_partial_die could
1476 return DW_AT_sibling values to its caller load_partial_dies. */
1477 const gdb_byte
*sibling
;
1479 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1480 DW_AT_specification (or DW_AT_abstract_origin or
1481 DW_AT_extension). */
1482 sect_offset spec_offset
;
1484 /* Pointers to this DIE's parent, first child, and next sibling,
1486 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
1489 /* This data structure holds the information of an abbrev. */
1492 unsigned int number
; /* number identifying abbrev */
1493 enum dwarf_tag tag
; /* dwarf tag */
1494 unsigned short has_children
; /* boolean */
1495 unsigned short num_attrs
; /* number of attributes */
1496 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1497 struct abbrev_info
*next
; /* next in chain */
1502 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1503 ENUM_BITFIELD(dwarf_form
) form
: 16;
1505 /* It is valid only if FORM is DW_FORM_implicit_const. */
1506 LONGEST implicit_const
;
1509 /* Size of abbrev_table.abbrev_hash_table. */
1510 #define ABBREV_HASH_SIZE 121
1512 /* Top level data structure to contain an abbreviation table. */
1516 explicit abbrev_table (sect_offset off
)
1520 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1521 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1524 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1526 /* Allocate space for a struct abbrev_info object in
1528 struct abbrev_info
*alloc_abbrev ();
1530 /* Add an abbreviation to the table. */
1531 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1533 /* Look up an abbrev in the table.
1534 Returns NULL if the abbrev is not found. */
1536 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1539 /* Where the abbrev table came from.
1540 This is used as a sanity check when the table is used. */
1541 const sect_offset sect_off
;
1543 /* Storage for the abbrev table. */
1544 auto_obstack abbrev_obstack
;
1548 /* Hash table of abbrevs.
1549 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1550 It could be statically allocated, but the previous code didn't so we
1552 struct abbrev_info
**m_abbrevs
;
1555 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1557 /* Attributes have a name and a value. */
1560 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1561 ENUM_BITFIELD(dwarf_form
) form
: 15;
1563 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1564 field should be in u.str (existing only for DW_STRING) but it is kept
1565 here for better struct attribute alignment. */
1566 unsigned int string_is_canonical
: 1;
1571 struct dwarf_block
*blk
;
1580 /* This data structure holds a complete die structure. */
1583 /* DWARF-2 tag for this DIE. */
1584 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1586 /* Number of attributes */
1587 unsigned char num_attrs
;
1589 /* True if we're presently building the full type name for the
1590 type derived from this DIE. */
1591 unsigned char building_fullname
: 1;
1593 /* True if this die is in process. PR 16581. */
1594 unsigned char in_process
: 1;
1597 unsigned int abbrev
;
1599 /* Offset in .debug_info or .debug_types section. */
1600 sect_offset sect_off
;
1602 /* The dies in a compilation unit form an n-ary tree. PARENT
1603 points to this die's parent; CHILD points to the first child of
1604 this node; and all the children of a given node are chained
1605 together via their SIBLING fields. */
1606 struct die_info
*child
; /* Its first child, if any. */
1607 struct die_info
*sibling
; /* Its next sibling, if any. */
1608 struct die_info
*parent
; /* Its parent, if any. */
1610 /* An array of attributes, with NUM_ATTRS elements. There may be
1611 zero, but it's not common and zero-sized arrays are not
1612 sufficiently portable C. */
1613 struct attribute attrs
[1];
1616 /* Get at parts of an attribute structure. */
1618 #define DW_STRING(attr) ((attr)->u.str)
1619 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1620 #define DW_UNSND(attr) ((attr)->u.unsnd)
1621 #define DW_BLOCK(attr) ((attr)->u.blk)
1622 #define DW_SND(attr) ((attr)->u.snd)
1623 #define DW_ADDR(attr) ((attr)->u.addr)
1624 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1626 /* Blocks are a bunch of untyped bytes. */
1631 /* Valid only if SIZE is not zero. */
1632 const gdb_byte
*data
;
1635 #ifndef ATTR_ALLOC_CHUNK
1636 #define ATTR_ALLOC_CHUNK 4
1639 /* Allocate fields for structs, unions and enums in this size. */
1640 #ifndef DW_FIELD_ALLOC_CHUNK
1641 #define DW_FIELD_ALLOC_CHUNK 4
1644 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1645 but this would require a corresponding change in unpack_field_as_long
1647 static int bits_per_byte
= 8;
1651 struct nextfield
*next
;
1659 struct nextfnfield
*next
;
1660 struct fn_field fnfield
;
1667 struct nextfnfield
*head
;
1670 struct decl_field_list
1672 struct decl_field field
;
1673 struct decl_field_list
*next
;
1676 /* The routines that read and process dies for a C struct or C++ class
1677 pass lists of data member fields and lists of member function fields
1678 in an instance of a field_info structure, as defined below. */
1681 /* List of data member and baseclasses fields. */
1682 struct nextfield
*fields
, *baseclasses
;
1684 /* Number of fields (including baseclasses). */
1687 /* Number of baseclasses. */
1690 /* Set if the accesibility of one of the fields is not public. */
1691 int non_public_fields
;
1693 /* Member function fieldlist array, contains name of possibly overloaded
1694 member function, number of overloaded member functions and a pointer
1695 to the head of the member function field chain. */
1696 struct fnfieldlist
*fnfieldlists
;
1698 /* Number of entries in the fnfieldlists array. */
1701 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1702 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1703 struct decl_field_list
*typedef_field_list
;
1704 unsigned typedef_field_list_count
;
1706 /* Nested types defined by this class and the number of elements in this
1708 struct decl_field_list
*nested_types_list
;
1709 unsigned nested_types_list_count
;
1712 /* One item on the queue of compilation units to read in full symbols
1714 struct dwarf2_queue_item
1716 struct dwarf2_per_cu_data
*per_cu
;
1717 enum language pretend_language
;
1718 struct dwarf2_queue_item
*next
;
1721 /* The current queue. */
1722 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1724 /* Loaded secondary compilation units are kept in memory until they
1725 have not been referenced for the processing of this many
1726 compilation units. Set this to zero to disable caching. Cache
1727 sizes of up to at least twenty will improve startup time for
1728 typical inter-CU-reference binaries, at an obvious memory cost. */
1729 static int dwarf_max_cache_age
= 5;
1731 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1732 struct cmd_list_element
*c
, const char *value
)
1734 fprintf_filtered (file
, _("The upper bound on the age of cached "
1735 "DWARF compilation units is %s.\n"),
1739 /* local function prototypes */
1741 static const char *get_section_name (const struct dwarf2_section_info
*);
1743 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1745 static void dwarf2_find_base_address (struct die_info
*die
,
1746 struct dwarf2_cu
*cu
);
1748 static struct partial_symtab
*create_partial_symtab
1749 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1751 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1752 const gdb_byte
*info_ptr
,
1753 struct die_info
*type_unit_die
,
1754 int has_children
, void *data
);
1756 static void dwarf2_build_psymtabs_hard
1757 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1759 static void scan_partial_symbols (struct partial_die_info
*,
1760 CORE_ADDR
*, CORE_ADDR
*,
1761 int, struct dwarf2_cu
*);
1763 static void add_partial_symbol (struct partial_die_info
*,
1764 struct dwarf2_cu
*);
1766 static void add_partial_namespace (struct partial_die_info
*pdi
,
1767 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1768 int set_addrmap
, struct dwarf2_cu
*cu
);
1770 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1771 CORE_ADDR
*highpc
, int set_addrmap
,
1772 struct dwarf2_cu
*cu
);
1774 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1775 struct dwarf2_cu
*cu
);
1777 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1778 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1779 int need_pc
, struct dwarf2_cu
*cu
);
1781 static void dwarf2_read_symtab (struct partial_symtab
*,
1784 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1786 static abbrev_table_up abbrev_table_read_table
1787 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1790 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1792 static struct partial_die_info
*load_partial_dies
1793 (const struct die_reader_specs
*, const gdb_byte
*, int);
1795 static const gdb_byte
*read_partial_die (const struct die_reader_specs
*,
1796 struct partial_die_info
*,
1797 const struct abbrev_info
&,
1801 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1802 struct dwarf2_cu
*);
1804 static void fixup_partial_die (struct partial_die_info
*,
1805 struct dwarf2_cu
*);
1807 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1808 struct attribute
*, struct attr_abbrev
*,
1811 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1813 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1815 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1817 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1819 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1821 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1824 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1826 static LONGEST read_checked_initial_length_and_offset
1827 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1828 unsigned int *, unsigned int *);
1830 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1831 const struct comp_unit_head
*,
1834 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1836 static sect_offset read_abbrev_offset
1837 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1838 struct dwarf2_section_info
*, sect_offset
);
1840 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1842 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1844 static const char *read_indirect_string
1845 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1846 const struct comp_unit_head
*, unsigned int *);
1848 static const char *read_indirect_line_string
1849 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1850 const struct comp_unit_head
*, unsigned int *);
1852 static const char *read_indirect_string_at_offset
1853 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1854 LONGEST str_offset
);
1856 static const char *read_indirect_string_from_dwz
1857 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1859 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1861 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1865 static const char *read_str_index (const struct die_reader_specs
*reader
,
1866 ULONGEST str_index
);
1868 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1870 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1871 struct dwarf2_cu
*);
1873 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1876 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1877 struct dwarf2_cu
*cu
);
1879 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1880 struct dwarf2_cu
*cu
);
1882 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1884 static struct die_info
*die_specification (struct die_info
*die
,
1885 struct dwarf2_cu
**);
1887 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1888 struct dwarf2_cu
*cu
);
1890 static void dwarf_decode_lines (struct line_header
*, const char *,
1891 struct dwarf2_cu
*, struct partial_symtab
*,
1892 CORE_ADDR
, int decode_mapping
);
1894 static void dwarf2_start_subfile (const char *, const char *);
1896 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1897 const char *, const char *,
1900 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1901 struct dwarf2_cu
*, struct symbol
* = NULL
);
1903 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1904 struct dwarf2_cu
*);
1906 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1909 struct obstack
*obstack
,
1910 struct dwarf2_cu
*cu
, LONGEST
*value
,
1911 const gdb_byte
**bytes
,
1912 struct dwarf2_locexpr_baton
**baton
);
1914 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1916 static int need_gnat_info (struct dwarf2_cu
*);
1918 static struct type
*die_descriptive_type (struct die_info
*,
1919 struct dwarf2_cu
*);
1921 static void set_descriptive_type (struct type
*, struct die_info
*,
1922 struct dwarf2_cu
*);
1924 static struct type
*die_containing_type (struct die_info
*,
1925 struct dwarf2_cu
*);
1927 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1928 struct dwarf2_cu
*);
1930 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1932 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1934 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1936 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1937 const char *suffix
, int physname
,
1938 struct dwarf2_cu
*cu
);
1940 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1942 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1944 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1946 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1948 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1950 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1952 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1953 struct dwarf2_cu
*, struct partial_symtab
*);
1955 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1956 values. Keep the items ordered with increasing constraints compliance. */
1959 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1960 PC_BOUNDS_NOT_PRESENT
,
1962 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1963 were present but they do not form a valid range of PC addresses. */
1966 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1969 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1973 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1974 CORE_ADDR
*, CORE_ADDR
*,
1976 struct partial_symtab
*);
1978 static void get_scope_pc_bounds (struct die_info
*,
1979 CORE_ADDR
*, CORE_ADDR
*,
1980 struct dwarf2_cu
*);
1982 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1983 CORE_ADDR
, struct dwarf2_cu
*);
1985 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1986 struct dwarf2_cu
*);
1988 static void dwarf2_attach_fields_to_type (struct field_info
*,
1989 struct type
*, struct dwarf2_cu
*);
1991 static void dwarf2_add_member_fn (struct field_info
*,
1992 struct die_info
*, struct type
*,
1993 struct dwarf2_cu
*);
1995 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1997 struct dwarf2_cu
*);
1999 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
2001 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
2003 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
2005 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
2007 static struct using_direct
**using_directives (enum language
);
2009 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
2011 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
2013 static struct type
*read_module_type (struct die_info
*die
,
2014 struct dwarf2_cu
*cu
);
2016 static const char *namespace_name (struct die_info
*die
,
2017 int *is_anonymous
, struct dwarf2_cu
*);
2019 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
2021 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
2023 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
2024 struct dwarf2_cu
*);
2026 static struct die_info
*read_die_and_siblings_1
2027 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
2030 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
2031 const gdb_byte
*info_ptr
,
2032 const gdb_byte
**new_info_ptr
,
2033 struct die_info
*parent
);
2035 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
2036 struct die_info
**, const gdb_byte
*,
2039 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
2040 struct die_info
**, const gdb_byte
*,
2043 static void process_die (struct die_info
*, struct dwarf2_cu
*);
2045 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
2048 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
2050 static const char *dwarf2_full_name (const char *name
,
2051 struct die_info
*die
,
2052 struct dwarf2_cu
*cu
);
2054 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
2055 struct dwarf2_cu
*cu
);
2057 static struct die_info
*dwarf2_extension (struct die_info
*die
,
2058 struct dwarf2_cu
**);
2060 static const char *dwarf_tag_name (unsigned int);
2062 static const char *dwarf_attr_name (unsigned int);
2064 static const char *dwarf_form_name (unsigned int);
2066 static const char *dwarf_bool_name (unsigned int);
2068 static const char *dwarf_type_encoding_name (unsigned int);
2070 static struct die_info
*sibling_die (struct die_info
*);
2072 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
2074 static void dump_die_for_error (struct die_info
*);
2076 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
2079 /*static*/ void dump_die (struct die_info
*, int max_level
);
2081 static void store_in_ref_table (struct die_info
*,
2082 struct dwarf2_cu
*);
2084 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
2086 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
2088 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
2089 const struct attribute
*,
2090 struct dwarf2_cu
**);
2092 static struct die_info
*follow_die_ref (struct die_info
*,
2093 const struct attribute
*,
2094 struct dwarf2_cu
**);
2096 static struct die_info
*follow_die_sig (struct die_info
*,
2097 const struct attribute
*,
2098 struct dwarf2_cu
**);
2100 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
2101 struct dwarf2_cu
*);
2103 static struct type
*get_DW_AT_signature_type (struct die_info
*,
2104 const struct attribute
*,
2105 struct dwarf2_cu
*);
2107 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
2109 static void read_signatured_type (struct signatured_type
*);
2111 static int attr_to_dynamic_prop (const struct attribute
*attr
,
2112 struct die_info
*die
, struct dwarf2_cu
*cu
,
2113 struct dynamic_prop
*prop
);
2115 /* memory allocation interface */
2117 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
2119 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
2121 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
2123 static int attr_form_is_block (const struct attribute
*);
2125 static int attr_form_is_section_offset (const struct attribute
*);
2127 static int attr_form_is_constant (const struct attribute
*);
2129 static int attr_form_is_ref (const struct attribute
*);
2131 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
2132 struct dwarf2_loclist_baton
*baton
,
2133 const struct attribute
*attr
);
2135 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
2137 struct dwarf2_cu
*cu
,
2140 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
2141 const gdb_byte
*info_ptr
,
2142 struct abbrev_info
*abbrev
);
2144 static hashval_t
partial_die_hash (const void *item
);
2146 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
2148 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
2149 (sect_offset sect_off
, unsigned int offset_in_dwz
,
2150 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2152 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2153 struct die_info
*comp_unit_die
,
2154 enum language pretend_language
);
2156 static void free_cached_comp_units (void *);
2158 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2160 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2162 static struct type
*set_die_type (struct die_info
*, struct type
*,
2163 struct dwarf2_cu
*);
2165 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2167 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2169 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2172 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2175 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2178 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2179 struct dwarf2_per_cu_data
*);
2181 static void dwarf2_mark (struct dwarf2_cu
*);
2183 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2185 static struct type
*get_die_type_at_offset (sect_offset
,
2186 struct dwarf2_per_cu_data
*);
2188 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2190 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2191 enum language pretend_language
);
2193 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2195 /* Class, the destructor of which frees all allocated queue entries. This
2196 will only have work to do if an error was thrown while processing the
2197 dwarf. If no error was thrown then the queue entries should have all
2198 been processed, and freed, as we went along. */
2200 class dwarf2_queue_guard
2203 dwarf2_queue_guard () = default;
2205 /* Free any entries remaining on the queue. There should only be
2206 entries left if we hit an error while processing the dwarf. */
2207 ~dwarf2_queue_guard ()
2209 struct dwarf2_queue_item
*item
, *last
;
2211 item
= dwarf2_queue
;
2214 /* Anything still marked queued is likely to be in an
2215 inconsistent state, so discard it. */
2216 if (item
->per_cu
->queued
)
2218 if (item
->per_cu
->cu
!= NULL
)
2219 free_one_cached_comp_unit (item
->per_cu
);
2220 item
->per_cu
->queued
= 0;
2228 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2232 /* The return type of find_file_and_directory. Note, the enclosed
2233 string pointers are only valid while this object is valid. */
2235 struct file_and_directory
2237 /* The filename. This is never NULL. */
2240 /* The compilation directory. NULL if not known. If we needed to
2241 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2242 points directly to the DW_AT_comp_dir string attribute owned by
2243 the obstack that owns the DIE. */
2244 const char *comp_dir
;
2246 /* If we needed to build a new string for comp_dir, this is what
2247 owns the storage. */
2248 std::string comp_dir_storage
;
2251 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2252 struct dwarf2_cu
*cu
);
2254 static char *file_full_name (int file
, struct line_header
*lh
,
2255 const char *comp_dir
);
2257 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2258 enum class rcuh_kind
{ COMPILE
, TYPE
};
2260 static const gdb_byte
*read_and_check_comp_unit_head
2261 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2262 struct comp_unit_head
*header
,
2263 struct dwarf2_section_info
*section
,
2264 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2265 rcuh_kind section_kind
);
2267 static void init_cutu_and_read_dies
2268 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2269 int use_existing_cu
, int keep
,
2270 die_reader_func_ftype
*die_reader_func
, void *data
);
2272 static void init_cutu_and_read_dies_simple
2273 (struct dwarf2_per_cu_data
*this_cu
,
2274 die_reader_func_ftype
*die_reader_func
, void *data
);
2276 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2278 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2280 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2281 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2282 struct dwp_file
*dwp_file
, const char *comp_dir
,
2283 ULONGEST signature
, int is_debug_types
);
2285 static struct dwp_file
*get_dwp_file
2286 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2288 static struct dwo_unit
*lookup_dwo_comp_unit
2289 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2291 static struct dwo_unit
*lookup_dwo_type_unit
2292 (struct signatured_type
*, const char *, const char *);
2294 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2296 static void free_dwo_file_cleanup (void *);
2298 struct free_dwo_file_cleanup_data
2300 struct dwo_file
*dwo_file
;
2301 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
2304 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2306 static void check_producer (struct dwarf2_cu
*cu
);
2308 static void free_line_header_voidp (void *arg
);
2310 /* Various complaints about symbol reading that don't abort the process. */
2313 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2315 complaint (&symfile_complaints
,
2316 _("statement list doesn't fit in .debug_line section"));
2320 dwarf2_debug_line_missing_file_complaint (void)
2322 complaint (&symfile_complaints
,
2323 _(".debug_line section has line data without a file"));
2327 dwarf2_debug_line_missing_end_sequence_complaint (void)
2329 complaint (&symfile_complaints
,
2330 _(".debug_line section has line "
2331 "program sequence without an end"));
2335 dwarf2_complex_location_expr_complaint (void)
2337 complaint (&symfile_complaints
, _("location expression too complex"));
2341 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2344 complaint (&symfile_complaints
,
2345 _("const value length mismatch for '%s', got %d, expected %d"),
2350 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2352 complaint (&symfile_complaints
,
2353 _("debug info runs off end of %s section"
2355 get_section_name (section
),
2356 get_section_file_name (section
));
2360 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2362 complaint (&symfile_complaints
,
2363 _("macro debug info contains a "
2364 "malformed macro definition:\n`%s'"),
2369 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2371 complaint (&symfile_complaints
,
2372 _("invalid attribute class or form for '%s' in '%s'"),
2376 /* Hash function for line_header_hash. */
2379 line_header_hash (const struct line_header
*ofs
)
2381 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2384 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2387 line_header_hash_voidp (const void *item
)
2389 const struct line_header
*ofs
= (const struct line_header
*) item
;
2391 return line_header_hash (ofs
);
2394 /* Equality function for line_header_hash. */
2397 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2399 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2400 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2402 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2403 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2408 /* Read the given attribute value as an address, taking the attribute's
2409 form into account. */
2412 attr_value_as_address (struct attribute
*attr
)
2416 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2418 /* Aside from a few clearly defined exceptions, attributes that
2419 contain an address must always be in DW_FORM_addr form.
2420 Unfortunately, some compilers happen to be violating this
2421 requirement by encoding addresses using other forms, such
2422 as DW_FORM_data4 for example. For those broken compilers,
2423 we try to do our best, without any guarantee of success,
2424 to interpret the address correctly. It would also be nice
2425 to generate a complaint, but that would require us to maintain
2426 a list of legitimate cases where a non-address form is allowed,
2427 as well as update callers to pass in at least the CU's DWARF
2428 version. This is more overhead than what we're willing to
2429 expand for a pretty rare case. */
2430 addr
= DW_UNSND (attr
);
2433 addr
= DW_ADDR (attr
);
2438 /* The suffix for an index file. */
2439 #define INDEX4_SUFFIX ".gdb-index"
2440 #define INDEX5_SUFFIX ".debug_names"
2441 #define DEBUG_STR_SUFFIX ".debug_str"
2443 /* See declaration. */
2445 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2446 const dwarf2_debug_sections
*names
)
2447 : objfile (objfile_
)
2450 names
= &dwarf2_elf_names
;
2452 bfd
*obfd
= objfile
->obfd
;
2454 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2455 locate_sections (obfd
, sec
, *names
);
2458 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2460 dwarf2_per_objfile::~dwarf2_per_objfile ()
2462 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2463 free_cached_comp_units ();
2465 if (quick_file_names_table
)
2466 htab_delete (quick_file_names_table
);
2468 if (line_header_hash
)
2469 htab_delete (line_header_hash
);
2471 for (int ix
= 0; ix
< n_comp_units
; ++ix
)
2472 VEC_free (dwarf2_per_cu_ptr
, all_comp_units
[ix
]->imported_symtabs
);
2474 for (int ix
= 0; ix
< n_type_units
; ++ix
)
2475 VEC_free (dwarf2_per_cu_ptr
,
2476 all_type_units
[ix
]->per_cu
.imported_symtabs
);
2477 xfree (all_type_units
);
2479 VEC_free (dwarf2_section_info_def
, types
);
2481 if (dwo_files
!= NULL
)
2482 free_dwo_files (dwo_files
, objfile
);
2483 if (dwp_file
!= NULL
)
2484 gdb_bfd_unref (dwp_file
->dbfd
);
2486 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2487 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2489 if (index_table
!= NULL
)
2490 index_table
->~mapped_index ();
2492 /* Everything else should be on the objfile obstack. */
2495 /* See declaration. */
2498 dwarf2_per_objfile::free_cached_comp_units ()
2500 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2501 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2502 while (per_cu
!= NULL
)
2504 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2507 *last_chain
= next_cu
;
2512 /* Try to locate the sections we need for DWARF 2 debugging
2513 information and return true if we have enough to do something.
2514 NAMES points to the dwarf2 section names, or is NULL if the standard
2515 ELF names are used. */
2518 dwarf2_has_info (struct objfile
*objfile
,
2519 const struct dwarf2_debug_sections
*names
)
2521 if (objfile
->flags
& OBJF_READNEVER
)
2524 struct dwarf2_per_objfile
*dwarf2_per_objfile
2525 = get_dwarf2_per_objfile (objfile
);
2527 if (dwarf2_per_objfile
== NULL
)
2529 /* Initialize per-objfile state. */
2531 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2533 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2535 return (!dwarf2_per_objfile
->info
.is_virtual
2536 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2537 && !dwarf2_per_objfile
->abbrev
.is_virtual
2538 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2541 /* Return the containing section of virtual section SECTION. */
2543 static struct dwarf2_section_info
*
2544 get_containing_section (const struct dwarf2_section_info
*section
)
2546 gdb_assert (section
->is_virtual
);
2547 return section
->s
.containing_section
;
2550 /* Return the bfd owner of SECTION. */
2553 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2555 if (section
->is_virtual
)
2557 section
= get_containing_section (section
);
2558 gdb_assert (!section
->is_virtual
);
2560 return section
->s
.section
->owner
;
2563 /* Return the bfd section of SECTION.
2564 Returns NULL if the section is not present. */
2567 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2569 if (section
->is_virtual
)
2571 section
= get_containing_section (section
);
2572 gdb_assert (!section
->is_virtual
);
2574 return section
->s
.section
;
2577 /* Return the name of SECTION. */
2580 get_section_name (const struct dwarf2_section_info
*section
)
2582 asection
*sectp
= get_section_bfd_section (section
);
2584 gdb_assert (sectp
!= NULL
);
2585 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2588 /* Return the name of the file SECTION is in. */
2591 get_section_file_name (const struct dwarf2_section_info
*section
)
2593 bfd
*abfd
= get_section_bfd_owner (section
);
2595 return bfd_get_filename (abfd
);
2598 /* Return the id of SECTION.
2599 Returns 0 if SECTION doesn't exist. */
2602 get_section_id (const struct dwarf2_section_info
*section
)
2604 asection
*sectp
= get_section_bfd_section (section
);
2611 /* Return the flags of SECTION.
2612 SECTION (or containing section if this is a virtual section) must exist. */
2615 get_section_flags (const struct dwarf2_section_info
*section
)
2617 asection
*sectp
= get_section_bfd_section (section
);
2619 gdb_assert (sectp
!= NULL
);
2620 return bfd_get_section_flags (sectp
->owner
, sectp
);
2623 /* When loading sections, we look either for uncompressed section or for
2624 compressed section names. */
2627 section_is_p (const char *section_name
,
2628 const struct dwarf2_section_names
*names
)
2630 if (names
->normal
!= NULL
2631 && strcmp (section_name
, names
->normal
) == 0)
2633 if (names
->compressed
!= NULL
2634 && strcmp (section_name
, names
->compressed
) == 0)
2639 /* See declaration. */
2642 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2643 const dwarf2_debug_sections
&names
)
2645 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2647 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2650 else if (section_is_p (sectp
->name
, &names
.info
))
2652 this->info
.s
.section
= sectp
;
2653 this->info
.size
= bfd_get_section_size (sectp
);
2655 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2657 this->abbrev
.s
.section
= sectp
;
2658 this->abbrev
.size
= bfd_get_section_size (sectp
);
2660 else if (section_is_p (sectp
->name
, &names
.line
))
2662 this->line
.s
.section
= sectp
;
2663 this->line
.size
= bfd_get_section_size (sectp
);
2665 else if (section_is_p (sectp
->name
, &names
.loc
))
2667 this->loc
.s
.section
= sectp
;
2668 this->loc
.size
= bfd_get_section_size (sectp
);
2670 else if (section_is_p (sectp
->name
, &names
.loclists
))
2672 this->loclists
.s
.section
= sectp
;
2673 this->loclists
.size
= bfd_get_section_size (sectp
);
2675 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2677 this->macinfo
.s
.section
= sectp
;
2678 this->macinfo
.size
= bfd_get_section_size (sectp
);
2680 else if (section_is_p (sectp
->name
, &names
.macro
))
2682 this->macro
.s
.section
= sectp
;
2683 this->macro
.size
= bfd_get_section_size (sectp
);
2685 else if (section_is_p (sectp
->name
, &names
.str
))
2687 this->str
.s
.section
= sectp
;
2688 this->str
.size
= bfd_get_section_size (sectp
);
2690 else if (section_is_p (sectp
->name
, &names
.line_str
))
2692 this->line_str
.s
.section
= sectp
;
2693 this->line_str
.size
= bfd_get_section_size (sectp
);
2695 else if (section_is_p (sectp
->name
, &names
.addr
))
2697 this->addr
.s
.section
= sectp
;
2698 this->addr
.size
= bfd_get_section_size (sectp
);
2700 else if (section_is_p (sectp
->name
, &names
.frame
))
2702 this->frame
.s
.section
= sectp
;
2703 this->frame
.size
= bfd_get_section_size (sectp
);
2705 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2707 this->eh_frame
.s
.section
= sectp
;
2708 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2710 else if (section_is_p (sectp
->name
, &names
.ranges
))
2712 this->ranges
.s
.section
= sectp
;
2713 this->ranges
.size
= bfd_get_section_size (sectp
);
2715 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2717 this->rnglists
.s
.section
= sectp
;
2718 this->rnglists
.size
= bfd_get_section_size (sectp
);
2720 else if (section_is_p (sectp
->name
, &names
.types
))
2722 struct dwarf2_section_info type_section
;
2724 memset (&type_section
, 0, sizeof (type_section
));
2725 type_section
.s
.section
= sectp
;
2726 type_section
.size
= bfd_get_section_size (sectp
);
2728 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2731 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2733 this->gdb_index
.s
.section
= sectp
;
2734 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2736 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2738 this->debug_names
.s
.section
= sectp
;
2739 this->debug_names
.size
= bfd_get_section_size (sectp
);
2741 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2743 this->debug_aranges
.s
.section
= sectp
;
2744 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2747 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2748 && bfd_section_vma (abfd
, sectp
) == 0)
2749 this->has_section_at_zero
= true;
2752 /* A helper function that decides whether a section is empty,
2756 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2758 if (section
->is_virtual
)
2759 return section
->size
== 0;
2760 return section
->s
.section
== NULL
|| section
->size
== 0;
2763 /* Read the contents of the section INFO.
2764 OBJFILE is the main object file, but not necessarily the file where
2765 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2767 If the section is compressed, uncompress it before returning. */
2770 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2774 gdb_byte
*buf
, *retbuf
;
2778 info
->buffer
= NULL
;
2781 if (dwarf2_section_empty_p (info
))
2784 sectp
= get_section_bfd_section (info
);
2786 /* If this is a virtual section we need to read in the real one first. */
2787 if (info
->is_virtual
)
2789 struct dwarf2_section_info
*containing_section
=
2790 get_containing_section (info
);
2792 gdb_assert (sectp
!= NULL
);
2793 if ((sectp
->flags
& SEC_RELOC
) != 0)
2795 error (_("Dwarf Error: DWP format V2 with relocations is not"
2796 " supported in section %s [in module %s]"),
2797 get_section_name (info
), get_section_file_name (info
));
2799 dwarf2_read_section (objfile
, containing_section
);
2800 /* Other code should have already caught virtual sections that don't
2802 gdb_assert (info
->virtual_offset
+ info
->size
2803 <= containing_section
->size
);
2804 /* If the real section is empty or there was a problem reading the
2805 section we shouldn't get here. */
2806 gdb_assert (containing_section
->buffer
!= NULL
);
2807 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2811 /* If the section has relocations, we must read it ourselves.
2812 Otherwise we attach it to the BFD. */
2813 if ((sectp
->flags
& SEC_RELOC
) == 0)
2815 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2819 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2822 /* When debugging .o files, we may need to apply relocations; see
2823 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2824 We never compress sections in .o files, so we only need to
2825 try this when the section is not compressed. */
2826 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2829 info
->buffer
= retbuf
;
2833 abfd
= get_section_bfd_owner (info
);
2834 gdb_assert (abfd
!= NULL
);
2836 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2837 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2839 error (_("Dwarf Error: Can't read DWARF data"
2840 " in section %s [in module %s]"),
2841 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2845 /* A helper function that returns the size of a section in a safe way.
2846 If you are positive that the section has been read before using the
2847 size, then it is safe to refer to the dwarf2_section_info object's
2848 "size" field directly. In other cases, you must call this
2849 function, because for compressed sections the size field is not set
2850 correctly until the section has been read. */
2852 static bfd_size_type
2853 dwarf2_section_size (struct objfile
*objfile
,
2854 struct dwarf2_section_info
*info
)
2857 dwarf2_read_section (objfile
, info
);
2861 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2865 dwarf2_get_section_info (struct objfile
*objfile
,
2866 enum dwarf2_section_enum sect
,
2867 asection
**sectp
, const gdb_byte
**bufp
,
2868 bfd_size_type
*sizep
)
2870 struct dwarf2_per_objfile
*data
2871 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2872 dwarf2_objfile_data_key
);
2873 struct dwarf2_section_info
*info
;
2875 /* We may see an objfile without any DWARF, in which case we just
2886 case DWARF2_DEBUG_FRAME
:
2887 info
= &data
->frame
;
2889 case DWARF2_EH_FRAME
:
2890 info
= &data
->eh_frame
;
2893 gdb_assert_not_reached ("unexpected section");
2896 dwarf2_read_section (objfile
, info
);
2898 *sectp
= get_section_bfd_section (info
);
2899 *bufp
= info
->buffer
;
2900 *sizep
= info
->size
;
2903 /* A helper function to find the sections for a .dwz file. */
2906 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2908 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2910 /* Note that we only support the standard ELF names, because .dwz
2911 is ELF-only (at the time of writing). */
2912 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2914 dwz_file
->abbrev
.s
.section
= sectp
;
2915 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2917 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2919 dwz_file
->info
.s
.section
= sectp
;
2920 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2922 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2924 dwz_file
->str
.s
.section
= sectp
;
2925 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2927 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2929 dwz_file
->line
.s
.section
= sectp
;
2930 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2932 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2934 dwz_file
->macro
.s
.section
= sectp
;
2935 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2937 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2939 dwz_file
->gdb_index
.s
.section
= sectp
;
2940 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2942 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2944 dwz_file
->debug_names
.s
.section
= sectp
;
2945 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2949 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2950 there is no .gnu_debugaltlink section in the file. Error if there
2951 is such a section but the file cannot be found. */
2953 static struct dwz_file
*
2954 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2956 const char *filename
;
2957 struct dwz_file
*result
;
2958 bfd_size_type buildid_len_arg
;
2962 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2963 return dwarf2_per_objfile
->dwz_file
;
2965 bfd_set_error (bfd_error_no_error
);
2966 gdb::unique_xmalloc_ptr
<char> data
2967 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2968 &buildid_len_arg
, &buildid
));
2971 if (bfd_get_error () == bfd_error_no_error
)
2973 error (_("could not read '.gnu_debugaltlink' section: %s"),
2974 bfd_errmsg (bfd_get_error ()));
2977 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2979 buildid_len
= (size_t) buildid_len_arg
;
2981 filename
= data
.get ();
2983 std::string abs_storage
;
2984 if (!IS_ABSOLUTE_PATH (filename
))
2986 gdb::unique_xmalloc_ptr
<char> abs
2987 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2989 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2990 filename
= abs_storage
.c_str ();
2993 /* First try the file name given in the section. If that doesn't
2994 work, try to use the build-id instead. */
2995 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2996 if (dwz_bfd
!= NULL
)
2998 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
3002 if (dwz_bfd
== NULL
)
3003 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
3005 if (dwz_bfd
== NULL
)
3006 error (_("could not find '.gnu_debugaltlink' file for %s"),
3007 objfile_name (dwarf2_per_objfile
->objfile
));
3009 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
3011 result
->dwz_bfd
= dwz_bfd
.release ();
3013 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
3015 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
3016 dwarf2_per_objfile
->dwz_file
= result
;
3020 /* DWARF quick_symbols_functions support. */
3022 /* TUs can share .debug_line entries, and there can be a lot more TUs than
3023 unique line tables, so we maintain a separate table of all .debug_line
3024 derived entries to support the sharing.
3025 All the quick functions need is the list of file names. We discard the
3026 line_header when we're done and don't need to record it here. */
3027 struct quick_file_names
3029 /* The data used to construct the hash key. */
3030 struct stmt_list_hash hash
;
3032 /* The number of entries in file_names, real_names. */
3033 unsigned int num_file_names
;
3035 /* The file names from the line table, after being run through
3037 const char **file_names
;
3039 /* The file names from the line table after being run through
3040 gdb_realpath. These are computed lazily. */
3041 const char **real_names
;
3044 /* When using the index (and thus not using psymtabs), each CU has an
3045 object of this type. This is used to hold information needed by
3046 the various "quick" methods. */
3047 struct dwarf2_per_cu_quick_data
3049 /* The file table. This can be NULL if there was no file table
3050 or it's currently not read in.
3051 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
3052 struct quick_file_names
*file_names
;
3054 /* The corresponding symbol table. This is NULL if symbols for this
3055 CU have not yet been read. */
3056 struct compunit_symtab
*compunit_symtab
;
3058 /* A temporary mark bit used when iterating over all CUs in
3059 expand_symtabs_matching. */
3060 unsigned int mark
: 1;
3062 /* True if we've tried to read the file table and found there isn't one.
3063 There will be no point in trying to read it again next time. */
3064 unsigned int no_file_data
: 1;
3067 /* Utility hash function for a stmt_list_hash. */
3070 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
3074 if (stmt_list_hash
->dwo_unit
!= NULL
)
3075 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
3076 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
3080 /* Utility equality function for a stmt_list_hash. */
3083 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
3084 const struct stmt_list_hash
*rhs
)
3086 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
3088 if (lhs
->dwo_unit
!= NULL
3089 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
3092 return lhs
->line_sect_off
== rhs
->line_sect_off
;
3095 /* Hash function for a quick_file_names. */
3098 hash_file_name_entry (const void *e
)
3100 const struct quick_file_names
*file_data
3101 = (const struct quick_file_names
*) e
;
3103 return hash_stmt_list_entry (&file_data
->hash
);
3106 /* Equality function for a quick_file_names. */
3109 eq_file_name_entry (const void *a
, const void *b
)
3111 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
3112 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
3114 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
3117 /* Delete function for a quick_file_names. */
3120 delete_file_name_entry (void *e
)
3122 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
3125 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3127 xfree ((void*) file_data
->file_names
[i
]);
3128 if (file_data
->real_names
)
3129 xfree ((void*) file_data
->real_names
[i
]);
3132 /* The space for the struct itself lives on objfile_obstack,
3133 so we don't free it here. */
3136 /* Create a quick_file_names hash table. */
3139 create_quick_file_names_table (unsigned int nr_initial_entries
)
3141 return htab_create_alloc (nr_initial_entries
,
3142 hash_file_name_entry
, eq_file_name_entry
,
3143 delete_file_name_entry
, xcalloc
, xfree
);
3146 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
3147 have to be created afterwards. You should call age_cached_comp_units after
3148 processing PER_CU->CU. dw2_setup must have been already called. */
3151 load_cu (struct dwarf2_per_cu_data
*per_cu
)
3153 if (per_cu
->is_debug_types
)
3154 load_full_type_unit (per_cu
);
3156 load_full_comp_unit (per_cu
, language_minimal
);
3158 if (per_cu
->cu
== NULL
)
3159 return; /* Dummy CU. */
3161 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
3164 /* Read in the symbols for PER_CU. */
3167 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3169 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3171 /* Skip type_unit_groups, reading the type units they contain
3172 is handled elsewhere. */
3173 if (IS_TYPE_UNIT_GROUP (per_cu
))
3176 /* The destructor of dwarf2_queue_guard frees any entries left on
3177 the queue. After this point we're guaranteed to leave this function
3178 with the dwarf queue empty. */
3179 dwarf2_queue_guard q_guard
;
3181 if (dwarf2_per_objfile
->using_index
3182 ? per_cu
->v
.quick
->compunit_symtab
== NULL
3183 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
3185 queue_comp_unit (per_cu
, language_minimal
);
3188 /* If we just loaded a CU from a DWO, and we're working with an index
3189 that may badly handle TUs, load all the TUs in that DWO as well.
3190 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
3191 if (!per_cu
->is_debug_types
3192 && per_cu
->cu
!= NULL
3193 && per_cu
->cu
->dwo_unit
!= NULL
3194 && dwarf2_per_objfile
->index_table
!= NULL
3195 && dwarf2_per_objfile
->index_table
->version
<= 7
3196 /* DWP files aren't supported yet. */
3197 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
3198 queue_and_load_all_dwo_tus (per_cu
);
3201 process_queue (dwarf2_per_objfile
);
3203 /* Age the cache, releasing compilation units that have not
3204 been used recently. */
3205 age_cached_comp_units (dwarf2_per_objfile
);
3208 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
3209 the objfile from which this CU came. Returns the resulting symbol
3212 static struct compunit_symtab
*
3213 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3215 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3217 gdb_assert (dwarf2_per_objfile
->using_index
);
3218 if (!per_cu
->v
.quick
->compunit_symtab
)
3220 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
,
3221 dwarf2_per_objfile
);
3222 scoped_restore decrementer
= increment_reading_symtab ();
3223 dw2_do_instantiate_symtab (per_cu
);
3224 process_cu_includes (dwarf2_per_objfile
);
3225 do_cleanups (back_to
);
3228 return per_cu
->v
.quick
->compunit_symtab
;
3231 /* Return the CU/TU given its index.
3233 This is intended for loops like:
3235 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3236 + dwarf2_per_objfile->n_type_units); ++i)
3238 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3244 static struct dwarf2_per_cu_data
*
3245 dw2_get_cutu (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3248 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3250 index
-= dwarf2_per_objfile
->n_comp_units
;
3251 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3252 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3255 return dwarf2_per_objfile
->all_comp_units
[index
];
3258 /* Return the CU given its index.
3259 This differs from dw2_get_cutu in that it's for when you know INDEX
3262 static struct dwarf2_per_cu_data
*
3263 dw2_get_cu (struct dwarf2_per_objfile
*dwarf2_per_objfile
, int index
)
3265 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3267 return dwarf2_per_objfile
->all_comp_units
[index
];
3270 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3271 objfile_obstack, and constructed with the specified field
3274 static dwarf2_per_cu_data
*
3275 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3276 struct dwarf2_section_info
*section
,
3278 sect_offset sect_off
, ULONGEST length
)
3280 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3281 dwarf2_per_cu_data
*the_cu
3282 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3283 struct dwarf2_per_cu_data
);
3284 the_cu
->sect_off
= sect_off
;
3285 the_cu
->length
= length
;
3286 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3287 the_cu
->section
= section
;
3288 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3289 struct dwarf2_per_cu_quick_data
);
3290 the_cu
->is_dwz
= is_dwz
;
3294 /* A helper for create_cus_from_index that handles a given list of
3298 create_cus_from_index_list (struct objfile
*objfile
,
3299 const gdb_byte
*cu_list
, offset_type n_elements
,
3300 struct dwarf2_section_info
*section
,
3305 struct dwarf2_per_objfile
*dwarf2_per_objfile
3306 = get_dwarf2_per_objfile (objfile
);
3308 for (i
= 0; i
< n_elements
; i
+= 2)
3310 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3312 sect_offset sect_off
3313 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3314 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3317 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
3318 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3323 /* Read the CU list from the mapped index, and use it to create all
3324 the CU objects for this objfile. */
3327 create_cus_from_index (struct objfile
*objfile
,
3328 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3329 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3331 struct dwz_file
*dwz
;
3332 struct dwarf2_per_objfile
*dwarf2_per_objfile
3333 = get_dwarf2_per_objfile (objfile
);
3335 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3336 dwarf2_per_objfile
->all_comp_units
=
3337 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3338 dwarf2_per_objfile
->n_comp_units
);
3340 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3341 &dwarf2_per_objfile
->info
, 0, 0);
3343 if (dwz_elements
== 0)
3346 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3347 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3348 cu_list_elements
/ 2);
3351 /* Create the signatured type hash table from the index. */
3354 create_signatured_type_table_from_index (struct objfile
*objfile
,
3355 struct dwarf2_section_info
*section
,
3356 const gdb_byte
*bytes
,
3357 offset_type elements
)
3360 htab_t sig_types_hash
;
3361 struct dwarf2_per_objfile
*dwarf2_per_objfile
3362 = get_dwarf2_per_objfile (objfile
);
3364 dwarf2_per_objfile
->n_type_units
3365 = dwarf2_per_objfile
->n_allocated_type_units
3367 dwarf2_per_objfile
->all_type_units
=
3368 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3370 sig_types_hash
= allocate_signatured_type_table (objfile
);
3372 for (i
= 0; i
< elements
; i
+= 3)
3374 struct signatured_type
*sig_type
;
3377 cu_offset type_offset_in_tu
;
3379 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3380 sect_offset sect_off
3381 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3383 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3385 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3388 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3389 struct signatured_type
);
3390 sig_type
->signature
= signature
;
3391 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3392 sig_type
->per_cu
.is_debug_types
= 1;
3393 sig_type
->per_cu
.section
= section
;
3394 sig_type
->per_cu
.sect_off
= sect_off
;
3395 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3396 sig_type
->per_cu
.v
.quick
3397 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3398 struct dwarf2_per_cu_quick_data
);
3400 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3403 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3406 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3409 /* Create the signatured type hash table from .debug_names. */
3412 create_signatured_type_table_from_debug_names
3413 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3414 const mapped_debug_names
&map
,
3415 struct dwarf2_section_info
*section
,
3416 struct dwarf2_section_info
*abbrev_section
)
3418 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3420 dwarf2_read_section (objfile
, section
);
3421 dwarf2_read_section (objfile
, abbrev_section
);
3423 dwarf2_per_objfile
->n_type_units
3424 = dwarf2_per_objfile
->n_allocated_type_units
3426 dwarf2_per_objfile
->all_type_units
3427 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3429 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3431 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3433 struct signatured_type
*sig_type
;
3436 cu_offset type_offset_in_tu
;
3438 sect_offset sect_off
3439 = (sect_offset
) (extract_unsigned_integer
3440 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3442 map
.dwarf5_byte_order
));
3444 comp_unit_head cu_header
;
3445 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3447 section
->buffer
+ to_underlying (sect_off
),
3450 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3451 struct signatured_type
);
3452 sig_type
->signature
= cu_header
.signature
;
3453 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3454 sig_type
->per_cu
.is_debug_types
= 1;
3455 sig_type
->per_cu
.section
= section
;
3456 sig_type
->per_cu
.sect_off
= sect_off
;
3457 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3458 sig_type
->per_cu
.v
.quick
3459 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3460 struct dwarf2_per_cu_quick_data
);
3462 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3465 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3468 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3471 /* Read the address map data from the mapped index, and use it to
3472 populate the objfile's psymtabs_addrmap. */
3475 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3476 struct mapped_index
*index
)
3478 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3479 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3480 const gdb_byte
*iter
, *end
;
3481 struct addrmap
*mutable_map
;
3484 auto_obstack temp_obstack
;
3486 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3488 iter
= index
->address_table
.data ();
3489 end
= iter
+ index
->address_table
.size ();
3491 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3495 ULONGEST hi
, lo
, cu_index
;
3496 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3498 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3500 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3505 complaint (&symfile_complaints
,
3506 _(".gdb_index address table has invalid range (%s - %s)"),
3507 hex_string (lo
), hex_string (hi
));
3511 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3513 complaint (&symfile_complaints
,
3514 _(".gdb_index address table has invalid CU number %u"),
3515 (unsigned) cu_index
);
3519 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3520 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3521 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3522 dw2_get_cutu (dwarf2_per_objfile
, cu_index
));
3525 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3526 &objfile
->objfile_obstack
);
3529 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3530 populate the objfile's psymtabs_addrmap. */
3533 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3534 struct dwarf2_section_info
*section
)
3536 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3537 bfd
*abfd
= objfile
->obfd
;
3538 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3539 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3540 SECT_OFF_TEXT (objfile
));
3542 auto_obstack temp_obstack
;
3543 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3545 std::unordered_map
<sect_offset
,
3546 dwarf2_per_cu_data
*,
3547 gdb::hash_enum
<sect_offset
>>
3548 debug_info_offset_to_per_cu
;
3549 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3551 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cui
);
3552 const auto insertpair
3553 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3554 if (!insertpair
.second
)
3556 warning (_("Section .debug_aranges in %s has duplicate "
3557 "debug_info_offset %s, ignoring .debug_aranges."),
3558 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3563 dwarf2_read_section (objfile
, section
);
3565 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3567 const gdb_byte
*addr
= section
->buffer
;
3569 while (addr
< section
->buffer
+ section
->size
)
3571 const gdb_byte
*const entry_addr
= addr
;
3572 unsigned int bytes_read
;
3574 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3578 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3579 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3580 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3581 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3583 warning (_("Section .debug_aranges in %s entry at offset %zu "
3584 "length %s exceeds section length %s, "
3585 "ignoring .debug_aranges."),
3586 objfile_name (objfile
), entry_addr
- section
->buffer
,
3587 plongest (bytes_read
+ entry_length
),
3588 pulongest (section
->size
));
3592 /* The version number. */
3593 const uint16_t version
= read_2_bytes (abfd
, addr
);
3597 warning (_("Section .debug_aranges in %s entry at offset %zu "
3598 "has unsupported version %d, ignoring .debug_aranges."),
3599 objfile_name (objfile
), entry_addr
- section
->buffer
,
3604 const uint64_t debug_info_offset
3605 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3606 addr
+= offset_size
;
3607 const auto per_cu_it
3608 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3609 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3611 warning (_("Section .debug_aranges in %s entry at offset %zu "
3612 "debug_info_offset %s does not exists, "
3613 "ignoring .debug_aranges."),
3614 objfile_name (objfile
), entry_addr
- section
->buffer
,
3615 pulongest (debug_info_offset
));
3618 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3620 const uint8_t address_size
= *addr
++;
3621 if (address_size
< 1 || address_size
> 8)
3623 warning (_("Section .debug_aranges in %s entry at offset %zu "
3624 "address_size %u is invalid, ignoring .debug_aranges."),
3625 objfile_name (objfile
), entry_addr
- section
->buffer
,
3630 const uint8_t segment_selector_size
= *addr
++;
3631 if (segment_selector_size
!= 0)
3633 warning (_("Section .debug_aranges in %s entry at offset %zu "
3634 "segment_selector_size %u is not supported, "
3635 "ignoring .debug_aranges."),
3636 objfile_name (objfile
), entry_addr
- section
->buffer
,
3637 segment_selector_size
);
3641 /* Must pad to an alignment boundary that is twice the address
3642 size. It is undocumented by the DWARF standard but GCC does
3644 for (size_t padding
= ((-(addr
- section
->buffer
))
3645 & (2 * address_size
- 1));
3646 padding
> 0; padding
--)
3649 warning (_("Section .debug_aranges in %s entry at offset %zu "
3650 "padding is not zero, ignoring .debug_aranges."),
3651 objfile_name (objfile
), entry_addr
- section
->buffer
);
3657 if (addr
+ 2 * address_size
> entry_end
)
3659 warning (_("Section .debug_aranges in %s entry at offset %zu "
3660 "address list is not properly terminated, "
3661 "ignoring .debug_aranges."),
3662 objfile_name (objfile
), entry_addr
- section
->buffer
);
3665 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3667 addr
+= address_size
;
3668 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3670 addr
+= address_size
;
3671 if (start
== 0 && length
== 0)
3673 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3675 /* Symbol was eliminated due to a COMDAT group. */
3678 ULONGEST end
= start
+ length
;
3679 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3680 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3681 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3685 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3686 &objfile
->objfile_obstack
);
3689 /* The hash function for strings in the mapped index. This is the same as
3690 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3691 implementation. This is necessary because the hash function is tied to the
3692 format of the mapped index file. The hash values do not have to match with
3695 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3698 mapped_index_string_hash (int index_version
, const void *p
)
3700 const unsigned char *str
= (const unsigned char *) p
;
3704 while ((c
= *str
++) != 0)
3706 if (index_version
>= 5)
3708 r
= r
* 67 + c
- 113;
3714 /* Find a slot in the mapped index INDEX for the object named NAME.
3715 If NAME is found, set *VEC_OUT to point to the CU vector in the
3716 constant pool and return true. If NAME cannot be found, return
3720 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3721 offset_type
**vec_out
)
3724 offset_type slot
, step
;
3725 int (*cmp
) (const char *, const char *);
3727 gdb::unique_xmalloc_ptr
<char> without_params
;
3728 if (current_language
->la_language
== language_cplus
3729 || current_language
->la_language
== language_fortran
3730 || current_language
->la_language
== language_d
)
3732 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3735 if (strchr (name
, '(') != NULL
)
3737 without_params
= cp_remove_params (name
);
3739 if (without_params
!= NULL
)
3740 name
= without_params
.get ();
3744 /* Index version 4 did not support case insensitive searches. But the
3745 indices for case insensitive languages are built in lowercase, therefore
3746 simulate our NAME being searched is also lowercased. */
3747 hash
= mapped_index_string_hash ((index
->version
== 4
3748 && case_sensitivity
== case_sensitive_off
3749 ? 5 : index
->version
),
3752 slot
= hash
& (index
->symbol_table
.size () - 1);
3753 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3754 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3760 const auto &bucket
= index
->symbol_table
[slot
];
3761 if (bucket
.name
== 0 && bucket
.vec
== 0)
3764 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3765 if (!cmp (name
, str
))
3767 *vec_out
= (offset_type
*) (index
->constant_pool
3768 + MAYBE_SWAP (bucket
.vec
));
3772 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3776 /* A helper function that reads the .gdb_index from SECTION and fills
3777 in MAP. FILENAME is the name of the file containing the section;
3778 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3779 ok to use deprecated sections.
3781 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3782 out parameters that are filled in with information about the CU and
3783 TU lists in the section.
3785 Returns 1 if all went well, 0 otherwise. */
3788 read_index_from_section (struct objfile
*objfile
,
3789 const char *filename
,
3791 struct dwarf2_section_info
*section
,
3792 struct mapped_index
*map
,
3793 const gdb_byte
**cu_list
,
3794 offset_type
*cu_list_elements
,
3795 const gdb_byte
**types_list
,
3796 offset_type
*types_list_elements
)
3798 const gdb_byte
*addr
;
3799 offset_type version
;
3800 offset_type
*metadata
;
3803 if (dwarf2_section_empty_p (section
))
3806 /* Older elfutils strip versions could keep the section in the main
3807 executable while splitting it for the separate debug info file. */
3808 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3811 dwarf2_read_section (objfile
, section
);
3813 addr
= section
->buffer
;
3814 /* Version check. */
3815 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3816 /* Versions earlier than 3 emitted every copy of a psymbol. This
3817 causes the index to behave very poorly for certain requests. Version 3
3818 contained incomplete addrmap. So, it seems better to just ignore such
3822 static int warning_printed
= 0;
3823 if (!warning_printed
)
3825 warning (_("Skipping obsolete .gdb_index section in %s."),
3827 warning_printed
= 1;
3831 /* Index version 4 uses a different hash function than index version
3834 Versions earlier than 6 did not emit psymbols for inlined
3835 functions. Using these files will cause GDB not to be able to
3836 set breakpoints on inlined functions by name, so we ignore these
3837 indices unless the user has done
3838 "set use-deprecated-index-sections on". */
3839 if (version
< 6 && !deprecated_ok
)
3841 static int warning_printed
= 0;
3842 if (!warning_printed
)
3845 Skipping deprecated .gdb_index section in %s.\n\
3846 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3847 to use the section anyway."),
3849 warning_printed
= 1;
3853 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3854 of the TU (for symbols coming from TUs),
3855 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3856 Plus gold-generated indices can have duplicate entries for global symbols,
3857 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3858 These are just performance bugs, and we can't distinguish gdb-generated
3859 indices from gold-generated ones, so issue no warning here. */
3861 /* Indexes with higher version than the one supported by GDB may be no
3862 longer backward compatible. */
3866 map
->version
= version
;
3867 map
->total_size
= section
->size
;
3869 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3872 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3873 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3877 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3878 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3879 - MAYBE_SWAP (metadata
[i
]))
3883 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3884 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3886 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3889 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3890 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3892 = gdb::array_view
<mapped_index::symbol_table_slot
>
3893 ((mapped_index::symbol_table_slot
*) symbol_table
,
3894 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3897 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3902 /* Read .gdb_index. If everything went ok, initialize the "quick"
3903 elements of all the CUs and return 1. Otherwise, return 0. */
3906 dwarf2_read_index (struct objfile
*objfile
)
3908 struct mapped_index local_map
, *map
;
3909 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3910 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3911 struct dwz_file
*dwz
;
3912 struct dwarf2_per_objfile
*dwarf2_per_objfile
3913 = get_dwarf2_per_objfile (objfile
);
3915 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3916 use_deprecated_index_sections
,
3917 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3918 &cu_list
, &cu_list_elements
,
3919 &types_list
, &types_list_elements
))
3922 /* Don't use the index if it's empty. */
3923 if (local_map
.symbol_table
.empty ())
3926 /* If there is a .dwz file, read it so we can get its CU list as
3928 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3931 struct mapped_index dwz_map
;
3932 const gdb_byte
*dwz_types_ignore
;
3933 offset_type dwz_types_elements_ignore
;
3935 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3937 &dwz
->gdb_index
, &dwz_map
,
3938 &dwz_list
, &dwz_list_elements
,
3940 &dwz_types_elements_ignore
))
3942 warning (_("could not read '.gdb_index' section from %s; skipping"),
3943 bfd_get_filename (dwz
->dwz_bfd
));
3948 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
3951 if (types_list_elements
)
3953 struct dwarf2_section_info
*section
;
3955 /* We can only handle a single .debug_types when we have an
3957 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
3960 section
= VEC_index (dwarf2_section_info_def
,
3961 dwarf2_per_objfile
->types
, 0);
3963 create_signatured_type_table_from_index (objfile
, section
, types_list
,
3964 types_list_elements
);
3967 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
3969 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
3970 map
= new (map
) mapped_index ();
3973 dwarf2_per_objfile
->index_table
= map
;
3974 dwarf2_per_objfile
->using_index
= 1;
3975 dwarf2_per_objfile
->quick_file_names_table
=
3976 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
3981 /* die_reader_func for dw2_get_file_names. */
3984 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3985 const gdb_byte
*info_ptr
,
3986 struct die_info
*comp_unit_die
,
3990 struct dwarf2_cu
*cu
= reader
->cu
;
3991 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3992 struct dwarf2_per_objfile
*dwarf2_per_objfile
3993 = cu
->per_cu
->dwarf2_per_objfile
;
3994 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3995 struct dwarf2_per_cu_data
*lh_cu
;
3996 struct attribute
*attr
;
3999 struct quick_file_names
*qfn
;
4001 gdb_assert (! this_cu
->is_debug_types
);
4003 /* Our callers never want to match partial units -- instead they
4004 will match the enclosing full CU. */
4005 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
4007 this_cu
->v
.quick
->no_file_data
= 1;
4015 sect_offset line_offset
{};
4017 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4020 struct quick_file_names find_entry
;
4022 line_offset
= (sect_offset
) DW_UNSND (attr
);
4024 /* We may have already read in this line header (TU line header sharing).
4025 If we have we're done. */
4026 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
4027 find_entry
.hash
.line_sect_off
= line_offset
;
4028 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
4029 &find_entry
, INSERT
);
4032 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
4036 lh
= dwarf_decode_line_header (line_offset
, cu
);
4040 lh_cu
->v
.quick
->no_file_data
= 1;
4044 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
4045 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
4046 qfn
->hash
.line_sect_off
= line_offset
;
4047 gdb_assert (slot
!= NULL
);
4050 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
4052 qfn
->num_file_names
= lh
->file_names
.size ();
4054 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
4055 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
4056 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
4057 qfn
->real_names
= NULL
;
4059 lh_cu
->v
.quick
->file_names
= qfn
;
4062 /* A helper for the "quick" functions which attempts to read the line
4063 table for THIS_CU. */
4065 static struct quick_file_names
*
4066 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
4068 /* This should never be called for TUs. */
4069 gdb_assert (! this_cu
->is_debug_types
);
4070 /* Nor type unit groups. */
4071 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
4073 if (this_cu
->v
.quick
->file_names
!= NULL
)
4074 return this_cu
->v
.quick
->file_names
;
4075 /* If we know there is no line data, no point in looking again. */
4076 if (this_cu
->v
.quick
->no_file_data
)
4079 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
4081 if (this_cu
->v
.quick
->no_file_data
)
4083 return this_cu
->v
.quick
->file_names
;
4086 /* A helper for the "quick" functions which computes and caches the
4087 real path for a given file name from the line table. */
4090 dw2_get_real_path (struct objfile
*objfile
,
4091 struct quick_file_names
*qfn
, int index
)
4093 if (qfn
->real_names
== NULL
)
4094 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
4095 qfn
->num_file_names
, const char *);
4097 if (qfn
->real_names
[index
] == NULL
)
4098 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
4100 return qfn
->real_names
[index
];
4103 static struct symtab
*
4104 dw2_find_last_source_symtab (struct objfile
*objfile
)
4106 struct dwarf2_per_objfile
*dwarf2_per_objfile
4107 = get_dwarf2_per_objfile (objfile
);
4108 int index
= dwarf2_per_objfile
->n_comp_units
- 1;
4109 dwarf2_per_cu_data
*dwarf_cu
= dw2_get_cutu (dwarf2_per_objfile
, index
);
4110 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
4115 return compunit_primary_filetab (cust
);
4118 /* Traversal function for dw2_forget_cached_source_info. */
4121 dw2_free_cached_file_names (void **slot
, void *info
)
4123 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
4125 if (file_data
->real_names
)
4129 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
4131 xfree ((void*) file_data
->real_names
[i
]);
4132 file_data
->real_names
[i
] = NULL
;
4140 dw2_forget_cached_source_info (struct objfile
*objfile
)
4142 struct dwarf2_per_objfile
*dwarf2_per_objfile
4143 = get_dwarf2_per_objfile (objfile
);
4145 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
4146 dw2_free_cached_file_names
, NULL
);
4149 /* Helper function for dw2_map_symtabs_matching_filename that expands
4150 the symtabs and calls the iterator. */
4153 dw2_map_expand_apply (struct objfile
*objfile
,
4154 struct dwarf2_per_cu_data
*per_cu
,
4155 const char *name
, const char *real_path
,
4156 gdb::function_view
<bool (symtab
*)> callback
)
4158 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
4160 /* Don't visit already-expanded CUs. */
4161 if (per_cu
->v
.quick
->compunit_symtab
)
4164 /* This may expand more than one symtab, and we want to iterate over
4166 dw2_instantiate_symtab (per_cu
);
4168 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
4169 last_made
, callback
);
4172 /* Implementation of the map_symtabs_matching_filename method. */
4175 dw2_map_symtabs_matching_filename
4176 (struct objfile
*objfile
, const char *name
, const char *real_path
,
4177 gdb::function_view
<bool (symtab
*)> callback
)
4180 const char *name_basename
= lbasename (name
);
4181 struct dwarf2_per_objfile
*dwarf2_per_objfile
4182 = get_dwarf2_per_objfile (objfile
);
4184 /* The rule is CUs specify all the files, including those used by
4185 any TU, so there's no need to scan TUs here. */
4187 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4190 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
4191 struct quick_file_names
*file_data
;
4193 /* We only need to look at symtabs not already expanded. */
4194 if (per_cu
->v
.quick
->compunit_symtab
)
4197 file_data
= dw2_get_file_names (per_cu
);
4198 if (file_data
== NULL
)
4201 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4203 const char *this_name
= file_data
->file_names
[j
];
4204 const char *this_real_name
;
4206 if (compare_filenames_for_search (this_name
, name
))
4208 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4214 /* Before we invoke realpath, which can get expensive when many
4215 files are involved, do a quick comparison of the basenames. */
4216 if (! basenames_may_differ
4217 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
4220 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4221 if (compare_filenames_for_search (this_real_name
, name
))
4223 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4229 if (real_path
!= NULL
)
4231 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
4232 gdb_assert (IS_ABSOLUTE_PATH (name
));
4233 if (this_real_name
!= NULL
4234 && FILENAME_CMP (real_path
, this_real_name
) == 0)
4236 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4248 /* Struct used to manage iterating over all CUs looking for a symbol. */
4250 struct dw2_symtab_iterator
4252 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
4253 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
4254 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
4255 int want_specific_block
;
4256 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
4257 Unused if !WANT_SPECIFIC_BLOCK. */
4259 /* The kind of symbol we're looking for. */
4261 /* The list of CUs from the index entry of the symbol,
4262 or NULL if not found. */
4264 /* The next element in VEC to look at. */
4266 /* The number of elements in VEC, or zero if there is no match. */
4268 /* Have we seen a global version of the symbol?
4269 If so we can ignore all further global instances.
4270 This is to work around gold/15646, inefficient gold-generated
4275 /* Initialize the index symtab iterator ITER.
4276 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
4277 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
4280 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
4281 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4282 int want_specific_block
,
4287 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
4288 iter
->want_specific_block
= want_specific_block
;
4289 iter
->block_index
= block_index
;
4290 iter
->domain
= domain
;
4292 iter
->global_seen
= 0;
4294 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
4296 /* index is NULL if OBJF_READNOW. */
4297 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
4298 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4306 /* Return the next matching CU or NULL if there are no more. */
4308 static struct dwarf2_per_cu_data
*
4309 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4311 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4313 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4315 offset_type cu_index_and_attrs
=
4316 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4317 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4318 struct dwarf2_per_cu_data
*per_cu
;
4319 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
4320 /* This value is only valid for index versions >= 7. */
4321 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4322 gdb_index_symbol_kind symbol_kind
=
4323 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4324 /* Only check the symbol attributes if they're present.
4325 Indices prior to version 7 don't record them,
4326 and indices >= 7 may elide them for certain symbols
4327 (gold does this). */
4329 (dwarf2_per_objfile
->index_table
->version
>= 7
4330 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4332 /* Don't crash on bad data. */
4333 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4334 + dwarf2_per_objfile
->n_type_units
))
4336 complaint (&symfile_complaints
,
4337 _(".gdb_index entry has bad CU index"
4339 objfile_name (dwarf2_per_objfile
->objfile
));
4343 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
4345 /* Skip if already read in. */
4346 if (per_cu
->v
.quick
->compunit_symtab
)
4349 /* Check static vs global. */
4352 if (iter
->want_specific_block
4353 && want_static
!= is_static
)
4355 /* Work around gold/15646. */
4356 if (!is_static
&& iter
->global_seen
)
4359 iter
->global_seen
= 1;
4362 /* Only check the symbol's kind if it has one. */
4365 switch (iter
->domain
)
4368 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4369 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4370 /* Some types are also in VAR_DOMAIN. */
4371 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4375 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4379 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4394 static struct compunit_symtab
*
4395 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4396 const char *name
, domain_enum domain
)
4398 struct compunit_symtab
*stab_best
= NULL
;
4399 struct dwarf2_per_objfile
*dwarf2_per_objfile
4400 = get_dwarf2_per_objfile (objfile
);
4402 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4404 struct dw2_symtab_iterator iter
;
4405 struct dwarf2_per_cu_data
*per_cu
;
4407 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4409 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4411 struct symbol
*sym
, *with_opaque
= NULL
;
4412 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4413 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4414 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4416 sym
= block_find_symbol (block
, name
, domain
,
4417 block_find_non_opaque_type_preferred
,
4420 /* Some caution must be observed with overloaded functions
4421 and methods, since the index will not contain any overload
4422 information (but NAME might contain it). */
4425 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4427 if (with_opaque
!= NULL
4428 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4431 /* Keep looking through other CUs. */
4438 dw2_print_stats (struct objfile
*objfile
)
4440 struct dwarf2_per_objfile
*dwarf2_per_objfile
4441 = get_dwarf2_per_objfile (objfile
);
4442 int total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4445 for (int i
= 0; i
< total
; ++i
)
4447 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4449 if (!per_cu
->v
.quick
->compunit_symtab
)
4452 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4453 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4456 /* This dumps minimal information about the index.
4457 It is called via "mt print objfiles".
4458 One use is to verify .gdb_index has been loaded by the
4459 gdb.dwarf2/gdb-index.exp testcase. */
4462 dw2_dump (struct objfile
*objfile
)
4464 struct dwarf2_per_objfile
*dwarf2_per_objfile
4465 = get_dwarf2_per_objfile (objfile
);
4467 gdb_assert (dwarf2_per_objfile
->using_index
);
4468 printf_filtered (".gdb_index:");
4469 if (dwarf2_per_objfile
->index_table
!= NULL
)
4471 printf_filtered (" version %d\n",
4472 dwarf2_per_objfile
->index_table
->version
);
4475 printf_filtered (" faked for \"readnow\"\n");
4476 printf_filtered ("\n");
4480 dw2_relocate (struct objfile
*objfile
,
4481 const struct section_offsets
*new_offsets
,
4482 const struct section_offsets
*delta
)
4484 /* There's nothing to relocate here. */
4488 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4489 const char *func_name
)
4491 struct dwarf2_per_objfile
*dwarf2_per_objfile
4492 = get_dwarf2_per_objfile (objfile
);
4494 struct dw2_symtab_iterator iter
;
4495 struct dwarf2_per_cu_data
*per_cu
;
4497 /* Note: It doesn't matter what we pass for block_index here. */
4498 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4501 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4502 dw2_instantiate_symtab (per_cu
);
4507 dw2_expand_all_symtabs (struct objfile
*objfile
)
4509 struct dwarf2_per_objfile
*dwarf2_per_objfile
4510 = get_dwarf2_per_objfile (objfile
);
4511 int total_units
= (dwarf2_per_objfile
->n_comp_units
4512 + dwarf2_per_objfile
->n_type_units
);
4514 for (int i
= 0; i
< total_units
; ++i
)
4516 struct dwarf2_per_cu_data
*per_cu
4517 = dw2_get_cutu (dwarf2_per_objfile
, i
);
4519 dw2_instantiate_symtab (per_cu
);
4524 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4525 const char *fullname
)
4527 struct dwarf2_per_objfile
*dwarf2_per_objfile
4528 = get_dwarf2_per_objfile (objfile
);
4530 /* We don't need to consider type units here.
4531 This is only called for examining code, e.g. expand_line_sal.
4532 There can be an order of magnitude (or more) more type units
4533 than comp units, and we avoid them if we can. */
4535 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4538 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4539 struct quick_file_names
*file_data
;
4541 /* We only need to look at symtabs not already expanded. */
4542 if (per_cu
->v
.quick
->compunit_symtab
)
4545 file_data
= dw2_get_file_names (per_cu
);
4546 if (file_data
== NULL
)
4549 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4551 const char *this_fullname
= file_data
->file_names
[j
];
4553 if (filename_cmp (this_fullname
, fullname
) == 0)
4555 dw2_instantiate_symtab (per_cu
);
4563 dw2_map_matching_symbols (struct objfile
*objfile
,
4564 const char * name
, domain_enum domain
,
4566 int (*callback
) (struct block
*,
4567 struct symbol
*, void *),
4568 void *data
, symbol_name_match_type match
,
4569 symbol_compare_ftype
*ordered_compare
)
4571 /* Currently unimplemented; used for Ada. The function can be called if the
4572 current language is Ada for a non-Ada objfile using GNU index. As Ada
4573 does not look for non-Ada symbols this function should just return. */
4576 /* Symbol name matcher for .gdb_index names.
4578 Symbol names in .gdb_index have a few particularities:
4580 - There's no indication of which is the language of each symbol.
4582 Since each language has its own symbol name matching algorithm,
4583 and we don't know which language is the right one, we must match
4584 each symbol against all languages. This would be a potential
4585 performance problem if it were not mitigated by the
4586 mapped_index::name_components lookup table, which significantly
4587 reduces the number of times we need to call into this matcher,
4588 making it a non-issue.
4590 - Symbol names in the index have no overload (parameter)
4591 information. I.e., in C++, "foo(int)" and "foo(long)" both
4592 appear as "foo" in the index, for example.
4594 This means that the lookup names passed to the symbol name
4595 matcher functions must have no parameter information either
4596 because (e.g.) symbol search name "foo" does not match
4597 lookup-name "foo(int)" [while swapping search name for lookup
4600 class gdb_index_symbol_name_matcher
4603 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4604 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4606 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4607 Returns true if any matcher matches. */
4608 bool matches (const char *symbol_name
);
4611 /* A reference to the lookup name we're matching against. */
4612 const lookup_name_info
&m_lookup_name
;
4614 /* A vector holding all the different symbol name matchers, for all
4616 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4619 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4620 (const lookup_name_info
&lookup_name
)
4621 : m_lookup_name (lookup_name
)
4623 /* Prepare the vector of comparison functions upfront, to avoid
4624 doing the same work for each symbol. Care is taken to avoid
4625 matching with the same matcher more than once if/when multiple
4626 languages use the same matcher function. */
4627 auto &matchers
= m_symbol_name_matcher_funcs
;
4628 matchers
.reserve (nr_languages
);
4630 matchers
.push_back (default_symbol_name_matcher
);
4632 for (int i
= 0; i
< nr_languages
; i
++)
4634 const language_defn
*lang
= language_def ((enum language
) i
);
4635 symbol_name_matcher_ftype
*name_matcher
4636 = get_symbol_name_matcher (lang
, m_lookup_name
);
4638 /* Don't insert the same comparison routine more than once.
4639 Note that we do this linear walk instead of a seemingly
4640 cheaper sorted insert, or use a std::set or something like
4641 that, because relative order of function addresses is not
4642 stable. This is not a problem in practice because the number
4643 of supported languages is low, and the cost here is tiny
4644 compared to the number of searches we'll do afterwards using
4646 if (name_matcher
!= default_symbol_name_matcher
4647 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4648 == matchers
.end ()))
4649 matchers
.push_back (name_matcher
);
4654 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4656 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4657 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4663 /* Starting from a search name, return the string that finds the upper
4664 bound of all strings that start with SEARCH_NAME in a sorted name
4665 list. Returns the empty string to indicate that the upper bound is
4666 the end of the list. */
4669 make_sort_after_prefix_name (const char *search_name
)
4671 /* When looking to complete "func", we find the upper bound of all
4672 symbols that start with "func" by looking for where we'd insert
4673 the closest string that would follow "func" in lexicographical
4674 order. Usually, that's "func"-with-last-character-incremented,
4675 i.e. "fund". Mind non-ASCII characters, though. Usually those
4676 will be UTF-8 multi-byte sequences, but we can't be certain.
4677 Especially mind the 0xff character, which is a valid character in
4678 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4679 rule out compilers allowing it in identifiers. Note that
4680 conveniently, strcmp/strcasecmp are specified to compare
4681 characters interpreted as unsigned char. So what we do is treat
4682 the whole string as a base 256 number composed of a sequence of
4683 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4684 to 0, and carries 1 to the following more-significant position.
4685 If the very first character in SEARCH_NAME ends up incremented
4686 and carries/overflows, then the upper bound is the end of the
4687 list. The string after the empty string is also the empty
4690 Some examples of this operation:
4692 SEARCH_NAME => "+1" RESULT
4696 "\xff" "a" "\xff" => "\xff" "b"
4701 Then, with these symbols for example:
4707 completing "func" looks for symbols between "func" and
4708 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4709 which finds "func" and "func1", but not "fund".
4713 funcÿ (Latin1 'ÿ' [0xff])
4717 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4718 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4722 ÿÿ (Latin1 'ÿ' [0xff])
4725 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4726 the end of the list.
4728 std::string after
= search_name
;
4729 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4731 if (!after
.empty ())
4732 after
.back () = (unsigned char) after
.back () + 1;
4736 /* See declaration. */
4738 std::pair
<std::vector
<name_component
>::const_iterator
,
4739 std::vector
<name_component
>::const_iterator
>
4740 mapped_index_base::find_name_components_bounds
4741 (const lookup_name_info
&lookup_name_without_params
) const
4744 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4747 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4749 /* Comparison function object for lower_bound that matches against a
4750 given symbol name. */
4751 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4754 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4755 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4756 return name_cmp (elem_name
, name
) < 0;
4759 /* Comparison function object for upper_bound that matches against a
4760 given symbol name. */
4761 auto lookup_compare_upper
= [&] (const char *name
,
4762 const name_component
&elem
)
4764 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4765 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4766 return name_cmp (name
, elem_name
) < 0;
4769 auto begin
= this->name_components
.begin ();
4770 auto end
= this->name_components
.end ();
4772 /* Find the lower bound. */
4775 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4778 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4781 /* Find the upper bound. */
4784 if (lookup_name_without_params
.completion_mode ())
4786 /* In completion mode, we want UPPER to point past all
4787 symbols names that have the same prefix. I.e., with
4788 these symbols, and completing "func":
4790 function << lower bound
4792 other_function << upper bound
4794 We find the upper bound by looking for the insertion
4795 point of "func"-with-last-character-incremented,
4797 std::string after
= make_sort_after_prefix_name (cplus
);
4800 return std::lower_bound (lower
, end
, after
.c_str (),
4801 lookup_compare_lower
);
4804 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4807 return {lower
, upper
};
4810 /* See declaration. */
4813 mapped_index_base::build_name_components ()
4815 if (!this->name_components
.empty ())
4818 this->name_components_casing
= case_sensitivity
;
4820 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4822 /* The code below only knows how to break apart components of C++
4823 symbol names (and other languages that use '::' as
4824 namespace/module separator). If we add support for wild matching
4825 to some language that uses some other operator (E.g., Ada, Go and
4826 D use '.'), then we'll need to try splitting the symbol name
4827 according to that language too. Note that Ada does support wild
4828 matching, but doesn't currently support .gdb_index. */
4829 auto count
= this->symbol_name_count ();
4830 for (offset_type idx
= 0; idx
< count
; idx
++)
4832 if (this->symbol_name_slot_invalid (idx
))
4835 const char *name
= this->symbol_name_at (idx
);
4837 /* Add each name component to the name component table. */
4838 unsigned int previous_len
= 0;
4839 for (unsigned int current_len
= cp_find_first_component (name
);
4840 name
[current_len
] != '\0';
4841 current_len
+= cp_find_first_component (name
+ current_len
))
4843 gdb_assert (name
[current_len
] == ':');
4844 this->name_components
.push_back ({previous_len
, idx
});
4845 /* Skip the '::'. */
4847 previous_len
= current_len
;
4849 this->name_components
.push_back ({previous_len
, idx
});
4852 /* Sort name_components elements by name. */
4853 auto name_comp_compare
= [&] (const name_component
&left
,
4854 const name_component
&right
)
4856 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4857 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4859 const char *left_name
= left_qualified
+ left
.name_offset
;
4860 const char *right_name
= right_qualified
+ right
.name_offset
;
4862 return name_cmp (left_name
, right_name
) < 0;
4865 std::sort (this->name_components
.begin (),
4866 this->name_components
.end (),
4870 /* Helper for dw2_expand_symtabs_matching that works with a
4871 mapped_index_base instead of the containing objfile. This is split
4872 to a separate function in order to be able to unit test the
4873 name_components matching using a mock mapped_index_base. For each
4874 symbol name that matches, calls MATCH_CALLBACK, passing it the
4875 symbol's index in the mapped_index_base symbol table. */
4878 dw2_expand_symtabs_matching_symbol
4879 (mapped_index_base
&index
,
4880 const lookup_name_info
&lookup_name_in
,
4881 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4882 enum search_domain kind
,
4883 gdb::function_view
<void (offset_type
)> match_callback
)
4885 lookup_name_info lookup_name_without_params
4886 = lookup_name_in
.make_ignore_params ();
4887 gdb_index_symbol_name_matcher lookup_name_matcher
4888 (lookup_name_without_params
);
4890 /* Build the symbol name component sorted vector, if we haven't
4892 index
.build_name_components ();
4894 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4896 /* Now for each symbol name in range, check to see if we have a name
4897 match, and if so, call the MATCH_CALLBACK callback. */
4899 /* The same symbol may appear more than once in the range though.
4900 E.g., if we're looking for symbols that complete "w", and we have
4901 a symbol named "w1::w2", we'll find the two name components for
4902 that same symbol in the range. To be sure we only call the
4903 callback once per symbol, we first collect the symbol name
4904 indexes that matched in a temporary vector and ignore
4906 std::vector
<offset_type
> matches
;
4907 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4909 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4911 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4913 if (!lookup_name_matcher
.matches (qualified
)
4914 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4917 matches
.push_back (bounds
.first
->idx
);
4920 std::sort (matches
.begin (), matches
.end ());
4922 /* Finally call the callback, once per match. */
4924 for (offset_type idx
: matches
)
4928 match_callback (idx
);
4933 /* Above we use a type wider than idx's for 'prev', since 0 and
4934 (offset_type)-1 are both possible values. */
4935 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4940 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4942 /* A mock .gdb_index/.debug_names-like name index table, enough to
4943 exercise dw2_expand_symtabs_matching_symbol, which works with the
4944 mapped_index_base interface. Builds an index from the symbol list
4945 passed as parameter to the constructor. */
4946 class mock_mapped_index
: public mapped_index_base
4949 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4950 : m_symbol_table (symbols
)
4953 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4955 /* Return the number of names in the symbol table. */
4956 virtual size_t symbol_name_count () const
4958 return m_symbol_table
.size ();
4961 /* Get the name of the symbol at IDX in the symbol table. */
4962 virtual const char *symbol_name_at (offset_type idx
) const
4964 return m_symbol_table
[idx
];
4968 gdb::array_view
<const char *> m_symbol_table
;
4971 /* Convenience function that converts a NULL pointer to a "<null>"
4972 string, to pass to print routines. */
4975 string_or_null (const char *str
)
4977 return str
!= NULL
? str
: "<null>";
4980 /* Check if a lookup_name_info built from
4981 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4982 index. EXPECTED_LIST is the list of expected matches, in expected
4983 matching order. If no match expected, then an empty list is
4984 specified. Returns true on success. On failure prints a warning
4985 indicating the file:line that failed, and returns false. */
4988 check_match (const char *file
, int line
,
4989 mock_mapped_index
&mock_index
,
4990 const char *name
, symbol_name_match_type match_type
,
4991 bool completion_mode
,
4992 std::initializer_list
<const char *> expected_list
)
4994 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4996 bool matched
= true;
4998 auto mismatch
= [&] (const char *expected_str
,
5001 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
5002 "expected=\"%s\", got=\"%s\"\n"),
5004 (match_type
== symbol_name_match_type::FULL
5006 name
, string_or_null (expected_str
), string_or_null (got
));
5010 auto expected_it
= expected_list
.begin ();
5011 auto expected_end
= expected_list
.end ();
5013 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
5015 [&] (offset_type idx
)
5017 const char *matched_name
= mock_index
.symbol_name_at (idx
);
5018 const char *expected_str
5019 = expected_it
== expected_end
? NULL
: *expected_it
++;
5021 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
5022 mismatch (expected_str
, matched_name
);
5025 const char *expected_str
5026 = expected_it
== expected_end
? NULL
: *expected_it
++;
5027 if (expected_str
!= NULL
)
5028 mismatch (expected_str
, NULL
);
5033 /* The symbols added to the mock mapped_index for testing (in
5035 static const char *test_symbols
[] = {
5044 "ns2::tmpl<int>::foo2",
5045 "(anonymous namespace)::A::B::C",
5047 /* These are used to check that the increment-last-char in the
5048 matching algorithm for completion doesn't match "t1_fund" when
5049 completing "t1_func". */
5055 /* A UTF-8 name with multi-byte sequences to make sure that
5056 cp-name-parser understands this as a single identifier ("função"
5057 is "function" in PT). */
5060 /* \377 (0xff) is Latin1 'ÿ'. */
5063 /* \377 (0xff) is Latin1 'ÿ'. */
5067 /* A name with all sorts of complications. Starts with "z" to make
5068 it easier for the completion tests below. */
5069 #define Z_SYM_NAME \
5070 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
5071 "::tuple<(anonymous namespace)::ui*, " \
5072 "std::default_delete<(anonymous namespace)::ui>, void>"
5077 /* Returns true if the mapped_index_base::find_name_component_bounds
5078 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
5079 in completion mode. */
5082 check_find_bounds_finds (mapped_index_base
&index
,
5083 const char *search_name
,
5084 gdb::array_view
<const char *> expected_syms
)
5086 lookup_name_info
lookup_name (search_name
,
5087 symbol_name_match_type::FULL
, true);
5089 auto bounds
= index
.find_name_components_bounds (lookup_name
);
5091 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
5092 if (distance
!= expected_syms
.size ())
5095 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
5097 auto nc_elem
= bounds
.first
+ exp_elem
;
5098 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
5099 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
5106 /* Test the lower-level mapped_index::find_name_component_bounds
5110 test_mapped_index_find_name_component_bounds ()
5112 mock_mapped_index
mock_index (test_symbols
);
5114 mock_index
.build_name_components ();
5116 /* Test the lower-level mapped_index::find_name_component_bounds
5117 method in completion mode. */
5119 static const char *expected_syms
[] = {
5124 SELF_CHECK (check_find_bounds_finds (mock_index
,
5125 "t1_func", expected_syms
));
5128 /* Check that the increment-last-char in the name matching algorithm
5129 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
5131 static const char *expected_syms1
[] = {
5135 SELF_CHECK (check_find_bounds_finds (mock_index
,
5136 "\377", expected_syms1
));
5138 static const char *expected_syms2
[] = {
5141 SELF_CHECK (check_find_bounds_finds (mock_index
,
5142 "\377\377", expected_syms2
));
5146 /* Test dw2_expand_symtabs_matching_symbol. */
5149 test_dw2_expand_symtabs_matching_symbol ()
5151 mock_mapped_index
mock_index (test_symbols
);
5153 /* We let all tests run until the end even if some fails, for debug
5155 bool any_mismatch
= false;
5157 /* Create the expected symbols list (an initializer_list). Needed
5158 because lists have commas, and we need to pass them to CHECK,
5159 which is a macro. */
5160 #define EXPECT(...) { __VA_ARGS__ }
5162 /* Wrapper for check_match that passes down the current
5163 __FILE__/__LINE__. */
5164 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
5165 any_mismatch |= !check_match (__FILE__, __LINE__, \
5167 NAME, MATCH_TYPE, COMPLETION_MODE, \
5170 /* Identity checks. */
5171 for (const char *sym
: test_symbols
)
5173 /* Should be able to match all existing symbols. */
5174 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
5177 /* Should be able to match all existing symbols with
5179 std::string with_params
= std::string (sym
) + "(int)";
5180 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5183 /* Should be able to match all existing symbols with
5184 parameters and qualifiers. */
5185 with_params
= std::string (sym
) + " ( int ) const";
5186 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5189 /* This should really find sym, but cp-name-parser.y doesn't
5190 know about lvalue/rvalue qualifiers yet. */
5191 with_params
= std::string (sym
) + " ( int ) &&";
5192 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5196 /* Check that the name matching algorithm for completion doesn't get
5197 confused with Latin1 'ÿ' / 0xff. */
5199 static const char str
[] = "\377";
5200 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5201 EXPECT ("\377", "\377\377123"));
5204 /* Check that the increment-last-char in the matching algorithm for
5205 completion doesn't match "t1_fund" when completing "t1_func". */
5207 static const char str
[] = "t1_func";
5208 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5209 EXPECT ("t1_func", "t1_func1"));
5212 /* Check that completion mode works at each prefix of the expected
5215 static const char str
[] = "function(int)";
5216 size_t len
= strlen (str
);
5219 for (size_t i
= 1; i
< len
; i
++)
5221 lookup
.assign (str
, i
);
5222 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5223 EXPECT ("function"));
5227 /* While "w" is a prefix of both components, the match function
5228 should still only be called once. */
5230 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
5232 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
5236 /* Same, with a "complicated" symbol. */
5238 static const char str
[] = Z_SYM_NAME
;
5239 size_t len
= strlen (str
);
5242 for (size_t i
= 1; i
< len
; i
++)
5244 lookup
.assign (str
, i
);
5245 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5246 EXPECT (Z_SYM_NAME
));
5250 /* In FULL mode, an incomplete symbol doesn't match. */
5252 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
5256 /* A complete symbol with parameters matches any overload, since the
5257 index has no overload info. */
5259 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
5260 EXPECT ("std::zfunction", "std::zfunction2"));
5261 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
5262 EXPECT ("std::zfunction", "std::zfunction2"));
5263 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
5264 EXPECT ("std::zfunction", "std::zfunction2"));
5267 /* Check that whitespace is ignored appropriately. A symbol with a
5268 template argument list. */
5270 static const char expected
[] = "ns::foo<int>";
5271 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
5273 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
5277 /* Check that whitespace is ignored appropriately. A symbol with a
5278 template argument list that includes a pointer. */
5280 static const char expected
[] = "ns::foo<char*>";
5281 /* Try both completion and non-completion modes. */
5282 static const bool completion_mode
[2] = {false, true};
5283 for (size_t i
= 0; i
< 2; i
++)
5285 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
5286 completion_mode
[i
], EXPECT (expected
));
5287 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
5288 completion_mode
[i
], EXPECT (expected
));
5290 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
5291 completion_mode
[i
], EXPECT (expected
));
5292 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
5293 completion_mode
[i
], EXPECT (expected
));
5298 /* Check method qualifiers are ignored. */
5299 static const char expected
[] = "ns::foo<char*>";
5300 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
5301 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5302 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
5303 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5304 CHECK_MATCH ("foo < char * > ( int ) const",
5305 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5306 CHECK_MATCH ("foo < char * > ( int ) &&",
5307 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5310 /* Test lookup names that don't match anything. */
5312 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
5315 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
5319 /* Some wild matching tests, exercising "(anonymous namespace)",
5320 which should not be confused with a parameter list. */
5322 static const char *syms
[] = {
5326 "A :: B :: C ( int )",
5331 for (const char *s
: syms
)
5333 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
5334 EXPECT ("(anonymous namespace)::A::B::C"));
5339 static const char expected
[] = "ns2::tmpl<int>::foo2";
5340 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5342 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5346 SELF_CHECK (!any_mismatch
);
5355 test_mapped_index_find_name_component_bounds ();
5356 test_dw2_expand_symtabs_matching_symbol ();
5359 }} // namespace selftests::dw2_expand_symtabs_matching
5361 #endif /* GDB_SELF_TEST */
5363 /* If FILE_MATCHER is NULL or if PER_CU has
5364 dwarf2_per_cu_quick_data::MARK set (see
5365 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5366 EXPANSION_NOTIFY on it. */
5369 dw2_expand_symtabs_matching_one
5370 (struct dwarf2_per_cu_data
*per_cu
,
5371 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5372 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5374 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5376 bool symtab_was_null
5377 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5379 dw2_instantiate_symtab (per_cu
);
5381 if (expansion_notify
!= NULL
5383 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5384 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5388 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5389 matched, to expand corresponding CUs that were marked. IDX is the
5390 index of the symbol name that matched. */
5393 dw2_expand_marked_cus
5394 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5395 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5396 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5399 offset_type
*vec
, vec_len
, vec_idx
;
5400 bool global_seen
= false;
5401 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5403 vec
= (offset_type
*) (index
.constant_pool
5404 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5405 vec_len
= MAYBE_SWAP (vec
[0]);
5406 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5408 struct dwarf2_per_cu_data
*per_cu
;
5409 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5410 /* This value is only valid for index versions >= 7. */
5411 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5412 gdb_index_symbol_kind symbol_kind
=
5413 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5414 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5415 /* Only check the symbol attributes if they're present.
5416 Indices prior to version 7 don't record them,
5417 and indices >= 7 may elide them for certain symbols
5418 (gold does this). */
5421 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5423 /* Work around gold/15646. */
5426 if (!is_static
&& global_seen
)
5432 /* Only check the symbol's kind if it has one. */
5437 case VARIABLES_DOMAIN
:
5438 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5441 case FUNCTIONS_DOMAIN
:
5442 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5446 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5454 /* Don't crash on bad data. */
5455 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5456 + dwarf2_per_objfile
->n_type_units
))
5458 complaint (&symfile_complaints
,
5459 _(".gdb_index entry has bad CU index"
5461 objfile_name (dwarf2_per_objfile
->objfile
));
5465 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
5466 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5471 /* If FILE_MATCHER is non-NULL, set all the
5472 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5473 that match FILE_MATCHER. */
5476 dw_expand_symtabs_matching_file_matcher
5477 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5478 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5480 if (file_matcher
== NULL
)
5483 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5485 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5487 NULL
, xcalloc
, xfree
));
5488 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5490 NULL
, xcalloc
, xfree
));
5492 /* The rule is CUs specify all the files, including those used by
5493 any TU, so there's no need to scan TUs here. */
5495 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5498 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5499 struct quick_file_names
*file_data
;
5504 per_cu
->v
.quick
->mark
= 0;
5506 /* We only need to look at symtabs not already expanded. */
5507 if (per_cu
->v
.quick
->compunit_symtab
)
5510 file_data
= dw2_get_file_names (per_cu
);
5511 if (file_data
== NULL
)
5514 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5516 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5518 per_cu
->v
.quick
->mark
= 1;
5522 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5524 const char *this_real_name
;
5526 if (file_matcher (file_data
->file_names
[j
], false))
5528 per_cu
->v
.quick
->mark
= 1;
5532 /* Before we invoke realpath, which can get expensive when many
5533 files are involved, do a quick comparison of the basenames. */
5534 if (!basenames_may_differ
5535 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5539 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5540 if (file_matcher (this_real_name
, false))
5542 per_cu
->v
.quick
->mark
= 1;
5547 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5548 ? visited_found
.get ()
5549 : visited_not_found
.get (),
5556 dw2_expand_symtabs_matching
5557 (struct objfile
*objfile
,
5558 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5559 const lookup_name_info
&lookup_name
,
5560 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5561 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5562 enum search_domain kind
)
5564 struct dwarf2_per_objfile
*dwarf2_per_objfile
5565 = get_dwarf2_per_objfile (objfile
);
5567 /* index_table is NULL if OBJF_READNOW. */
5568 if (!dwarf2_per_objfile
->index_table
)
5571 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5573 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5575 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5577 kind
, [&] (offset_type idx
)
5579 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5580 expansion_notify
, kind
);
5584 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5587 static struct compunit_symtab
*
5588 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5593 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5594 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5597 if (cust
->includes
== NULL
)
5600 for (i
= 0; cust
->includes
[i
]; ++i
)
5602 struct compunit_symtab
*s
= cust
->includes
[i
];
5604 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5612 static struct compunit_symtab
*
5613 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5614 struct bound_minimal_symbol msymbol
,
5616 struct obj_section
*section
,
5619 struct dwarf2_per_cu_data
*data
;
5620 struct compunit_symtab
*result
;
5622 if (!objfile
->psymtabs_addrmap
)
5625 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5630 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5631 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5632 paddress (get_objfile_arch (objfile
), pc
));
5635 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5637 gdb_assert (result
!= NULL
);
5642 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5643 void *data
, int need_fullname
)
5645 struct dwarf2_per_objfile
*dwarf2_per_objfile
5646 = get_dwarf2_per_objfile (objfile
);
5648 if (!dwarf2_per_objfile
->filenames_cache
)
5650 dwarf2_per_objfile
->filenames_cache
.emplace ();
5652 htab_up
visited (htab_create_alloc (10,
5653 htab_hash_pointer
, htab_eq_pointer
,
5654 NULL
, xcalloc
, xfree
));
5656 /* The rule is CUs specify all the files, including those used
5657 by any TU, so there's no need to scan TUs here. We can
5658 ignore file names coming from already-expanded CUs. */
5660 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5662 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
5664 if (per_cu
->v
.quick
->compunit_symtab
)
5666 void **slot
= htab_find_slot (visited
.get (),
5667 per_cu
->v
.quick
->file_names
,
5670 *slot
= per_cu
->v
.quick
->file_names
;
5674 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5676 dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5677 struct quick_file_names
*file_data
;
5680 /* We only need to look at symtabs not already expanded. */
5681 if (per_cu
->v
.quick
->compunit_symtab
)
5684 file_data
= dw2_get_file_names (per_cu
);
5685 if (file_data
== NULL
)
5688 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5691 /* Already visited. */
5696 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5698 const char *filename
= file_data
->file_names
[j
];
5699 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5704 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5706 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5709 this_real_name
= gdb_realpath (filename
);
5710 (*fun
) (filename
, this_real_name
.get (), data
);
5715 dw2_has_symbols (struct objfile
*objfile
)
5720 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5723 dw2_find_last_source_symtab
,
5724 dw2_forget_cached_source_info
,
5725 dw2_map_symtabs_matching_filename
,
5730 dw2_expand_symtabs_for_function
,
5731 dw2_expand_all_symtabs
,
5732 dw2_expand_symtabs_with_fullname
,
5733 dw2_map_matching_symbols
,
5734 dw2_expand_symtabs_matching
,
5735 dw2_find_pc_sect_compunit_symtab
,
5737 dw2_map_symbol_filenames
5740 /* DWARF-5 debug_names reader. */
5742 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5743 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5745 /* A helper function that reads the .debug_names section in SECTION
5746 and fills in MAP. FILENAME is the name of the file containing the
5747 section; it is used for error reporting.
5749 Returns true if all went well, false otherwise. */
5752 read_debug_names_from_section (struct objfile
*objfile
,
5753 const char *filename
,
5754 struct dwarf2_section_info
*section
,
5755 mapped_debug_names
&map
)
5757 if (dwarf2_section_empty_p (section
))
5760 /* Older elfutils strip versions could keep the section in the main
5761 executable while splitting it for the separate debug info file. */
5762 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5765 dwarf2_read_section (objfile
, section
);
5767 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5769 const gdb_byte
*addr
= section
->buffer
;
5771 bfd
*const abfd
= get_section_bfd_owner (section
);
5773 unsigned int bytes_read
;
5774 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5777 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5778 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5779 if (bytes_read
+ length
!= section
->size
)
5781 /* There may be multiple per-CU indices. */
5782 warning (_("Section .debug_names in %s length %s does not match "
5783 "section length %s, ignoring .debug_names."),
5784 filename
, plongest (bytes_read
+ length
),
5785 pulongest (section
->size
));
5789 /* The version number. */
5790 uint16_t version
= read_2_bytes (abfd
, addr
);
5794 warning (_("Section .debug_names in %s has unsupported version %d, "
5795 "ignoring .debug_names."),
5801 uint16_t padding
= read_2_bytes (abfd
, addr
);
5805 warning (_("Section .debug_names in %s has unsupported padding %d, "
5806 "ignoring .debug_names."),
5811 /* comp_unit_count - The number of CUs in the CU list. */
5812 map
.cu_count
= read_4_bytes (abfd
, addr
);
5815 /* local_type_unit_count - The number of TUs in the local TU
5817 map
.tu_count
= read_4_bytes (abfd
, addr
);
5820 /* foreign_type_unit_count - The number of TUs in the foreign TU
5822 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5824 if (foreign_tu_count
!= 0)
5826 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5827 "ignoring .debug_names."),
5828 filename
, static_cast<unsigned long> (foreign_tu_count
));
5832 /* bucket_count - The number of hash buckets in the hash lookup
5834 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5837 /* name_count - The number of unique names in the index. */
5838 map
.name_count
= read_4_bytes (abfd
, addr
);
5841 /* abbrev_table_size - The size in bytes of the abbreviations
5843 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5846 /* augmentation_string_size - The size in bytes of the augmentation
5847 string. This value is rounded up to a multiple of 4. */
5848 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5850 map
.augmentation_is_gdb
= ((augmentation_string_size
5851 == sizeof (dwarf5_augmentation
))
5852 && memcmp (addr
, dwarf5_augmentation
,
5853 sizeof (dwarf5_augmentation
)) == 0);
5854 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5855 addr
+= augmentation_string_size
;
5858 map
.cu_table_reordered
= addr
;
5859 addr
+= map
.cu_count
* map
.offset_size
;
5861 /* List of Local TUs */
5862 map
.tu_table_reordered
= addr
;
5863 addr
+= map
.tu_count
* map
.offset_size
;
5865 /* Hash Lookup Table */
5866 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5867 addr
+= map
.bucket_count
* 4;
5868 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5869 addr
+= map
.name_count
* 4;
5872 map
.name_table_string_offs_reordered
= addr
;
5873 addr
+= map
.name_count
* map
.offset_size
;
5874 map
.name_table_entry_offs_reordered
= addr
;
5875 addr
+= map
.name_count
* map
.offset_size
;
5877 const gdb_byte
*abbrev_table_start
= addr
;
5880 unsigned int bytes_read
;
5881 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5886 const auto insertpair
5887 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5888 if (!insertpair
.second
)
5890 warning (_("Section .debug_names in %s has duplicate index %s, "
5891 "ignoring .debug_names."),
5892 filename
, pulongest (index_num
));
5895 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5896 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5901 mapped_debug_names::index_val::attr attr
;
5902 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5904 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5906 if (attr
.form
== DW_FORM_implicit_const
)
5908 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5912 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5914 indexval
.attr_vec
.push_back (std::move (attr
));
5917 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5919 warning (_("Section .debug_names in %s has abbreviation_table "
5920 "of size %zu vs. written as %u, ignoring .debug_names."),
5921 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5924 map
.entry_pool
= addr
;
5929 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5933 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5934 const mapped_debug_names
&map
,
5935 dwarf2_section_info
§ion
,
5936 bool is_dwz
, int base_offset
)
5938 sect_offset sect_off_prev
;
5939 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5941 sect_offset sect_off_next
;
5942 if (i
< map
.cu_count
)
5945 = (sect_offset
) (extract_unsigned_integer
5946 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5948 map
.dwarf5_byte_order
));
5951 sect_off_next
= (sect_offset
) section
.size
;
5954 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5955 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
5956 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5957 sect_off_prev
, length
);
5959 sect_off_prev
= sect_off_next
;
5963 /* Read the CU list from the mapped index, and use it to create all
5964 the CU objects for this dwarf2_per_objfile. */
5967 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5968 const mapped_debug_names
&map
,
5969 const mapped_debug_names
&dwz_map
)
5971 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5973 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
5974 dwarf2_per_objfile
->all_comp_units
5975 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
5976 dwarf2_per_objfile
->n_comp_units
);
5978 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5979 dwarf2_per_objfile
->info
,
5981 0 /* base_offset */);
5983 if (dwz_map
.cu_count
== 0)
5986 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5987 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5989 map
.cu_count
/* base_offset */);
5992 /* Read .debug_names. If everything went ok, initialize the "quick"
5993 elements of all the CUs and return true. Otherwise, return false. */
5996 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5998 mapped_debug_names
local_map (dwarf2_per_objfile
);
5999 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
6000 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6002 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
6003 &dwarf2_per_objfile
->debug_names
,
6007 /* Don't use the index if it's empty. */
6008 if (local_map
.name_count
== 0)
6011 /* If there is a .dwz file, read it so we can get its CU list as
6013 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
6016 if (!read_debug_names_from_section (objfile
,
6017 bfd_get_filename (dwz
->dwz_bfd
),
6018 &dwz
->debug_names
, dwz_map
))
6020 warning (_("could not read '.debug_names' section from %s; skipping"),
6021 bfd_get_filename (dwz
->dwz_bfd
));
6026 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
6028 if (local_map
.tu_count
!= 0)
6030 /* We can only handle a single .debug_types when we have an
6032 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
6035 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
6036 dwarf2_per_objfile
->types
, 0);
6038 create_signatured_type_table_from_debug_names
6039 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
6042 create_addrmap_from_aranges (dwarf2_per_objfile
,
6043 &dwarf2_per_objfile
->debug_aranges
);
6045 dwarf2_per_objfile
->debug_names_table
.reset
6046 (new mapped_debug_names (dwarf2_per_objfile
));
6047 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
6048 dwarf2_per_objfile
->using_index
= 1;
6049 dwarf2_per_objfile
->quick_file_names_table
=
6050 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6055 /* Symbol name hashing function as specified by DWARF-5. */
6058 dwarf5_djb_hash (const char *str_
)
6060 const unsigned char *str
= (const unsigned char *) str_
;
6062 /* Note: tolower here ignores UTF-8, which isn't fully compliant.
6063 See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
6065 uint32_t hash
= 5381;
6066 while (int c
= *str
++)
6067 hash
= hash
* 33 + tolower (c
);
6071 /* Type used to manage iterating over all CUs looking for a symbol for
6074 class dw2_debug_names_iterator
6077 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
6078 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
6079 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6080 bool want_specific_block
,
6081 block_enum block_index
, domain_enum domain
,
6083 : m_map (map
), m_want_specific_block (want_specific_block
),
6084 m_block_index (block_index
), m_domain (domain
),
6085 m_addr (find_vec_in_debug_names (map
, name
))
6088 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6089 search_domain search
, uint32_t namei
)
6092 m_addr (find_vec_in_debug_names (map
, namei
))
6095 /* Return the next matching CU or NULL if there are no more. */
6096 dwarf2_per_cu_data
*next ();
6099 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6101 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6104 /* The internalized form of .debug_names. */
6105 const mapped_debug_names
&m_map
;
6107 /* If true, only look for symbols that match BLOCK_INDEX. */
6108 const bool m_want_specific_block
= false;
6110 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
6111 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
6113 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
6115 /* The kind of symbol we're looking for. */
6116 const domain_enum m_domain
= UNDEF_DOMAIN
;
6117 const search_domain m_search
= ALL_DOMAIN
;
6119 /* The list of CUs from the index entry of the symbol, or NULL if
6121 const gdb_byte
*m_addr
;
6125 mapped_debug_names::namei_to_name (uint32_t namei
) const
6127 const ULONGEST namei_string_offs
6128 = extract_unsigned_integer ((name_table_string_offs_reordered
6129 + namei
* offset_size
),
6132 return read_indirect_string_at_offset
6133 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
6136 /* Find a slot in .debug_names for the object named NAME. If NAME is
6137 found, return pointer to its pool data. If NAME cannot be found,
6141 dw2_debug_names_iterator::find_vec_in_debug_names
6142 (const mapped_debug_names
&map
, const char *name
)
6144 int (*cmp
) (const char *, const char *);
6146 if (current_language
->la_language
== language_cplus
6147 || current_language
->la_language
== language_fortran
6148 || current_language
->la_language
== language_d
)
6150 /* NAME is already canonical. Drop any qualifiers as
6151 .debug_names does not contain any. */
6153 if (strchr (name
, '(') != NULL
)
6155 gdb::unique_xmalloc_ptr
<char> without_params
6156 = cp_remove_params (name
);
6158 if (without_params
!= NULL
)
6160 name
= without_params
.get();
6165 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
6167 const uint32_t full_hash
= dwarf5_djb_hash (name
);
6169 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6170 (map
.bucket_table_reordered
6171 + (full_hash
% map
.bucket_count
)), 4,
6172 map
.dwarf5_byte_order
);
6176 if (namei
>= map
.name_count
)
6178 complaint (&symfile_complaints
,
6179 _("Wrong .debug_names with name index %u but name_count=%u "
6181 namei
, map
.name_count
,
6182 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6188 const uint32_t namei_full_hash
6189 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6190 (map
.hash_table_reordered
+ namei
), 4,
6191 map
.dwarf5_byte_order
);
6192 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
6195 if (full_hash
== namei_full_hash
)
6197 const char *const namei_string
= map
.namei_to_name (namei
);
6199 #if 0 /* An expensive sanity check. */
6200 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
6202 complaint (&symfile_complaints
,
6203 _("Wrong .debug_names hash for string at index %u "
6205 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
6210 if (cmp (namei_string
, name
) == 0)
6212 const ULONGEST namei_entry_offs
6213 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6214 + namei
* map
.offset_size
),
6215 map
.offset_size
, map
.dwarf5_byte_order
);
6216 return map
.entry_pool
+ namei_entry_offs
;
6221 if (namei
>= map
.name_count
)
6227 dw2_debug_names_iterator::find_vec_in_debug_names
6228 (const mapped_debug_names
&map
, uint32_t namei
)
6230 if (namei
>= map
.name_count
)
6232 complaint (&symfile_complaints
,
6233 _("Wrong .debug_names with name index %u but name_count=%u "
6235 namei
, map
.name_count
,
6236 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6240 const ULONGEST namei_entry_offs
6241 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6242 + namei
* map
.offset_size
),
6243 map
.offset_size
, map
.dwarf5_byte_order
);
6244 return map
.entry_pool
+ namei_entry_offs
;
6247 /* See dw2_debug_names_iterator. */
6249 dwarf2_per_cu_data
*
6250 dw2_debug_names_iterator::next ()
6255 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
6256 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6257 bfd
*const abfd
= objfile
->obfd
;
6261 unsigned int bytes_read
;
6262 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6263 m_addr
+= bytes_read
;
6267 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
6268 if (indexval_it
== m_map
.abbrev_map
.cend ())
6270 complaint (&symfile_complaints
,
6271 _("Wrong .debug_names undefined abbrev code %s "
6273 pulongest (abbrev
), objfile_name (objfile
));
6276 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
6277 bool have_is_static
= false;
6279 dwarf2_per_cu_data
*per_cu
= NULL
;
6280 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
6285 case DW_FORM_implicit_const
:
6286 ull
= attr
.implicit_const
;
6288 case DW_FORM_flag_present
:
6292 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6293 m_addr
+= bytes_read
;
6296 complaint (&symfile_complaints
,
6297 _("Unsupported .debug_names form %s [in module %s]"),
6298 dwarf_form_name (attr
.form
),
6299 objfile_name (objfile
));
6302 switch (attr
.dw_idx
)
6304 case DW_IDX_compile_unit
:
6305 /* Don't crash on bad data. */
6306 if (ull
>= dwarf2_per_objfile
->n_comp_units
)
6308 complaint (&symfile_complaints
,
6309 _(".debug_names entry has bad CU index %s"
6312 objfile_name (dwarf2_per_objfile
->objfile
));
6315 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, ull
);
6317 case DW_IDX_type_unit
:
6318 /* Don't crash on bad data. */
6319 if (ull
>= dwarf2_per_objfile
->n_type_units
)
6321 complaint (&symfile_complaints
,
6322 _(".debug_names entry has bad TU index %s"
6325 objfile_name (dwarf2_per_objfile
->objfile
));
6328 per_cu
= dw2_get_cutu (dwarf2_per_objfile
,
6329 dwarf2_per_objfile
->n_comp_units
+ ull
);
6331 case DW_IDX_GNU_internal
:
6332 if (!m_map
.augmentation_is_gdb
)
6334 have_is_static
= true;
6337 case DW_IDX_GNU_external
:
6338 if (!m_map
.augmentation_is_gdb
)
6340 have_is_static
= true;
6346 /* Skip if already read in. */
6347 if (per_cu
->v
.quick
->compunit_symtab
)
6350 /* Check static vs global. */
6353 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
6354 if (m_want_specific_block
&& want_static
!= is_static
)
6358 /* Match dw2_symtab_iter_next, symbol_kind
6359 and debug_names::psymbol_tag. */
6363 switch (indexval
.dwarf_tag
)
6365 case DW_TAG_variable
:
6366 case DW_TAG_subprogram
:
6367 /* Some types are also in VAR_DOMAIN. */
6368 case DW_TAG_typedef
:
6369 case DW_TAG_structure_type
:
6376 switch (indexval
.dwarf_tag
)
6378 case DW_TAG_typedef
:
6379 case DW_TAG_structure_type
:
6386 switch (indexval
.dwarf_tag
)
6389 case DW_TAG_variable
:
6399 /* Match dw2_expand_symtabs_matching, symbol_kind and
6400 debug_names::psymbol_tag. */
6403 case VARIABLES_DOMAIN
:
6404 switch (indexval
.dwarf_tag
)
6406 case DW_TAG_variable
:
6412 case FUNCTIONS_DOMAIN
:
6413 switch (indexval
.dwarf_tag
)
6415 case DW_TAG_subprogram
:
6422 switch (indexval
.dwarf_tag
)
6424 case DW_TAG_typedef
:
6425 case DW_TAG_structure_type
:
6438 static struct compunit_symtab
*
6439 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6440 const char *name
, domain_enum domain
)
6442 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6443 struct dwarf2_per_objfile
*dwarf2_per_objfile
6444 = get_dwarf2_per_objfile (objfile
);
6446 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6449 /* index is NULL if OBJF_READNOW. */
6452 const auto &map
= *mapp
;
6454 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6455 block_index
, domain
, name
);
6457 struct compunit_symtab
*stab_best
= NULL
;
6458 struct dwarf2_per_cu_data
*per_cu
;
6459 while ((per_cu
= iter
.next ()) != NULL
)
6461 struct symbol
*sym
, *with_opaque
= NULL
;
6462 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6463 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6464 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6466 sym
= block_find_symbol (block
, name
, domain
,
6467 block_find_non_opaque_type_preferred
,
6470 /* Some caution must be observed with overloaded functions and
6471 methods, since the index will not contain any overload
6472 information (but NAME might contain it). */
6475 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6477 if (with_opaque
!= NULL
6478 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6481 /* Keep looking through other CUs. */
6487 /* This dumps minimal information about .debug_names. It is called
6488 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6489 uses this to verify that .debug_names has been loaded. */
6492 dw2_debug_names_dump (struct objfile
*objfile
)
6494 struct dwarf2_per_objfile
*dwarf2_per_objfile
6495 = get_dwarf2_per_objfile (objfile
);
6497 gdb_assert (dwarf2_per_objfile
->using_index
);
6498 printf_filtered (".debug_names:");
6499 if (dwarf2_per_objfile
->debug_names_table
)
6500 printf_filtered (" exists\n");
6502 printf_filtered (" faked for \"readnow\"\n");
6503 printf_filtered ("\n");
6507 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6508 const char *func_name
)
6510 struct dwarf2_per_objfile
*dwarf2_per_objfile
6511 = get_dwarf2_per_objfile (objfile
);
6513 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6514 if (dwarf2_per_objfile
->debug_names_table
)
6516 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6518 /* Note: It doesn't matter what we pass for block_index here. */
6519 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6520 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6522 struct dwarf2_per_cu_data
*per_cu
;
6523 while ((per_cu
= iter
.next ()) != NULL
)
6524 dw2_instantiate_symtab (per_cu
);
6529 dw2_debug_names_expand_symtabs_matching
6530 (struct objfile
*objfile
,
6531 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6532 const lookup_name_info
&lookup_name
,
6533 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6534 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6535 enum search_domain kind
)
6537 struct dwarf2_per_objfile
*dwarf2_per_objfile
6538 = get_dwarf2_per_objfile (objfile
);
6540 /* debug_names_table is NULL if OBJF_READNOW. */
6541 if (!dwarf2_per_objfile
->debug_names_table
)
6544 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6546 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6548 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6550 kind
, [&] (offset_type namei
)
6552 /* The name was matched, now expand corresponding CUs that were
6554 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6556 struct dwarf2_per_cu_data
*per_cu
;
6557 while ((per_cu
= iter
.next ()) != NULL
)
6558 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6563 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6566 dw2_find_last_source_symtab
,
6567 dw2_forget_cached_source_info
,
6568 dw2_map_symtabs_matching_filename
,
6569 dw2_debug_names_lookup_symbol
,
6571 dw2_debug_names_dump
,
6573 dw2_debug_names_expand_symtabs_for_function
,
6574 dw2_expand_all_symtabs
,
6575 dw2_expand_symtabs_with_fullname
,
6576 dw2_map_matching_symbols
,
6577 dw2_debug_names_expand_symtabs_matching
,
6578 dw2_find_pc_sect_compunit_symtab
,
6580 dw2_map_symbol_filenames
6583 /* See symfile.h. */
6586 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6588 struct dwarf2_per_objfile
*dwarf2_per_objfile
6589 = get_dwarf2_per_objfile (objfile
);
6591 /* If we're about to read full symbols, don't bother with the
6592 indices. In this case we also don't care if some other debug
6593 format is making psymtabs, because they are all about to be
6595 if ((objfile
->flags
& OBJF_READNOW
))
6599 dwarf2_per_objfile
->using_index
= 1;
6600 create_all_comp_units (dwarf2_per_objfile
);
6601 create_all_type_units (dwarf2_per_objfile
);
6602 dwarf2_per_objfile
->quick_file_names_table
=
6603 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6605 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6606 + dwarf2_per_objfile
->n_type_units
); ++i
)
6608 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
6610 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6611 struct dwarf2_per_cu_quick_data
);
6614 /* Return 1 so that gdb sees the "quick" functions. However,
6615 these functions will be no-ops because we will have expanded
6617 *index_kind
= dw_index_kind::GDB_INDEX
;
6621 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6623 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6627 if (dwarf2_read_index (objfile
))
6629 *index_kind
= dw_index_kind::GDB_INDEX
;
6638 /* Build a partial symbol table. */
6641 dwarf2_build_psymtabs (struct objfile
*objfile
)
6643 struct dwarf2_per_objfile
*dwarf2_per_objfile
6644 = get_dwarf2_per_objfile (objfile
);
6646 if (objfile
->global_psymbols
.capacity () == 0
6647 && objfile
->static_psymbols
.capacity () == 0)
6648 init_psymbol_list (objfile
, 1024);
6652 /* This isn't really ideal: all the data we allocate on the
6653 objfile's obstack is still uselessly kept around. However,
6654 freeing it seems unsafe. */
6655 psymtab_discarder
psymtabs (objfile
);
6656 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6659 CATCH (except
, RETURN_MASK_ERROR
)
6661 exception_print (gdb_stderr
, except
);
6666 /* Return the total length of the CU described by HEADER. */
6669 get_cu_length (const struct comp_unit_head
*header
)
6671 return header
->initial_length_size
+ header
->length
;
6674 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6677 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6679 sect_offset bottom
= cu_header
->sect_off
;
6680 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6682 return sect_off
>= bottom
&& sect_off
< top
;
6685 /* Find the base address of the compilation unit for range lists and
6686 location lists. It will normally be specified by DW_AT_low_pc.
6687 In DWARF-3 draft 4, the base address could be overridden by
6688 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6689 compilation units with discontinuous ranges. */
6692 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6694 struct attribute
*attr
;
6697 cu
->base_address
= 0;
6699 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6702 cu
->base_address
= attr_value_as_address (attr
);
6707 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6710 cu
->base_address
= attr_value_as_address (attr
);
6716 /* Read in the comp unit header information from the debug_info at info_ptr.
6717 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6718 NOTE: This leaves members offset, first_die_offset to be filled in
6721 static const gdb_byte
*
6722 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6723 const gdb_byte
*info_ptr
,
6724 struct dwarf2_section_info
*section
,
6725 rcuh_kind section_kind
)
6728 unsigned int bytes_read
;
6729 const char *filename
= get_section_file_name (section
);
6730 bfd
*abfd
= get_section_bfd_owner (section
);
6732 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6733 cu_header
->initial_length_size
= bytes_read
;
6734 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6735 info_ptr
+= bytes_read
;
6736 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6738 if (cu_header
->version
< 5)
6739 switch (section_kind
)
6741 case rcuh_kind::COMPILE
:
6742 cu_header
->unit_type
= DW_UT_compile
;
6744 case rcuh_kind::TYPE
:
6745 cu_header
->unit_type
= DW_UT_type
;
6748 internal_error (__FILE__
, __LINE__
,
6749 _("read_comp_unit_head: invalid section_kind"));
6753 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6754 (read_1_byte (abfd
, info_ptr
));
6756 switch (cu_header
->unit_type
)
6759 if (section_kind
!= rcuh_kind::COMPILE
)
6760 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6761 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6765 section_kind
= rcuh_kind::TYPE
;
6768 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6769 "(is %d, should be %d or %d) [in module %s]"),
6770 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6773 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6776 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6779 info_ptr
+= bytes_read
;
6780 if (cu_header
->version
< 5)
6782 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6785 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6786 if (signed_addr
< 0)
6787 internal_error (__FILE__
, __LINE__
,
6788 _("read_comp_unit_head: dwarf from non elf file"));
6789 cu_header
->signed_addr_p
= signed_addr
;
6791 if (section_kind
== rcuh_kind::TYPE
)
6793 LONGEST type_offset
;
6795 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6798 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6799 info_ptr
+= bytes_read
;
6800 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6801 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6802 error (_("Dwarf Error: Too big type_offset in compilation unit "
6803 "header (is %s) [in module %s]"), plongest (type_offset
),
6810 /* Helper function that returns the proper abbrev section for
6813 static struct dwarf2_section_info
*
6814 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6816 struct dwarf2_section_info
*abbrev
;
6817 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6819 if (this_cu
->is_dwz
)
6820 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6822 abbrev
= &dwarf2_per_objfile
->abbrev
;
6827 /* Subroutine of read_and_check_comp_unit_head and
6828 read_and_check_type_unit_head to simplify them.
6829 Perform various error checking on the header. */
6832 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6833 struct comp_unit_head
*header
,
6834 struct dwarf2_section_info
*section
,
6835 struct dwarf2_section_info
*abbrev_section
)
6837 const char *filename
= get_section_file_name (section
);
6839 if (header
->version
< 2 || header
->version
> 5)
6840 error (_("Dwarf Error: wrong version in compilation unit header "
6841 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6844 if (to_underlying (header
->abbrev_sect_off
)
6845 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6846 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6847 "(offset %s + 6) [in module %s]"),
6848 sect_offset_str (header
->abbrev_sect_off
),
6849 sect_offset_str (header
->sect_off
),
6852 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6853 avoid potential 32-bit overflow. */
6854 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6856 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6857 "(offset %s + 0) [in module %s]"),
6858 header
->length
, sect_offset_str (header
->sect_off
),
6862 /* Read in a CU/TU header and perform some basic error checking.
6863 The contents of the header are stored in HEADER.
6864 The result is a pointer to the start of the first DIE. */
6866 static const gdb_byte
*
6867 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6868 struct comp_unit_head
*header
,
6869 struct dwarf2_section_info
*section
,
6870 struct dwarf2_section_info
*abbrev_section
,
6871 const gdb_byte
*info_ptr
,
6872 rcuh_kind section_kind
)
6874 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6876 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6878 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6880 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6882 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6888 /* Fetch the abbreviation table offset from a comp or type unit header. */
6891 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6892 struct dwarf2_section_info
*section
,
6893 sect_offset sect_off
)
6895 bfd
*abfd
= get_section_bfd_owner (section
);
6896 const gdb_byte
*info_ptr
;
6897 unsigned int initial_length_size
, offset_size
;
6900 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6901 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6902 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6903 offset_size
= initial_length_size
== 4 ? 4 : 8;
6904 info_ptr
+= initial_length_size
;
6906 version
= read_2_bytes (abfd
, info_ptr
);
6910 /* Skip unit type and address size. */
6914 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6917 /* Allocate a new partial symtab for file named NAME and mark this new
6918 partial symtab as being an include of PST. */
6921 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6922 struct objfile
*objfile
)
6924 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6926 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6928 /* It shares objfile->objfile_obstack. */
6929 subpst
->dirname
= pst
->dirname
;
6932 subpst
->textlow
= 0;
6933 subpst
->texthigh
= 0;
6935 subpst
->dependencies
6936 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6937 subpst
->dependencies
[0] = pst
;
6938 subpst
->number_of_dependencies
= 1;
6940 subpst
->globals_offset
= 0;
6941 subpst
->n_global_syms
= 0;
6942 subpst
->statics_offset
= 0;
6943 subpst
->n_static_syms
= 0;
6944 subpst
->compunit_symtab
= NULL
;
6945 subpst
->read_symtab
= pst
->read_symtab
;
6948 /* No private part is necessary for include psymtabs. This property
6949 can be used to differentiate between such include psymtabs and
6950 the regular ones. */
6951 subpst
->read_symtab_private
= NULL
;
6954 /* Read the Line Number Program data and extract the list of files
6955 included by the source file represented by PST. Build an include
6956 partial symtab for each of these included files. */
6959 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6960 struct die_info
*die
,
6961 struct partial_symtab
*pst
)
6964 struct attribute
*attr
;
6966 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6968 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6970 return; /* No linetable, so no includes. */
6972 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
6973 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
6977 hash_signatured_type (const void *item
)
6979 const struct signatured_type
*sig_type
6980 = (const struct signatured_type
*) item
;
6982 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6983 return sig_type
->signature
;
6987 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6989 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6990 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6992 return lhs
->signature
== rhs
->signature
;
6995 /* Allocate a hash table for signatured types. */
6998 allocate_signatured_type_table (struct objfile
*objfile
)
7000 return htab_create_alloc_ex (41,
7001 hash_signatured_type
,
7004 &objfile
->objfile_obstack
,
7005 hashtab_obstack_allocate
,
7006 dummy_obstack_deallocate
);
7009 /* A helper function to add a signatured type CU to a table. */
7012 add_signatured_type_cu_to_table (void **slot
, void *datum
)
7014 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
7015 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
7023 /* A helper for create_debug_types_hash_table. Read types from SECTION
7024 and fill them into TYPES_HTAB. It will process only type units,
7025 therefore DW_UT_type. */
7028 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7029 struct dwo_file
*dwo_file
,
7030 dwarf2_section_info
*section
, htab_t
&types_htab
,
7031 rcuh_kind section_kind
)
7033 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7034 struct dwarf2_section_info
*abbrev_section
;
7036 const gdb_byte
*info_ptr
, *end_ptr
;
7038 abbrev_section
= (dwo_file
!= NULL
7039 ? &dwo_file
->sections
.abbrev
7040 : &dwarf2_per_objfile
->abbrev
);
7042 if (dwarf_read_debug
)
7043 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
7044 get_section_name (section
),
7045 get_section_file_name (abbrev_section
));
7047 dwarf2_read_section (objfile
, section
);
7048 info_ptr
= section
->buffer
;
7050 if (info_ptr
== NULL
)
7053 /* We can't set abfd until now because the section may be empty or
7054 not present, in which case the bfd is unknown. */
7055 abfd
= get_section_bfd_owner (section
);
7057 /* We don't use init_cutu_and_read_dies_simple, or some such, here
7058 because we don't need to read any dies: the signature is in the
7061 end_ptr
= info_ptr
+ section
->size
;
7062 while (info_ptr
< end_ptr
)
7064 struct signatured_type
*sig_type
;
7065 struct dwo_unit
*dwo_tu
;
7067 const gdb_byte
*ptr
= info_ptr
;
7068 struct comp_unit_head header
;
7069 unsigned int length
;
7071 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
7073 /* Initialize it due to a false compiler warning. */
7074 header
.signature
= -1;
7075 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
7077 /* We need to read the type's signature in order to build the hash
7078 table, but we don't need anything else just yet. */
7080 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
7081 abbrev_section
, ptr
, section_kind
);
7083 length
= get_cu_length (&header
);
7085 /* Skip dummy type units. */
7086 if (ptr
>= info_ptr
+ length
7087 || peek_abbrev_code (abfd
, ptr
) == 0
7088 || header
.unit_type
!= DW_UT_type
)
7094 if (types_htab
== NULL
)
7097 types_htab
= allocate_dwo_unit_table (objfile
);
7099 types_htab
= allocate_signatured_type_table (objfile
);
7105 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7107 dwo_tu
->dwo_file
= dwo_file
;
7108 dwo_tu
->signature
= header
.signature
;
7109 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7110 dwo_tu
->section
= section
;
7111 dwo_tu
->sect_off
= sect_off
;
7112 dwo_tu
->length
= length
;
7116 /* N.B.: type_offset is not usable if this type uses a DWO file.
7117 The real type_offset is in the DWO file. */
7119 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7120 struct signatured_type
);
7121 sig_type
->signature
= header
.signature
;
7122 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7123 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7124 sig_type
->per_cu
.is_debug_types
= 1;
7125 sig_type
->per_cu
.section
= section
;
7126 sig_type
->per_cu
.sect_off
= sect_off
;
7127 sig_type
->per_cu
.length
= length
;
7130 slot
= htab_find_slot (types_htab
,
7131 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
7133 gdb_assert (slot
!= NULL
);
7136 sect_offset dup_sect_off
;
7140 const struct dwo_unit
*dup_tu
7141 = (const struct dwo_unit
*) *slot
;
7143 dup_sect_off
= dup_tu
->sect_off
;
7147 const struct signatured_type
*dup_tu
7148 = (const struct signatured_type
*) *slot
;
7150 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
7153 complaint (&symfile_complaints
,
7154 _("debug type entry at offset %s is duplicate to"
7155 " the entry at offset %s, signature %s"),
7156 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
7157 hex_string (header
.signature
));
7159 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
7161 if (dwarf_read_debug
> 1)
7162 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
7163 sect_offset_str (sect_off
),
7164 hex_string (header
.signature
));
7170 /* Create the hash table of all entries in the .debug_types
7171 (or .debug_types.dwo) section(s).
7172 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
7173 otherwise it is NULL.
7175 The result is a pointer to the hash table or NULL if there are no types.
7177 Note: This function processes DWO files only, not DWP files. */
7180 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7181 struct dwo_file
*dwo_file
,
7182 VEC (dwarf2_section_info_def
) *types
,
7186 struct dwarf2_section_info
*section
;
7188 if (VEC_empty (dwarf2_section_info_def
, types
))
7192 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
7194 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
7195 types_htab
, rcuh_kind::TYPE
);
7198 /* Create the hash table of all entries in the .debug_types section,
7199 and initialize all_type_units.
7200 The result is zero if there is an error (e.g. missing .debug_types section),
7201 otherwise non-zero. */
7204 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7206 htab_t types_htab
= NULL
;
7207 struct signatured_type
**iter
;
7209 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
7210 &dwarf2_per_objfile
->info
, types_htab
,
7211 rcuh_kind::COMPILE
);
7212 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
7213 dwarf2_per_objfile
->types
, types_htab
);
7214 if (types_htab
== NULL
)
7216 dwarf2_per_objfile
->signatured_types
= NULL
;
7220 dwarf2_per_objfile
->signatured_types
= types_htab
;
7222 dwarf2_per_objfile
->n_type_units
7223 = dwarf2_per_objfile
->n_allocated_type_units
7224 = htab_elements (types_htab
);
7225 dwarf2_per_objfile
->all_type_units
=
7226 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
7227 iter
= &dwarf2_per_objfile
->all_type_units
[0];
7228 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
7229 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
7230 == dwarf2_per_objfile
->n_type_units
);
7235 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
7236 If SLOT is non-NULL, it is the entry to use in the hash table.
7237 Otherwise we find one. */
7239 static struct signatured_type
*
7240 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
7243 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7244 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
7245 struct signatured_type
*sig_type
;
7247 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
7249 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
7251 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
7252 dwarf2_per_objfile
->n_allocated_type_units
= 1;
7253 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
7254 dwarf2_per_objfile
->all_type_units
7255 = XRESIZEVEC (struct signatured_type
*,
7256 dwarf2_per_objfile
->all_type_units
,
7257 dwarf2_per_objfile
->n_allocated_type_units
);
7258 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
7260 dwarf2_per_objfile
->n_type_units
= n_type_units
;
7262 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7263 struct signatured_type
);
7264 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
7265 sig_type
->signature
= sig
;
7266 sig_type
->per_cu
.is_debug_types
= 1;
7267 if (dwarf2_per_objfile
->using_index
)
7269 sig_type
->per_cu
.v
.quick
=
7270 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7271 struct dwarf2_per_cu_quick_data
);
7276 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7279 gdb_assert (*slot
== NULL
);
7281 /* The rest of sig_type must be filled in by the caller. */
7285 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7286 Fill in SIG_ENTRY with DWO_ENTRY. */
7289 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7290 struct signatured_type
*sig_entry
,
7291 struct dwo_unit
*dwo_entry
)
7293 /* Make sure we're not clobbering something we don't expect to. */
7294 gdb_assert (! sig_entry
->per_cu
.queued
);
7295 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7296 if (dwarf2_per_objfile
->using_index
)
7298 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7299 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7302 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7303 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7304 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7305 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7306 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7308 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7309 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7310 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7311 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7312 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7313 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7314 sig_entry
->dwo_unit
= dwo_entry
;
7317 /* Subroutine of lookup_signatured_type.
7318 If we haven't read the TU yet, create the signatured_type data structure
7319 for a TU to be read in directly from a DWO file, bypassing the stub.
7320 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7321 using .gdb_index, then when reading a CU we want to stay in the DWO file
7322 containing that CU. Otherwise we could end up reading several other DWO
7323 files (due to comdat folding) to process the transitive closure of all the
7324 mentioned TUs, and that can be slow. The current DWO file will have every
7325 type signature that it needs.
7326 We only do this for .gdb_index because in the psymtab case we already have
7327 to read all the DWOs to build the type unit groups. */
7329 static struct signatured_type
*
7330 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7332 struct dwarf2_per_objfile
*dwarf2_per_objfile
7333 = cu
->per_cu
->dwarf2_per_objfile
;
7334 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7335 struct dwo_file
*dwo_file
;
7336 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7337 struct signatured_type find_sig_entry
, *sig_entry
;
7340 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7342 /* If TU skeletons have been removed then we may not have read in any
7344 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7346 dwarf2_per_objfile
->signatured_types
7347 = allocate_signatured_type_table (objfile
);
7350 /* We only ever need to read in one copy of a signatured type.
7351 Use the global signatured_types array to do our own comdat-folding
7352 of types. If this is the first time we're reading this TU, and
7353 the TU has an entry in .gdb_index, replace the recorded data from
7354 .gdb_index with this TU. */
7356 find_sig_entry
.signature
= sig
;
7357 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7358 &find_sig_entry
, INSERT
);
7359 sig_entry
= (struct signatured_type
*) *slot
;
7361 /* We can get here with the TU already read, *or* in the process of being
7362 read. Don't reassign the global entry to point to this DWO if that's
7363 the case. Also note that if the TU is already being read, it may not
7364 have come from a DWO, the program may be a mix of Fission-compiled
7365 code and non-Fission-compiled code. */
7367 /* Have we already tried to read this TU?
7368 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7369 needn't exist in the global table yet). */
7370 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7373 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7374 dwo_unit of the TU itself. */
7375 dwo_file
= cu
->dwo_unit
->dwo_file
;
7377 /* Ok, this is the first time we're reading this TU. */
7378 if (dwo_file
->tus
== NULL
)
7380 find_dwo_entry
.signature
= sig
;
7381 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7382 if (dwo_entry
== NULL
)
7385 /* If the global table doesn't have an entry for this TU, add one. */
7386 if (sig_entry
== NULL
)
7387 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7389 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7390 sig_entry
->per_cu
.tu_read
= 1;
7394 /* Subroutine of lookup_signatured_type.
7395 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7396 then try the DWP file. If the TU stub (skeleton) has been removed then
7397 it won't be in .gdb_index. */
7399 static struct signatured_type
*
7400 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7402 struct dwarf2_per_objfile
*dwarf2_per_objfile
7403 = cu
->per_cu
->dwarf2_per_objfile
;
7404 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7405 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7406 struct dwo_unit
*dwo_entry
;
7407 struct signatured_type find_sig_entry
, *sig_entry
;
7410 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7411 gdb_assert (dwp_file
!= NULL
);
7413 /* If TU skeletons have been removed then we may not have read in any
7415 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7417 dwarf2_per_objfile
->signatured_types
7418 = allocate_signatured_type_table (objfile
);
7421 find_sig_entry
.signature
= sig
;
7422 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7423 &find_sig_entry
, INSERT
);
7424 sig_entry
= (struct signatured_type
*) *slot
;
7426 /* Have we already tried to read this TU?
7427 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7428 needn't exist in the global table yet). */
7429 if (sig_entry
!= NULL
)
7432 if (dwp_file
->tus
== NULL
)
7434 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7435 sig
, 1 /* is_debug_types */);
7436 if (dwo_entry
== NULL
)
7439 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7440 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7445 /* Lookup a signature based type for DW_FORM_ref_sig8.
7446 Returns NULL if signature SIG is not present in the table.
7447 It is up to the caller to complain about this. */
7449 static struct signatured_type
*
7450 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7452 struct dwarf2_per_objfile
*dwarf2_per_objfile
7453 = cu
->per_cu
->dwarf2_per_objfile
;
7456 && dwarf2_per_objfile
->using_index
)
7458 /* We're in a DWO/DWP file, and we're using .gdb_index.
7459 These cases require special processing. */
7460 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7461 return lookup_dwo_signatured_type (cu
, sig
);
7463 return lookup_dwp_signatured_type (cu
, sig
);
7467 struct signatured_type find_entry
, *entry
;
7469 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7471 find_entry
.signature
= sig
;
7472 entry
= ((struct signatured_type
*)
7473 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7478 /* Low level DIE reading support. */
7480 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7483 init_cu_die_reader (struct die_reader_specs
*reader
,
7484 struct dwarf2_cu
*cu
,
7485 struct dwarf2_section_info
*section
,
7486 struct dwo_file
*dwo_file
,
7487 struct abbrev_table
*abbrev_table
)
7489 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7490 reader
->abfd
= get_section_bfd_owner (section
);
7492 reader
->dwo_file
= dwo_file
;
7493 reader
->die_section
= section
;
7494 reader
->buffer
= section
->buffer
;
7495 reader
->buffer_end
= section
->buffer
+ section
->size
;
7496 reader
->comp_dir
= NULL
;
7497 reader
->abbrev_table
= abbrev_table
;
7500 /* Subroutine of init_cutu_and_read_dies to simplify it.
7501 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7502 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7505 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7506 from it to the DIE in the DWO. If NULL we are skipping the stub.
7507 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7508 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7509 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7510 STUB_COMP_DIR may be non-NULL.
7511 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7512 are filled in with the info of the DIE from the DWO file.
7513 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7514 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7515 kept around for at least as long as *RESULT_READER.
7517 The result is non-zero if a valid (non-dummy) DIE was found. */
7520 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7521 struct dwo_unit
*dwo_unit
,
7522 struct die_info
*stub_comp_unit_die
,
7523 const char *stub_comp_dir
,
7524 struct die_reader_specs
*result_reader
,
7525 const gdb_byte
**result_info_ptr
,
7526 struct die_info
**result_comp_unit_die
,
7527 int *result_has_children
,
7528 abbrev_table_up
*result_dwo_abbrev_table
)
7530 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7531 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7532 struct dwarf2_cu
*cu
= this_cu
->cu
;
7534 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7535 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7536 int i
,num_extra_attrs
;
7537 struct dwarf2_section_info
*dwo_abbrev_section
;
7538 struct attribute
*attr
;
7539 struct die_info
*comp_unit_die
;
7541 /* At most one of these may be provided. */
7542 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7544 /* These attributes aren't processed until later:
7545 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7546 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7547 referenced later. However, these attributes are found in the stub
7548 which we won't have later. In order to not impose this complication
7549 on the rest of the code, we read them here and copy them to the
7558 if (stub_comp_unit_die
!= NULL
)
7560 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7562 if (! this_cu
->is_debug_types
)
7563 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7564 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7565 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7566 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7567 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7569 /* There should be a DW_AT_addr_base attribute here (if needed).
7570 We need the value before we can process DW_FORM_GNU_addr_index. */
7572 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7574 cu
->addr_base
= DW_UNSND (attr
);
7576 /* There should be a DW_AT_ranges_base attribute here (if needed).
7577 We need the value before we can process DW_AT_ranges. */
7578 cu
->ranges_base
= 0;
7579 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7581 cu
->ranges_base
= DW_UNSND (attr
);
7583 else if (stub_comp_dir
!= NULL
)
7585 /* Reconstruct the comp_dir attribute to simplify the code below. */
7586 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7587 comp_dir
->name
= DW_AT_comp_dir
;
7588 comp_dir
->form
= DW_FORM_string
;
7589 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7590 DW_STRING (comp_dir
) = stub_comp_dir
;
7593 /* Set up for reading the DWO CU/TU. */
7594 cu
->dwo_unit
= dwo_unit
;
7595 dwarf2_section_info
*section
= dwo_unit
->section
;
7596 dwarf2_read_section (objfile
, section
);
7597 abfd
= get_section_bfd_owner (section
);
7598 begin_info_ptr
= info_ptr
= (section
->buffer
7599 + to_underlying (dwo_unit
->sect_off
));
7600 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7602 if (this_cu
->is_debug_types
)
7604 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7606 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7607 &cu
->header
, section
,
7609 info_ptr
, rcuh_kind::TYPE
);
7610 /* This is not an assert because it can be caused by bad debug info. */
7611 if (sig_type
->signature
!= cu
->header
.signature
)
7613 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7614 " TU at offset %s [in module %s]"),
7615 hex_string (sig_type
->signature
),
7616 hex_string (cu
->header
.signature
),
7617 sect_offset_str (dwo_unit
->sect_off
),
7618 bfd_get_filename (abfd
));
7620 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7621 /* For DWOs coming from DWP files, we don't know the CU length
7622 nor the type's offset in the TU until now. */
7623 dwo_unit
->length
= get_cu_length (&cu
->header
);
7624 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7626 /* Establish the type offset that can be used to lookup the type.
7627 For DWO files, we don't know it until now. */
7628 sig_type
->type_offset_in_section
7629 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7633 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7634 &cu
->header
, section
,
7636 info_ptr
, rcuh_kind::COMPILE
);
7637 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7638 /* For DWOs coming from DWP files, we don't know the CU length
7640 dwo_unit
->length
= get_cu_length (&cu
->header
);
7643 *result_dwo_abbrev_table
7644 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7645 cu
->header
.abbrev_sect_off
);
7646 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7647 result_dwo_abbrev_table
->get ());
7649 /* Read in the die, but leave space to copy over the attributes
7650 from the stub. This has the benefit of simplifying the rest of
7651 the code - all the work to maintain the illusion of a single
7652 DW_TAG_{compile,type}_unit DIE is done here. */
7653 num_extra_attrs
= ((stmt_list
!= NULL
)
7657 + (comp_dir
!= NULL
));
7658 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7659 result_has_children
, num_extra_attrs
);
7661 /* Copy over the attributes from the stub to the DIE we just read in. */
7662 comp_unit_die
= *result_comp_unit_die
;
7663 i
= comp_unit_die
->num_attrs
;
7664 if (stmt_list
!= NULL
)
7665 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7667 comp_unit_die
->attrs
[i
++] = *low_pc
;
7668 if (high_pc
!= NULL
)
7669 comp_unit_die
->attrs
[i
++] = *high_pc
;
7671 comp_unit_die
->attrs
[i
++] = *ranges
;
7672 if (comp_dir
!= NULL
)
7673 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7674 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7676 if (dwarf_die_debug
)
7678 fprintf_unfiltered (gdb_stdlog
,
7679 "Read die from %s@0x%x of %s:\n",
7680 get_section_name (section
),
7681 (unsigned) (begin_info_ptr
- section
->buffer
),
7682 bfd_get_filename (abfd
));
7683 dump_die (comp_unit_die
, dwarf_die_debug
);
7686 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7687 TUs by skipping the stub and going directly to the entry in the DWO file.
7688 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7689 to get it via circuitous means. Blech. */
7690 if (comp_dir
!= NULL
)
7691 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7693 /* Skip dummy compilation units. */
7694 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7695 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7698 *result_info_ptr
= info_ptr
;
7702 /* Subroutine of init_cutu_and_read_dies to simplify it.
7703 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7704 Returns NULL if the specified DWO unit cannot be found. */
7706 static struct dwo_unit
*
7707 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7708 struct die_info
*comp_unit_die
)
7710 struct dwarf2_cu
*cu
= this_cu
->cu
;
7712 struct dwo_unit
*dwo_unit
;
7713 const char *comp_dir
, *dwo_name
;
7715 gdb_assert (cu
!= NULL
);
7717 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7718 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7719 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7721 if (this_cu
->is_debug_types
)
7723 struct signatured_type
*sig_type
;
7725 /* Since this_cu is the first member of struct signatured_type,
7726 we can go from a pointer to one to a pointer to the other. */
7727 sig_type
= (struct signatured_type
*) this_cu
;
7728 signature
= sig_type
->signature
;
7729 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7733 struct attribute
*attr
;
7735 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7737 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7739 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7740 signature
= DW_UNSND (attr
);
7741 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7748 /* Subroutine of init_cutu_and_read_dies to simplify it.
7749 See it for a description of the parameters.
7750 Read a TU directly from a DWO file, bypassing the stub. */
7753 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7754 int use_existing_cu
, int keep
,
7755 die_reader_func_ftype
*die_reader_func
,
7758 std::unique_ptr
<dwarf2_cu
> new_cu
;
7759 struct signatured_type
*sig_type
;
7760 struct die_reader_specs reader
;
7761 const gdb_byte
*info_ptr
;
7762 struct die_info
*comp_unit_die
;
7764 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7766 /* Verify we can do the following downcast, and that we have the
7768 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7769 sig_type
= (struct signatured_type
*) this_cu
;
7770 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7772 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7774 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7775 /* There's no need to do the rereading_dwo_cu handling that
7776 init_cutu_and_read_dies does since we don't read the stub. */
7780 /* If !use_existing_cu, this_cu->cu must be NULL. */
7781 gdb_assert (this_cu
->cu
== NULL
);
7782 new_cu
.reset (new dwarf2_cu (this_cu
));
7785 /* A future optimization, if needed, would be to use an existing
7786 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7787 could share abbrev tables. */
7789 /* The abbreviation table used by READER, this must live at least as long as
7791 abbrev_table_up dwo_abbrev_table
;
7793 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7794 NULL
/* stub_comp_unit_die */,
7795 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7797 &comp_unit_die
, &has_children
,
7798 &dwo_abbrev_table
) == 0)
7804 /* All the "real" work is done here. */
7805 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7807 /* This duplicates the code in init_cutu_and_read_dies,
7808 but the alternative is making the latter more complex.
7809 This function is only for the special case of using DWO files directly:
7810 no point in overly complicating the general case just to handle this. */
7811 if (new_cu
!= NULL
&& keep
)
7813 /* Link this CU into read_in_chain. */
7814 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7815 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7816 /* The chain owns it now. */
7821 /* Initialize a CU (or TU) and read its DIEs.
7822 If the CU defers to a DWO file, read the DWO file as well.
7824 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7825 Otherwise the table specified in the comp unit header is read in and used.
7826 This is an optimization for when we already have the abbrev table.
7828 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7829 Otherwise, a new CU is allocated with xmalloc.
7831 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7832 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7834 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7835 linker) then DIE_READER_FUNC will not get called. */
7838 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7839 struct abbrev_table
*abbrev_table
,
7840 int use_existing_cu
, int keep
,
7841 die_reader_func_ftype
*die_reader_func
,
7844 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7845 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7846 struct dwarf2_section_info
*section
= this_cu
->section
;
7847 bfd
*abfd
= get_section_bfd_owner (section
);
7848 struct dwarf2_cu
*cu
;
7849 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7850 struct die_reader_specs reader
;
7851 struct die_info
*comp_unit_die
;
7853 struct attribute
*attr
;
7854 struct signatured_type
*sig_type
= NULL
;
7855 struct dwarf2_section_info
*abbrev_section
;
7856 /* Non-zero if CU currently points to a DWO file and we need to
7857 reread it. When this happens we need to reread the skeleton die
7858 before we can reread the DWO file (this only applies to CUs, not TUs). */
7859 int rereading_dwo_cu
= 0;
7861 if (dwarf_die_debug
)
7862 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7863 this_cu
->is_debug_types
? "type" : "comp",
7864 sect_offset_str (this_cu
->sect_off
));
7866 if (use_existing_cu
)
7869 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7870 file (instead of going through the stub), short-circuit all of this. */
7871 if (this_cu
->reading_dwo_directly
)
7873 /* Narrow down the scope of possibilities to have to understand. */
7874 gdb_assert (this_cu
->is_debug_types
);
7875 gdb_assert (abbrev_table
== NULL
);
7876 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7877 die_reader_func
, data
);
7881 /* This is cheap if the section is already read in. */
7882 dwarf2_read_section (objfile
, section
);
7884 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7886 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7888 std::unique_ptr
<dwarf2_cu
> new_cu
;
7889 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7892 /* If this CU is from a DWO file we need to start over, we need to
7893 refetch the attributes from the skeleton CU.
7894 This could be optimized by retrieving those attributes from when we
7895 were here the first time: the previous comp_unit_die was stored in
7896 comp_unit_obstack. But there's no data yet that we need this
7898 if (cu
->dwo_unit
!= NULL
)
7899 rereading_dwo_cu
= 1;
7903 /* If !use_existing_cu, this_cu->cu must be NULL. */
7904 gdb_assert (this_cu
->cu
== NULL
);
7905 new_cu
.reset (new dwarf2_cu (this_cu
));
7909 /* Get the header. */
7910 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7912 /* We already have the header, there's no need to read it in again. */
7913 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7917 if (this_cu
->is_debug_types
)
7919 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7920 &cu
->header
, section
,
7921 abbrev_section
, info_ptr
,
7924 /* Since per_cu is the first member of struct signatured_type,
7925 we can go from a pointer to one to a pointer to the other. */
7926 sig_type
= (struct signatured_type
*) this_cu
;
7927 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7928 gdb_assert (sig_type
->type_offset_in_tu
7929 == cu
->header
.type_cu_offset_in_tu
);
7930 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7932 /* LENGTH has not been set yet for type units if we're
7933 using .gdb_index. */
7934 this_cu
->length
= get_cu_length (&cu
->header
);
7936 /* Establish the type offset that can be used to lookup the type. */
7937 sig_type
->type_offset_in_section
=
7938 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7940 this_cu
->dwarf_version
= cu
->header
.version
;
7944 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7945 &cu
->header
, section
,
7948 rcuh_kind::COMPILE
);
7950 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7951 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7952 this_cu
->dwarf_version
= cu
->header
.version
;
7956 /* Skip dummy compilation units. */
7957 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7958 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7961 /* If we don't have them yet, read the abbrevs for this compilation unit.
7962 And if we need to read them now, make sure they're freed when we're
7963 done (own the table through ABBREV_TABLE_HOLDER). */
7964 abbrev_table_up abbrev_table_holder
;
7965 if (abbrev_table
!= NULL
)
7966 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7970 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7971 cu
->header
.abbrev_sect_off
);
7972 abbrev_table
= abbrev_table_holder
.get ();
7975 /* Read the top level CU/TU die. */
7976 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7977 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7979 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7980 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7981 table from the DWO file and pass the ownership over to us. It will be
7982 referenced from READER, so we must make sure to free it after we're done
7985 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7986 DWO CU, that this test will fail (the attribute will not be present). */
7987 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7988 abbrev_table_up dwo_abbrev_table
;
7991 struct dwo_unit
*dwo_unit
;
7992 struct die_info
*dwo_comp_unit_die
;
7996 complaint (&symfile_complaints
,
7997 _("compilation unit with DW_AT_GNU_dwo_name"
7998 " has children (offset %s) [in module %s]"),
7999 sect_offset_str (this_cu
->sect_off
),
8000 bfd_get_filename (abfd
));
8002 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
8003 if (dwo_unit
!= NULL
)
8005 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
8006 comp_unit_die
, NULL
,
8008 &dwo_comp_unit_die
, &has_children
,
8009 &dwo_abbrev_table
) == 0)
8014 comp_unit_die
= dwo_comp_unit_die
;
8018 /* Yikes, we couldn't find the rest of the DIE, we only have
8019 the stub. A complaint has already been logged. There's
8020 not much more we can do except pass on the stub DIE to
8021 die_reader_func. We don't want to throw an error on bad
8026 /* All of the above is setup for this call. Yikes. */
8027 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8029 /* Done, clean up. */
8030 if (new_cu
!= NULL
&& keep
)
8032 /* Link this CU into read_in_chain. */
8033 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
8034 dwarf2_per_objfile
->read_in_chain
= this_cu
;
8035 /* The chain owns it now. */
8040 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
8041 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
8042 to have already done the lookup to find the DWO file).
8044 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
8045 THIS_CU->is_debug_types, but nothing else.
8047 We fill in THIS_CU->length.
8049 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
8050 linker) then DIE_READER_FUNC will not get called.
8052 THIS_CU->cu is always freed when done.
8053 This is done in order to not leave THIS_CU->cu in a state where we have
8054 to care whether it refers to the "main" CU or the DWO CU. */
8057 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
8058 struct dwo_file
*dwo_file
,
8059 die_reader_func_ftype
*die_reader_func
,
8062 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
8063 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8064 struct dwarf2_section_info
*section
= this_cu
->section
;
8065 bfd
*abfd
= get_section_bfd_owner (section
);
8066 struct dwarf2_section_info
*abbrev_section
;
8067 const gdb_byte
*begin_info_ptr
, *info_ptr
;
8068 struct die_reader_specs reader
;
8069 struct die_info
*comp_unit_die
;
8072 if (dwarf_die_debug
)
8073 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
8074 this_cu
->is_debug_types
? "type" : "comp",
8075 sect_offset_str (this_cu
->sect_off
));
8077 gdb_assert (this_cu
->cu
== NULL
);
8079 abbrev_section
= (dwo_file
!= NULL
8080 ? &dwo_file
->sections
.abbrev
8081 : get_abbrev_section_for_cu (this_cu
));
8083 /* This is cheap if the section is already read in. */
8084 dwarf2_read_section (objfile
, section
);
8086 struct dwarf2_cu
cu (this_cu
);
8088 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
8089 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
8090 &cu
.header
, section
,
8091 abbrev_section
, info_ptr
,
8092 (this_cu
->is_debug_types
8094 : rcuh_kind::COMPILE
));
8096 this_cu
->length
= get_cu_length (&cu
.header
);
8098 /* Skip dummy compilation units. */
8099 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8100 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8103 abbrev_table_up abbrev_table
8104 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8105 cu
.header
.abbrev_sect_off
);
8107 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
8108 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8110 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8113 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
8114 does not lookup the specified DWO file.
8115 This cannot be used to read DWO files.
8117 THIS_CU->cu is always freed when done.
8118 This is done in order to not leave THIS_CU->cu in a state where we have
8119 to care whether it refers to the "main" CU or the DWO CU.
8120 We can revisit this if the data shows there's a performance issue. */
8123 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
8124 die_reader_func_ftype
*die_reader_func
,
8127 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
8130 /* Type Unit Groups.
8132 Type Unit Groups are a way to collapse the set of all TUs (type units) into
8133 a more manageable set. The grouping is done by DW_AT_stmt_list entry
8134 so that all types coming from the same compilation (.o file) are grouped
8135 together. A future step could be to put the types in the same symtab as
8136 the CU the types ultimately came from. */
8139 hash_type_unit_group (const void *item
)
8141 const struct type_unit_group
*tu_group
8142 = (const struct type_unit_group
*) item
;
8144 return hash_stmt_list_entry (&tu_group
->hash
);
8148 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
8150 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
8151 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
8153 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
8156 /* Allocate a hash table for type unit groups. */
8159 allocate_type_unit_groups_table (struct objfile
*objfile
)
8161 return htab_create_alloc_ex (3,
8162 hash_type_unit_group
,
8165 &objfile
->objfile_obstack
,
8166 hashtab_obstack_allocate
,
8167 dummy_obstack_deallocate
);
8170 /* Type units that don't have DW_AT_stmt_list are grouped into their own
8171 partial symtabs. We combine several TUs per psymtab to not let the size
8172 of any one psymtab grow too big. */
8173 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
8174 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
8176 /* Helper routine for get_type_unit_group.
8177 Create the type_unit_group object used to hold one or more TUs. */
8179 static struct type_unit_group
*
8180 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
8182 struct dwarf2_per_objfile
*dwarf2_per_objfile
8183 = cu
->per_cu
->dwarf2_per_objfile
;
8184 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8185 struct dwarf2_per_cu_data
*per_cu
;
8186 struct type_unit_group
*tu_group
;
8188 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8189 struct type_unit_group
);
8190 per_cu
= &tu_group
->per_cu
;
8191 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8193 if (dwarf2_per_objfile
->using_index
)
8195 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8196 struct dwarf2_per_cu_quick_data
);
8200 unsigned int line_offset
= to_underlying (line_offset_struct
);
8201 struct partial_symtab
*pst
;
8204 /* Give the symtab a useful name for debug purposes. */
8205 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
8206 name
= xstrprintf ("<type_units_%d>",
8207 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
8209 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
8211 pst
= create_partial_symtab (per_cu
, name
);
8217 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
8218 tu_group
->hash
.line_sect_off
= line_offset_struct
;
8223 /* Look up the type_unit_group for type unit CU, and create it if necessary.
8224 STMT_LIST is a DW_AT_stmt_list attribute. */
8226 static struct type_unit_group
*
8227 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
8229 struct dwarf2_per_objfile
*dwarf2_per_objfile
8230 = cu
->per_cu
->dwarf2_per_objfile
;
8231 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8232 struct type_unit_group
*tu_group
;
8234 unsigned int line_offset
;
8235 struct type_unit_group type_unit_group_for_lookup
;
8237 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
8239 dwarf2_per_objfile
->type_unit_groups
=
8240 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
8243 /* Do we need to create a new group, or can we use an existing one? */
8247 line_offset
= DW_UNSND (stmt_list
);
8248 ++tu_stats
->nr_symtab_sharers
;
8252 /* Ugh, no stmt_list. Rare, but we have to handle it.
8253 We can do various things here like create one group per TU or
8254 spread them over multiple groups to split up the expansion work.
8255 To avoid worst case scenarios (too many groups or too large groups)
8256 we, umm, group them in bunches. */
8257 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
8258 | (tu_stats
->nr_stmt_less_type_units
8259 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
8260 ++tu_stats
->nr_stmt_less_type_units
;
8263 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
8264 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
8265 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8266 &type_unit_group_for_lookup
, INSERT
);
8269 tu_group
= (struct type_unit_group
*) *slot
;
8270 gdb_assert (tu_group
!= NULL
);
8274 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8275 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8277 ++tu_stats
->nr_symtabs
;
8283 /* Partial symbol tables. */
8285 /* Create a psymtab named NAME and assign it to PER_CU.
8287 The caller must fill in the following details:
8288 dirname, textlow, texthigh. */
8290 static struct partial_symtab
*
8291 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8293 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8294 struct partial_symtab
*pst
;
8296 pst
= start_psymtab_common (objfile
, name
, 0,
8297 objfile
->global_psymbols
,
8298 objfile
->static_psymbols
);
8300 pst
->psymtabs_addrmap_supported
= 1;
8302 /* This is the glue that links PST into GDB's symbol API. */
8303 pst
->read_symtab_private
= per_cu
;
8304 pst
->read_symtab
= dwarf2_read_symtab
;
8305 per_cu
->v
.psymtab
= pst
;
8310 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8313 struct process_psymtab_comp_unit_data
8315 /* True if we are reading a DW_TAG_partial_unit. */
8317 int want_partial_unit
;
8319 /* The "pretend" language that is used if the CU doesn't declare a
8322 enum language pretend_language
;
8325 /* die_reader_func for process_psymtab_comp_unit. */
8328 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8329 const gdb_byte
*info_ptr
,
8330 struct die_info
*comp_unit_die
,
8334 struct dwarf2_cu
*cu
= reader
->cu
;
8335 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8336 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8337 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8339 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8340 struct partial_symtab
*pst
;
8341 enum pc_bounds_kind cu_bounds_kind
;
8342 const char *filename
;
8343 struct process_psymtab_comp_unit_data
*info
8344 = (struct process_psymtab_comp_unit_data
*) data
;
8346 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8349 gdb_assert (! per_cu
->is_debug_types
);
8351 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8353 cu
->list_in_scope
= &file_symbols
;
8355 /* Allocate a new partial symbol table structure. */
8356 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8357 if (filename
== NULL
)
8360 pst
= create_partial_symtab (per_cu
, filename
);
8362 /* This must be done before calling dwarf2_build_include_psymtabs. */
8363 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8365 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8367 dwarf2_find_base_address (comp_unit_die
, cu
);
8369 /* Possibly set the default values of LOWPC and HIGHPC from
8371 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8372 &best_highpc
, cu
, pst
);
8373 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8374 /* Store the contiguous range if it is not empty; it can be empty for
8375 CUs with no code. */
8376 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8377 gdbarch_adjust_dwarf2_addr (gdbarch
,
8378 best_lowpc
+ baseaddr
),
8379 gdbarch_adjust_dwarf2_addr (gdbarch
,
8380 best_highpc
+ baseaddr
) - 1,
8383 /* Check if comp unit has_children.
8384 If so, read the rest of the partial symbols from this comp unit.
8385 If not, there's no more debug_info for this comp unit. */
8388 struct partial_die_info
*first_die
;
8389 CORE_ADDR lowpc
, highpc
;
8391 lowpc
= ((CORE_ADDR
) -1);
8392 highpc
= ((CORE_ADDR
) 0);
8394 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8396 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8397 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8399 /* If we didn't find a lowpc, set it to highpc to avoid
8400 complaints from `maint check'. */
8401 if (lowpc
== ((CORE_ADDR
) -1))
8404 /* If the compilation unit didn't have an explicit address range,
8405 then use the information extracted from its child dies. */
8406 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8409 best_highpc
= highpc
;
8412 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8413 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8415 end_psymtab_common (objfile
, pst
);
8417 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8420 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8421 struct dwarf2_per_cu_data
*iter
;
8423 /* Fill in 'dependencies' here; we fill in 'users' in a
8425 pst
->number_of_dependencies
= len
;
8427 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8429 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8432 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8434 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8437 /* Get the list of files included in the current compilation unit,
8438 and build a psymtab for each of them. */
8439 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8441 if (dwarf_read_debug
)
8443 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8445 fprintf_unfiltered (gdb_stdlog
,
8446 "Psymtab for %s unit @%s: %s - %s"
8447 ", %d global, %d static syms\n",
8448 per_cu
->is_debug_types
? "type" : "comp",
8449 sect_offset_str (per_cu
->sect_off
),
8450 paddress (gdbarch
, pst
->textlow
),
8451 paddress (gdbarch
, pst
->texthigh
),
8452 pst
->n_global_syms
, pst
->n_static_syms
);
8456 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8457 Process compilation unit THIS_CU for a psymtab. */
8460 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8461 int want_partial_unit
,
8462 enum language pretend_language
)
8464 /* If this compilation unit was already read in, free the
8465 cached copy in order to read it in again. This is
8466 necessary because we skipped some symbols when we first
8467 read in the compilation unit (see load_partial_dies).
8468 This problem could be avoided, but the benefit is unclear. */
8469 if (this_cu
->cu
!= NULL
)
8470 free_one_cached_comp_unit (this_cu
);
8472 if (this_cu
->is_debug_types
)
8473 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8477 process_psymtab_comp_unit_data info
;
8478 info
.want_partial_unit
= want_partial_unit
;
8479 info
.pretend_language
= pretend_language
;
8480 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8481 process_psymtab_comp_unit_reader
, &info
);
8484 /* Age out any secondary CUs. */
8485 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8488 /* Reader function for build_type_psymtabs. */
8491 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8492 const gdb_byte
*info_ptr
,
8493 struct die_info
*type_unit_die
,
8497 struct dwarf2_per_objfile
*dwarf2_per_objfile
8498 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8499 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8500 struct dwarf2_cu
*cu
= reader
->cu
;
8501 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8502 struct signatured_type
*sig_type
;
8503 struct type_unit_group
*tu_group
;
8504 struct attribute
*attr
;
8505 struct partial_die_info
*first_die
;
8506 CORE_ADDR lowpc
, highpc
;
8507 struct partial_symtab
*pst
;
8509 gdb_assert (data
== NULL
);
8510 gdb_assert (per_cu
->is_debug_types
);
8511 sig_type
= (struct signatured_type
*) per_cu
;
8516 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8517 tu_group
= get_type_unit_group (cu
, attr
);
8519 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8521 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8522 cu
->list_in_scope
= &file_symbols
;
8523 pst
= create_partial_symtab (per_cu
, "");
8526 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8528 lowpc
= (CORE_ADDR
) -1;
8529 highpc
= (CORE_ADDR
) 0;
8530 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8532 end_psymtab_common (objfile
, pst
);
8535 /* Struct used to sort TUs by their abbreviation table offset. */
8537 struct tu_abbrev_offset
8539 struct signatured_type
*sig_type
;
8540 sect_offset abbrev_offset
;
8543 /* Helper routine for build_type_psymtabs_1, passed to qsort. */
8546 sort_tu_by_abbrev_offset (const void *ap
, const void *bp
)
8548 const struct tu_abbrev_offset
* const *a
8549 = (const struct tu_abbrev_offset
* const*) ap
;
8550 const struct tu_abbrev_offset
* const *b
8551 = (const struct tu_abbrev_offset
* const*) bp
;
8552 sect_offset aoff
= (*a
)->abbrev_offset
;
8553 sect_offset boff
= (*b
)->abbrev_offset
;
8555 return (aoff
> boff
) - (aoff
< boff
);
8558 /* Efficiently read all the type units.
8559 This does the bulk of the work for build_type_psymtabs.
8561 The efficiency is because we sort TUs by the abbrev table they use and
8562 only read each abbrev table once. In one program there are 200K TUs
8563 sharing 8K abbrev tables.
8565 The main purpose of this function is to support building the
8566 dwarf2_per_objfile->type_unit_groups table.
8567 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8568 can collapse the search space by grouping them by stmt_list.
8569 The savings can be significant, in the same program from above the 200K TUs
8570 share 8K stmt_list tables.
8572 FUNC is expected to call get_type_unit_group, which will create the
8573 struct type_unit_group if necessary and add it to
8574 dwarf2_per_objfile->type_unit_groups. */
8577 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8579 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8580 struct cleanup
*cleanups
;
8581 abbrev_table_up abbrev_table
;
8582 sect_offset abbrev_offset
;
8583 struct tu_abbrev_offset
*sorted_by_abbrev
;
8586 /* It's up to the caller to not call us multiple times. */
8587 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8589 if (dwarf2_per_objfile
->n_type_units
== 0)
8592 /* TUs typically share abbrev tables, and there can be way more TUs than
8593 abbrev tables. Sort by abbrev table to reduce the number of times we
8594 read each abbrev table in.
8595 Alternatives are to punt or to maintain a cache of abbrev tables.
8596 This is simpler and efficient enough for now.
8598 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8599 symtab to use). Typically TUs with the same abbrev offset have the same
8600 stmt_list value too so in practice this should work well.
8602 The basic algorithm here is:
8604 sort TUs by abbrev table
8605 for each TU with same abbrev table:
8606 read abbrev table if first user
8607 read TU top level DIE
8608 [IWBN if DWO skeletons had DW_AT_stmt_list]
8611 if (dwarf_read_debug
)
8612 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8614 /* Sort in a separate table to maintain the order of all_type_units
8615 for .gdb_index: TU indices directly index all_type_units. */
8616 sorted_by_abbrev
= XNEWVEC (struct tu_abbrev_offset
,
8617 dwarf2_per_objfile
->n_type_units
);
8618 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8620 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8622 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8623 sorted_by_abbrev
[i
].abbrev_offset
=
8624 read_abbrev_offset (dwarf2_per_objfile
,
8625 sig_type
->per_cu
.section
,
8626 sig_type
->per_cu
.sect_off
);
8628 cleanups
= make_cleanup (xfree
, sorted_by_abbrev
);
8629 qsort (sorted_by_abbrev
, dwarf2_per_objfile
->n_type_units
,
8630 sizeof (struct tu_abbrev_offset
), sort_tu_by_abbrev_offset
);
8632 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8634 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8636 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8638 /* Switch to the next abbrev table if necessary. */
8639 if (abbrev_table
== NULL
8640 || tu
->abbrev_offset
!= abbrev_offset
)
8642 abbrev_offset
= tu
->abbrev_offset
;
8644 abbrev_table_read_table (dwarf2_per_objfile
,
8645 &dwarf2_per_objfile
->abbrev
,
8647 ++tu_stats
->nr_uniq_abbrev_tables
;
8650 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8651 0, 0, build_type_psymtabs_reader
, NULL
);
8654 do_cleanups (cleanups
);
8657 /* Print collected type unit statistics. */
8660 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8662 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8664 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8665 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8666 dwarf2_per_objfile
->n_type_units
);
8667 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8668 tu_stats
->nr_uniq_abbrev_tables
);
8669 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8670 tu_stats
->nr_symtabs
);
8671 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8672 tu_stats
->nr_symtab_sharers
);
8673 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8674 tu_stats
->nr_stmt_less_type_units
);
8675 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8676 tu_stats
->nr_all_type_units_reallocs
);
8679 /* Traversal function for build_type_psymtabs. */
8682 build_type_psymtab_dependencies (void **slot
, void *info
)
8684 struct dwarf2_per_objfile
*dwarf2_per_objfile
8685 = (struct dwarf2_per_objfile
*) info
;
8686 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8687 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8688 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8689 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8690 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8691 struct signatured_type
*iter
;
8694 gdb_assert (len
> 0);
8695 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8697 pst
->number_of_dependencies
= len
;
8699 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8701 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8704 gdb_assert (iter
->per_cu
.is_debug_types
);
8705 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8706 iter
->type_unit_group
= tu_group
;
8709 VEC_free (sig_type_ptr
, tu_group
->tus
);
8714 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8715 Build partial symbol tables for the .debug_types comp-units. */
8718 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8720 if (! create_all_type_units (dwarf2_per_objfile
))
8723 build_type_psymtabs_1 (dwarf2_per_objfile
);
8726 /* Traversal function for process_skeletonless_type_unit.
8727 Read a TU in a DWO file and build partial symbols for it. */
8730 process_skeletonless_type_unit (void **slot
, void *info
)
8732 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8733 struct dwarf2_per_objfile
*dwarf2_per_objfile
8734 = (struct dwarf2_per_objfile
*) info
;
8735 struct signatured_type find_entry
, *entry
;
8737 /* If this TU doesn't exist in the global table, add it and read it in. */
8739 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8741 dwarf2_per_objfile
->signatured_types
8742 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8745 find_entry
.signature
= dwo_unit
->signature
;
8746 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8748 /* If we've already seen this type there's nothing to do. What's happening
8749 is we're doing our own version of comdat-folding here. */
8753 /* This does the job that create_all_type_units would have done for
8755 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8756 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8759 /* This does the job that build_type_psymtabs_1 would have done. */
8760 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8761 build_type_psymtabs_reader
, NULL
);
8766 /* Traversal function for process_skeletonless_type_units. */
8769 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8771 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8773 if (dwo_file
->tus
!= NULL
)
8775 htab_traverse_noresize (dwo_file
->tus
,
8776 process_skeletonless_type_unit
, info
);
8782 /* Scan all TUs of DWO files, verifying we've processed them.
8783 This is needed in case a TU was emitted without its skeleton.
8784 Note: This can't be done until we know what all the DWO files are. */
8787 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8789 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8790 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8791 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8793 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8794 process_dwo_file_for_skeletonless_type_units
,
8795 dwarf2_per_objfile
);
8799 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8802 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8806 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8808 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8809 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8815 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8817 /* Set the 'user' field only if it is not already set. */
8818 if (pst
->dependencies
[j
]->user
== NULL
)
8819 pst
->dependencies
[j
]->user
= pst
;
8824 /* Build the partial symbol table by doing a quick pass through the
8825 .debug_info and .debug_abbrev sections. */
8828 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8830 struct cleanup
*back_to
;
8832 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8834 if (dwarf_read_debug
)
8836 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8837 objfile_name (objfile
));
8840 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8842 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8844 /* Any cached compilation units will be linked by the per-objfile
8845 read_in_chain. Make sure to free them when we're done. */
8846 back_to
= make_cleanup (free_cached_comp_units
, dwarf2_per_objfile
);
8848 build_type_psymtabs (dwarf2_per_objfile
);
8850 create_all_comp_units (dwarf2_per_objfile
);
8852 /* Create a temporary address map on a temporary obstack. We later
8853 copy this to the final obstack. */
8854 auto_obstack temp_obstack
;
8856 scoped_restore save_psymtabs_addrmap
8857 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8858 addrmap_create_mutable (&temp_obstack
));
8860 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8862 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8864 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8867 /* This has to wait until we read the CUs, we need the list of DWOs. */
8868 process_skeletonless_type_units (dwarf2_per_objfile
);
8870 /* Now that all TUs have been processed we can fill in the dependencies. */
8871 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8873 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8874 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8877 if (dwarf_read_debug
)
8878 print_tu_stats (dwarf2_per_objfile
);
8880 set_partial_user (dwarf2_per_objfile
);
8882 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8883 &objfile
->objfile_obstack
);
8884 /* At this point we want to keep the address map. */
8885 save_psymtabs_addrmap
.release ();
8887 do_cleanups (back_to
);
8889 if (dwarf_read_debug
)
8890 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8891 objfile_name (objfile
));
8894 /* die_reader_func for load_partial_comp_unit. */
8897 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8898 const gdb_byte
*info_ptr
,
8899 struct die_info
*comp_unit_die
,
8903 struct dwarf2_cu
*cu
= reader
->cu
;
8905 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8907 /* Check if comp unit has_children.
8908 If so, read the rest of the partial symbols from this comp unit.
8909 If not, there's no more debug_info for this comp unit. */
8911 load_partial_dies (reader
, info_ptr
, 0);
8914 /* Load the partial DIEs for a secondary CU into memory.
8915 This is also used when rereading a primary CU with load_all_dies. */
8918 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8920 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8921 load_partial_comp_unit_reader
, NULL
);
8925 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8926 struct dwarf2_section_info
*section
,
8927 struct dwarf2_section_info
*abbrev_section
,
8928 unsigned int is_dwz
,
8931 struct dwarf2_per_cu_data
***all_comp_units
)
8933 const gdb_byte
*info_ptr
;
8934 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8936 if (dwarf_read_debug
)
8937 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8938 get_section_name (section
),
8939 get_section_file_name (section
));
8941 dwarf2_read_section (objfile
, section
);
8943 info_ptr
= section
->buffer
;
8945 while (info_ptr
< section
->buffer
+ section
->size
)
8947 struct dwarf2_per_cu_data
*this_cu
;
8949 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8951 comp_unit_head cu_header
;
8952 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8953 abbrev_section
, info_ptr
,
8954 rcuh_kind::COMPILE
);
8956 /* Save the compilation unit for later lookup. */
8957 if (cu_header
.unit_type
!= DW_UT_type
)
8959 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8960 struct dwarf2_per_cu_data
);
8961 memset (this_cu
, 0, sizeof (*this_cu
));
8965 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8966 struct signatured_type
);
8967 memset (sig_type
, 0, sizeof (*sig_type
));
8968 sig_type
->signature
= cu_header
.signature
;
8969 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8970 this_cu
= &sig_type
->per_cu
;
8972 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8973 this_cu
->sect_off
= sect_off
;
8974 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8975 this_cu
->is_dwz
= is_dwz
;
8976 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8977 this_cu
->section
= section
;
8979 if (*n_comp_units
== *n_allocated
)
8982 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
8983 *all_comp_units
, *n_allocated
);
8985 (*all_comp_units
)[*n_comp_units
] = this_cu
;
8988 info_ptr
= info_ptr
+ this_cu
->length
;
8992 /* Create a list of all compilation units in OBJFILE.
8993 This is only done for -readnow and building partial symtabs. */
8996 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9000 struct dwarf2_per_cu_data
**all_comp_units
;
9001 struct dwz_file
*dwz
;
9002 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9006 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
9008 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
9009 &dwarf2_per_objfile
->abbrev
, 0,
9010 &n_allocated
, &n_comp_units
, &all_comp_units
);
9012 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
9014 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
9015 1, &n_allocated
, &n_comp_units
,
9018 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
9019 struct dwarf2_per_cu_data
*,
9021 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
9022 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
9023 xfree (all_comp_units
);
9024 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
9027 /* Process all loaded DIEs for compilation unit CU, starting at
9028 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
9029 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
9030 DW_AT_ranges). See the comments of add_partial_subprogram on how
9031 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
9034 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
9035 CORE_ADDR
*highpc
, int set_addrmap
,
9036 struct dwarf2_cu
*cu
)
9038 struct partial_die_info
*pdi
;
9040 /* Now, march along the PDI's, descending into ones which have
9041 interesting children but skipping the children of the other ones,
9042 until we reach the end of the compilation unit. */
9048 fixup_partial_die (pdi
, cu
);
9050 /* Anonymous namespaces or modules have no name but have interesting
9051 children, so we need to look at them. Ditto for anonymous
9054 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
9055 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
9056 || pdi
->tag
== DW_TAG_imported_unit
9057 || pdi
->tag
== DW_TAG_inlined_subroutine
)
9061 case DW_TAG_subprogram
:
9062 case DW_TAG_inlined_subroutine
:
9063 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9065 case DW_TAG_constant
:
9066 case DW_TAG_variable
:
9067 case DW_TAG_typedef
:
9068 case DW_TAG_union_type
:
9069 if (!pdi
->is_declaration
)
9071 add_partial_symbol (pdi
, cu
);
9074 case DW_TAG_class_type
:
9075 case DW_TAG_interface_type
:
9076 case DW_TAG_structure_type
:
9077 if (!pdi
->is_declaration
)
9079 add_partial_symbol (pdi
, cu
);
9081 if (cu
->language
== language_rust
&& pdi
->has_children
)
9082 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
9085 case DW_TAG_enumeration_type
:
9086 if (!pdi
->is_declaration
)
9087 add_partial_enumeration (pdi
, cu
);
9089 case DW_TAG_base_type
:
9090 case DW_TAG_subrange_type
:
9091 /* File scope base type definitions are added to the partial
9093 add_partial_symbol (pdi
, cu
);
9095 case DW_TAG_namespace
:
9096 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9099 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9101 case DW_TAG_imported_unit
:
9103 struct dwarf2_per_cu_data
*per_cu
;
9105 /* For now we don't handle imported units in type units. */
9106 if (cu
->per_cu
->is_debug_types
)
9108 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9109 " supported in type units [in module %s]"),
9110 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9113 per_cu
= dwarf2_find_containing_comp_unit
9114 (pdi
->d
.sect_off
, pdi
->is_dwz
,
9115 cu
->per_cu
->dwarf2_per_objfile
);
9117 /* Go read the partial unit, if needed. */
9118 if (per_cu
->v
.psymtab
== NULL
)
9119 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
9121 VEC_safe_push (dwarf2_per_cu_ptr
,
9122 cu
->per_cu
->imported_symtabs
, per_cu
);
9125 case DW_TAG_imported_declaration
:
9126 add_partial_symbol (pdi
, cu
);
9133 /* If the die has a sibling, skip to the sibling. */
9135 pdi
= pdi
->die_sibling
;
9139 /* Functions used to compute the fully scoped name of a partial DIE.
9141 Normally, this is simple. For C++, the parent DIE's fully scoped
9142 name is concatenated with "::" and the partial DIE's name.
9143 Enumerators are an exception; they use the scope of their parent
9144 enumeration type, i.e. the name of the enumeration type is not
9145 prepended to the enumerator.
9147 There are two complexities. One is DW_AT_specification; in this
9148 case "parent" means the parent of the target of the specification,
9149 instead of the direct parent of the DIE. The other is compilers
9150 which do not emit DW_TAG_namespace; in this case we try to guess
9151 the fully qualified name of structure types from their members'
9152 linkage names. This must be done using the DIE's children rather
9153 than the children of any DW_AT_specification target. We only need
9154 to do this for structures at the top level, i.e. if the target of
9155 any DW_AT_specification (if any; otherwise the DIE itself) does not
9158 /* Compute the scope prefix associated with PDI's parent, in
9159 compilation unit CU. The result will be allocated on CU's
9160 comp_unit_obstack, or a copy of the already allocated PDI->NAME
9161 field. NULL is returned if no prefix is necessary. */
9163 partial_die_parent_scope (struct partial_die_info
*pdi
,
9164 struct dwarf2_cu
*cu
)
9166 const char *grandparent_scope
;
9167 struct partial_die_info
*parent
, *real_pdi
;
9169 /* We need to look at our parent DIE; if we have a DW_AT_specification,
9170 then this means the parent of the specification DIE. */
9173 while (real_pdi
->has_specification
)
9174 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
9175 real_pdi
->spec_is_dwz
, cu
);
9177 parent
= real_pdi
->die_parent
;
9181 if (parent
->scope_set
)
9182 return parent
->scope
;
9184 fixup_partial_die (parent
, cu
);
9186 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
9188 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9189 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9190 Work around this problem here. */
9191 if (cu
->language
== language_cplus
9192 && parent
->tag
== DW_TAG_namespace
9193 && strcmp (parent
->name
, "::") == 0
9194 && grandparent_scope
== NULL
)
9196 parent
->scope
= NULL
;
9197 parent
->scope_set
= 1;
9201 if (pdi
->tag
== DW_TAG_enumerator
)
9202 /* Enumerators should not get the name of the enumeration as a prefix. */
9203 parent
->scope
= grandparent_scope
;
9204 else if (parent
->tag
== DW_TAG_namespace
9205 || parent
->tag
== DW_TAG_module
9206 || parent
->tag
== DW_TAG_structure_type
9207 || parent
->tag
== DW_TAG_class_type
9208 || parent
->tag
== DW_TAG_interface_type
9209 || parent
->tag
== DW_TAG_union_type
9210 || parent
->tag
== DW_TAG_enumeration_type
)
9212 if (grandparent_scope
== NULL
)
9213 parent
->scope
= parent
->name
;
9215 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
9217 parent
->name
, 0, cu
);
9221 /* FIXME drow/2004-04-01: What should we be doing with
9222 function-local names? For partial symbols, we should probably be
9224 complaint (&symfile_complaints
,
9225 _("unhandled containing DIE tag %d for DIE at %s"),
9226 parent
->tag
, sect_offset_str (pdi
->sect_off
));
9227 parent
->scope
= grandparent_scope
;
9230 parent
->scope_set
= 1;
9231 return parent
->scope
;
9234 /* Return the fully scoped name associated with PDI, from compilation unit
9235 CU. The result will be allocated with malloc. */
9238 partial_die_full_name (struct partial_die_info
*pdi
,
9239 struct dwarf2_cu
*cu
)
9241 const char *parent_scope
;
9243 /* If this is a template instantiation, we can not work out the
9244 template arguments from partial DIEs. So, unfortunately, we have
9245 to go through the full DIEs. At least any work we do building
9246 types here will be reused if full symbols are loaded later. */
9247 if (pdi
->has_template_arguments
)
9249 fixup_partial_die (pdi
, cu
);
9251 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
9253 struct die_info
*die
;
9254 struct attribute attr
;
9255 struct dwarf2_cu
*ref_cu
= cu
;
9257 /* DW_FORM_ref_addr is using section offset. */
9258 attr
.name
= (enum dwarf_attribute
) 0;
9259 attr
.form
= DW_FORM_ref_addr
;
9260 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
9261 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
9263 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
9267 parent_scope
= partial_die_parent_scope (pdi
, cu
);
9268 if (parent_scope
== NULL
)
9271 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
9275 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
9277 struct dwarf2_per_objfile
*dwarf2_per_objfile
9278 = cu
->per_cu
->dwarf2_per_objfile
;
9279 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9280 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9282 const char *actual_name
= NULL
;
9284 char *built_actual_name
;
9286 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9288 built_actual_name
= partial_die_full_name (pdi
, cu
);
9289 if (built_actual_name
!= NULL
)
9290 actual_name
= built_actual_name
;
9292 if (actual_name
== NULL
)
9293 actual_name
= pdi
->name
;
9297 case DW_TAG_inlined_subroutine
:
9298 case DW_TAG_subprogram
:
9299 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
9300 if (pdi
->is_external
|| cu
->language
== language_ada
)
9302 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
9303 of the global scope. But in Ada, we want to be able to access
9304 nested procedures globally. So all Ada subprograms are stored
9305 in the global scope. */
9306 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9307 built_actual_name
!= NULL
,
9308 VAR_DOMAIN
, LOC_BLOCK
,
9309 &objfile
->global_psymbols
,
9310 addr
, cu
->language
, objfile
);
9314 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9315 built_actual_name
!= NULL
,
9316 VAR_DOMAIN
, LOC_BLOCK
,
9317 &objfile
->static_psymbols
,
9318 addr
, cu
->language
, objfile
);
9321 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9322 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9324 case DW_TAG_constant
:
9326 std::vector
<partial_symbol
*> *list
;
9328 if (pdi
->is_external
)
9329 list
= &objfile
->global_psymbols
;
9331 list
= &objfile
->static_psymbols
;
9332 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9333 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9334 list
, 0, cu
->language
, objfile
);
9337 case DW_TAG_variable
:
9339 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9343 && !dwarf2_per_objfile
->has_section_at_zero
)
9345 /* A global or static variable may also have been stripped
9346 out by the linker if unused, in which case its address
9347 will be nullified; do not add such variables into partial
9348 symbol table then. */
9350 else if (pdi
->is_external
)
9353 Don't enter into the minimal symbol tables as there is
9354 a minimal symbol table entry from the ELF symbols already.
9355 Enter into partial symbol table if it has a location
9356 descriptor or a type.
9357 If the location descriptor is missing, new_symbol will create
9358 a LOC_UNRESOLVED symbol, the address of the variable will then
9359 be determined from the minimal symbol table whenever the variable
9361 The address for the partial symbol table entry is not
9362 used by GDB, but it comes in handy for debugging partial symbol
9365 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9366 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9367 built_actual_name
!= NULL
,
9368 VAR_DOMAIN
, LOC_STATIC
,
9369 &objfile
->global_psymbols
,
9371 cu
->language
, objfile
);
9375 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9377 /* Static Variable. Skip symbols whose value we cannot know (those
9378 without location descriptors or constant values). */
9379 if (!has_loc
&& !pdi
->has_const_value
)
9381 xfree (built_actual_name
);
9385 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9386 built_actual_name
!= NULL
,
9387 VAR_DOMAIN
, LOC_STATIC
,
9388 &objfile
->static_psymbols
,
9389 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9390 cu
->language
, objfile
);
9393 case DW_TAG_typedef
:
9394 case DW_TAG_base_type
:
9395 case DW_TAG_subrange_type
:
9396 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9397 built_actual_name
!= NULL
,
9398 VAR_DOMAIN
, LOC_TYPEDEF
,
9399 &objfile
->static_psymbols
,
9400 0, cu
->language
, objfile
);
9402 case DW_TAG_imported_declaration
:
9403 case DW_TAG_namespace
:
9404 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9405 built_actual_name
!= NULL
,
9406 VAR_DOMAIN
, LOC_TYPEDEF
,
9407 &objfile
->global_psymbols
,
9408 0, cu
->language
, objfile
);
9411 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9412 built_actual_name
!= NULL
,
9413 MODULE_DOMAIN
, LOC_TYPEDEF
,
9414 &objfile
->global_psymbols
,
9415 0, cu
->language
, objfile
);
9417 case DW_TAG_class_type
:
9418 case DW_TAG_interface_type
:
9419 case DW_TAG_structure_type
:
9420 case DW_TAG_union_type
:
9421 case DW_TAG_enumeration_type
:
9422 /* Skip external references. The DWARF standard says in the section
9423 about "Structure, Union, and Class Type Entries": "An incomplete
9424 structure, union or class type is represented by a structure,
9425 union or class entry that does not have a byte size attribute
9426 and that has a DW_AT_declaration attribute." */
9427 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9429 xfree (built_actual_name
);
9433 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9434 static vs. global. */
9435 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9436 built_actual_name
!= NULL
,
9437 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9438 cu
->language
== language_cplus
9439 ? &objfile
->global_psymbols
9440 : &objfile
->static_psymbols
,
9441 0, cu
->language
, objfile
);
9444 case DW_TAG_enumerator
:
9445 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9446 built_actual_name
!= NULL
,
9447 VAR_DOMAIN
, LOC_CONST
,
9448 cu
->language
== language_cplus
9449 ? &objfile
->global_psymbols
9450 : &objfile
->static_psymbols
,
9451 0, cu
->language
, objfile
);
9457 xfree (built_actual_name
);
9460 /* Read a partial die corresponding to a namespace; also, add a symbol
9461 corresponding to that namespace to the symbol table. NAMESPACE is
9462 the name of the enclosing namespace. */
9465 add_partial_namespace (struct partial_die_info
*pdi
,
9466 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9467 int set_addrmap
, struct dwarf2_cu
*cu
)
9469 /* Add a symbol for the namespace. */
9471 add_partial_symbol (pdi
, cu
);
9473 /* Now scan partial symbols in that namespace. */
9475 if (pdi
->has_children
)
9476 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9479 /* Read a partial die corresponding to a Fortran module. */
9482 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9483 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9485 /* Add a symbol for the namespace. */
9487 add_partial_symbol (pdi
, cu
);
9489 /* Now scan partial symbols in that module. */
9491 if (pdi
->has_children
)
9492 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9495 /* Read a partial die corresponding to a subprogram or an inlined
9496 subprogram and create a partial symbol for that subprogram.
9497 When the CU language allows it, this routine also defines a partial
9498 symbol for each nested subprogram that this subprogram contains.
9499 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9500 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9502 PDI may also be a lexical block, in which case we simply search
9503 recursively for subprograms defined inside that lexical block.
9504 Again, this is only performed when the CU language allows this
9505 type of definitions. */
9508 add_partial_subprogram (struct partial_die_info
*pdi
,
9509 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9510 int set_addrmap
, struct dwarf2_cu
*cu
)
9512 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9514 if (pdi
->has_pc_info
)
9516 if (pdi
->lowpc
< *lowpc
)
9517 *lowpc
= pdi
->lowpc
;
9518 if (pdi
->highpc
> *highpc
)
9519 *highpc
= pdi
->highpc
;
9522 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9523 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9528 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9529 SECT_OFF_TEXT (objfile
));
9530 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9531 pdi
->lowpc
+ baseaddr
);
9532 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9533 pdi
->highpc
+ baseaddr
);
9534 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9535 cu
->per_cu
->v
.psymtab
);
9539 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9541 if (!pdi
->is_declaration
)
9542 /* Ignore subprogram DIEs that do not have a name, they are
9543 illegal. Do not emit a complaint at this point, we will
9544 do so when we convert this psymtab into a symtab. */
9546 add_partial_symbol (pdi
, cu
);
9550 if (! pdi
->has_children
)
9553 if (cu
->language
== language_ada
)
9555 pdi
= pdi
->die_child
;
9558 fixup_partial_die (pdi
, cu
);
9559 if (pdi
->tag
== DW_TAG_subprogram
9560 || pdi
->tag
== DW_TAG_inlined_subroutine
9561 || pdi
->tag
== DW_TAG_lexical_block
)
9562 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9563 pdi
= pdi
->die_sibling
;
9568 /* Read a partial die corresponding to an enumeration type. */
9571 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9572 struct dwarf2_cu
*cu
)
9574 struct partial_die_info
*pdi
;
9576 if (enum_pdi
->name
!= NULL
)
9577 add_partial_symbol (enum_pdi
, cu
);
9579 pdi
= enum_pdi
->die_child
;
9582 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9583 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9585 add_partial_symbol (pdi
, cu
);
9586 pdi
= pdi
->die_sibling
;
9590 /* Return the initial uleb128 in the die at INFO_PTR. */
9593 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9595 unsigned int bytes_read
;
9597 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9600 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9601 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9603 Return the corresponding abbrev, or NULL if the number is zero (indicating
9604 an empty DIE). In either case *BYTES_READ will be set to the length of
9605 the initial number. */
9607 static struct abbrev_info
*
9608 peek_die_abbrev (const die_reader_specs
&reader
,
9609 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9611 dwarf2_cu
*cu
= reader
.cu
;
9612 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9613 unsigned int abbrev_number
9614 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9616 if (abbrev_number
== 0)
9619 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9622 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9623 " at offset %s [in module %s]"),
9624 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9625 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9631 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9632 Returns a pointer to the end of a series of DIEs, terminated by an empty
9633 DIE. Any children of the skipped DIEs will also be skipped. */
9635 static const gdb_byte
*
9636 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9640 unsigned int bytes_read
;
9641 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9644 return info_ptr
+ bytes_read
;
9646 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9650 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9651 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9652 abbrev corresponding to that skipped uleb128 should be passed in
9653 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9656 static const gdb_byte
*
9657 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9658 struct abbrev_info
*abbrev
)
9660 unsigned int bytes_read
;
9661 struct attribute attr
;
9662 bfd
*abfd
= reader
->abfd
;
9663 struct dwarf2_cu
*cu
= reader
->cu
;
9664 const gdb_byte
*buffer
= reader
->buffer
;
9665 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9666 unsigned int form
, i
;
9668 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9670 /* The only abbrev we care about is DW_AT_sibling. */
9671 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9673 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9674 if (attr
.form
== DW_FORM_ref_addr
)
9675 complaint (&symfile_complaints
,
9676 _("ignoring absolute DW_AT_sibling"));
9679 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9680 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9682 if (sibling_ptr
< info_ptr
)
9683 complaint (&symfile_complaints
,
9684 _("DW_AT_sibling points backwards"));
9685 else if (sibling_ptr
> reader
->buffer_end
)
9686 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9692 /* If it isn't DW_AT_sibling, skip this attribute. */
9693 form
= abbrev
->attrs
[i
].form
;
9697 case DW_FORM_ref_addr
:
9698 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9699 and later it is offset sized. */
9700 if (cu
->header
.version
== 2)
9701 info_ptr
+= cu
->header
.addr_size
;
9703 info_ptr
+= cu
->header
.offset_size
;
9705 case DW_FORM_GNU_ref_alt
:
9706 info_ptr
+= cu
->header
.offset_size
;
9709 info_ptr
+= cu
->header
.addr_size
;
9716 case DW_FORM_flag_present
:
9717 case DW_FORM_implicit_const
:
9729 case DW_FORM_ref_sig8
:
9732 case DW_FORM_data16
:
9735 case DW_FORM_string
:
9736 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9737 info_ptr
+= bytes_read
;
9739 case DW_FORM_sec_offset
:
9741 case DW_FORM_GNU_strp_alt
:
9742 info_ptr
+= cu
->header
.offset_size
;
9744 case DW_FORM_exprloc
:
9746 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9747 info_ptr
+= bytes_read
;
9749 case DW_FORM_block1
:
9750 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9752 case DW_FORM_block2
:
9753 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9755 case DW_FORM_block4
:
9756 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9760 case DW_FORM_ref_udata
:
9761 case DW_FORM_GNU_addr_index
:
9762 case DW_FORM_GNU_str_index
:
9763 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9765 case DW_FORM_indirect
:
9766 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9767 info_ptr
+= bytes_read
;
9768 /* We need to continue parsing from here, so just go back to
9770 goto skip_attribute
;
9773 error (_("Dwarf Error: Cannot handle %s "
9774 "in DWARF reader [in module %s]"),
9775 dwarf_form_name (form
),
9776 bfd_get_filename (abfd
));
9780 if (abbrev
->has_children
)
9781 return skip_children (reader
, info_ptr
);
9786 /* Locate ORIG_PDI's sibling.
9787 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9789 static const gdb_byte
*
9790 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9791 struct partial_die_info
*orig_pdi
,
9792 const gdb_byte
*info_ptr
)
9794 /* Do we know the sibling already? */
9796 if (orig_pdi
->sibling
)
9797 return orig_pdi
->sibling
;
9799 /* Are there any children to deal with? */
9801 if (!orig_pdi
->has_children
)
9804 /* Skip the children the long way. */
9806 return skip_children (reader
, info_ptr
);
9809 /* Expand this partial symbol table into a full symbol table. SELF is
9813 dwarf2_read_symtab (struct partial_symtab
*self
,
9814 struct objfile
*objfile
)
9816 struct dwarf2_per_objfile
*dwarf2_per_objfile
9817 = get_dwarf2_per_objfile (objfile
);
9821 warning (_("bug: psymtab for %s is already read in."),
9828 printf_filtered (_("Reading in symbols for %s..."),
9830 gdb_flush (gdb_stdout
);
9833 /* If this psymtab is constructed from a debug-only objfile, the
9834 has_section_at_zero flag will not necessarily be correct. We
9835 can get the correct value for this flag by looking at the data
9836 associated with the (presumably stripped) associated objfile. */
9837 if (objfile
->separate_debug_objfile_backlink
)
9839 struct dwarf2_per_objfile
*dpo_backlink
9840 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9842 dwarf2_per_objfile
->has_section_at_zero
9843 = dpo_backlink
->has_section_at_zero
;
9846 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9848 psymtab_to_symtab_1 (self
);
9850 /* Finish up the debug error message. */
9852 printf_filtered (_("done.\n"));
9855 process_cu_includes (dwarf2_per_objfile
);
9858 /* Reading in full CUs. */
9860 /* Add PER_CU to the queue. */
9863 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9864 enum language pretend_language
)
9866 struct dwarf2_queue_item
*item
;
9869 item
= XNEW (struct dwarf2_queue_item
);
9870 item
->per_cu
= per_cu
;
9871 item
->pretend_language
= pretend_language
;
9874 if (dwarf2_queue
== NULL
)
9875 dwarf2_queue
= item
;
9877 dwarf2_queue_tail
->next
= item
;
9879 dwarf2_queue_tail
= item
;
9882 /* If PER_CU is not yet queued, add it to the queue.
9883 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9885 The result is non-zero if PER_CU was queued, otherwise the result is zero
9886 meaning either PER_CU is already queued or it is already loaded.
9888 N.B. There is an invariant here that if a CU is queued then it is loaded.
9889 The caller is required to load PER_CU if we return non-zero. */
9892 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9893 struct dwarf2_per_cu_data
*per_cu
,
9894 enum language pretend_language
)
9896 /* We may arrive here during partial symbol reading, if we need full
9897 DIEs to process an unusual case (e.g. template arguments). Do
9898 not queue PER_CU, just tell our caller to load its DIEs. */
9899 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9901 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9906 /* Mark the dependence relation so that we don't flush PER_CU
9908 if (dependent_cu
!= NULL
)
9909 dwarf2_add_dependence (dependent_cu
, per_cu
);
9911 /* If it's already on the queue, we have nothing to do. */
9915 /* If the compilation unit is already loaded, just mark it as
9917 if (per_cu
->cu
!= NULL
)
9919 per_cu
->cu
->last_used
= 0;
9923 /* Add it to the queue. */
9924 queue_comp_unit (per_cu
, pretend_language
);
9929 /* Process the queue. */
9932 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9934 struct dwarf2_queue_item
*item
, *next_item
;
9936 if (dwarf_read_debug
)
9938 fprintf_unfiltered (gdb_stdlog
,
9939 "Expanding one or more symtabs of objfile %s ...\n",
9940 objfile_name (dwarf2_per_objfile
->objfile
));
9943 /* The queue starts out with one item, but following a DIE reference
9944 may load a new CU, adding it to the end of the queue. */
9945 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9947 if ((dwarf2_per_objfile
->using_index
9948 ? !item
->per_cu
->v
.quick
->compunit_symtab
9949 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9950 /* Skip dummy CUs. */
9951 && item
->per_cu
->cu
!= NULL
)
9953 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9954 unsigned int debug_print_threshold
;
9957 if (per_cu
->is_debug_types
)
9959 struct signatured_type
*sig_type
=
9960 (struct signatured_type
*) per_cu
;
9962 sprintf (buf
, "TU %s at offset %s",
9963 hex_string (sig_type
->signature
),
9964 sect_offset_str (per_cu
->sect_off
));
9965 /* There can be 100s of TUs.
9966 Only print them in verbose mode. */
9967 debug_print_threshold
= 2;
9971 sprintf (buf
, "CU at offset %s",
9972 sect_offset_str (per_cu
->sect_off
));
9973 debug_print_threshold
= 1;
9976 if (dwarf_read_debug
>= debug_print_threshold
)
9977 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9979 if (per_cu
->is_debug_types
)
9980 process_full_type_unit (per_cu
, item
->pretend_language
);
9982 process_full_comp_unit (per_cu
, item
->pretend_language
);
9984 if (dwarf_read_debug
>= debug_print_threshold
)
9985 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9988 item
->per_cu
->queued
= 0;
9989 next_item
= item
->next
;
9993 dwarf2_queue_tail
= NULL
;
9995 if (dwarf_read_debug
)
9997 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9998 objfile_name (dwarf2_per_objfile
->objfile
));
10002 /* Read in full symbols for PST, and anything it depends on. */
10005 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
10007 struct dwarf2_per_cu_data
*per_cu
;
10013 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
10014 if (!pst
->dependencies
[i
]->readin
10015 && pst
->dependencies
[i
]->user
== NULL
)
10017 /* Inform about additional files that need to be read in. */
10020 /* FIXME: i18n: Need to make this a single string. */
10021 fputs_filtered (" ", gdb_stdout
);
10023 fputs_filtered ("and ", gdb_stdout
);
10025 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
10026 wrap_here (""); /* Flush output. */
10027 gdb_flush (gdb_stdout
);
10029 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
10032 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
10034 if (per_cu
== NULL
)
10036 /* It's an include file, no symbols to read for it.
10037 Everything is in the parent symtab. */
10042 dw2_do_instantiate_symtab (per_cu
);
10045 /* Trivial hash function for die_info: the hash value of a DIE
10046 is its offset in .debug_info for this objfile. */
10049 die_hash (const void *item
)
10051 const struct die_info
*die
= (const struct die_info
*) item
;
10053 return to_underlying (die
->sect_off
);
10056 /* Trivial comparison function for die_info structures: two DIEs
10057 are equal if they have the same offset. */
10060 die_eq (const void *item_lhs
, const void *item_rhs
)
10062 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
10063 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
10065 return die_lhs
->sect_off
== die_rhs
->sect_off
;
10068 /* die_reader_func for load_full_comp_unit.
10069 This is identical to read_signatured_type_reader,
10070 but is kept separate for now. */
10073 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
10074 const gdb_byte
*info_ptr
,
10075 struct die_info
*comp_unit_die
,
10079 struct dwarf2_cu
*cu
= reader
->cu
;
10080 enum language
*language_ptr
= (enum language
*) data
;
10082 gdb_assert (cu
->die_hash
== NULL
);
10084 htab_create_alloc_ex (cu
->header
.length
/ 12,
10088 &cu
->comp_unit_obstack
,
10089 hashtab_obstack_allocate
,
10090 dummy_obstack_deallocate
);
10093 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
10094 &info_ptr
, comp_unit_die
);
10095 cu
->dies
= comp_unit_die
;
10096 /* comp_unit_die is not stored in die_hash, no need. */
10098 /* We try not to read any attributes in this function, because not
10099 all CUs needed for references have been loaded yet, and symbol
10100 table processing isn't initialized. But we have to set the CU language,
10101 or we won't be able to build types correctly.
10102 Similarly, if we do not read the producer, we can not apply
10103 producer-specific interpretation. */
10104 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
10107 /* Load the DIEs associated with PER_CU into memory. */
10110 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10111 enum language pretend_language
)
10113 gdb_assert (! this_cu
->is_debug_types
);
10115 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
10116 load_full_comp_unit_reader
, &pretend_language
);
10119 /* Add a DIE to the delayed physname list. */
10122 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
10123 const char *name
, struct die_info
*die
,
10124 struct dwarf2_cu
*cu
)
10126 struct delayed_method_info mi
;
10128 mi
.fnfield_index
= fnfield_index
;
10132 cu
->method_list
.push_back (mi
);
10135 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
10136 "const" / "volatile". If so, decrements LEN by the length of the
10137 modifier and return true. Otherwise return false. */
10141 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
10143 size_t mod_len
= sizeof (mod
) - 1;
10144 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
10152 /* Compute the physnames of any methods on the CU's method list.
10154 The computation of method physnames is delayed in order to avoid the
10155 (bad) condition that one of the method's formal parameters is of an as yet
10156 incomplete type. */
10159 compute_delayed_physnames (struct dwarf2_cu
*cu
)
10161 /* Only C++ delays computing physnames. */
10162 if (cu
->method_list
.empty ())
10164 gdb_assert (cu
->language
== language_cplus
);
10166 for (struct delayed_method_info
&mi
: cu
->method_list
)
10168 const char *physname
;
10169 struct fn_fieldlist
*fn_flp
10170 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
10171 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
10172 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
10173 = physname
? physname
: "";
10175 /* Since there's no tag to indicate whether a method is a
10176 const/volatile overload, extract that information out of the
10178 if (physname
!= NULL
)
10180 size_t len
= strlen (physname
);
10184 if (physname
[len
] == ')') /* shortcut */
10186 else if (check_modifier (physname
, len
, " const"))
10187 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
10188 else if (check_modifier (physname
, len
, " volatile"))
10189 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
10196 /* The list is no longer needed. */
10197 cu
->method_list
.clear ();
10200 /* Go objects should be embedded in a DW_TAG_module DIE,
10201 and it's not clear if/how imported objects will appear.
10202 To keep Go support simple until that's worked out,
10203 go back through what we've read and create something usable.
10204 We could do this while processing each DIE, and feels kinda cleaner,
10205 but that way is more invasive.
10206 This is to, for example, allow the user to type "p var" or "b main"
10207 without having to specify the package name, and allow lookups
10208 of module.object to work in contexts that use the expression
10212 fixup_go_packaging (struct dwarf2_cu
*cu
)
10214 char *package_name
= NULL
;
10215 struct pending
*list
;
10218 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
10220 for (i
= 0; i
< list
->nsyms
; ++i
)
10222 struct symbol
*sym
= list
->symbol
[i
];
10224 if (SYMBOL_LANGUAGE (sym
) == language_go
10225 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
10227 char *this_package_name
= go_symbol_package_name (sym
);
10229 if (this_package_name
== NULL
)
10231 if (package_name
== NULL
)
10232 package_name
= this_package_name
;
10235 struct objfile
*objfile
10236 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10237 if (strcmp (package_name
, this_package_name
) != 0)
10238 complaint (&symfile_complaints
,
10239 _("Symtab %s has objects from two different Go packages: %s and %s"),
10240 (symbol_symtab (sym
) != NULL
10241 ? symtab_to_filename_for_display
10242 (symbol_symtab (sym
))
10243 : objfile_name (objfile
)),
10244 this_package_name
, package_name
);
10245 xfree (this_package_name
);
10251 if (package_name
!= NULL
)
10253 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10254 const char *saved_package_name
10255 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10257 strlen (package_name
));
10258 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
10259 saved_package_name
);
10260 struct symbol
*sym
;
10262 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10264 sym
= allocate_symbol (objfile
);
10265 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
10266 SYMBOL_SET_NAMES (sym
, saved_package_name
,
10267 strlen (saved_package_name
), 0, objfile
);
10268 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
10269 e.g., "main" finds the "main" module and not C's main(). */
10270 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10271 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
10272 SYMBOL_TYPE (sym
) = type
;
10274 add_symbol_to_list (sym
, &global_symbols
);
10276 xfree (package_name
);
10280 /* Return the symtab for PER_CU. This works properly regardless of
10281 whether we're using the index or psymtabs. */
10283 static struct compunit_symtab
*
10284 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10286 return (per_cu
->dwarf2_per_objfile
->using_index
10287 ? per_cu
->v
.quick
->compunit_symtab
10288 : per_cu
->v
.psymtab
->compunit_symtab
);
10291 /* A helper function for computing the list of all symbol tables
10292 included by PER_CU. */
10295 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10296 htab_t all_children
, htab_t all_type_symtabs
,
10297 struct dwarf2_per_cu_data
*per_cu
,
10298 struct compunit_symtab
*immediate_parent
)
10302 struct compunit_symtab
*cust
;
10303 struct dwarf2_per_cu_data
*iter
;
10305 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10308 /* This inclusion and its children have been processed. */
10313 /* Only add a CU if it has a symbol table. */
10314 cust
= get_compunit_symtab (per_cu
);
10317 /* If this is a type unit only add its symbol table if we haven't
10318 seen it yet (type unit per_cu's can share symtabs). */
10319 if (per_cu
->is_debug_types
)
10321 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10325 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10326 if (cust
->user
== NULL
)
10327 cust
->user
= immediate_parent
;
10332 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10333 if (cust
->user
== NULL
)
10334 cust
->user
= immediate_parent
;
10339 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10342 recursively_compute_inclusions (result
, all_children
,
10343 all_type_symtabs
, iter
, cust
);
10347 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10351 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10353 gdb_assert (! per_cu
->is_debug_types
);
10355 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10358 struct dwarf2_per_cu_data
*per_cu_iter
;
10359 struct compunit_symtab
*compunit_symtab_iter
;
10360 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10361 htab_t all_children
, all_type_symtabs
;
10362 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10364 /* If we don't have a symtab, we can just skip this case. */
10368 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10369 NULL
, xcalloc
, xfree
);
10370 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10371 NULL
, xcalloc
, xfree
);
10374 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10378 recursively_compute_inclusions (&result_symtabs
, all_children
,
10379 all_type_symtabs
, per_cu_iter
,
10383 /* Now we have a transitive closure of all the included symtabs. */
10384 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10386 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10387 struct compunit_symtab
*, len
+ 1);
10389 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10390 compunit_symtab_iter
);
10392 cust
->includes
[ix
] = compunit_symtab_iter
;
10393 cust
->includes
[len
] = NULL
;
10395 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10396 htab_delete (all_children
);
10397 htab_delete (all_type_symtabs
);
10401 /* Compute the 'includes' field for the symtabs of all the CUs we just
10405 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10408 struct dwarf2_per_cu_data
*iter
;
10411 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10415 if (! iter
->is_debug_types
)
10416 compute_compunit_symtab_includes (iter
);
10419 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10422 /* Generate full symbol information for PER_CU, whose DIEs have
10423 already been loaded into memory. */
10426 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10427 enum language pretend_language
)
10429 struct dwarf2_cu
*cu
= per_cu
->cu
;
10430 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10432 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10433 CORE_ADDR lowpc
, highpc
;
10434 struct compunit_symtab
*cust
;
10435 CORE_ADDR baseaddr
;
10436 struct block
*static_block
;
10439 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10442 scoped_free_pendings free_pending
;
10444 /* Clear the list here in case something was left over. */
10445 cu
->method_list
.clear ();
10447 cu
->list_in_scope
= &file_symbols
;
10449 cu
->language
= pretend_language
;
10450 cu
->language_defn
= language_def (cu
->language
);
10452 /* Do line number decoding in read_file_scope () */
10453 process_die (cu
->dies
, cu
);
10455 /* For now fudge the Go package. */
10456 if (cu
->language
== language_go
)
10457 fixup_go_packaging (cu
);
10459 /* Now that we have processed all the DIEs in the CU, all the types
10460 should be complete, and it should now be safe to compute all of the
10462 compute_delayed_physnames (cu
);
10464 /* Some compilers don't define a DW_AT_high_pc attribute for the
10465 compilation unit. If the DW_AT_high_pc is missing, synthesize
10466 it, by scanning the DIE's below the compilation unit. */
10467 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10469 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10470 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10472 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10473 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10474 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10475 addrmap to help ensure it has an accurate map of pc values belonging to
10477 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10479 cust
= end_symtab_from_static_block (static_block
,
10480 SECT_OFF_TEXT (objfile
), 0);
10484 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10486 /* Set symtab language to language from DW_AT_language. If the
10487 compilation is from a C file generated by language preprocessors, do
10488 not set the language if it was already deduced by start_subfile. */
10489 if (!(cu
->language
== language_c
10490 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10491 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10493 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10494 produce DW_AT_location with location lists but it can be possibly
10495 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10496 there were bugs in prologue debug info, fixed later in GCC-4.5
10497 by "unwind info for epilogues" patch (which is not directly related).
10499 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10500 needed, it would be wrong due to missing DW_AT_producer there.
10502 Still one can confuse GDB by using non-standard GCC compilation
10503 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10505 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10506 cust
->locations_valid
= 1;
10508 if (gcc_4_minor
>= 5)
10509 cust
->epilogue_unwind_valid
= 1;
10511 cust
->call_site_htab
= cu
->call_site_htab
;
10514 if (dwarf2_per_objfile
->using_index
)
10515 per_cu
->v
.quick
->compunit_symtab
= cust
;
10518 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10519 pst
->compunit_symtab
= cust
;
10523 /* Push it for inclusion processing later. */
10524 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10527 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10528 already been loaded into memory. */
10531 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10532 enum language pretend_language
)
10534 struct dwarf2_cu
*cu
= per_cu
->cu
;
10535 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10536 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10537 struct compunit_symtab
*cust
;
10538 struct signatured_type
*sig_type
;
10540 gdb_assert (per_cu
->is_debug_types
);
10541 sig_type
= (struct signatured_type
*) per_cu
;
10544 scoped_free_pendings free_pending
;
10546 /* Clear the list here in case something was left over. */
10547 cu
->method_list
.clear ();
10549 cu
->list_in_scope
= &file_symbols
;
10551 cu
->language
= pretend_language
;
10552 cu
->language_defn
= language_def (cu
->language
);
10554 /* The symbol tables are set up in read_type_unit_scope. */
10555 process_die (cu
->dies
, cu
);
10557 /* For now fudge the Go package. */
10558 if (cu
->language
== language_go
)
10559 fixup_go_packaging (cu
);
10561 /* Now that we have processed all the DIEs in the CU, all the types
10562 should be complete, and it should now be safe to compute all of the
10564 compute_delayed_physnames (cu
);
10566 /* TUs share symbol tables.
10567 If this is the first TU to use this symtab, complete the construction
10568 of it with end_expandable_symtab. Otherwise, complete the addition of
10569 this TU's symbols to the existing symtab. */
10570 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10572 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10573 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10577 /* Set symtab language to language from DW_AT_language. If the
10578 compilation is from a C file generated by language preprocessors,
10579 do not set the language if it was already deduced by
10581 if (!(cu
->language
== language_c
10582 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10583 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10588 augment_type_symtab ();
10589 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10592 if (dwarf2_per_objfile
->using_index
)
10593 per_cu
->v
.quick
->compunit_symtab
= cust
;
10596 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10597 pst
->compunit_symtab
= cust
;
10602 /* Process an imported unit DIE. */
10605 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10607 struct attribute
*attr
;
10609 /* For now we don't handle imported units in type units. */
10610 if (cu
->per_cu
->is_debug_types
)
10612 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10613 " supported in type units [in module %s]"),
10614 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10617 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10620 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10621 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10622 dwarf2_per_cu_data
*per_cu
10623 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10624 cu
->per_cu
->dwarf2_per_objfile
);
10626 /* If necessary, add it to the queue and load its DIEs. */
10627 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10628 load_full_comp_unit (per_cu
, cu
->language
);
10630 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10635 /* RAII object that represents a process_die scope: i.e.,
10636 starts/finishes processing a DIE. */
10637 class process_die_scope
10640 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10641 : m_die (die
), m_cu (cu
)
10643 /* We should only be processing DIEs not already in process. */
10644 gdb_assert (!m_die
->in_process
);
10645 m_die
->in_process
= true;
10648 ~process_die_scope ()
10650 m_die
->in_process
= false;
10652 /* If we're done processing the DIE for the CU that owns the line
10653 header, we don't need the line header anymore. */
10654 if (m_cu
->line_header_die_owner
== m_die
)
10656 delete m_cu
->line_header
;
10657 m_cu
->line_header
= NULL
;
10658 m_cu
->line_header_die_owner
= NULL
;
10667 /* Process a die and its children. */
10670 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10672 process_die_scope
scope (die
, cu
);
10676 case DW_TAG_padding
:
10678 case DW_TAG_compile_unit
:
10679 case DW_TAG_partial_unit
:
10680 read_file_scope (die
, cu
);
10682 case DW_TAG_type_unit
:
10683 read_type_unit_scope (die
, cu
);
10685 case DW_TAG_subprogram
:
10686 case DW_TAG_inlined_subroutine
:
10687 read_func_scope (die
, cu
);
10689 case DW_TAG_lexical_block
:
10690 case DW_TAG_try_block
:
10691 case DW_TAG_catch_block
:
10692 read_lexical_block_scope (die
, cu
);
10694 case DW_TAG_call_site
:
10695 case DW_TAG_GNU_call_site
:
10696 read_call_site_scope (die
, cu
);
10698 case DW_TAG_class_type
:
10699 case DW_TAG_interface_type
:
10700 case DW_TAG_structure_type
:
10701 case DW_TAG_union_type
:
10702 process_structure_scope (die
, cu
);
10704 case DW_TAG_enumeration_type
:
10705 process_enumeration_scope (die
, cu
);
10708 /* These dies have a type, but processing them does not create
10709 a symbol or recurse to process the children. Therefore we can
10710 read them on-demand through read_type_die. */
10711 case DW_TAG_subroutine_type
:
10712 case DW_TAG_set_type
:
10713 case DW_TAG_array_type
:
10714 case DW_TAG_pointer_type
:
10715 case DW_TAG_ptr_to_member_type
:
10716 case DW_TAG_reference_type
:
10717 case DW_TAG_rvalue_reference_type
:
10718 case DW_TAG_string_type
:
10721 case DW_TAG_base_type
:
10722 case DW_TAG_subrange_type
:
10723 case DW_TAG_typedef
:
10724 /* Add a typedef symbol for the type definition, if it has a
10726 new_symbol (die
, read_type_die (die
, cu
), cu
);
10728 case DW_TAG_common_block
:
10729 read_common_block (die
, cu
);
10731 case DW_TAG_common_inclusion
:
10733 case DW_TAG_namespace
:
10734 cu
->processing_has_namespace_info
= 1;
10735 read_namespace (die
, cu
);
10737 case DW_TAG_module
:
10738 cu
->processing_has_namespace_info
= 1;
10739 read_module (die
, cu
);
10741 case DW_TAG_imported_declaration
:
10742 cu
->processing_has_namespace_info
= 1;
10743 if (read_namespace_alias (die
, cu
))
10745 /* The declaration is not a global namespace alias: fall through. */
10746 case DW_TAG_imported_module
:
10747 cu
->processing_has_namespace_info
= 1;
10748 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10749 || cu
->language
!= language_fortran
))
10750 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
10751 dwarf_tag_name (die
->tag
));
10752 read_import_statement (die
, cu
);
10755 case DW_TAG_imported_unit
:
10756 process_imported_unit_die (die
, cu
);
10759 case DW_TAG_variable
:
10760 read_variable (die
, cu
);
10764 new_symbol (die
, NULL
, cu
);
10769 /* DWARF name computation. */
10771 /* A helper function for dwarf2_compute_name which determines whether DIE
10772 needs to have the name of the scope prepended to the name listed in the
10776 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10778 struct attribute
*attr
;
10782 case DW_TAG_namespace
:
10783 case DW_TAG_typedef
:
10784 case DW_TAG_class_type
:
10785 case DW_TAG_interface_type
:
10786 case DW_TAG_structure_type
:
10787 case DW_TAG_union_type
:
10788 case DW_TAG_enumeration_type
:
10789 case DW_TAG_enumerator
:
10790 case DW_TAG_subprogram
:
10791 case DW_TAG_inlined_subroutine
:
10792 case DW_TAG_member
:
10793 case DW_TAG_imported_declaration
:
10796 case DW_TAG_variable
:
10797 case DW_TAG_constant
:
10798 /* We only need to prefix "globally" visible variables. These include
10799 any variable marked with DW_AT_external or any variable that
10800 lives in a namespace. [Variables in anonymous namespaces
10801 require prefixing, but they are not DW_AT_external.] */
10803 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10805 struct dwarf2_cu
*spec_cu
= cu
;
10807 return die_needs_namespace (die_specification (die
, &spec_cu
),
10811 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10812 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10813 && die
->parent
->tag
!= DW_TAG_module
)
10815 /* A variable in a lexical block of some kind does not need a
10816 namespace, even though in C++ such variables may be external
10817 and have a mangled name. */
10818 if (die
->parent
->tag
== DW_TAG_lexical_block
10819 || die
->parent
->tag
== DW_TAG_try_block
10820 || die
->parent
->tag
== DW_TAG_catch_block
10821 || die
->parent
->tag
== DW_TAG_subprogram
)
10830 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10831 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10832 defined for the given DIE. */
10834 static struct attribute
*
10835 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10837 struct attribute
*attr
;
10839 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10841 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10846 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10847 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10848 defined for the given DIE. */
10850 static const char *
10851 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10853 const char *linkage_name
;
10855 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10856 if (linkage_name
== NULL
)
10857 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10859 return linkage_name
;
10862 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10863 compute the physname for the object, which include a method's:
10864 - formal parameters (C++),
10865 - receiver type (Go),
10867 The term "physname" is a bit confusing.
10868 For C++, for example, it is the demangled name.
10869 For Go, for example, it's the mangled name.
10871 For Ada, return the DIE's linkage name rather than the fully qualified
10872 name. PHYSNAME is ignored..
10874 The result is allocated on the objfile_obstack and canonicalized. */
10876 static const char *
10877 dwarf2_compute_name (const char *name
,
10878 struct die_info
*die
, struct dwarf2_cu
*cu
,
10881 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10884 name
= dwarf2_name (die
, cu
);
10886 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10887 but otherwise compute it by typename_concat inside GDB.
10888 FIXME: Actually this is not really true, or at least not always true.
10889 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10890 Fortran names because there is no mangling standard. So new_symbol
10891 will set the demangled name to the result of dwarf2_full_name, and it is
10892 the demangled name that GDB uses if it exists. */
10893 if (cu
->language
== language_ada
10894 || (cu
->language
== language_fortran
&& physname
))
10896 /* For Ada unit, we prefer the linkage name over the name, as
10897 the former contains the exported name, which the user expects
10898 to be able to reference. Ideally, we want the user to be able
10899 to reference this entity using either natural or linkage name,
10900 but we haven't started looking at this enhancement yet. */
10901 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10903 if (linkage_name
!= NULL
)
10904 return linkage_name
;
10907 /* These are the only languages we know how to qualify names in. */
10909 && (cu
->language
== language_cplus
10910 || cu
->language
== language_fortran
|| cu
->language
== language_d
10911 || cu
->language
== language_rust
))
10913 if (die_needs_namespace (die
, cu
))
10915 const char *prefix
;
10916 const char *canonical_name
= NULL
;
10920 prefix
= determine_prefix (die
, cu
);
10921 if (*prefix
!= '\0')
10923 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10926 buf
.puts (prefixed_name
);
10927 xfree (prefixed_name
);
10932 /* Template parameters may be specified in the DIE's DW_AT_name, or
10933 as children with DW_TAG_template_type_param or
10934 DW_TAG_value_type_param. If the latter, add them to the name
10935 here. If the name already has template parameters, then
10936 skip this step; some versions of GCC emit both, and
10937 it is more efficient to use the pre-computed name.
10939 Something to keep in mind about this process: it is very
10940 unlikely, or in some cases downright impossible, to produce
10941 something that will match the mangled name of a function.
10942 If the definition of the function has the same debug info,
10943 we should be able to match up with it anyway. But fallbacks
10944 using the minimal symbol, for instance to find a method
10945 implemented in a stripped copy of libstdc++, will not work.
10946 If we do not have debug info for the definition, we will have to
10947 match them up some other way.
10949 When we do name matching there is a related problem with function
10950 templates; two instantiated function templates are allowed to
10951 differ only by their return types, which we do not add here. */
10953 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10955 struct attribute
*attr
;
10956 struct die_info
*child
;
10959 die
->building_fullname
= 1;
10961 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10965 const gdb_byte
*bytes
;
10966 struct dwarf2_locexpr_baton
*baton
;
10969 if (child
->tag
!= DW_TAG_template_type_param
10970 && child
->tag
!= DW_TAG_template_value_param
)
10981 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10984 complaint (&symfile_complaints
,
10985 _("template parameter missing DW_AT_type"));
10986 buf
.puts ("UNKNOWN_TYPE");
10989 type
= die_type (child
, cu
);
10991 if (child
->tag
== DW_TAG_template_type_param
)
10993 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
10997 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
11000 complaint (&symfile_complaints
,
11001 _("template parameter missing "
11002 "DW_AT_const_value"));
11003 buf
.puts ("UNKNOWN_VALUE");
11007 dwarf2_const_value_attr (attr
, type
, name
,
11008 &cu
->comp_unit_obstack
, cu
,
11009 &value
, &bytes
, &baton
);
11011 if (TYPE_NOSIGN (type
))
11012 /* GDB prints characters as NUMBER 'CHAR'. If that's
11013 changed, this can use value_print instead. */
11014 c_printchar (value
, type
, &buf
);
11017 struct value_print_options opts
;
11020 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
11024 else if (bytes
!= NULL
)
11026 v
= allocate_value (type
);
11027 memcpy (value_contents_writeable (v
), bytes
,
11028 TYPE_LENGTH (type
));
11031 v
= value_from_longest (type
, value
);
11033 /* Specify decimal so that we do not depend on
11035 get_formatted_print_options (&opts
, 'd');
11037 value_print (v
, &buf
, &opts
);
11043 die
->building_fullname
= 0;
11047 /* Close the argument list, with a space if necessary
11048 (nested templates). */
11049 if (!buf
.empty () && buf
.string ().back () == '>')
11056 /* For C++ methods, append formal parameter type
11057 information, if PHYSNAME. */
11059 if (physname
&& die
->tag
== DW_TAG_subprogram
11060 && cu
->language
== language_cplus
)
11062 struct type
*type
= read_type_die (die
, cu
);
11064 c_type_print_args (type
, &buf
, 1, cu
->language
,
11065 &type_print_raw_options
);
11067 if (cu
->language
== language_cplus
)
11069 /* Assume that an artificial first parameter is
11070 "this", but do not crash if it is not. RealView
11071 marks unnamed (and thus unused) parameters as
11072 artificial; there is no way to differentiate
11074 if (TYPE_NFIELDS (type
) > 0
11075 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11076 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11077 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11079 buf
.puts (" const");
11083 const std::string
&intermediate_name
= buf
.string ();
11085 if (cu
->language
== language_cplus
)
11087 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11088 &objfile
->per_bfd
->storage_obstack
);
11090 /* If we only computed INTERMEDIATE_NAME, or if
11091 INTERMEDIATE_NAME is already canonical, then we need to
11092 copy it to the appropriate obstack. */
11093 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11094 name
= ((const char *)
11095 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11096 intermediate_name
.c_str (),
11097 intermediate_name
.length ()));
11099 name
= canonical_name
;
11106 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11107 If scope qualifiers are appropriate they will be added. The result
11108 will be allocated on the storage_obstack, or NULL if the DIE does
11109 not have a name. NAME may either be from a previous call to
11110 dwarf2_name or NULL.
11112 The output string will be canonicalized (if C++). */
11114 static const char *
11115 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11117 return dwarf2_compute_name (name
, die
, cu
, 0);
11120 /* Construct a physname for the given DIE in CU. NAME may either be
11121 from a previous call to dwarf2_name or NULL. The result will be
11122 allocated on the objfile_objstack or NULL if the DIE does not have a
11125 The output string will be canonicalized (if C++). */
11127 static const char *
11128 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11130 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11131 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11134 /* In this case dwarf2_compute_name is just a shortcut not building anything
11136 if (!die_needs_namespace (die
, cu
))
11137 return dwarf2_compute_name (name
, die
, cu
, 1);
11139 mangled
= dw2_linkage_name (die
, cu
);
11141 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11142 See https://github.com/rust-lang/rust/issues/32925. */
11143 if (cu
->language
== language_rust
&& mangled
!= NULL
11144 && strchr (mangled
, '{') != NULL
)
11147 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11149 gdb::unique_xmalloc_ptr
<char> demangled
;
11150 if (mangled
!= NULL
)
11153 if (cu
->language
== language_go
)
11155 /* This is a lie, but we already lie to the caller new_symbol.
11156 new_symbol assumes we return the mangled name.
11157 This just undoes that lie until things are cleaned up. */
11161 /* Use DMGL_RET_DROP for C++ template functions to suppress
11162 their return type. It is easier for GDB users to search
11163 for such functions as `name(params)' than `long name(params)'.
11164 In such case the minimal symbol names do not match the full
11165 symbol names but for template functions there is never a need
11166 to look up their definition from their declaration so
11167 the only disadvantage remains the minimal symbol variant
11168 `long name(params)' does not have the proper inferior type. */
11169 demangled
.reset (gdb_demangle (mangled
,
11170 (DMGL_PARAMS
| DMGL_ANSI
11171 | DMGL_RET_DROP
)));
11174 canon
= demangled
.get ();
11182 if (canon
== NULL
|| check_physname
)
11184 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11186 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11188 /* It may not mean a bug in GDB. The compiler could also
11189 compute DW_AT_linkage_name incorrectly. But in such case
11190 GDB would need to be bug-to-bug compatible. */
11192 complaint (&symfile_complaints
,
11193 _("Computed physname <%s> does not match demangled <%s> "
11194 "(from linkage <%s>) - DIE at %s [in module %s]"),
11195 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11196 objfile_name (objfile
));
11198 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11199 is available here - over computed PHYSNAME. It is safer
11200 against both buggy GDB and buggy compilers. */
11214 retval
= ((const char *)
11215 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11216 retval
, strlen (retval
)));
11221 /* Inspect DIE in CU for a namespace alias. If one exists, record
11222 a new symbol for it.
11224 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11227 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11229 struct attribute
*attr
;
11231 /* If the die does not have a name, this is not a namespace
11233 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11237 struct die_info
*d
= die
;
11238 struct dwarf2_cu
*imported_cu
= cu
;
11240 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11241 keep inspecting DIEs until we hit the underlying import. */
11242 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11243 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11245 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11249 d
= follow_die_ref (d
, attr
, &imported_cu
);
11250 if (d
->tag
!= DW_TAG_imported_declaration
)
11254 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11256 complaint (&symfile_complaints
,
11257 _("DIE at %s has too many recursively imported "
11258 "declarations"), sect_offset_str (d
->sect_off
));
11265 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11267 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11268 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11270 /* This declaration is a global namespace alias. Add
11271 a symbol for it whose type is the aliased namespace. */
11272 new_symbol (die
, type
, cu
);
11281 /* Return the using directives repository (global or local?) to use in the
11282 current context for LANGUAGE.
11284 For Ada, imported declarations can materialize renamings, which *may* be
11285 global. However it is impossible (for now?) in DWARF to distinguish
11286 "external" imported declarations and "static" ones. As all imported
11287 declarations seem to be static in all other languages, make them all CU-wide
11288 global only in Ada. */
11290 static struct using_direct
**
11291 using_directives (enum language language
)
11293 if (language
== language_ada
&& context_stack_depth
== 0)
11294 return &global_using_directives
;
11296 return &local_using_directives
;
11299 /* Read the import statement specified by the given die and record it. */
11302 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11304 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11305 struct attribute
*import_attr
;
11306 struct die_info
*imported_die
, *child_die
;
11307 struct dwarf2_cu
*imported_cu
;
11308 const char *imported_name
;
11309 const char *imported_name_prefix
;
11310 const char *canonical_name
;
11311 const char *import_alias
;
11312 const char *imported_declaration
= NULL
;
11313 const char *import_prefix
;
11314 std::vector
<const char *> excludes
;
11316 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11317 if (import_attr
== NULL
)
11319 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11320 dwarf_tag_name (die
->tag
));
11325 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11326 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11327 if (imported_name
== NULL
)
11329 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11331 The import in the following code:
11345 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11346 <52> DW_AT_decl_file : 1
11347 <53> DW_AT_decl_line : 6
11348 <54> DW_AT_import : <0x75>
11349 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11350 <59> DW_AT_name : B
11351 <5b> DW_AT_decl_file : 1
11352 <5c> DW_AT_decl_line : 2
11353 <5d> DW_AT_type : <0x6e>
11355 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11356 <76> DW_AT_byte_size : 4
11357 <77> DW_AT_encoding : 5 (signed)
11359 imports the wrong die ( 0x75 instead of 0x58 ).
11360 This case will be ignored until the gcc bug is fixed. */
11364 /* Figure out the local name after import. */
11365 import_alias
= dwarf2_name (die
, cu
);
11367 /* Figure out where the statement is being imported to. */
11368 import_prefix
= determine_prefix (die
, cu
);
11370 /* Figure out what the scope of the imported die is and prepend it
11371 to the name of the imported die. */
11372 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11374 if (imported_die
->tag
!= DW_TAG_namespace
11375 && imported_die
->tag
!= DW_TAG_module
)
11377 imported_declaration
= imported_name
;
11378 canonical_name
= imported_name_prefix
;
11380 else if (strlen (imported_name_prefix
) > 0)
11381 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11382 imported_name_prefix
,
11383 (cu
->language
== language_d
? "." : "::"),
11384 imported_name
, (char *) NULL
);
11386 canonical_name
= imported_name
;
11388 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11389 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11390 child_die
= sibling_die (child_die
))
11392 /* DWARF-4: A Fortran use statement with a “rename list” may be
11393 represented by an imported module entry with an import attribute
11394 referring to the module and owned entries corresponding to those
11395 entities that are renamed as part of being imported. */
11397 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11399 complaint (&symfile_complaints
,
11400 _("child DW_TAG_imported_declaration expected "
11401 "- DIE at %s [in module %s]"),
11402 sect_offset_str (child_die
->sect_off
),
11403 objfile_name (objfile
));
11407 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11408 if (import_attr
== NULL
)
11410 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11411 dwarf_tag_name (child_die
->tag
));
11416 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11418 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11419 if (imported_name
== NULL
)
11421 complaint (&symfile_complaints
,
11422 _("child DW_TAG_imported_declaration has unknown "
11423 "imported name - DIE at %s [in module %s]"),
11424 sect_offset_str (child_die
->sect_off
),
11425 objfile_name (objfile
));
11429 excludes
.push_back (imported_name
);
11431 process_die (child_die
, cu
);
11434 add_using_directive (using_directives (cu
->language
),
11438 imported_declaration
,
11441 &objfile
->objfile_obstack
);
11444 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11445 types, but gives them a size of zero. Starting with version 14,
11446 ICC is compatible with GCC. */
11449 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11451 if (!cu
->checked_producer
)
11452 check_producer (cu
);
11454 return cu
->producer_is_icc_lt_14
;
11457 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11458 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11459 this, it was first present in GCC release 4.3.0. */
11462 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11464 if (!cu
->checked_producer
)
11465 check_producer (cu
);
11467 return cu
->producer_is_gcc_lt_4_3
;
11470 static file_and_directory
11471 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11473 file_and_directory res
;
11475 /* Find the filename. Do not use dwarf2_name here, since the filename
11476 is not a source language identifier. */
11477 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11478 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11480 if (res
.comp_dir
== NULL
11481 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11482 && IS_ABSOLUTE_PATH (res
.name
))
11484 res
.comp_dir_storage
= ldirname (res
.name
);
11485 if (!res
.comp_dir_storage
.empty ())
11486 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11488 if (res
.comp_dir
!= NULL
)
11490 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11491 directory, get rid of it. */
11492 const char *cp
= strchr (res
.comp_dir
, ':');
11494 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11495 res
.comp_dir
= cp
+ 1;
11498 if (res
.name
== NULL
)
11499 res
.name
= "<unknown>";
11504 /* Handle DW_AT_stmt_list for a compilation unit.
11505 DIE is the DW_TAG_compile_unit die for CU.
11506 COMP_DIR is the compilation directory. LOWPC is passed to
11507 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11510 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11511 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11513 struct dwarf2_per_objfile
*dwarf2_per_objfile
11514 = cu
->per_cu
->dwarf2_per_objfile
;
11515 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11516 struct attribute
*attr
;
11517 struct line_header line_header_local
;
11518 hashval_t line_header_local_hash
;
11520 int decode_mapping
;
11522 gdb_assert (! cu
->per_cu
->is_debug_types
);
11524 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11528 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11530 /* The line header hash table is only created if needed (it exists to
11531 prevent redundant reading of the line table for partial_units).
11532 If we're given a partial_unit, we'll need it. If we're given a
11533 compile_unit, then use the line header hash table if it's already
11534 created, but don't create one just yet. */
11536 if (dwarf2_per_objfile
->line_header_hash
== NULL
11537 && die
->tag
== DW_TAG_partial_unit
)
11539 dwarf2_per_objfile
->line_header_hash
11540 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11541 line_header_eq_voidp
,
11542 free_line_header_voidp
,
11543 &objfile
->objfile_obstack
,
11544 hashtab_obstack_allocate
,
11545 dummy_obstack_deallocate
);
11548 line_header_local
.sect_off
= line_offset
;
11549 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11550 line_header_local_hash
= line_header_hash (&line_header_local
);
11551 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11553 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11554 &line_header_local
,
11555 line_header_local_hash
, NO_INSERT
);
11557 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11558 is not present in *SLOT (since if there is something in *SLOT then
11559 it will be for a partial_unit). */
11560 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11562 gdb_assert (*slot
!= NULL
);
11563 cu
->line_header
= (struct line_header
*) *slot
;
11568 /* dwarf_decode_line_header does not yet provide sufficient information.
11569 We always have to call also dwarf_decode_lines for it. */
11570 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11574 cu
->line_header
= lh
.release ();
11575 cu
->line_header_die_owner
= die
;
11577 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11581 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11582 &line_header_local
,
11583 line_header_local_hash
, INSERT
);
11584 gdb_assert (slot
!= NULL
);
11586 if (slot
!= NULL
&& *slot
== NULL
)
11588 /* This newly decoded line number information unit will be owned
11589 by line_header_hash hash table. */
11590 *slot
= cu
->line_header
;
11591 cu
->line_header_die_owner
= NULL
;
11595 /* We cannot free any current entry in (*slot) as that struct line_header
11596 may be already used by multiple CUs. Create only temporary decoded
11597 line_header for this CU - it may happen at most once for each line
11598 number information unit. And if we're not using line_header_hash
11599 then this is what we want as well. */
11600 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11602 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11603 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11608 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11611 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11613 struct dwarf2_per_objfile
*dwarf2_per_objfile
11614 = cu
->per_cu
->dwarf2_per_objfile
;
11615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11616 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11617 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11618 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11619 struct attribute
*attr
;
11620 struct die_info
*child_die
;
11621 CORE_ADDR baseaddr
;
11623 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11625 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11627 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11628 from finish_block. */
11629 if (lowpc
== ((CORE_ADDR
) -1))
11631 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11633 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11635 prepare_one_comp_unit (cu
, die
, cu
->language
);
11637 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11638 standardised yet. As a workaround for the language detection we fall
11639 back to the DW_AT_producer string. */
11640 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11641 cu
->language
= language_opencl
;
11643 /* Similar hack for Go. */
11644 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11645 set_cu_language (DW_LANG_Go
, cu
);
11647 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11649 /* Decode line number information if present. We do this before
11650 processing child DIEs, so that the line header table is available
11651 for DW_AT_decl_file. */
11652 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11654 /* Process all dies in compilation unit. */
11655 if (die
->child
!= NULL
)
11657 child_die
= die
->child
;
11658 while (child_die
&& child_die
->tag
)
11660 process_die (child_die
, cu
);
11661 child_die
= sibling_die (child_die
);
11665 /* Decode macro information, if present. Dwarf 2 macro information
11666 refers to information in the line number info statement program
11667 header, so we can only read it if we've read the header
11669 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11671 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11672 if (attr
&& cu
->line_header
)
11674 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11675 complaint (&symfile_complaints
,
11676 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11678 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11682 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11683 if (attr
&& cu
->line_header
)
11685 unsigned int macro_offset
= DW_UNSND (attr
);
11687 dwarf_decode_macros (cu
, macro_offset
, 0);
11692 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
11693 Create the set of symtabs used by this TU, or if this TU is sharing
11694 symtabs with another TU and the symtabs have already been created
11695 then restore those symtabs in the line header.
11696 We don't need the pc/line-number mapping for type units. */
11699 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
11701 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
11702 struct type_unit_group
*tu_group
;
11704 struct attribute
*attr
;
11706 struct signatured_type
*sig_type
;
11708 gdb_assert (per_cu
->is_debug_types
);
11709 sig_type
= (struct signatured_type
*) per_cu
;
11711 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11713 /* If we're using .gdb_index (includes -readnow) then
11714 per_cu->type_unit_group may not have been set up yet. */
11715 if (sig_type
->type_unit_group
== NULL
)
11716 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
11717 tu_group
= sig_type
->type_unit_group
;
11719 /* If we've already processed this stmt_list there's no real need to
11720 do it again, we could fake it and just recreate the part we need
11721 (file name,index -> symtab mapping). If data shows this optimization
11722 is useful we can do it then. */
11723 first_time
= tu_group
->compunit_symtab
== NULL
;
11725 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11730 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11731 lh
= dwarf_decode_line_header (line_offset
, cu
);
11736 dwarf2_start_symtab (cu
, "", NULL
, 0);
11739 gdb_assert (tu_group
->symtabs
== NULL
);
11740 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11745 cu
->line_header
= lh
.release ();
11746 cu
->line_header_die_owner
= die
;
11750 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
11752 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11753 still initializing it, and our caller (a few levels up)
11754 process_full_type_unit still needs to know if this is the first
11757 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
11758 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11759 cu
->line_header
->file_names
.size ());
11761 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11763 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11765 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
11767 if (current_subfile
->symtab
== NULL
)
11769 /* NOTE: start_subfile will recognize when it's been
11770 passed a file it has already seen. So we can't
11771 assume there's a simple mapping from
11772 cu->line_header->file_names to subfiles, plus
11773 cu->line_header->file_names may contain dups. */
11774 current_subfile
->symtab
11775 = allocate_symtab (cust
, current_subfile
->name
);
11778 fe
.symtab
= current_subfile
->symtab
;
11779 tu_group
->symtabs
[i
] = fe
.symtab
;
11784 restart_symtab (tu_group
->compunit_symtab
, "", 0);
11786 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
11788 file_entry
&fe
= cu
->line_header
->file_names
[i
];
11790 fe
.symtab
= tu_group
->symtabs
[i
];
11794 /* The main symtab is allocated last. Type units don't have DW_AT_name
11795 so they don't have a "real" (so to speak) symtab anyway.
11796 There is later code that will assign the main symtab to all symbols
11797 that don't have one. We need to handle the case of a symbol with a
11798 missing symtab (DW_AT_decl_file) anyway. */
11801 /* Process DW_TAG_type_unit.
11802 For TUs we want to skip the first top level sibling if it's not the
11803 actual type being defined by this TU. In this case the first top
11804 level sibling is there to provide context only. */
11807 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11809 struct die_info
*child_die
;
11811 prepare_one_comp_unit (cu
, die
, language_minimal
);
11813 /* Initialize (or reinitialize) the machinery for building symtabs.
11814 We do this before processing child DIEs, so that the line header table
11815 is available for DW_AT_decl_file. */
11816 setup_type_unit_groups (die
, cu
);
11818 if (die
->child
!= NULL
)
11820 child_die
= die
->child
;
11821 while (child_die
&& child_die
->tag
)
11823 process_die (child_die
, cu
);
11824 child_die
= sibling_die (child_die
);
11831 http://gcc.gnu.org/wiki/DebugFission
11832 http://gcc.gnu.org/wiki/DebugFissionDWP
11834 To simplify handling of both DWO files ("object" files with the DWARF info)
11835 and DWP files (a file with the DWOs packaged up into one file), we treat
11836 DWP files as having a collection of virtual DWO files. */
11839 hash_dwo_file (const void *item
)
11841 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11844 hash
= htab_hash_string (dwo_file
->dwo_name
);
11845 if (dwo_file
->comp_dir
!= NULL
)
11846 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11851 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11853 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11854 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11856 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11858 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11859 return lhs
->comp_dir
== rhs
->comp_dir
;
11860 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11863 /* Allocate a hash table for DWO files. */
11866 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11868 return htab_create_alloc_ex (41,
11872 &objfile
->objfile_obstack
,
11873 hashtab_obstack_allocate
,
11874 dummy_obstack_deallocate
);
11877 /* Lookup DWO file DWO_NAME. */
11880 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11881 const char *dwo_name
,
11882 const char *comp_dir
)
11884 struct dwo_file find_entry
;
11887 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11888 dwarf2_per_objfile
->dwo_files
11889 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11891 memset (&find_entry
, 0, sizeof (find_entry
));
11892 find_entry
.dwo_name
= dwo_name
;
11893 find_entry
.comp_dir
= comp_dir
;
11894 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
11900 hash_dwo_unit (const void *item
)
11902 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11904 /* This drops the top 32 bits of the id, but is ok for a hash. */
11905 return dwo_unit
->signature
;
11909 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11911 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11912 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11914 /* The signature is assumed to be unique within the DWO file.
11915 So while object file CU dwo_id's always have the value zero,
11916 that's OK, assuming each object file DWO file has only one CU,
11917 and that's the rule for now. */
11918 return lhs
->signature
== rhs
->signature
;
11921 /* Allocate a hash table for DWO CUs,TUs.
11922 There is one of these tables for each of CUs,TUs for each DWO file. */
11925 allocate_dwo_unit_table (struct objfile
*objfile
)
11927 /* Start out with a pretty small number.
11928 Generally DWO files contain only one CU and maybe some TUs. */
11929 return htab_create_alloc_ex (3,
11933 &objfile
->objfile_obstack
,
11934 hashtab_obstack_allocate
,
11935 dummy_obstack_deallocate
);
11938 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11940 struct create_dwo_cu_data
11942 struct dwo_file
*dwo_file
;
11943 struct dwo_unit dwo_unit
;
11946 /* die_reader_func for create_dwo_cu. */
11949 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11950 const gdb_byte
*info_ptr
,
11951 struct die_info
*comp_unit_die
,
11955 struct dwarf2_cu
*cu
= reader
->cu
;
11956 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11957 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11958 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11959 struct dwo_file
*dwo_file
= data
->dwo_file
;
11960 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11961 struct attribute
*attr
;
11963 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
11966 complaint (&symfile_complaints
,
11967 _("Dwarf Error: debug entry at offset %s is missing"
11968 " its dwo_id [in module %s]"),
11969 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11973 dwo_unit
->dwo_file
= dwo_file
;
11974 dwo_unit
->signature
= DW_UNSND (attr
);
11975 dwo_unit
->section
= section
;
11976 dwo_unit
->sect_off
= sect_off
;
11977 dwo_unit
->length
= cu
->per_cu
->length
;
11979 if (dwarf_read_debug
)
11980 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11981 sect_offset_str (sect_off
),
11982 hex_string (dwo_unit
->signature
));
11985 /* Create the dwo_units for the CUs in a DWO_FILE.
11986 Note: This function processes DWO files only, not DWP files. */
11989 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11990 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11993 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11994 const gdb_byte
*info_ptr
, *end_ptr
;
11996 dwarf2_read_section (objfile
, §ion
);
11997 info_ptr
= section
.buffer
;
11999 if (info_ptr
== NULL
)
12002 if (dwarf_read_debug
)
12004 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12005 get_section_name (§ion
),
12006 get_section_file_name (§ion
));
12009 end_ptr
= info_ptr
+ section
.size
;
12010 while (info_ptr
< end_ptr
)
12012 struct dwarf2_per_cu_data per_cu
;
12013 struct create_dwo_cu_data create_dwo_cu_data
;
12014 struct dwo_unit
*dwo_unit
;
12016 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12018 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12019 sizeof (create_dwo_cu_data
.dwo_unit
));
12020 memset (&per_cu
, 0, sizeof (per_cu
));
12021 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12022 per_cu
.is_debug_types
= 0;
12023 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12024 per_cu
.section
= §ion
;
12025 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12027 init_cutu_and_read_dies_no_follow (
12028 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12029 info_ptr
+= per_cu
.length
;
12031 // If the unit could not be parsed, skip it.
12032 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12035 if (cus_htab
== NULL
)
12036 cus_htab
= allocate_dwo_unit_table (objfile
);
12038 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12039 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12040 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12041 gdb_assert (slot
!= NULL
);
12044 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12045 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12047 complaint (&symfile_complaints
,
12048 _("debug cu entry at offset %s is duplicate to"
12049 " the entry at offset %s, signature %s"),
12050 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12051 hex_string (dwo_unit
->signature
));
12053 *slot
= (void *)dwo_unit
;
12057 /* DWP file .debug_{cu,tu}_index section format:
12058 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12062 Both index sections have the same format, and serve to map a 64-bit
12063 signature to a set of section numbers. Each section begins with a header,
12064 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12065 indexes, and a pool of 32-bit section numbers. The index sections will be
12066 aligned at 8-byte boundaries in the file.
12068 The index section header consists of:
12070 V, 32 bit version number
12072 N, 32 bit number of compilation units or type units in the index
12073 M, 32 bit number of slots in the hash table
12075 Numbers are recorded using the byte order of the application binary.
12077 The hash table begins at offset 16 in the section, and consists of an array
12078 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12079 order of the application binary). Unused slots in the hash table are 0.
12080 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12082 The parallel table begins immediately after the hash table
12083 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12084 array of 32-bit indexes (using the byte order of the application binary),
12085 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12086 table contains a 32-bit index into the pool of section numbers. For unused
12087 hash table slots, the corresponding entry in the parallel table will be 0.
12089 The pool of section numbers begins immediately following the hash table
12090 (at offset 16 + 12 * M from the beginning of the section). The pool of
12091 section numbers consists of an array of 32-bit words (using the byte order
12092 of the application binary). Each item in the array is indexed starting
12093 from 0. The hash table entry provides the index of the first section
12094 number in the set. Additional section numbers in the set follow, and the
12095 set is terminated by a 0 entry (section number 0 is not used in ELF).
12097 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12098 section must be the first entry in the set, and the .debug_abbrev.dwo must
12099 be the second entry. Other members of the set may follow in any order.
12105 DWP Version 2 combines all the .debug_info, etc. sections into one,
12106 and the entries in the index tables are now offsets into these sections.
12107 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12110 Index Section Contents:
12112 Hash Table of Signatures dwp_hash_table.hash_table
12113 Parallel Table of Indices dwp_hash_table.unit_table
12114 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12115 Table of Section Sizes dwp_hash_table.v2.sizes
12117 The index section header consists of:
12119 V, 32 bit version number
12120 L, 32 bit number of columns in the table of section offsets
12121 N, 32 bit number of compilation units or type units in the index
12122 M, 32 bit number of slots in the hash table
12124 Numbers are recorded using the byte order of the application binary.
12126 The hash table has the same format as version 1.
12127 The parallel table of indices has the same format as version 1,
12128 except that the entries are origin-1 indices into the table of sections
12129 offsets and the table of section sizes.
12131 The table of offsets begins immediately following the parallel table
12132 (at offset 16 + 12 * M from the beginning of the section). The table is
12133 a two-dimensional array of 32-bit words (using the byte order of the
12134 application binary), with L columns and N+1 rows, in row-major order.
12135 Each row in the array is indexed starting from 0. The first row provides
12136 a key to the remaining rows: each column in this row provides an identifier
12137 for a debug section, and the offsets in the same column of subsequent rows
12138 refer to that section. The section identifiers are:
12140 DW_SECT_INFO 1 .debug_info.dwo
12141 DW_SECT_TYPES 2 .debug_types.dwo
12142 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12143 DW_SECT_LINE 4 .debug_line.dwo
12144 DW_SECT_LOC 5 .debug_loc.dwo
12145 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12146 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12147 DW_SECT_MACRO 8 .debug_macro.dwo
12149 The offsets provided by the CU and TU index sections are the base offsets
12150 for the contributions made by each CU or TU to the corresponding section
12151 in the package file. Each CU and TU header contains an abbrev_offset
12152 field, used to find the abbreviations table for that CU or TU within the
12153 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12154 be interpreted as relative to the base offset given in the index section.
12155 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12156 should be interpreted as relative to the base offset for .debug_line.dwo,
12157 and offsets into other debug sections obtained from DWARF attributes should
12158 also be interpreted as relative to the corresponding base offset.
12160 The table of sizes begins immediately following the table of offsets.
12161 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12162 with L columns and N rows, in row-major order. Each row in the array is
12163 indexed starting from 1 (row 0 is shared by the two tables).
12167 Hash table lookup is handled the same in version 1 and 2:
12169 We assume that N and M will not exceed 2^32 - 1.
12170 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12172 Given a 64-bit compilation unit signature or a type signature S, an entry
12173 in the hash table is located as follows:
12175 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12176 the low-order k bits all set to 1.
12178 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12180 3) If the hash table entry at index H matches the signature, use that
12181 entry. If the hash table entry at index H is unused (all zeroes),
12182 terminate the search: the signature is not present in the table.
12184 4) Let H = (H + H') modulo M. Repeat at Step 3.
12186 Because M > N and H' and M are relatively prime, the search is guaranteed
12187 to stop at an unused slot or find the match. */
12189 /* Create a hash table to map DWO IDs to their CU/TU entry in
12190 .debug_{info,types}.dwo in DWP_FILE.
12191 Returns NULL if there isn't one.
12192 Note: This function processes DWP files only, not DWO files. */
12194 static struct dwp_hash_table
*
12195 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12196 struct dwp_file
*dwp_file
, int is_debug_types
)
12198 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12199 bfd
*dbfd
= dwp_file
->dbfd
;
12200 const gdb_byte
*index_ptr
, *index_end
;
12201 struct dwarf2_section_info
*index
;
12202 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12203 struct dwp_hash_table
*htab
;
12205 if (is_debug_types
)
12206 index
= &dwp_file
->sections
.tu_index
;
12208 index
= &dwp_file
->sections
.cu_index
;
12210 if (dwarf2_section_empty_p (index
))
12212 dwarf2_read_section (objfile
, index
);
12214 index_ptr
= index
->buffer
;
12215 index_end
= index_ptr
+ index
->size
;
12217 version
= read_4_bytes (dbfd
, index_ptr
);
12220 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12224 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12226 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12229 if (version
!= 1 && version
!= 2)
12231 error (_("Dwarf Error: unsupported DWP file version (%s)"
12232 " [in module %s]"),
12233 pulongest (version
), dwp_file
->name
);
12235 if (nr_slots
!= (nr_slots
& -nr_slots
))
12237 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12238 " is not power of 2 [in module %s]"),
12239 pulongest (nr_slots
), dwp_file
->name
);
12242 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12243 htab
->version
= version
;
12244 htab
->nr_columns
= nr_columns
;
12245 htab
->nr_units
= nr_units
;
12246 htab
->nr_slots
= nr_slots
;
12247 htab
->hash_table
= index_ptr
;
12248 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12250 /* Exit early if the table is empty. */
12251 if (nr_slots
== 0 || nr_units
== 0
12252 || (version
== 2 && nr_columns
== 0))
12254 /* All must be zero. */
12255 if (nr_slots
!= 0 || nr_units
!= 0
12256 || (version
== 2 && nr_columns
!= 0))
12258 complaint (&symfile_complaints
,
12259 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12260 " all zero [in modules %s]"),
12268 htab
->section_pool
.v1
.indices
=
12269 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12270 /* It's harder to decide whether the section is too small in v1.
12271 V1 is deprecated anyway so we punt. */
12275 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12276 int *ids
= htab
->section_pool
.v2
.section_ids
;
12277 /* Reverse map for error checking. */
12278 int ids_seen
[DW_SECT_MAX
+ 1];
12281 if (nr_columns
< 2)
12283 error (_("Dwarf Error: bad DWP hash table, too few columns"
12284 " in section table [in module %s]"),
12287 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12289 error (_("Dwarf Error: bad DWP hash table, too many columns"
12290 " in section table [in module %s]"),
12293 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12294 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12295 for (i
= 0; i
< nr_columns
; ++i
)
12297 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12299 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12301 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12302 " in section table [in module %s]"),
12303 id
, dwp_file
->name
);
12305 if (ids_seen
[id
] != -1)
12307 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12308 " id %d in section table [in module %s]"),
12309 id
, dwp_file
->name
);
12314 /* Must have exactly one info or types section. */
12315 if (((ids_seen
[DW_SECT_INFO
] != -1)
12316 + (ids_seen
[DW_SECT_TYPES
] != -1))
12319 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12320 " DWO info/types section [in module %s]"),
12323 /* Must have an abbrev section. */
12324 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12326 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12327 " section [in module %s]"),
12330 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12331 htab
->section_pool
.v2
.sizes
=
12332 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12333 * nr_units
* nr_columns
);
12334 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12335 * nr_units
* nr_columns
))
12338 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12339 " [in module %s]"),
12347 /* Update SECTIONS with the data from SECTP.
12349 This function is like the other "locate" section routines that are
12350 passed to bfd_map_over_sections, but in this context the sections to
12351 read comes from the DWP V1 hash table, not the full ELF section table.
12353 The result is non-zero for success, or zero if an error was found. */
12356 locate_v1_virtual_dwo_sections (asection
*sectp
,
12357 struct virtual_v1_dwo_sections
*sections
)
12359 const struct dwop_section_names
*names
= &dwop_section_names
;
12361 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12363 /* There can be only one. */
12364 if (sections
->abbrev
.s
.section
!= NULL
)
12366 sections
->abbrev
.s
.section
= sectp
;
12367 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12369 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12370 || section_is_p (sectp
->name
, &names
->types_dwo
))
12372 /* There can be only one. */
12373 if (sections
->info_or_types
.s
.section
!= NULL
)
12375 sections
->info_or_types
.s
.section
= sectp
;
12376 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12378 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12380 /* There can be only one. */
12381 if (sections
->line
.s
.section
!= NULL
)
12383 sections
->line
.s
.section
= sectp
;
12384 sections
->line
.size
= bfd_get_section_size (sectp
);
12386 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12388 /* There can be only one. */
12389 if (sections
->loc
.s
.section
!= NULL
)
12391 sections
->loc
.s
.section
= sectp
;
12392 sections
->loc
.size
= bfd_get_section_size (sectp
);
12394 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12396 /* There can be only one. */
12397 if (sections
->macinfo
.s
.section
!= NULL
)
12399 sections
->macinfo
.s
.section
= sectp
;
12400 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12402 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12404 /* There can be only one. */
12405 if (sections
->macro
.s
.section
!= NULL
)
12407 sections
->macro
.s
.section
= sectp
;
12408 sections
->macro
.size
= bfd_get_section_size (sectp
);
12410 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12412 /* There can be only one. */
12413 if (sections
->str_offsets
.s
.section
!= NULL
)
12415 sections
->str_offsets
.s
.section
= sectp
;
12416 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12420 /* No other kind of section is valid. */
12427 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12428 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12429 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12430 This is for DWP version 1 files. */
12432 static struct dwo_unit
*
12433 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12434 struct dwp_file
*dwp_file
,
12435 uint32_t unit_index
,
12436 const char *comp_dir
,
12437 ULONGEST signature
, int is_debug_types
)
12439 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12440 const struct dwp_hash_table
*dwp_htab
=
12441 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12442 bfd
*dbfd
= dwp_file
->dbfd
;
12443 const char *kind
= is_debug_types
? "TU" : "CU";
12444 struct dwo_file
*dwo_file
;
12445 struct dwo_unit
*dwo_unit
;
12446 struct virtual_v1_dwo_sections sections
;
12447 void **dwo_file_slot
;
12450 gdb_assert (dwp_file
->version
== 1);
12452 if (dwarf_read_debug
)
12454 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12456 pulongest (unit_index
), hex_string (signature
),
12460 /* Fetch the sections of this DWO unit.
12461 Put a limit on the number of sections we look for so that bad data
12462 doesn't cause us to loop forever. */
12464 #define MAX_NR_V1_DWO_SECTIONS \
12465 (1 /* .debug_info or .debug_types */ \
12466 + 1 /* .debug_abbrev */ \
12467 + 1 /* .debug_line */ \
12468 + 1 /* .debug_loc */ \
12469 + 1 /* .debug_str_offsets */ \
12470 + 1 /* .debug_macro or .debug_macinfo */ \
12471 + 1 /* trailing zero */)
12473 memset (§ions
, 0, sizeof (sections
));
12475 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12478 uint32_t section_nr
=
12479 read_4_bytes (dbfd
,
12480 dwp_htab
->section_pool
.v1
.indices
12481 + (unit_index
+ i
) * sizeof (uint32_t));
12483 if (section_nr
== 0)
12485 if (section_nr
>= dwp_file
->num_sections
)
12487 error (_("Dwarf Error: bad DWP hash table, section number too large"
12488 " [in module %s]"),
12492 sectp
= dwp_file
->elf_sections
[section_nr
];
12493 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12495 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12496 " [in module %s]"),
12502 || dwarf2_section_empty_p (§ions
.info_or_types
)
12503 || dwarf2_section_empty_p (§ions
.abbrev
))
12505 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12506 " [in module %s]"),
12509 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12511 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12512 " [in module %s]"),
12516 /* It's easier for the rest of the code if we fake a struct dwo_file and
12517 have dwo_unit "live" in that. At least for now.
12519 The DWP file can be made up of a random collection of CUs and TUs.
12520 However, for each CU + set of TUs that came from the same original DWO
12521 file, we can combine them back into a virtual DWO file to save space
12522 (fewer struct dwo_file objects to allocate). Remember that for really
12523 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12525 std::string virtual_dwo_name
=
12526 string_printf ("virtual-dwo/%d-%d-%d-%d",
12527 get_section_id (§ions
.abbrev
),
12528 get_section_id (§ions
.line
),
12529 get_section_id (§ions
.loc
),
12530 get_section_id (§ions
.str_offsets
));
12531 /* Can we use an existing virtual DWO file? */
12532 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12533 virtual_dwo_name
.c_str (),
12535 /* Create one if necessary. */
12536 if (*dwo_file_slot
== NULL
)
12538 if (dwarf_read_debug
)
12540 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12541 virtual_dwo_name
.c_str ());
12543 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12545 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12546 virtual_dwo_name
.c_str (),
12547 virtual_dwo_name
.size ());
12548 dwo_file
->comp_dir
= comp_dir
;
12549 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12550 dwo_file
->sections
.line
= sections
.line
;
12551 dwo_file
->sections
.loc
= sections
.loc
;
12552 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12553 dwo_file
->sections
.macro
= sections
.macro
;
12554 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12555 /* The "str" section is global to the entire DWP file. */
12556 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12557 /* The info or types section is assigned below to dwo_unit,
12558 there's no need to record it in dwo_file.
12559 Also, we can't simply record type sections in dwo_file because
12560 we record a pointer into the vector in dwo_unit. As we collect more
12561 types we'll grow the vector and eventually have to reallocate space
12562 for it, invalidating all copies of pointers into the previous
12564 *dwo_file_slot
= dwo_file
;
12568 if (dwarf_read_debug
)
12570 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12571 virtual_dwo_name
.c_str ());
12573 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12576 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12577 dwo_unit
->dwo_file
= dwo_file
;
12578 dwo_unit
->signature
= signature
;
12579 dwo_unit
->section
=
12580 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12581 *dwo_unit
->section
= sections
.info_or_types
;
12582 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12587 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12588 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12589 piece within that section used by a TU/CU, return a virtual section
12590 of just that piece. */
12592 static struct dwarf2_section_info
12593 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12594 struct dwarf2_section_info
*section
,
12595 bfd_size_type offset
, bfd_size_type size
)
12597 struct dwarf2_section_info result
;
12600 gdb_assert (section
!= NULL
);
12601 gdb_assert (!section
->is_virtual
);
12603 memset (&result
, 0, sizeof (result
));
12604 result
.s
.containing_section
= section
;
12605 result
.is_virtual
= 1;
12610 sectp
= get_section_bfd_section (section
);
12612 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12613 bounds of the real section. This is a pretty-rare event, so just
12614 flag an error (easier) instead of a warning and trying to cope. */
12616 || offset
+ size
> bfd_get_section_size (sectp
))
12618 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12619 " in section %s [in module %s]"),
12620 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12621 objfile_name (dwarf2_per_objfile
->objfile
));
12624 result
.virtual_offset
= offset
;
12625 result
.size
= size
;
12629 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12630 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12631 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12632 This is for DWP version 2 files. */
12634 static struct dwo_unit
*
12635 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12636 struct dwp_file
*dwp_file
,
12637 uint32_t unit_index
,
12638 const char *comp_dir
,
12639 ULONGEST signature
, int is_debug_types
)
12641 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12642 const struct dwp_hash_table
*dwp_htab
=
12643 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12644 bfd
*dbfd
= dwp_file
->dbfd
;
12645 const char *kind
= is_debug_types
? "TU" : "CU";
12646 struct dwo_file
*dwo_file
;
12647 struct dwo_unit
*dwo_unit
;
12648 struct virtual_v2_dwo_sections sections
;
12649 void **dwo_file_slot
;
12652 gdb_assert (dwp_file
->version
== 2);
12654 if (dwarf_read_debug
)
12656 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12658 pulongest (unit_index
), hex_string (signature
),
12662 /* Fetch the section offsets of this DWO unit. */
12664 memset (§ions
, 0, sizeof (sections
));
12666 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12668 uint32_t offset
= read_4_bytes (dbfd
,
12669 dwp_htab
->section_pool
.v2
.offsets
12670 + (((unit_index
- 1) * dwp_htab
->nr_columns
12672 * sizeof (uint32_t)));
12673 uint32_t size
= read_4_bytes (dbfd
,
12674 dwp_htab
->section_pool
.v2
.sizes
12675 + (((unit_index
- 1) * dwp_htab
->nr_columns
12677 * sizeof (uint32_t)));
12679 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12682 case DW_SECT_TYPES
:
12683 sections
.info_or_types_offset
= offset
;
12684 sections
.info_or_types_size
= size
;
12686 case DW_SECT_ABBREV
:
12687 sections
.abbrev_offset
= offset
;
12688 sections
.abbrev_size
= size
;
12691 sections
.line_offset
= offset
;
12692 sections
.line_size
= size
;
12695 sections
.loc_offset
= offset
;
12696 sections
.loc_size
= size
;
12698 case DW_SECT_STR_OFFSETS
:
12699 sections
.str_offsets_offset
= offset
;
12700 sections
.str_offsets_size
= size
;
12702 case DW_SECT_MACINFO
:
12703 sections
.macinfo_offset
= offset
;
12704 sections
.macinfo_size
= size
;
12706 case DW_SECT_MACRO
:
12707 sections
.macro_offset
= offset
;
12708 sections
.macro_size
= size
;
12713 /* It's easier for the rest of the code if we fake a struct dwo_file and
12714 have dwo_unit "live" in that. At least for now.
12716 The DWP file can be made up of a random collection of CUs and TUs.
12717 However, for each CU + set of TUs that came from the same original DWO
12718 file, we can combine them back into a virtual DWO file to save space
12719 (fewer struct dwo_file objects to allocate). Remember that for really
12720 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12722 std::string virtual_dwo_name
=
12723 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12724 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12725 (long) (sections
.line_size
? sections
.line_offset
: 0),
12726 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12727 (long) (sections
.str_offsets_size
12728 ? sections
.str_offsets_offset
: 0));
12729 /* Can we use an existing virtual DWO file? */
12730 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12731 virtual_dwo_name
.c_str (),
12733 /* Create one if necessary. */
12734 if (*dwo_file_slot
== NULL
)
12736 if (dwarf_read_debug
)
12738 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12739 virtual_dwo_name
.c_str ());
12741 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12743 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12744 virtual_dwo_name
.c_str (),
12745 virtual_dwo_name
.size ());
12746 dwo_file
->comp_dir
= comp_dir
;
12747 dwo_file
->sections
.abbrev
=
12748 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12749 sections
.abbrev_offset
, sections
.abbrev_size
);
12750 dwo_file
->sections
.line
=
12751 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12752 sections
.line_offset
, sections
.line_size
);
12753 dwo_file
->sections
.loc
=
12754 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12755 sections
.loc_offset
, sections
.loc_size
);
12756 dwo_file
->sections
.macinfo
=
12757 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12758 sections
.macinfo_offset
, sections
.macinfo_size
);
12759 dwo_file
->sections
.macro
=
12760 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12761 sections
.macro_offset
, sections
.macro_size
);
12762 dwo_file
->sections
.str_offsets
=
12763 create_dwp_v2_section (dwarf2_per_objfile
,
12764 &dwp_file
->sections
.str_offsets
,
12765 sections
.str_offsets_offset
,
12766 sections
.str_offsets_size
);
12767 /* The "str" section is global to the entire DWP file. */
12768 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12769 /* The info or types section is assigned below to dwo_unit,
12770 there's no need to record it in dwo_file.
12771 Also, we can't simply record type sections in dwo_file because
12772 we record a pointer into the vector in dwo_unit. As we collect more
12773 types we'll grow the vector and eventually have to reallocate space
12774 for it, invalidating all copies of pointers into the previous
12776 *dwo_file_slot
= dwo_file
;
12780 if (dwarf_read_debug
)
12782 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12783 virtual_dwo_name
.c_str ());
12785 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12788 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12789 dwo_unit
->dwo_file
= dwo_file
;
12790 dwo_unit
->signature
= signature
;
12791 dwo_unit
->section
=
12792 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12793 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12795 ? &dwp_file
->sections
.types
12796 : &dwp_file
->sections
.info
,
12797 sections
.info_or_types_offset
,
12798 sections
.info_or_types_size
);
12799 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12804 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12805 Returns NULL if the signature isn't found. */
12807 static struct dwo_unit
*
12808 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12809 struct dwp_file
*dwp_file
, const char *comp_dir
,
12810 ULONGEST signature
, int is_debug_types
)
12812 const struct dwp_hash_table
*dwp_htab
=
12813 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12814 bfd
*dbfd
= dwp_file
->dbfd
;
12815 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12816 uint32_t hash
= signature
& mask
;
12817 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12820 struct dwo_unit find_dwo_cu
;
12822 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12823 find_dwo_cu
.signature
= signature
;
12824 slot
= htab_find_slot (is_debug_types
12825 ? dwp_file
->loaded_tus
12826 : dwp_file
->loaded_cus
,
12827 &find_dwo_cu
, INSERT
);
12830 return (struct dwo_unit
*) *slot
;
12832 /* Use a for loop so that we don't loop forever on bad debug info. */
12833 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12835 ULONGEST signature_in_table
;
12837 signature_in_table
=
12838 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12839 if (signature_in_table
== signature
)
12841 uint32_t unit_index
=
12842 read_4_bytes (dbfd
,
12843 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12845 if (dwp_file
->version
== 1)
12847 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12848 dwp_file
, unit_index
,
12849 comp_dir
, signature
,
12854 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12855 dwp_file
, unit_index
,
12856 comp_dir
, signature
,
12859 return (struct dwo_unit
*) *slot
;
12861 if (signature_in_table
== 0)
12863 hash
= (hash
+ hash2
) & mask
;
12866 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12867 " [in module %s]"),
12871 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12872 Open the file specified by FILE_NAME and hand it off to BFD for
12873 preliminary analysis. Return a newly initialized bfd *, which
12874 includes a canonicalized copy of FILE_NAME.
12875 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12876 SEARCH_CWD is true if the current directory is to be searched.
12877 It will be searched before debug-file-directory.
12878 If successful, the file is added to the bfd include table of the
12879 objfile's bfd (see gdb_bfd_record_inclusion).
12880 If unable to find/open the file, return NULL.
12881 NOTE: This function is derived from symfile_bfd_open. */
12883 static gdb_bfd_ref_ptr
12884 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12885 const char *file_name
, int is_dwp
, int search_cwd
)
12888 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12889 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12890 to debug_file_directory. */
12891 const char *search_path
;
12892 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12894 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12897 if (*debug_file_directory
!= '\0')
12899 search_path_holder
.reset (concat (".", dirname_separator_string
,
12900 debug_file_directory
,
12902 search_path
= search_path_holder
.get ();
12908 search_path
= debug_file_directory
;
12910 openp_flags flags
= OPF_RETURN_REALPATH
;
12912 flags
|= OPF_SEARCH_IN_PATH
;
12914 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12915 desc
= openp (search_path
, flags
, file_name
,
12916 O_RDONLY
| O_BINARY
, &absolute_name
);
12920 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12922 if (sym_bfd
== NULL
)
12924 bfd_set_cacheable (sym_bfd
.get (), 1);
12926 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12929 /* Success. Record the bfd as having been included by the objfile's bfd.
12930 This is important because things like demangled_names_hash lives in the
12931 objfile's per_bfd space and may have references to things like symbol
12932 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12933 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12938 /* Try to open DWO file FILE_NAME.
12939 COMP_DIR is the DW_AT_comp_dir attribute.
12940 The result is the bfd handle of the file.
12941 If there is a problem finding or opening the file, return NULL.
12942 Upon success, the canonicalized path of the file is stored in the bfd,
12943 same as symfile_bfd_open. */
12945 static gdb_bfd_ref_ptr
12946 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12947 const char *file_name
, const char *comp_dir
)
12949 if (IS_ABSOLUTE_PATH (file_name
))
12950 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12951 0 /*is_dwp*/, 0 /*search_cwd*/);
12953 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12955 if (comp_dir
!= NULL
)
12957 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12958 file_name
, (char *) NULL
);
12960 /* NOTE: If comp_dir is a relative path, this will also try the
12961 search path, which seems useful. */
12962 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12965 1 /*search_cwd*/));
12966 xfree (path_to_try
);
12971 /* That didn't work, try debug-file-directory, which, despite its name,
12972 is a list of paths. */
12974 if (*debug_file_directory
== '\0')
12977 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12978 0 /*is_dwp*/, 1 /*search_cwd*/);
12981 /* This function is mapped across the sections and remembers the offset and
12982 size of each of the DWO debugging sections we are interested in. */
12985 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12987 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12988 const struct dwop_section_names
*names
= &dwop_section_names
;
12990 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12992 dwo_sections
->abbrev
.s
.section
= sectp
;
12993 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12995 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12997 dwo_sections
->info
.s
.section
= sectp
;
12998 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
13000 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13002 dwo_sections
->line
.s
.section
= sectp
;
13003 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
13005 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13007 dwo_sections
->loc
.s
.section
= sectp
;
13008 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
13010 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13012 dwo_sections
->macinfo
.s
.section
= sectp
;
13013 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
13015 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13017 dwo_sections
->macro
.s
.section
= sectp
;
13018 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
13020 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13022 dwo_sections
->str
.s
.section
= sectp
;
13023 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
13025 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13027 dwo_sections
->str_offsets
.s
.section
= sectp
;
13028 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
13030 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13032 struct dwarf2_section_info type_section
;
13034 memset (&type_section
, 0, sizeof (type_section
));
13035 type_section
.s
.section
= sectp
;
13036 type_section
.size
= bfd_get_section_size (sectp
);
13037 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
13042 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13043 by PER_CU. This is for the non-DWP case.
13044 The result is NULL if DWO_NAME can't be found. */
13046 static struct dwo_file
*
13047 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13048 const char *dwo_name
, const char *comp_dir
)
13050 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13051 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13052 struct dwo_file
*dwo_file
;
13053 struct cleanup
*cleanups
;
13055 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
13058 if (dwarf_read_debug
)
13059 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13062 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13063 dwo_file
->dwo_name
= dwo_name
;
13064 dwo_file
->comp_dir
= comp_dir
;
13065 dwo_file
->dbfd
= dbfd
.release ();
13067 free_dwo_file_cleanup_data
*cleanup_data
= XNEW (free_dwo_file_cleanup_data
);
13068 cleanup_data
->dwo_file
= dwo_file
;
13069 cleanup_data
->dwarf2_per_objfile
= dwarf2_per_objfile
;
13071 cleanups
= make_cleanup (free_dwo_file_cleanup
, cleanup_data
);
13073 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13074 &dwo_file
->sections
);
13076 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13079 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
,
13080 dwo_file
->sections
.types
, dwo_file
->tus
);
13082 discard_cleanups (cleanups
);
13084 if (dwarf_read_debug
)
13085 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13090 /* This function is mapped across the sections and remembers the offset and
13091 size of each of the DWP debugging sections common to version 1 and 2 that
13092 we are interested in. */
13095 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13096 void *dwp_file_ptr
)
13098 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13099 const struct dwop_section_names
*names
= &dwop_section_names
;
13100 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13102 /* Record the ELF section number for later lookup: this is what the
13103 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13104 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13105 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13107 /* Look for specific sections that we need. */
13108 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13110 dwp_file
->sections
.str
.s
.section
= sectp
;
13111 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13113 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13115 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13116 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13118 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13120 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13121 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13125 /* This function is mapped across the sections and remembers the offset and
13126 size of each of the DWP version 2 debugging sections that we are interested
13127 in. This is split into a separate function because we don't know if we
13128 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13131 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13133 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13134 const struct dwop_section_names
*names
= &dwop_section_names
;
13135 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13137 /* Record the ELF section number for later lookup: this is what the
13138 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13139 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13140 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13142 /* Look for specific sections that we need. */
13143 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13145 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13146 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13148 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13150 dwp_file
->sections
.info
.s
.section
= sectp
;
13151 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13153 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13155 dwp_file
->sections
.line
.s
.section
= sectp
;
13156 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13158 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13160 dwp_file
->sections
.loc
.s
.section
= sectp
;
13161 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13163 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13165 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13166 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13168 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13170 dwp_file
->sections
.macro
.s
.section
= sectp
;
13171 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13173 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13175 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13176 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13178 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13180 dwp_file
->sections
.types
.s
.section
= sectp
;
13181 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13185 /* Hash function for dwp_file loaded CUs/TUs. */
13188 hash_dwp_loaded_cutus (const void *item
)
13190 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13192 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13193 return dwo_unit
->signature
;
13196 /* Equality function for dwp_file loaded CUs/TUs. */
13199 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13201 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13202 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13204 return dua
->signature
== dub
->signature
;
13207 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13210 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13212 return htab_create_alloc_ex (3,
13213 hash_dwp_loaded_cutus
,
13214 eq_dwp_loaded_cutus
,
13216 &objfile
->objfile_obstack
,
13217 hashtab_obstack_allocate
,
13218 dummy_obstack_deallocate
);
13221 /* Try to open DWP file FILE_NAME.
13222 The result is the bfd handle of the file.
13223 If there is a problem finding or opening the file, return NULL.
13224 Upon success, the canonicalized path of the file is stored in the bfd,
13225 same as symfile_bfd_open. */
13227 static gdb_bfd_ref_ptr
13228 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13229 const char *file_name
)
13231 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13233 1 /*search_cwd*/));
13237 /* Work around upstream bug 15652.
13238 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13239 [Whether that's a "bug" is debatable, but it is getting in our way.]
13240 We have no real idea where the dwp file is, because gdb's realpath-ing
13241 of the executable's path may have discarded the needed info.
13242 [IWBN if the dwp file name was recorded in the executable, akin to
13243 .gnu_debuglink, but that doesn't exist yet.]
13244 Strip the directory from FILE_NAME and search again. */
13245 if (*debug_file_directory
!= '\0')
13247 /* Don't implicitly search the current directory here.
13248 If the user wants to search "." to handle this case,
13249 it must be added to debug-file-directory. */
13250 return try_open_dwop_file (dwarf2_per_objfile
,
13251 lbasename (file_name
), 1 /*is_dwp*/,
13258 /* Initialize the use of the DWP file for the current objfile.
13259 By convention the name of the DWP file is ${objfile}.dwp.
13260 The result is NULL if it can't be found. */
13262 static struct dwp_file
*
13263 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13265 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13266 struct dwp_file
*dwp_file
;
13268 /* Try to find first .dwp for the binary file before any symbolic links
13271 /* If the objfile is a debug file, find the name of the real binary
13272 file and get the name of dwp file from there. */
13273 std::string dwp_name
;
13274 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13276 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13277 const char *backlink_basename
= lbasename (backlink
->original_name
);
13279 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13282 dwp_name
= objfile
->original_name
;
13284 dwp_name
+= ".dwp";
13286 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13288 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13290 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13291 dwp_name
= objfile_name (objfile
);
13292 dwp_name
+= ".dwp";
13293 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13298 if (dwarf_read_debug
)
13299 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13302 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13303 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13304 dwp_file
->dbfd
= dbfd
.release ();
13306 /* +1: section 0 is unused */
13307 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13308 dwp_file
->elf_sections
=
13309 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13310 dwp_file
->num_sections
, asection
*);
13312 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13315 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13317 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13319 /* The DWP file version is stored in the hash table. Oh well. */
13320 if (dwp_file
->cus
&& dwp_file
->tus
13321 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13323 /* Technically speaking, we should try to limp along, but this is
13324 pretty bizarre. We use pulongest here because that's the established
13325 portability solution (e.g, we cannot use %u for uint32_t). */
13326 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13327 " TU version %s [in DWP file %s]"),
13328 pulongest (dwp_file
->cus
->version
),
13329 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13333 dwp_file
->version
= dwp_file
->cus
->version
;
13334 else if (dwp_file
->tus
)
13335 dwp_file
->version
= dwp_file
->tus
->version
;
13337 dwp_file
->version
= 2;
13339 if (dwp_file
->version
== 2)
13340 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13343 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13344 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13346 if (dwarf_read_debug
)
13348 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13349 fprintf_unfiltered (gdb_stdlog
,
13350 " %s CUs, %s TUs\n",
13351 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13352 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13358 /* Wrapper around open_and_init_dwp_file, only open it once. */
13360 static struct dwp_file
*
13361 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13363 if (! dwarf2_per_objfile
->dwp_checked
)
13365 dwarf2_per_objfile
->dwp_file
13366 = open_and_init_dwp_file (dwarf2_per_objfile
);
13367 dwarf2_per_objfile
->dwp_checked
= 1;
13369 return dwarf2_per_objfile
->dwp_file
;
13372 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13373 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13374 or in the DWP file for the objfile, referenced by THIS_UNIT.
13375 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13376 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13378 This is called, for example, when wanting to read a variable with a
13379 complex location. Therefore we don't want to do file i/o for every call.
13380 Therefore we don't want to look for a DWO file on every call.
13381 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13382 then we check if we've already seen DWO_NAME, and only THEN do we check
13385 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13386 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13388 static struct dwo_unit
*
13389 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13390 const char *dwo_name
, const char *comp_dir
,
13391 ULONGEST signature
, int is_debug_types
)
13393 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13394 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13395 const char *kind
= is_debug_types
? "TU" : "CU";
13396 void **dwo_file_slot
;
13397 struct dwo_file
*dwo_file
;
13398 struct dwp_file
*dwp_file
;
13400 /* First see if there's a DWP file.
13401 If we have a DWP file but didn't find the DWO inside it, don't
13402 look for the original DWO file. It makes gdb behave differently
13403 depending on whether one is debugging in the build tree. */
13405 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13406 if (dwp_file
!= NULL
)
13408 const struct dwp_hash_table
*dwp_htab
=
13409 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13411 if (dwp_htab
!= NULL
)
13413 struct dwo_unit
*dwo_cutu
=
13414 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13415 signature
, is_debug_types
);
13417 if (dwo_cutu
!= NULL
)
13419 if (dwarf_read_debug
)
13421 fprintf_unfiltered (gdb_stdlog
,
13422 "Virtual DWO %s %s found: @%s\n",
13423 kind
, hex_string (signature
),
13424 host_address_to_string (dwo_cutu
));
13432 /* No DWP file, look for the DWO file. */
13434 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13435 dwo_name
, comp_dir
);
13436 if (*dwo_file_slot
== NULL
)
13438 /* Read in the file and build a table of the CUs/TUs it contains. */
13439 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13441 /* NOTE: This will be NULL if unable to open the file. */
13442 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13444 if (dwo_file
!= NULL
)
13446 struct dwo_unit
*dwo_cutu
= NULL
;
13448 if (is_debug_types
&& dwo_file
->tus
)
13450 struct dwo_unit find_dwo_cutu
;
13452 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13453 find_dwo_cutu
.signature
= signature
;
13455 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13457 else if (!is_debug_types
&& dwo_file
->cus
)
13459 struct dwo_unit find_dwo_cutu
;
13461 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13462 find_dwo_cutu
.signature
= signature
;
13463 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13467 if (dwo_cutu
!= NULL
)
13469 if (dwarf_read_debug
)
13471 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13472 kind
, dwo_name
, hex_string (signature
),
13473 host_address_to_string (dwo_cutu
));
13480 /* We didn't find it. This could mean a dwo_id mismatch, or
13481 someone deleted the DWO/DWP file, or the search path isn't set up
13482 correctly to find the file. */
13484 if (dwarf_read_debug
)
13486 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13487 kind
, dwo_name
, hex_string (signature
));
13490 /* This is a warning and not a complaint because it can be caused by
13491 pilot error (e.g., user accidentally deleting the DWO). */
13493 /* Print the name of the DWP file if we looked there, helps the user
13494 better diagnose the problem. */
13495 std::string dwp_text
;
13497 if (dwp_file
!= NULL
)
13498 dwp_text
= string_printf (" [in DWP file %s]",
13499 lbasename (dwp_file
->name
));
13501 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13502 " [in module %s]"),
13503 kind
, dwo_name
, hex_string (signature
),
13505 this_unit
->is_debug_types
? "TU" : "CU",
13506 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13511 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13512 See lookup_dwo_cutu_unit for details. */
13514 static struct dwo_unit
*
13515 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13516 const char *dwo_name
, const char *comp_dir
,
13517 ULONGEST signature
)
13519 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13522 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13523 See lookup_dwo_cutu_unit for details. */
13525 static struct dwo_unit
*
13526 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13527 const char *dwo_name
, const char *comp_dir
)
13529 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13532 /* Traversal function for queue_and_load_all_dwo_tus. */
13535 queue_and_load_dwo_tu (void **slot
, void *info
)
13537 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13538 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13539 ULONGEST signature
= dwo_unit
->signature
;
13540 struct signatured_type
*sig_type
=
13541 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13543 if (sig_type
!= NULL
)
13545 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13547 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13548 a real dependency of PER_CU on SIG_TYPE. That is detected later
13549 while processing PER_CU. */
13550 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13551 load_full_type_unit (sig_cu
);
13552 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13558 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13559 The DWO may have the only definition of the type, though it may not be
13560 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13561 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13564 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13566 struct dwo_unit
*dwo_unit
;
13567 struct dwo_file
*dwo_file
;
13569 gdb_assert (!per_cu
->is_debug_types
);
13570 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13571 gdb_assert (per_cu
->cu
!= NULL
);
13573 dwo_unit
= per_cu
->cu
->dwo_unit
;
13574 gdb_assert (dwo_unit
!= NULL
);
13576 dwo_file
= dwo_unit
->dwo_file
;
13577 if (dwo_file
->tus
!= NULL
)
13578 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13581 /* Free all resources associated with DWO_FILE.
13582 Close the DWO file and munmap the sections.
13583 All memory should be on the objfile obstack. */
13586 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
13589 /* Note: dbfd is NULL for virtual DWO files. */
13590 gdb_bfd_unref (dwo_file
->dbfd
);
13592 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13595 /* Wrapper for free_dwo_file for use in cleanups. */
13598 free_dwo_file_cleanup (void *arg
)
13600 struct free_dwo_file_cleanup_data
*data
13601 = (struct free_dwo_file_cleanup_data
*) arg
;
13602 struct objfile
*objfile
= data
->dwarf2_per_objfile
->objfile
;
13604 free_dwo_file (data
->dwo_file
, objfile
);
13609 /* Traversal function for free_dwo_files. */
13612 free_dwo_file_from_slot (void **slot
, void *info
)
13614 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13615 struct objfile
*objfile
= (struct objfile
*) info
;
13617 free_dwo_file (dwo_file
, objfile
);
13622 /* Free all resources associated with DWO_FILES. */
13625 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13627 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13630 /* Read in various DIEs. */
13632 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13633 Inherit only the children of the DW_AT_abstract_origin DIE not being
13634 already referenced by DW_AT_abstract_origin from the children of the
13638 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13640 struct die_info
*child_die
;
13641 sect_offset
*offsetp
;
13642 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13643 struct die_info
*origin_die
;
13644 /* Iterator of the ORIGIN_DIE children. */
13645 struct die_info
*origin_child_die
;
13646 struct attribute
*attr
;
13647 struct dwarf2_cu
*origin_cu
;
13648 struct pending
**origin_previous_list_in_scope
;
13650 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13654 /* Note that following die references may follow to a die in a
13658 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13660 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13662 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13663 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13665 if (die
->tag
!= origin_die
->tag
13666 && !(die
->tag
== DW_TAG_inlined_subroutine
13667 && origin_die
->tag
== DW_TAG_subprogram
))
13668 complaint (&symfile_complaints
,
13669 _("DIE %s and its abstract origin %s have different tags"),
13670 sect_offset_str (die
->sect_off
),
13671 sect_offset_str (origin_die
->sect_off
));
13673 std::vector
<sect_offset
> offsets
;
13675 for (child_die
= die
->child
;
13676 child_die
&& child_die
->tag
;
13677 child_die
= sibling_die (child_die
))
13679 struct die_info
*child_origin_die
;
13680 struct dwarf2_cu
*child_origin_cu
;
13682 /* We are trying to process concrete instance entries:
13683 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13684 it's not relevant to our analysis here. i.e. detecting DIEs that are
13685 present in the abstract instance but not referenced in the concrete
13687 if (child_die
->tag
== DW_TAG_call_site
13688 || child_die
->tag
== DW_TAG_GNU_call_site
)
13691 /* For each CHILD_DIE, find the corresponding child of
13692 ORIGIN_DIE. If there is more than one layer of
13693 DW_AT_abstract_origin, follow them all; there shouldn't be,
13694 but GCC versions at least through 4.4 generate this (GCC PR
13696 child_origin_die
= child_die
;
13697 child_origin_cu
= cu
;
13700 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13704 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13708 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13709 counterpart may exist. */
13710 if (child_origin_die
!= child_die
)
13712 if (child_die
->tag
!= child_origin_die
->tag
13713 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13714 && child_origin_die
->tag
== DW_TAG_subprogram
))
13715 complaint (&symfile_complaints
,
13716 _("Child DIE %s and its abstract origin %s have "
13718 sect_offset_str (child_die
->sect_off
),
13719 sect_offset_str (child_origin_die
->sect_off
));
13720 if (child_origin_die
->parent
!= origin_die
)
13721 complaint (&symfile_complaints
,
13722 _("Child DIE %s and its abstract origin %s have "
13723 "different parents"),
13724 sect_offset_str (child_die
->sect_off
),
13725 sect_offset_str (child_origin_die
->sect_off
));
13727 offsets
.push_back (child_origin_die
->sect_off
);
13730 std::sort (offsets
.begin (), offsets
.end ());
13731 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13732 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13733 if (offsetp
[-1] == *offsetp
)
13734 complaint (&symfile_complaints
,
13735 _("Multiple children of DIE %s refer "
13736 "to DIE %s as their abstract origin"),
13737 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13739 offsetp
= offsets
.data ();
13740 origin_child_die
= origin_die
->child
;
13741 while (origin_child_die
&& origin_child_die
->tag
)
13743 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13744 while (offsetp
< offsets_end
13745 && *offsetp
< origin_child_die
->sect_off
)
13747 if (offsetp
>= offsets_end
13748 || *offsetp
> origin_child_die
->sect_off
)
13750 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13751 Check whether we're already processing ORIGIN_CHILD_DIE.
13752 This can happen with mutually referenced abstract_origins.
13754 if (!origin_child_die
->in_process
)
13755 process_die (origin_child_die
, origin_cu
);
13757 origin_child_die
= sibling_die (origin_child_die
);
13759 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13763 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13765 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13766 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13767 struct context_stack
*newobj
;
13770 struct die_info
*child_die
;
13771 struct attribute
*attr
, *call_line
, *call_file
;
13773 CORE_ADDR baseaddr
;
13774 struct block
*block
;
13775 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13776 std::vector
<struct symbol
*> template_args
;
13777 struct template_symbol
*templ_func
= NULL
;
13781 /* If we do not have call site information, we can't show the
13782 caller of this inlined function. That's too confusing, so
13783 only use the scope for local variables. */
13784 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13785 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13786 if (call_line
== NULL
|| call_file
== NULL
)
13788 read_lexical_block_scope (die
, cu
);
13793 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13795 name
= dwarf2_name (die
, cu
);
13797 /* Ignore functions with missing or empty names. These are actually
13798 illegal according to the DWARF standard. */
13801 complaint (&symfile_complaints
,
13802 _("missing name for subprogram DIE at %s"),
13803 sect_offset_str (die
->sect_off
));
13807 /* Ignore functions with missing or invalid low and high pc attributes. */
13808 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13809 <= PC_BOUNDS_INVALID
)
13811 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13812 if (!attr
|| !DW_UNSND (attr
))
13813 complaint (&symfile_complaints
,
13814 _("cannot get low and high bounds "
13815 "for subprogram DIE at %s"),
13816 sect_offset_str (die
->sect_off
));
13820 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13821 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13823 /* If we have any template arguments, then we must allocate a
13824 different sort of symbol. */
13825 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13827 if (child_die
->tag
== DW_TAG_template_type_param
13828 || child_die
->tag
== DW_TAG_template_value_param
)
13830 templ_func
= allocate_template_symbol (objfile
);
13831 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13836 newobj
= push_context (0, lowpc
);
13837 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13838 (struct symbol
*) templ_func
);
13840 /* If there is a location expression for DW_AT_frame_base, record
13842 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13844 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13846 /* If there is a location for the static link, record it. */
13847 newobj
->static_link
= NULL
;
13848 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13851 newobj
->static_link
13852 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13853 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
13856 cu
->list_in_scope
= &local_symbols
;
13858 if (die
->child
!= NULL
)
13860 child_die
= die
->child
;
13861 while (child_die
&& child_die
->tag
)
13863 if (child_die
->tag
== DW_TAG_template_type_param
13864 || child_die
->tag
== DW_TAG_template_value_param
)
13866 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13869 template_args
.push_back (arg
);
13872 process_die (child_die
, cu
);
13873 child_die
= sibling_die (child_die
);
13877 inherit_abstract_dies (die
, cu
);
13879 /* If we have a DW_AT_specification, we might need to import using
13880 directives from the context of the specification DIE. See the
13881 comment in determine_prefix. */
13882 if (cu
->language
== language_cplus
13883 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13885 struct dwarf2_cu
*spec_cu
= cu
;
13886 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13890 child_die
= spec_die
->child
;
13891 while (child_die
&& child_die
->tag
)
13893 if (child_die
->tag
== DW_TAG_imported_module
)
13894 process_die (child_die
, spec_cu
);
13895 child_die
= sibling_die (child_die
);
13898 /* In some cases, GCC generates specification DIEs that
13899 themselves contain DW_AT_specification attributes. */
13900 spec_die
= die_specification (spec_die
, &spec_cu
);
13904 newobj
= pop_context ();
13905 /* Make a block for the local symbols within. */
13906 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
13907 newobj
->static_link
, lowpc
, highpc
);
13909 /* For C++, set the block's scope. */
13910 if ((cu
->language
== language_cplus
13911 || cu
->language
== language_fortran
13912 || cu
->language
== language_d
13913 || cu
->language
== language_rust
)
13914 && cu
->processing_has_namespace_info
)
13915 block_set_scope (block
, determine_prefix (die
, cu
),
13916 &objfile
->objfile_obstack
);
13918 /* If we have address ranges, record them. */
13919 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13921 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
13923 /* Attach template arguments to function. */
13924 if (!template_args
.empty ())
13926 gdb_assert (templ_func
!= NULL
);
13928 templ_func
->n_template_arguments
= template_args
.size ();
13929 templ_func
->template_arguments
13930 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13931 templ_func
->n_template_arguments
);
13932 memcpy (templ_func
->template_arguments
,
13933 template_args
.data (),
13934 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13937 /* In C++, we can have functions nested inside functions (e.g., when
13938 a function declares a class that has methods). This means that
13939 when we finish processing a function scope, we may need to go
13940 back to building a containing block's symbol lists. */
13941 local_symbols
= newobj
->locals
;
13942 local_using_directives
= newobj
->local_using_directives
;
13944 /* If we've finished processing a top-level function, subsequent
13945 symbols go in the file symbol list. */
13946 if (outermost_context_p ())
13947 cu
->list_in_scope
= &file_symbols
;
13950 /* Process all the DIES contained within a lexical block scope. Start
13951 a new scope, process the dies, and then close the scope. */
13954 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13956 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13957 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13958 struct context_stack
*newobj
;
13959 CORE_ADDR lowpc
, highpc
;
13960 struct die_info
*child_die
;
13961 CORE_ADDR baseaddr
;
13963 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13965 /* Ignore blocks with missing or invalid low and high pc attributes. */
13966 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13967 as multiple lexical blocks? Handling children in a sane way would
13968 be nasty. Might be easier to properly extend generic blocks to
13969 describe ranges. */
13970 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13972 case PC_BOUNDS_NOT_PRESENT
:
13973 /* DW_TAG_lexical_block has no attributes, process its children as if
13974 there was no wrapping by that DW_TAG_lexical_block.
13975 GCC does no longer produces such DWARF since GCC r224161. */
13976 for (child_die
= die
->child
;
13977 child_die
!= NULL
&& child_die
->tag
;
13978 child_die
= sibling_die (child_die
))
13979 process_die (child_die
, cu
);
13981 case PC_BOUNDS_INVALID
:
13984 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13985 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13987 push_context (0, lowpc
);
13988 if (die
->child
!= NULL
)
13990 child_die
= die
->child
;
13991 while (child_die
&& child_die
->tag
)
13993 process_die (child_die
, cu
);
13994 child_die
= sibling_die (child_die
);
13997 inherit_abstract_dies (die
, cu
);
13998 newobj
= pop_context ();
14000 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
14002 struct block
*block
14003 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
14004 newobj
->start_addr
, highpc
);
14006 /* Note that recording ranges after traversing children, as we
14007 do here, means that recording a parent's ranges entails
14008 walking across all its children's ranges as they appear in
14009 the address map, which is quadratic behavior.
14011 It would be nicer to record the parent's ranges before
14012 traversing its children, simply overriding whatever you find
14013 there. But since we don't even decide whether to create a
14014 block until after we've traversed its children, that's hard
14016 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14018 local_symbols
= newobj
->locals
;
14019 local_using_directives
= newobj
->local_using_directives
;
14022 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
14025 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14027 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14028 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14029 CORE_ADDR pc
, baseaddr
;
14030 struct attribute
*attr
;
14031 struct call_site
*call_site
, call_site_local
;
14034 struct die_info
*child_die
;
14036 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14038 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
14041 /* This was a pre-DWARF-5 GNU extension alias
14042 for DW_AT_call_return_pc. */
14043 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14047 complaint (&symfile_complaints
,
14048 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
14049 "DIE %s [in module %s]"),
14050 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14053 pc
= attr_value_as_address (attr
) + baseaddr
;
14054 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14056 if (cu
->call_site_htab
== NULL
)
14057 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14058 NULL
, &objfile
->objfile_obstack
,
14059 hashtab_obstack_allocate
, NULL
);
14060 call_site_local
.pc
= pc
;
14061 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14064 complaint (&symfile_complaints
,
14065 _("Duplicate PC %s for DW_TAG_call_site "
14066 "DIE %s [in module %s]"),
14067 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14068 objfile_name (objfile
));
14072 /* Count parameters at the caller. */
14075 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14076 child_die
= sibling_die (child_die
))
14078 if (child_die
->tag
!= DW_TAG_call_site_parameter
14079 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14081 complaint (&symfile_complaints
,
14082 _("Tag %d is not DW_TAG_call_site_parameter in "
14083 "DW_TAG_call_site child DIE %s [in module %s]"),
14084 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14085 objfile_name (objfile
));
14093 = ((struct call_site
*)
14094 obstack_alloc (&objfile
->objfile_obstack
,
14095 sizeof (*call_site
)
14096 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14098 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14099 call_site
->pc
= pc
;
14101 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14102 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14104 struct die_info
*func_die
;
14106 /* Skip also over DW_TAG_inlined_subroutine. */
14107 for (func_die
= die
->parent
;
14108 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14109 && func_die
->tag
!= DW_TAG_subroutine_type
;
14110 func_die
= func_die
->parent
);
14112 /* DW_AT_call_all_calls is a superset
14113 of DW_AT_call_all_tail_calls. */
14115 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14116 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14117 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14118 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14120 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14121 not complete. But keep CALL_SITE for look ups via call_site_htab,
14122 both the initial caller containing the real return address PC and
14123 the final callee containing the current PC of a chain of tail
14124 calls do not need to have the tail call list complete. But any
14125 function candidate for a virtual tail call frame searched via
14126 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14127 determined unambiguously. */
14131 struct type
*func_type
= NULL
;
14134 func_type
= get_die_type (func_die
, cu
);
14135 if (func_type
!= NULL
)
14137 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14139 /* Enlist this call site to the function. */
14140 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14141 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14144 complaint (&symfile_complaints
,
14145 _("Cannot find function owning DW_TAG_call_site "
14146 "DIE %s [in module %s]"),
14147 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14151 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14153 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14155 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14158 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14159 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14161 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14162 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14163 /* Keep NULL DWARF_BLOCK. */;
14164 else if (attr_form_is_block (attr
))
14166 struct dwarf2_locexpr_baton
*dlbaton
;
14168 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14169 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14170 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14171 dlbaton
->per_cu
= cu
->per_cu
;
14173 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14175 else if (attr_form_is_ref (attr
))
14177 struct dwarf2_cu
*target_cu
= cu
;
14178 struct die_info
*target_die
;
14180 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14181 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14182 if (die_is_declaration (target_die
, target_cu
))
14184 const char *target_physname
;
14186 /* Prefer the mangled name; otherwise compute the demangled one. */
14187 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14188 if (target_physname
== NULL
)
14189 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14190 if (target_physname
== NULL
)
14191 complaint (&symfile_complaints
,
14192 _("DW_AT_call_target target DIE has invalid "
14193 "physname, for referencing DIE %s [in module %s]"),
14194 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14196 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14202 /* DW_AT_entry_pc should be preferred. */
14203 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14204 <= PC_BOUNDS_INVALID
)
14205 complaint (&symfile_complaints
,
14206 _("DW_AT_call_target target DIE has invalid "
14207 "low pc, for referencing DIE %s [in module %s]"),
14208 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14211 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14212 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14217 complaint (&symfile_complaints
,
14218 _("DW_TAG_call_site DW_AT_call_target is neither "
14219 "block nor reference, for DIE %s [in module %s]"),
14220 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14222 call_site
->per_cu
= cu
->per_cu
;
14224 for (child_die
= die
->child
;
14225 child_die
&& child_die
->tag
;
14226 child_die
= sibling_die (child_die
))
14228 struct call_site_parameter
*parameter
;
14229 struct attribute
*loc
, *origin
;
14231 if (child_die
->tag
!= DW_TAG_call_site_parameter
14232 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14234 /* Already printed the complaint above. */
14238 gdb_assert (call_site
->parameter_count
< nparams
);
14239 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14241 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14242 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14243 register is contained in DW_AT_call_value. */
14245 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14246 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14247 if (origin
== NULL
)
14249 /* This was a pre-DWARF-5 GNU extension alias
14250 for DW_AT_call_parameter. */
14251 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14253 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14255 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14257 sect_offset sect_off
14258 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14259 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14261 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14262 binding can be done only inside one CU. Such referenced DIE
14263 therefore cannot be even moved to DW_TAG_partial_unit. */
14264 complaint (&symfile_complaints
,
14265 _("DW_AT_call_parameter offset is not in CU for "
14266 "DW_TAG_call_site child DIE %s [in module %s]"),
14267 sect_offset_str (child_die
->sect_off
),
14268 objfile_name (objfile
));
14271 parameter
->u
.param_cu_off
14272 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14274 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14276 complaint (&symfile_complaints
,
14277 _("No DW_FORM_block* DW_AT_location for "
14278 "DW_TAG_call_site child DIE %s [in module %s]"),
14279 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14284 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14285 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14286 if (parameter
->u
.dwarf_reg
!= -1)
14287 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14288 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14289 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14290 ¶meter
->u
.fb_offset
))
14291 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14294 complaint (&symfile_complaints
,
14295 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14296 "for DW_FORM_block* DW_AT_location is supported for "
14297 "DW_TAG_call_site child DIE %s "
14299 sect_offset_str (child_die
->sect_off
),
14300 objfile_name (objfile
));
14305 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14307 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14308 if (!attr_form_is_block (attr
))
14310 complaint (&symfile_complaints
,
14311 _("No DW_FORM_block* DW_AT_call_value for "
14312 "DW_TAG_call_site child DIE %s [in module %s]"),
14313 sect_offset_str (child_die
->sect_off
),
14314 objfile_name (objfile
));
14317 parameter
->value
= DW_BLOCK (attr
)->data
;
14318 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14320 /* Parameters are not pre-cleared by memset above. */
14321 parameter
->data_value
= NULL
;
14322 parameter
->data_value_size
= 0;
14323 call_site
->parameter_count
++;
14325 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14327 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14330 if (!attr_form_is_block (attr
))
14331 complaint (&symfile_complaints
,
14332 _("No DW_FORM_block* DW_AT_call_data_value for "
14333 "DW_TAG_call_site child DIE %s [in module %s]"),
14334 sect_offset_str (child_die
->sect_off
),
14335 objfile_name (objfile
));
14338 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14339 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14345 /* Helper function for read_variable. If DIE represents a virtual
14346 table, then return the type of the concrete object that is
14347 associated with the virtual table. Otherwise, return NULL. */
14349 static struct type
*
14350 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14352 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14356 /* Find the type DIE. */
14357 struct die_info
*type_die
= NULL
;
14358 struct dwarf2_cu
*type_cu
= cu
;
14360 if (attr_form_is_ref (attr
))
14361 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14362 if (type_die
== NULL
)
14365 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14367 return die_containing_type (type_die
, type_cu
);
14370 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14373 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14375 struct rust_vtable_symbol
*storage
= NULL
;
14377 if (cu
->language
== language_rust
)
14379 struct type
*containing_type
= rust_containing_type (die
, cu
);
14381 if (containing_type
!= NULL
)
14383 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14385 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14386 struct rust_vtable_symbol
);
14387 initialize_objfile_symbol (storage
);
14388 storage
->concrete_type
= containing_type
;
14389 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14393 new_symbol (die
, NULL
, cu
, storage
);
14396 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14397 reading .debug_rnglists.
14398 Callback's type should be:
14399 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14400 Return true if the attributes are present and valid, otherwise,
14403 template <typename Callback
>
14405 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14406 Callback
&&callback
)
14408 struct dwarf2_per_objfile
*dwarf2_per_objfile
14409 = cu
->per_cu
->dwarf2_per_objfile
;
14410 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14411 bfd
*obfd
= objfile
->obfd
;
14412 /* Base address selection entry. */
14415 const gdb_byte
*buffer
;
14416 CORE_ADDR baseaddr
;
14417 bool overflow
= false;
14419 found_base
= cu
->base_known
;
14420 base
= cu
->base_address
;
14422 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14423 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14425 complaint (&symfile_complaints
,
14426 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14430 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14432 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14436 /* Initialize it due to a false compiler warning. */
14437 CORE_ADDR range_beginning
= 0, range_end
= 0;
14438 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14439 + dwarf2_per_objfile
->rnglists
.size
);
14440 unsigned int bytes_read
;
14442 if (buffer
== buf_end
)
14447 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14450 case DW_RLE_end_of_list
:
14452 case DW_RLE_base_address
:
14453 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14458 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14460 buffer
+= bytes_read
;
14462 case DW_RLE_start_length
:
14463 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14468 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14469 buffer
+= bytes_read
;
14470 range_end
= (range_beginning
14471 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14472 buffer
+= bytes_read
;
14473 if (buffer
> buf_end
)
14479 case DW_RLE_offset_pair
:
14480 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14481 buffer
+= bytes_read
;
14482 if (buffer
> buf_end
)
14487 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14488 buffer
+= bytes_read
;
14489 if (buffer
> buf_end
)
14495 case DW_RLE_start_end
:
14496 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14501 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14502 buffer
+= bytes_read
;
14503 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14504 buffer
+= bytes_read
;
14507 complaint (&symfile_complaints
,
14508 _("Invalid .debug_rnglists data (no base address)"));
14511 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14513 if (rlet
== DW_RLE_base_address
)
14518 /* We have no valid base address for the ranges
14520 complaint (&symfile_complaints
,
14521 _("Invalid .debug_rnglists data (no base address)"));
14525 if (range_beginning
> range_end
)
14527 /* Inverted range entries are invalid. */
14528 complaint (&symfile_complaints
,
14529 _("Invalid .debug_rnglists data (inverted range)"));
14533 /* Empty range entries have no effect. */
14534 if (range_beginning
== range_end
)
14537 range_beginning
+= base
;
14540 /* A not-uncommon case of bad debug info.
14541 Don't pollute the addrmap with bad data. */
14542 if (range_beginning
+ baseaddr
== 0
14543 && !dwarf2_per_objfile
->has_section_at_zero
)
14545 complaint (&symfile_complaints
,
14546 _(".debug_rnglists entry has start address of zero"
14547 " [in module %s]"), objfile_name (objfile
));
14551 callback (range_beginning
, range_end
);
14556 complaint (&symfile_complaints
,
14557 _("Offset %d is not terminated "
14558 "for DW_AT_ranges attribute"),
14566 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14567 Callback's type should be:
14568 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14569 Return 1 if the attributes are present and valid, otherwise, return 0. */
14571 template <typename Callback
>
14573 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14574 Callback
&&callback
)
14576 struct dwarf2_per_objfile
*dwarf2_per_objfile
14577 = cu
->per_cu
->dwarf2_per_objfile
;
14578 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14579 struct comp_unit_head
*cu_header
= &cu
->header
;
14580 bfd
*obfd
= objfile
->obfd
;
14581 unsigned int addr_size
= cu_header
->addr_size
;
14582 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14583 /* Base address selection entry. */
14586 unsigned int dummy
;
14587 const gdb_byte
*buffer
;
14588 CORE_ADDR baseaddr
;
14590 if (cu_header
->version
>= 5)
14591 return dwarf2_rnglists_process (offset
, cu
, callback
);
14593 found_base
= cu
->base_known
;
14594 base
= cu
->base_address
;
14596 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14597 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14599 complaint (&symfile_complaints
,
14600 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14604 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14606 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14610 CORE_ADDR range_beginning
, range_end
;
14612 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14613 buffer
+= addr_size
;
14614 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14615 buffer
+= addr_size
;
14616 offset
+= 2 * addr_size
;
14618 /* An end of list marker is a pair of zero addresses. */
14619 if (range_beginning
== 0 && range_end
== 0)
14620 /* Found the end of list entry. */
14623 /* Each base address selection entry is a pair of 2 values.
14624 The first is the largest possible address, the second is
14625 the base address. Check for a base address here. */
14626 if ((range_beginning
& mask
) == mask
)
14628 /* If we found the largest possible address, then we already
14629 have the base address in range_end. */
14637 /* We have no valid base address for the ranges
14639 complaint (&symfile_complaints
,
14640 _("Invalid .debug_ranges data (no base address)"));
14644 if (range_beginning
> range_end
)
14646 /* Inverted range entries are invalid. */
14647 complaint (&symfile_complaints
,
14648 _("Invalid .debug_ranges data (inverted range)"));
14652 /* Empty range entries have no effect. */
14653 if (range_beginning
== range_end
)
14656 range_beginning
+= base
;
14659 /* A not-uncommon case of bad debug info.
14660 Don't pollute the addrmap with bad data. */
14661 if (range_beginning
+ baseaddr
== 0
14662 && !dwarf2_per_objfile
->has_section_at_zero
)
14664 complaint (&symfile_complaints
,
14665 _(".debug_ranges entry has start address of zero"
14666 " [in module %s]"), objfile_name (objfile
));
14670 callback (range_beginning
, range_end
);
14676 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14677 Return 1 if the attributes are present and valid, otherwise, return 0.
14678 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14681 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14682 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14683 struct partial_symtab
*ranges_pst
)
14685 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14686 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14687 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14688 SECT_OFF_TEXT (objfile
));
14691 CORE_ADDR high
= 0;
14694 retval
= dwarf2_ranges_process (offset
, cu
,
14695 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14697 if (ranges_pst
!= NULL
)
14702 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14703 range_beginning
+ baseaddr
);
14704 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
14705 range_end
+ baseaddr
);
14706 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
14710 /* FIXME: This is recording everything as a low-high
14711 segment of consecutive addresses. We should have a
14712 data structure for discontiguous block ranges
14716 low
= range_beginning
;
14722 if (range_beginning
< low
)
14723 low
= range_beginning
;
14724 if (range_end
> high
)
14732 /* If the first entry is an end-of-list marker, the range
14733 describes an empty scope, i.e. no instructions. */
14739 *high_return
= high
;
14743 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14744 definition for the return value. *LOWPC and *HIGHPC are set iff
14745 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14747 static enum pc_bounds_kind
14748 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14749 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14750 struct partial_symtab
*pst
)
14752 struct dwarf2_per_objfile
*dwarf2_per_objfile
14753 = cu
->per_cu
->dwarf2_per_objfile
;
14754 struct attribute
*attr
;
14755 struct attribute
*attr_high
;
14757 CORE_ADDR high
= 0;
14758 enum pc_bounds_kind ret
;
14760 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14763 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14766 low
= attr_value_as_address (attr
);
14767 high
= attr_value_as_address (attr_high
);
14768 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14772 /* Found high w/o low attribute. */
14773 return PC_BOUNDS_INVALID
;
14775 /* Found consecutive range of addresses. */
14776 ret
= PC_BOUNDS_HIGH_LOW
;
14780 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14783 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14784 We take advantage of the fact that DW_AT_ranges does not appear
14785 in DW_TAG_compile_unit of DWO files. */
14786 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14787 unsigned int ranges_offset
= (DW_UNSND (attr
)
14788 + (need_ranges_base
14792 /* Value of the DW_AT_ranges attribute is the offset in the
14793 .debug_ranges section. */
14794 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14795 return PC_BOUNDS_INVALID
;
14796 /* Found discontinuous range of addresses. */
14797 ret
= PC_BOUNDS_RANGES
;
14800 return PC_BOUNDS_NOT_PRESENT
;
14803 /* read_partial_die has also the strict LOW < HIGH requirement. */
14805 return PC_BOUNDS_INVALID
;
14807 /* When using the GNU linker, .gnu.linkonce. sections are used to
14808 eliminate duplicate copies of functions and vtables and such.
14809 The linker will arbitrarily choose one and discard the others.
14810 The AT_*_pc values for such functions refer to local labels in
14811 these sections. If the section from that file was discarded, the
14812 labels are not in the output, so the relocs get a value of 0.
14813 If this is a discarded function, mark the pc bounds as invalid,
14814 so that GDB will ignore it. */
14815 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14816 return PC_BOUNDS_INVALID
;
14824 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14825 its low and high PC addresses. Do nothing if these addresses could not
14826 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14827 and HIGHPC to the high address if greater than HIGHPC. */
14830 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14831 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14832 struct dwarf2_cu
*cu
)
14834 CORE_ADDR low
, high
;
14835 struct die_info
*child
= die
->child
;
14837 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14839 *lowpc
= std::min (*lowpc
, low
);
14840 *highpc
= std::max (*highpc
, high
);
14843 /* If the language does not allow nested subprograms (either inside
14844 subprograms or lexical blocks), we're done. */
14845 if (cu
->language
!= language_ada
)
14848 /* Check all the children of the given DIE. If it contains nested
14849 subprograms, then check their pc bounds. Likewise, we need to
14850 check lexical blocks as well, as they may also contain subprogram
14852 while (child
&& child
->tag
)
14854 if (child
->tag
== DW_TAG_subprogram
14855 || child
->tag
== DW_TAG_lexical_block
)
14856 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14857 child
= sibling_die (child
);
14861 /* Get the low and high pc's represented by the scope DIE, and store
14862 them in *LOWPC and *HIGHPC. If the correct values can't be
14863 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14866 get_scope_pc_bounds (struct die_info
*die
,
14867 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14868 struct dwarf2_cu
*cu
)
14870 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14871 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14872 CORE_ADDR current_low
, current_high
;
14874 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14875 >= PC_BOUNDS_RANGES
)
14877 best_low
= current_low
;
14878 best_high
= current_high
;
14882 struct die_info
*child
= die
->child
;
14884 while (child
&& child
->tag
)
14886 switch (child
->tag
) {
14887 case DW_TAG_subprogram
:
14888 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14890 case DW_TAG_namespace
:
14891 case DW_TAG_module
:
14892 /* FIXME: carlton/2004-01-16: Should we do this for
14893 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14894 that current GCC's always emit the DIEs corresponding
14895 to definitions of methods of classes as children of a
14896 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14897 the DIEs giving the declarations, which could be
14898 anywhere). But I don't see any reason why the
14899 standards says that they have to be there. */
14900 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14902 if (current_low
!= ((CORE_ADDR
) -1))
14904 best_low
= std::min (best_low
, current_low
);
14905 best_high
= std::max (best_high
, current_high
);
14913 child
= sibling_die (child
);
14918 *highpc
= best_high
;
14921 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14925 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14926 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14928 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14929 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14930 struct attribute
*attr
;
14931 struct attribute
*attr_high
;
14933 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14936 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14939 CORE_ADDR low
= attr_value_as_address (attr
);
14940 CORE_ADDR high
= attr_value_as_address (attr_high
);
14942 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14945 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14946 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14947 record_block_range (block
, low
, high
- 1);
14951 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14954 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14955 We take advantage of the fact that DW_AT_ranges does not appear
14956 in DW_TAG_compile_unit of DWO files. */
14957 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14959 /* The value of the DW_AT_ranges attribute is the offset of the
14960 address range list in the .debug_ranges section. */
14961 unsigned long offset
= (DW_UNSND (attr
)
14962 + (need_ranges_base
? cu
->ranges_base
: 0));
14963 const gdb_byte
*buffer
;
14965 /* For some target architectures, but not others, the
14966 read_address function sign-extends the addresses it returns.
14967 To recognize base address selection entries, we need a
14969 unsigned int addr_size
= cu
->header
.addr_size
;
14970 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14972 /* The base address, to which the next pair is relative. Note
14973 that this 'base' is a DWARF concept: most entries in a range
14974 list are relative, to reduce the number of relocs against the
14975 debugging information. This is separate from this function's
14976 'baseaddr' argument, which GDB uses to relocate debugging
14977 information from a shared library based on the address at
14978 which the library was loaded. */
14979 CORE_ADDR base
= cu
->base_address
;
14980 int base_known
= cu
->base_known
;
14982 dwarf2_ranges_process (offset
, cu
,
14983 [&] (CORE_ADDR start
, CORE_ADDR end
)
14987 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14988 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14989 record_block_range (block
, start
, end
- 1);
14994 /* Check whether the producer field indicates either of GCC < 4.6, or the
14995 Intel C/C++ compiler, and cache the result in CU. */
14998 check_producer (struct dwarf2_cu
*cu
)
15002 if (cu
->producer
== NULL
)
15004 /* For unknown compilers expect their behavior is DWARF version
15007 GCC started to support .debug_types sections by -gdwarf-4 since
15008 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
15009 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
15010 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
15011 interpreted incorrectly by GDB now - GCC PR debug/48229. */
15013 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
15015 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
15016 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
15018 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
15019 cu
->producer_is_icc_lt_14
= major
< 14;
15022 /* For other non-GCC compilers, expect their behavior is DWARF version
15026 cu
->checked_producer
= 1;
15029 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
15030 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
15031 during 4.6.0 experimental. */
15034 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
15036 if (!cu
->checked_producer
)
15037 check_producer (cu
);
15039 return cu
->producer_is_gxx_lt_4_6
;
15042 /* Return the default accessibility type if it is not overriden by
15043 DW_AT_accessibility. */
15045 static enum dwarf_access_attribute
15046 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15048 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15050 /* The default DWARF 2 accessibility for members is public, the default
15051 accessibility for inheritance is private. */
15053 if (die
->tag
!= DW_TAG_inheritance
)
15054 return DW_ACCESS_public
;
15056 return DW_ACCESS_private
;
15060 /* DWARF 3+ defines the default accessibility a different way. The same
15061 rules apply now for DW_TAG_inheritance as for the members and it only
15062 depends on the container kind. */
15064 if (die
->parent
->tag
== DW_TAG_class_type
)
15065 return DW_ACCESS_private
;
15067 return DW_ACCESS_public
;
15071 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15072 offset. If the attribute was not found return 0, otherwise return
15073 1. If it was found but could not properly be handled, set *OFFSET
15077 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15080 struct attribute
*attr
;
15082 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15087 /* Note that we do not check for a section offset first here.
15088 This is because DW_AT_data_member_location is new in DWARF 4,
15089 so if we see it, we can assume that a constant form is really
15090 a constant and not a section offset. */
15091 if (attr_form_is_constant (attr
))
15092 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15093 else if (attr_form_is_section_offset (attr
))
15094 dwarf2_complex_location_expr_complaint ();
15095 else if (attr_form_is_block (attr
))
15096 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15098 dwarf2_complex_location_expr_complaint ();
15106 /* Add an aggregate field to the field list. */
15109 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15110 struct dwarf2_cu
*cu
)
15112 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15113 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15114 struct nextfield
*new_field
;
15115 struct attribute
*attr
;
15117 const char *fieldname
= "";
15119 /* Allocate a new field list entry and link it in. */
15120 new_field
= XNEW (struct nextfield
);
15121 make_cleanup (xfree
, new_field
);
15122 memset (new_field
, 0, sizeof (struct nextfield
));
15124 if (die
->tag
== DW_TAG_inheritance
)
15126 new_field
->next
= fip
->baseclasses
;
15127 fip
->baseclasses
= new_field
;
15131 new_field
->next
= fip
->fields
;
15132 fip
->fields
= new_field
;
15136 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15138 new_field
->accessibility
= DW_UNSND (attr
);
15140 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15141 if (new_field
->accessibility
!= DW_ACCESS_public
)
15142 fip
->non_public_fields
= 1;
15144 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15146 new_field
->virtuality
= DW_UNSND (attr
);
15148 new_field
->virtuality
= DW_VIRTUALITY_none
;
15150 fp
= &new_field
->field
;
15152 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15156 /* Data member other than a C++ static data member. */
15158 /* Get type of field. */
15159 fp
->type
= die_type (die
, cu
);
15161 SET_FIELD_BITPOS (*fp
, 0);
15163 /* Get bit size of field (zero if none). */
15164 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15167 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15171 FIELD_BITSIZE (*fp
) = 0;
15174 /* Get bit offset of field. */
15175 if (handle_data_member_location (die
, cu
, &offset
))
15176 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15177 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15180 if (gdbarch_bits_big_endian (gdbarch
))
15182 /* For big endian bits, the DW_AT_bit_offset gives the
15183 additional bit offset from the MSB of the containing
15184 anonymous object to the MSB of the field. We don't
15185 have to do anything special since we don't need to
15186 know the size of the anonymous object. */
15187 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15191 /* For little endian bits, compute the bit offset to the
15192 MSB of the anonymous object, subtract off the number of
15193 bits from the MSB of the field to the MSB of the
15194 object, and then subtract off the number of bits of
15195 the field itself. The result is the bit offset of
15196 the LSB of the field. */
15197 int anonymous_size
;
15198 int bit_offset
= DW_UNSND (attr
);
15200 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15203 /* The size of the anonymous object containing
15204 the bit field is explicit, so use the
15205 indicated size (in bytes). */
15206 anonymous_size
= DW_UNSND (attr
);
15210 /* The size of the anonymous object containing
15211 the bit field must be inferred from the type
15212 attribute of the data member containing the
15214 anonymous_size
= TYPE_LENGTH (fp
->type
);
15216 SET_FIELD_BITPOS (*fp
,
15217 (FIELD_BITPOS (*fp
)
15218 + anonymous_size
* bits_per_byte
15219 - bit_offset
- FIELD_BITSIZE (*fp
)));
15222 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15224 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15225 + dwarf2_get_attr_constant_value (attr
, 0)));
15227 /* Get name of field. */
15228 fieldname
= dwarf2_name (die
, cu
);
15229 if (fieldname
== NULL
)
15232 /* The name is already allocated along with this objfile, so we don't
15233 need to duplicate it for the type. */
15234 fp
->name
= fieldname
;
15236 /* Change accessibility for artificial fields (e.g. virtual table
15237 pointer or virtual base class pointer) to private. */
15238 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15240 FIELD_ARTIFICIAL (*fp
) = 1;
15241 new_field
->accessibility
= DW_ACCESS_private
;
15242 fip
->non_public_fields
= 1;
15245 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15247 /* C++ static member. */
15249 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15250 is a declaration, but all versions of G++ as of this writing
15251 (so through at least 3.2.1) incorrectly generate
15252 DW_TAG_variable tags. */
15254 const char *physname
;
15256 /* Get name of field. */
15257 fieldname
= dwarf2_name (die
, cu
);
15258 if (fieldname
== NULL
)
15261 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15263 /* Only create a symbol if this is an external value.
15264 new_symbol checks this and puts the value in the global symbol
15265 table, which we want. If it is not external, new_symbol
15266 will try to put the value in cu->list_in_scope which is wrong. */
15267 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15269 /* A static const member, not much different than an enum as far as
15270 we're concerned, except that we can support more types. */
15271 new_symbol (die
, NULL
, cu
);
15274 /* Get physical name. */
15275 physname
= dwarf2_physname (fieldname
, die
, cu
);
15277 /* The name is already allocated along with this objfile, so we don't
15278 need to duplicate it for the type. */
15279 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15280 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15281 FIELD_NAME (*fp
) = fieldname
;
15283 else if (die
->tag
== DW_TAG_inheritance
)
15287 /* C++ base class field. */
15288 if (handle_data_member_location (die
, cu
, &offset
))
15289 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15290 FIELD_BITSIZE (*fp
) = 0;
15291 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15292 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15293 fip
->nbaseclasses
++;
15297 /* Can the type given by DIE define another type? */
15300 type_can_define_types (const struct die_info
*die
)
15304 case DW_TAG_typedef
:
15305 case DW_TAG_class_type
:
15306 case DW_TAG_structure_type
:
15307 case DW_TAG_union_type
:
15308 case DW_TAG_enumeration_type
:
15316 /* Add a type definition defined in the scope of the FIP's class. */
15319 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15320 struct dwarf2_cu
*cu
)
15322 struct decl_field_list
*new_field
;
15323 struct decl_field
*fp
;
15325 /* Allocate a new field list entry and link it in. */
15326 new_field
= XCNEW (struct decl_field_list
);
15327 make_cleanup (xfree
, new_field
);
15329 gdb_assert (type_can_define_types (die
));
15331 fp
= &new_field
->field
;
15333 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15334 fp
->name
= dwarf2_name (die
, cu
);
15335 fp
->type
= read_type_die (die
, cu
);
15337 /* Save accessibility. */
15338 enum dwarf_access_attribute accessibility
;
15339 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15341 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15343 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15344 switch (accessibility
)
15346 case DW_ACCESS_public
:
15347 /* The assumed value if neither private nor protected. */
15349 case DW_ACCESS_private
:
15350 fp
->is_private
= 1;
15352 case DW_ACCESS_protected
:
15353 fp
->is_protected
= 1;
15356 complaint (&symfile_complaints
,
15357 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15360 if (die
->tag
== DW_TAG_typedef
)
15362 new_field
->next
= fip
->typedef_field_list
;
15363 fip
->typedef_field_list
= new_field
;
15364 fip
->typedef_field_list_count
++;
15368 new_field
->next
= fip
->nested_types_list
;
15369 fip
->nested_types_list
= new_field
;
15370 fip
->nested_types_list_count
++;
15374 /* Create the vector of fields, and attach it to the type. */
15377 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15378 struct dwarf2_cu
*cu
)
15380 int nfields
= fip
->nfields
;
15382 /* Record the field count, allocate space for the array of fields,
15383 and create blank accessibility bitfields if necessary. */
15384 TYPE_NFIELDS (type
) = nfields
;
15385 TYPE_FIELDS (type
) = (struct field
*)
15386 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
15387 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
15389 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15391 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15393 TYPE_FIELD_PRIVATE_BITS (type
) =
15394 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15395 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15397 TYPE_FIELD_PROTECTED_BITS (type
) =
15398 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15399 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15401 TYPE_FIELD_IGNORE_BITS (type
) =
15402 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15403 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15406 /* If the type has baseclasses, allocate and clear a bit vector for
15407 TYPE_FIELD_VIRTUAL_BITS. */
15408 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
15410 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
15411 unsigned char *pointer
;
15413 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15414 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15415 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15416 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
15417 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
15420 /* Copy the saved-up fields into the field vector. Start from the head of
15421 the list, adding to the tail of the field array, so that they end up in
15422 the same order in the array in which they were added to the list. */
15423 while (nfields
-- > 0)
15425 struct nextfield
*fieldp
;
15429 fieldp
= fip
->fields
;
15430 fip
->fields
= fieldp
->next
;
15434 fieldp
= fip
->baseclasses
;
15435 fip
->baseclasses
= fieldp
->next
;
15438 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
15439 switch (fieldp
->accessibility
)
15441 case DW_ACCESS_private
:
15442 if (cu
->language
!= language_ada
)
15443 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
15446 case DW_ACCESS_protected
:
15447 if (cu
->language
!= language_ada
)
15448 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
15451 case DW_ACCESS_public
:
15455 /* Unknown accessibility. Complain and treat it as public. */
15457 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15458 fieldp
->accessibility
);
15462 if (nfields
< fip
->nbaseclasses
)
15464 switch (fieldp
->virtuality
)
15466 case DW_VIRTUALITY_virtual
:
15467 case DW_VIRTUALITY_pure_virtual
:
15468 if (cu
->language
== language_ada
)
15469 error (_("unexpected virtuality in component of Ada type"));
15470 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
15477 /* Return true if this member function is a constructor, false
15481 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15483 const char *fieldname
;
15484 const char *type_name
;
15487 if (die
->parent
== NULL
)
15490 if (die
->parent
->tag
!= DW_TAG_structure_type
15491 && die
->parent
->tag
!= DW_TAG_union_type
15492 && die
->parent
->tag
!= DW_TAG_class_type
)
15495 fieldname
= dwarf2_name (die
, cu
);
15496 type_name
= dwarf2_name (die
->parent
, cu
);
15497 if (fieldname
== NULL
|| type_name
== NULL
)
15500 len
= strlen (fieldname
);
15501 return (strncmp (fieldname
, type_name
, len
) == 0
15502 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15505 /* Add a member function to the proper fieldlist. */
15508 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15509 struct type
*type
, struct dwarf2_cu
*cu
)
15511 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15512 struct attribute
*attr
;
15513 struct fnfieldlist
*flp
;
15515 struct fn_field
*fnp
;
15516 const char *fieldname
;
15517 struct nextfnfield
*new_fnfield
;
15518 struct type
*this_type
;
15519 enum dwarf_access_attribute accessibility
;
15521 if (cu
->language
== language_ada
)
15522 error (_("unexpected member function in Ada type"));
15524 /* Get name of member function. */
15525 fieldname
= dwarf2_name (die
, cu
);
15526 if (fieldname
== NULL
)
15529 /* Look up member function name in fieldlist. */
15530 for (i
= 0; i
< fip
->nfnfields
; i
++)
15532 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15536 /* Create new list element if necessary. */
15537 if (i
< fip
->nfnfields
)
15538 flp
= &fip
->fnfieldlists
[i
];
15541 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
15543 fip
->fnfieldlists
= (struct fnfieldlist
*)
15544 xrealloc (fip
->fnfieldlists
,
15545 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
15546 * sizeof (struct fnfieldlist
));
15547 if (fip
->nfnfields
== 0)
15548 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
15550 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
15551 flp
->name
= fieldname
;
15554 i
= fip
->nfnfields
++;
15557 /* Create a new member function field and chain it to the field list
15559 new_fnfield
= XNEW (struct nextfnfield
);
15560 make_cleanup (xfree
, new_fnfield
);
15561 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
15562 new_fnfield
->next
= flp
->head
;
15563 flp
->head
= new_fnfield
;
15566 /* Fill in the member function field info. */
15567 fnp
= &new_fnfield
->fnfield
;
15569 /* Delay processing of the physname until later. */
15570 if (cu
->language
== language_cplus
)
15572 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
15577 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15578 fnp
->physname
= physname
? physname
: "";
15581 fnp
->type
= alloc_type (objfile
);
15582 this_type
= read_type_die (die
, cu
);
15583 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15585 int nparams
= TYPE_NFIELDS (this_type
);
15587 /* TYPE is the domain of this method, and THIS_TYPE is the type
15588 of the method itself (TYPE_CODE_METHOD). */
15589 smash_to_method_type (fnp
->type
, type
,
15590 TYPE_TARGET_TYPE (this_type
),
15591 TYPE_FIELDS (this_type
),
15592 TYPE_NFIELDS (this_type
),
15593 TYPE_VARARGS (this_type
));
15595 /* Handle static member functions.
15596 Dwarf2 has no clean way to discern C++ static and non-static
15597 member functions. G++ helps GDB by marking the first
15598 parameter for non-static member functions (which is the this
15599 pointer) as artificial. We obtain this information from
15600 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15601 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15602 fnp
->voffset
= VOFFSET_STATIC
;
15605 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15606 dwarf2_full_name (fieldname
, die
, cu
));
15608 /* Get fcontext from DW_AT_containing_type if present. */
15609 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15610 fnp
->fcontext
= die_containing_type (die
, cu
);
15612 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15613 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15615 /* Get accessibility. */
15616 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15618 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15620 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15621 switch (accessibility
)
15623 case DW_ACCESS_private
:
15624 fnp
->is_private
= 1;
15626 case DW_ACCESS_protected
:
15627 fnp
->is_protected
= 1;
15631 /* Check for artificial methods. */
15632 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15633 if (attr
&& DW_UNSND (attr
) != 0)
15634 fnp
->is_artificial
= 1;
15636 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15638 /* Get index in virtual function table if it is a virtual member
15639 function. For older versions of GCC, this is an offset in the
15640 appropriate virtual table, as specified by DW_AT_containing_type.
15641 For everyone else, it is an expression to be evaluated relative
15642 to the object address. */
15644 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15647 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15649 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15651 /* Old-style GCC. */
15652 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15654 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15655 || (DW_BLOCK (attr
)->size
> 1
15656 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15657 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15659 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15660 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15661 dwarf2_complex_location_expr_complaint ();
15663 fnp
->voffset
/= cu
->header
.addr_size
;
15667 dwarf2_complex_location_expr_complaint ();
15669 if (!fnp
->fcontext
)
15671 /* If there is no `this' field and no DW_AT_containing_type,
15672 we cannot actually find a base class context for the
15674 if (TYPE_NFIELDS (this_type
) == 0
15675 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15677 complaint (&symfile_complaints
,
15678 _("cannot determine context for virtual member "
15679 "function \"%s\" (offset %s)"),
15680 fieldname
, sect_offset_str (die
->sect_off
));
15685 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15689 else if (attr_form_is_section_offset (attr
))
15691 dwarf2_complex_location_expr_complaint ();
15695 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15701 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15702 if (attr
&& DW_UNSND (attr
))
15704 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15705 complaint (&symfile_complaints
,
15706 _("Member function \"%s\" (offset %s) is virtual "
15707 "but the vtable offset is not specified"),
15708 fieldname
, sect_offset_str (die
->sect_off
));
15709 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15710 TYPE_CPLUS_DYNAMIC (type
) = 1;
15715 /* Create the vector of member function fields, and attach it to the type. */
15718 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15719 struct dwarf2_cu
*cu
)
15721 struct fnfieldlist
*flp
;
15724 if (cu
->language
== language_ada
)
15725 error (_("unexpected member functions in Ada type"));
15727 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15728 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15729 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
15731 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
15733 struct nextfnfield
*nfp
= flp
->head
;
15734 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15737 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
15738 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
15739 fn_flp
->fn_fields
= (struct fn_field
*)
15740 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
15741 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
15742 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
15745 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
15748 /* Returns non-zero if NAME is the name of a vtable member in CU's
15749 language, zero otherwise. */
15751 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15753 static const char vptr
[] = "_vptr";
15755 /* Look for the C++ form of the vtable. */
15756 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15762 /* GCC outputs unnamed structures that are really pointers to member
15763 functions, with the ABI-specified layout. If TYPE describes
15764 such a structure, smash it into a member function type.
15766 GCC shouldn't do this; it should just output pointer to member DIEs.
15767 This is GCC PR debug/28767. */
15770 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15772 struct type
*pfn_type
, *self_type
, *new_type
;
15774 /* Check for a structure with no name and two children. */
15775 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15778 /* Check for __pfn and __delta members. */
15779 if (TYPE_FIELD_NAME (type
, 0) == NULL
15780 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15781 || TYPE_FIELD_NAME (type
, 1) == NULL
15782 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15785 /* Find the type of the method. */
15786 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15787 if (pfn_type
== NULL
15788 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15789 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15792 /* Look for the "this" argument. */
15793 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15794 if (TYPE_NFIELDS (pfn_type
) == 0
15795 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15796 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15799 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15800 new_type
= alloc_type (objfile
);
15801 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15802 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15803 TYPE_VARARGS (pfn_type
));
15804 smash_to_methodptr_type (type
, new_type
);
15808 /* Called when we find the DIE that starts a structure or union scope
15809 (definition) to create a type for the structure or union. Fill in
15810 the type's name and general properties; the members will not be
15811 processed until process_structure_scope. A symbol table entry for
15812 the type will also not be done until process_structure_scope (assuming
15813 the type has a name).
15815 NOTE: we need to call these functions regardless of whether or not the
15816 DIE has a DW_AT_name attribute, since it might be an anonymous
15817 structure or union. This gets the type entered into our set of
15818 user defined types. */
15820 static struct type
*
15821 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15823 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15825 struct attribute
*attr
;
15828 /* If the definition of this type lives in .debug_types, read that type.
15829 Don't follow DW_AT_specification though, that will take us back up
15830 the chain and we want to go down. */
15831 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15834 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15836 /* The type's CU may not be the same as CU.
15837 Ensure TYPE is recorded with CU in die_type_hash. */
15838 return set_die_type (die
, type
, cu
);
15841 type
= alloc_type (objfile
);
15842 INIT_CPLUS_SPECIFIC (type
);
15844 name
= dwarf2_name (die
, cu
);
15847 if (cu
->language
== language_cplus
15848 || cu
->language
== language_d
15849 || cu
->language
== language_rust
)
15851 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15853 /* dwarf2_full_name might have already finished building the DIE's
15854 type. If so, there is no need to continue. */
15855 if (get_die_type (die
, cu
) != NULL
)
15856 return get_die_type (die
, cu
);
15858 TYPE_TAG_NAME (type
) = full_name
;
15859 if (die
->tag
== DW_TAG_structure_type
15860 || die
->tag
== DW_TAG_class_type
)
15861 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15865 /* The name is already allocated along with this objfile, so
15866 we don't need to duplicate it for the type. */
15867 TYPE_TAG_NAME (type
) = name
;
15868 if (die
->tag
== DW_TAG_class_type
)
15869 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
15873 if (die
->tag
== DW_TAG_structure_type
)
15875 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15877 else if (die
->tag
== DW_TAG_union_type
)
15879 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15883 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15886 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15887 TYPE_DECLARED_CLASS (type
) = 1;
15889 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15892 if (attr_form_is_constant (attr
))
15893 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15896 /* For the moment, dynamic type sizes are not supported
15897 by GDB's struct type. The actual size is determined
15898 on-demand when resolving the type of a given object,
15899 so set the type's length to zero for now. Otherwise,
15900 we record an expression as the length, and that expression
15901 could lead to a very large value, which could eventually
15902 lead to us trying to allocate that much memory when creating
15903 a value of that type. */
15904 TYPE_LENGTH (type
) = 0;
15909 TYPE_LENGTH (type
) = 0;
15912 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15914 /* ICC<14 does not output the required DW_AT_declaration on
15915 incomplete types, but gives them a size of zero. */
15916 TYPE_STUB (type
) = 1;
15919 TYPE_STUB_SUPPORTED (type
) = 1;
15921 if (die_is_declaration (die
, cu
))
15922 TYPE_STUB (type
) = 1;
15923 else if (attr
== NULL
&& die
->child
== NULL
15924 && producer_is_realview (cu
->producer
))
15925 /* RealView does not output the required DW_AT_declaration
15926 on incomplete types. */
15927 TYPE_STUB (type
) = 1;
15929 /* We need to add the type field to the die immediately so we don't
15930 infinitely recurse when dealing with pointers to the structure
15931 type within the structure itself. */
15932 set_die_type (die
, type
, cu
);
15934 /* set_die_type should be already done. */
15935 set_descriptive_type (type
, die
, cu
);
15940 /* Finish creating a structure or union type, including filling in
15941 its members and creating a symbol for it. */
15944 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15946 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15947 struct die_info
*child_die
;
15950 type
= get_die_type (die
, cu
);
15952 type
= read_structure_type (die
, cu
);
15954 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15956 struct field_info fi
;
15957 std::vector
<struct symbol
*> template_args
;
15958 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
15960 memset (&fi
, 0, sizeof (struct field_info
));
15962 child_die
= die
->child
;
15964 while (child_die
&& child_die
->tag
)
15966 if (child_die
->tag
== DW_TAG_member
15967 || child_die
->tag
== DW_TAG_variable
)
15969 /* NOTE: carlton/2002-11-05: A C++ static data member
15970 should be a DW_TAG_member that is a declaration, but
15971 all versions of G++ as of this writing (so through at
15972 least 3.2.1) incorrectly generate DW_TAG_variable
15973 tags for them instead. */
15974 dwarf2_add_field (&fi
, child_die
, cu
);
15976 else if (child_die
->tag
== DW_TAG_subprogram
)
15978 /* Rust doesn't have member functions in the C++ sense.
15979 However, it does emit ordinary functions as children
15980 of a struct DIE. */
15981 if (cu
->language
== language_rust
)
15982 read_func_scope (child_die
, cu
);
15985 /* C++ member function. */
15986 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
15989 else if (child_die
->tag
== DW_TAG_inheritance
)
15991 /* C++ base class field. */
15992 dwarf2_add_field (&fi
, child_die
, cu
);
15994 else if (type_can_define_types (child_die
))
15995 dwarf2_add_type_defn (&fi
, child_die
, cu
);
15996 else if (child_die
->tag
== DW_TAG_template_type_param
15997 || child_die
->tag
== DW_TAG_template_value_param
)
15999 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16002 template_args
.push_back (arg
);
16005 child_die
= sibling_die (child_die
);
16008 /* Attach template arguments to type. */
16009 if (!template_args
.empty ())
16011 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16012 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16013 TYPE_TEMPLATE_ARGUMENTS (type
)
16014 = XOBNEWVEC (&objfile
->objfile_obstack
,
16016 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16017 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16018 template_args
.data (),
16019 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16020 * sizeof (struct symbol
*)));
16023 /* Attach fields and member functions to the type. */
16025 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16028 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16030 /* Get the type which refers to the base class (possibly this
16031 class itself) which contains the vtable pointer for the current
16032 class from the DW_AT_containing_type attribute. This use of
16033 DW_AT_containing_type is a GNU extension. */
16035 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16037 struct type
*t
= die_containing_type (die
, cu
);
16039 set_type_vptr_basetype (type
, t
);
16044 /* Our own class provides vtbl ptr. */
16045 for (i
= TYPE_NFIELDS (t
) - 1;
16046 i
>= TYPE_N_BASECLASSES (t
);
16049 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16051 if (is_vtable_name (fieldname
, cu
))
16053 set_type_vptr_fieldno (type
, i
);
16058 /* Complain if virtual function table field not found. */
16059 if (i
< TYPE_N_BASECLASSES (t
))
16060 complaint (&symfile_complaints
,
16061 _("virtual function table pointer "
16062 "not found when defining class '%s'"),
16063 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16068 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16071 else if (cu
->producer
16072 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16074 /* The IBM XLC compiler does not provide direct indication
16075 of the containing type, but the vtable pointer is
16076 always named __vfp. */
16080 for (i
= TYPE_NFIELDS (type
) - 1;
16081 i
>= TYPE_N_BASECLASSES (type
);
16084 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16086 set_type_vptr_fieldno (type
, i
);
16087 set_type_vptr_basetype (type
, type
);
16094 /* Copy fi.typedef_field_list linked list elements content into the
16095 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16096 if (fi
.typedef_field_list
)
16098 int i
= fi
.typedef_field_list_count
;
16100 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16101 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16102 = ((struct decl_field
*)
16103 TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
));
16104 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
16106 /* Reverse the list order to keep the debug info elements order. */
16109 struct decl_field
*dest
, *src
;
16111 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
16112 src
= &fi
.typedef_field_list
->field
;
16113 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
16118 /* Copy fi.nested_types_list linked list elements content into the
16119 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16120 if (fi
.nested_types_list
!= NULL
&& cu
->language
!= language_ada
)
16122 int i
= fi
.nested_types_list_count
;
16124 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16125 TYPE_NESTED_TYPES_ARRAY (type
)
16126 = ((struct decl_field
*)
16127 TYPE_ALLOC (type
, sizeof (struct decl_field
) * i
));
16128 TYPE_NESTED_TYPES_COUNT (type
) = i
;
16130 /* Reverse the list order to keep the debug info elements order. */
16133 struct decl_field
*dest
, *src
;
16135 dest
= &TYPE_NESTED_TYPES_FIELD (type
, i
);
16136 src
= &fi
.nested_types_list
->field
;
16137 fi
.nested_types_list
= fi
.nested_types_list
->next
;
16142 do_cleanups (back_to
);
16145 quirk_gcc_member_function_pointer (type
, objfile
);
16147 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16148 snapshots) has been known to create a die giving a declaration
16149 for a class that has, as a child, a die giving a definition for a
16150 nested class. So we have to process our children even if the
16151 current die is a declaration. Normally, of course, a declaration
16152 won't have any children at all. */
16154 child_die
= die
->child
;
16156 while (child_die
!= NULL
&& child_die
->tag
)
16158 if (child_die
->tag
== DW_TAG_member
16159 || child_die
->tag
== DW_TAG_variable
16160 || child_die
->tag
== DW_TAG_inheritance
16161 || child_die
->tag
== DW_TAG_template_value_param
16162 || child_die
->tag
== DW_TAG_template_type_param
)
16167 process_die (child_die
, cu
);
16169 child_die
= sibling_die (child_die
);
16172 /* Do not consider external references. According to the DWARF standard,
16173 these DIEs are identified by the fact that they have no byte_size
16174 attribute, and a declaration attribute. */
16175 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16176 || !die_is_declaration (die
, cu
))
16177 new_symbol (die
, type
, cu
);
16180 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16181 update TYPE using some information only available in DIE's children. */
16184 update_enumeration_type_from_children (struct die_info
*die
,
16186 struct dwarf2_cu
*cu
)
16188 struct die_info
*child_die
;
16189 int unsigned_enum
= 1;
16193 auto_obstack obstack
;
16195 for (child_die
= die
->child
;
16196 child_die
!= NULL
&& child_die
->tag
;
16197 child_die
= sibling_die (child_die
))
16199 struct attribute
*attr
;
16201 const gdb_byte
*bytes
;
16202 struct dwarf2_locexpr_baton
*baton
;
16205 if (child_die
->tag
!= DW_TAG_enumerator
)
16208 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16212 name
= dwarf2_name (child_die
, cu
);
16214 name
= "<anonymous enumerator>";
16216 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16217 &value
, &bytes
, &baton
);
16223 else if ((mask
& value
) != 0)
16228 /* If we already know that the enum type is neither unsigned, nor
16229 a flag type, no need to look at the rest of the enumerates. */
16230 if (!unsigned_enum
&& !flag_enum
)
16235 TYPE_UNSIGNED (type
) = 1;
16237 TYPE_FLAG_ENUM (type
) = 1;
16240 /* Given a DW_AT_enumeration_type die, set its type. We do not
16241 complete the type's fields yet, or create any symbols. */
16243 static struct type
*
16244 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16246 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16248 struct attribute
*attr
;
16251 /* If the definition of this type lives in .debug_types, read that type.
16252 Don't follow DW_AT_specification though, that will take us back up
16253 the chain and we want to go down. */
16254 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16257 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16259 /* The type's CU may not be the same as CU.
16260 Ensure TYPE is recorded with CU in die_type_hash. */
16261 return set_die_type (die
, type
, cu
);
16264 type
= alloc_type (objfile
);
16266 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16267 name
= dwarf2_full_name (NULL
, die
, cu
);
16269 TYPE_TAG_NAME (type
) = name
;
16271 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16274 struct type
*underlying_type
= die_type (die
, cu
);
16276 TYPE_TARGET_TYPE (type
) = underlying_type
;
16279 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16282 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16286 TYPE_LENGTH (type
) = 0;
16289 /* The enumeration DIE can be incomplete. In Ada, any type can be
16290 declared as private in the package spec, and then defined only
16291 inside the package body. Such types are known as Taft Amendment
16292 Types. When another package uses such a type, an incomplete DIE
16293 may be generated by the compiler. */
16294 if (die_is_declaration (die
, cu
))
16295 TYPE_STUB (type
) = 1;
16297 /* Finish the creation of this type by using the enum's children.
16298 We must call this even when the underlying type has been provided
16299 so that we can determine if we're looking at a "flag" enum. */
16300 update_enumeration_type_from_children (die
, type
, cu
);
16302 /* If this type has an underlying type that is not a stub, then we
16303 may use its attributes. We always use the "unsigned" attribute
16304 in this situation, because ordinarily we guess whether the type
16305 is unsigned -- but the guess can be wrong and the underlying type
16306 can tell us the reality. However, we defer to a local size
16307 attribute if one exists, because this lets the compiler override
16308 the underlying type if needed. */
16309 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16311 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16312 if (TYPE_LENGTH (type
) == 0)
16313 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16316 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16318 return set_die_type (die
, type
, cu
);
16321 /* Given a pointer to a die which begins an enumeration, process all
16322 the dies that define the members of the enumeration, and create the
16323 symbol for the enumeration type.
16325 NOTE: We reverse the order of the element list. */
16328 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16330 struct type
*this_type
;
16332 this_type
= get_die_type (die
, cu
);
16333 if (this_type
== NULL
)
16334 this_type
= read_enumeration_type (die
, cu
);
16336 if (die
->child
!= NULL
)
16338 struct die_info
*child_die
;
16339 struct symbol
*sym
;
16340 struct field
*fields
= NULL
;
16341 int num_fields
= 0;
16344 child_die
= die
->child
;
16345 while (child_die
&& child_die
->tag
)
16347 if (child_die
->tag
!= DW_TAG_enumerator
)
16349 process_die (child_die
, cu
);
16353 name
= dwarf2_name (child_die
, cu
);
16356 sym
= new_symbol (child_die
, this_type
, cu
);
16358 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16360 fields
= (struct field
*)
16362 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16363 * sizeof (struct field
));
16366 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16367 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16368 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16369 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16375 child_die
= sibling_die (child_die
);
16380 TYPE_NFIELDS (this_type
) = num_fields
;
16381 TYPE_FIELDS (this_type
) = (struct field
*)
16382 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16383 memcpy (TYPE_FIELDS (this_type
), fields
,
16384 sizeof (struct field
) * num_fields
);
16389 /* If we are reading an enum from a .debug_types unit, and the enum
16390 is a declaration, and the enum is not the signatured type in the
16391 unit, then we do not want to add a symbol for it. Adding a
16392 symbol would in some cases obscure the true definition of the
16393 enum, giving users an incomplete type when the definition is
16394 actually available. Note that we do not want to do this for all
16395 enums which are just declarations, because C++0x allows forward
16396 enum declarations. */
16397 if (cu
->per_cu
->is_debug_types
16398 && die_is_declaration (die
, cu
))
16400 struct signatured_type
*sig_type
;
16402 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16403 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16404 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16408 new_symbol (die
, this_type
, cu
);
16411 /* Extract all information from a DW_TAG_array_type DIE and put it in
16412 the DIE's type field. For now, this only handles one dimensional
16415 static struct type
*
16416 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16418 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16419 struct die_info
*child_die
;
16421 struct type
*element_type
, *range_type
, *index_type
;
16422 struct attribute
*attr
;
16424 struct dynamic_prop
*byte_stride_prop
= NULL
;
16425 unsigned int bit_stride
= 0;
16427 element_type
= die_type (die
, cu
);
16429 /* The die_type call above may have already set the type for this DIE. */
16430 type
= get_die_type (die
, cu
);
16434 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16440 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16441 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16444 complaint (&symfile_complaints
,
16445 _("unable to read array DW_AT_byte_stride "
16446 " - DIE at %s [in module %s]"),
16447 sect_offset_str (die
->sect_off
),
16448 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16449 /* Ignore this attribute. We will likely not be able to print
16450 arrays of this type correctly, but there is little we can do
16451 to help if we cannot read the attribute's value. */
16452 byte_stride_prop
= NULL
;
16456 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16458 bit_stride
= DW_UNSND (attr
);
16460 /* Irix 6.2 native cc creates array types without children for
16461 arrays with unspecified length. */
16462 if (die
->child
== NULL
)
16464 index_type
= objfile_type (objfile
)->builtin_int
;
16465 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16466 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16467 byte_stride_prop
, bit_stride
);
16468 return set_die_type (die
, type
, cu
);
16471 std::vector
<struct type
*> range_types
;
16472 child_die
= die
->child
;
16473 while (child_die
&& child_die
->tag
)
16475 if (child_die
->tag
== DW_TAG_subrange_type
)
16477 struct type
*child_type
= read_type_die (child_die
, cu
);
16479 if (child_type
!= NULL
)
16481 /* The range type was succesfully read. Save it for the
16482 array type creation. */
16483 range_types
.push_back (child_type
);
16486 child_die
= sibling_die (child_die
);
16489 /* Dwarf2 dimensions are output from left to right, create the
16490 necessary array types in backwards order. */
16492 type
= element_type
;
16494 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16498 while (i
< range_types
.size ())
16499 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16500 byte_stride_prop
, bit_stride
);
16504 size_t ndim
= range_types
.size ();
16506 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16507 byte_stride_prop
, bit_stride
);
16510 /* Understand Dwarf2 support for vector types (like they occur on
16511 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16512 array type. This is not part of the Dwarf2/3 standard yet, but a
16513 custom vendor extension. The main difference between a regular
16514 array and the vector variant is that vectors are passed by value
16516 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16518 make_vector_type (type
);
16520 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16521 implementation may choose to implement triple vectors using this
16523 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16526 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16527 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16529 complaint (&symfile_complaints
,
16530 _("DW_AT_byte_size for array type smaller "
16531 "than the total size of elements"));
16534 name
= dwarf2_name (die
, cu
);
16536 TYPE_NAME (type
) = name
;
16538 /* Install the type in the die. */
16539 set_die_type (die
, type
, cu
);
16541 /* set_die_type should be already done. */
16542 set_descriptive_type (type
, die
, cu
);
16547 static enum dwarf_array_dim_ordering
16548 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16550 struct attribute
*attr
;
16552 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16555 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16557 /* GNU F77 is a special case, as at 08/2004 array type info is the
16558 opposite order to the dwarf2 specification, but data is still
16559 laid out as per normal fortran.
16561 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16562 version checking. */
16564 if (cu
->language
== language_fortran
16565 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16567 return DW_ORD_row_major
;
16570 switch (cu
->language_defn
->la_array_ordering
)
16572 case array_column_major
:
16573 return DW_ORD_col_major
;
16574 case array_row_major
:
16576 return DW_ORD_row_major
;
16580 /* Extract all information from a DW_TAG_set_type DIE and put it in
16581 the DIE's type field. */
16583 static struct type
*
16584 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16586 struct type
*domain_type
, *set_type
;
16587 struct attribute
*attr
;
16589 domain_type
= die_type (die
, cu
);
16591 /* The die_type call above may have already set the type for this DIE. */
16592 set_type
= get_die_type (die
, cu
);
16596 set_type
= create_set_type (NULL
, domain_type
);
16598 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16600 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16602 return set_die_type (die
, set_type
, cu
);
16605 /* A helper for read_common_block that creates a locexpr baton.
16606 SYM is the symbol which we are marking as computed.
16607 COMMON_DIE is the DIE for the common block.
16608 COMMON_LOC is the location expression attribute for the common
16610 MEMBER_LOC is the location expression attribute for the particular
16611 member of the common block that we are processing.
16612 CU is the CU from which the above come. */
16615 mark_common_block_symbol_computed (struct symbol
*sym
,
16616 struct die_info
*common_die
,
16617 struct attribute
*common_loc
,
16618 struct attribute
*member_loc
,
16619 struct dwarf2_cu
*cu
)
16621 struct dwarf2_per_objfile
*dwarf2_per_objfile
16622 = cu
->per_cu
->dwarf2_per_objfile
;
16623 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16624 struct dwarf2_locexpr_baton
*baton
;
16626 unsigned int cu_off
;
16627 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16628 LONGEST offset
= 0;
16630 gdb_assert (common_loc
&& member_loc
);
16631 gdb_assert (attr_form_is_block (common_loc
));
16632 gdb_assert (attr_form_is_block (member_loc
)
16633 || attr_form_is_constant (member_loc
));
16635 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16636 baton
->per_cu
= cu
->per_cu
;
16637 gdb_assert (baton
->per_cu
);
16639 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16641 if (attr_form_is_constant (member_loc
))
16643 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16644 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16647 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16649 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16652 *ptr
++ = DW_OP_call4
;
16653 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16654 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16657 if (attr_form_is_constant (member_loc
))
16659 *ptr
++ = DW_OP_addr
;
16660 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16661 ptr
+= cu
->header
.addr_size
;
16665 /* We have to copy the data here, because DW_OP_call4 will only
16666 use a DW_AT_location attribute. */
16667 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16668 ptr
+= DW_BLOCK (member_loc
)->size
;
16671 *ptr
++ = DW_OP_plus
;
16672 gdb_assert (ptr
- baton
->data
== baton
->size
);
16674 SYMBOL_LOCATION_BATON (sym
) = baton
;
16675 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16678 /* Create appropriate locally-scoped variables for all the
16679 DW_TAG_common_block entries. Also create a struct common_block
16680 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16681 is used to sepate the common blocks name namespace from regular
16685 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16687 struct attribute
*attr
;
16689 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16692 /* Support the .debug_loc offsets. */
16693 if (attr_form_is_block (attr
))
16697 else if (attr_form_is_section_offset (attr
))
16699 dwarf2_complex_location_expr_complaint ();
16704 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16705 "common block member");
16710 if (die
->child
!= NULL
)
16712 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16713 struct die_info
*child_die
;
16714 size_t n_entries
= 0, size
;
16715 struct common_block
*common_block
;
16716 struct symbol
*sym
;
16718 for (child_die
= die
->child
;
16719 child_die
&& child_die
->tag
;
16720 child_die
= sibling_die (child_die
))
16723 size
= (sizeof (struct common_block
)
16724 + (n_entries
- 1) * sizeof (struct symbol
*));
16726 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16728 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16729 common_block
->n_entries
= 0;
16731 for (child_die
= die
->child
;
16732 child_die
&& child_die
->tag
;
16733 child_die
= sibling_die (child_die
))
16735 /* Create the symbol in the DW_TAG_common_block block in the current
16737 sym
= new_symbol (child_die
, NULL
, cu
);
16740 struct attribute
*member_loc
;
16742 common_block
->contents
[common_block
->n_entries
++] = sym
;
16744 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16748 /* GDB has handled this for a long time, but it is
16749 not specified by DWARF. It seems to have been
16750 emitted by gfortran at least as recently as:
16751 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16752 complaint (&symfile_complaints
,
16753 _("Variable in common block has "
16754 "DW_AT_data_member_location "
16755 "- DIE at %s [in module %s]"),
16756 sect_offset_str (child_die
->sect_off
),
16757 objfile_name (objfile
));
16759 if (attr_form_is_section_offset (member_loc
))
16760 dwarf2_complex_location_expr_complaint ();
16761 else if (attr_form_is_constant (member_loc
)
16762 || attr_form_is_block (member_loc
))
16765 mark_common_block_symbol_computed (sym
, die
, attr
,
16769 dwarf2_complex_location_expr_complaint ();
16774 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16775 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16779 /* Create a type for a C++ namespace. */
16781 static struct type
*
16782 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16784 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16785 const char *previous_prefix
, *name
;
16789 /* For extensions, reuse the type of the original namespace. */
16790 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16792 struct die_info
*ext_die
;
16793 struct dwarf2_cu
*ext_cu
= cu
;
16795 ext_die
= dwarf2_extension (die
, &ext_cu
);
16796 type
= read_type_die (ext_die
, ext_cu
);
16798 /* EXT_CU may not be the same as CU.
16799 Ensure TYPE is recorded with CU in die_type_hash. */
16800 return set_die_type (die
, type
, cu
);
16803 name
= namespace_name (die
, &is_anonymous
, cu
);
16805 /* Now build the name of the current namespace. */
16807 previous_prefix
= determine_prefix (die
, cu
);
16808 if (previous_prefix
[0] != '\0')
16809 name
= typename_concat (&objfile
->objfile_obstack
,
16810 previous_prefix
, name
, 0, cu
);
16812 /* Create the type. */
16813 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16814 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16816 return set_die_type (die
, type
, cu
);
16819 /* Read a namespace scope. */
16822 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16824 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16827 /* Add a symbol associated to this if we haven't seen the namespace
16828 before. Also, add a using directive if it's an anonymous
16831 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16835 type
= read_type_die (die
, cu
);
16836 new_symbol (die
, type
, cu
);
16838 namespace_name (die
, &is_anonymous
, cu
);
16841 const char *previous_prefix
= determine_prefix (die
, cu
);
16843 std::vector
<const char *> excludes
;
16844 add_using_directive (using_directives (cu
->language
),
16845 previous_prefix
, TYPE_NAME (type
), NULL
,
16846 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16850 if (die
->child
!= NULL
)
16852 struct die_info
*child_die
= die
->child
;
16854 while (child_die
&& child_die
->tag
)
16856 process_die (child_die
, cu
);
16857 child_die
= sibling_die (child_die
);
16862 /* Read a Fortran module as type. This DIE can be only a declaration used for
16863 imported module. Still we need that type as local Fortran "use ... only"
16864 declaration imports depend on the created type in determine_prefix. */
16866 static struct type
*
16867 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16869 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16870 const char *module_name
;
16873 module_name
= dwarf2_name (die
, cu
);
16875 complaint (&symfile_complaints
,
16876 _("DW_TAG_module has no name, offset %s"),
16877 sect_offset_str (die
->sect_off
));
16878 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16880 /* determine_prefix uses TYPE_TAG_NAME. */
16881 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
16883 return set_die_type (die
, type
, cu
);
16886 /* Read a Fortran module. */
16889 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16891 struct die_info
*child_die
= die
->child
;
16894 type
= read_type_die (die
, cu
);
16895 new_symbol (die
, type
, cu
);
16897 while (child_die
&& child_die
->tag
)
16899 process_die (child_die
, cu
);
16900 child_die
= sibling_die (child_die
);
16904 /* Return the name of the namespace represented by DIE. Set
16905 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16908 static const char *
16909 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16911 struct die_info
*current_die
;
16912 const char *name
= NULL
;
16914 /* Loop through the extensions until we find a name. */
16916 for (current_die
= die
;
16917 current_die
!= NULL
;
16918 current_die
= dwarf2_extension (die
, &cu
))
16920 /* We don't use dwarf2_name here so that we can detect the absence
16921 of a name -> anonymous namespace. */
16922 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16928 /* Is it an anonymous namespace? */
16930 *is_anonymous
= (name
== NULL
);
16932 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16937 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16938 the user defined type vector. */
16940 static struct type
*
16941 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16943 struct gdbarch
*gdbarch
16944 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16945 struct comp_unit_head
*cu_header
= &cu
->header
;
16947 struct attribute
*attr_byte_size
;
16948 struct attribute
*attr_address_class
;
16949 int byte_size
, addr_class
;
16950 struct type
*target_type
;
16952 target_type
= die_type (die
, cu
);
16954 /* The die_type call above may have already set the type for this DIE. */
16955 type
= get_die_type (die
, cu
);
16959 type
= lookup_pointer_type (target_type
);
16961 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16962 if (attr_byte_size
)
16963 byte_size
= DW_UNSND (attr_byte_size
);
16965 byte_size
= cu_header
->addr_size
;
16967 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16968 if (attr_address_class
)
16969 addr_class
= DW_UNSND (attr_address_class
);
16971 addr_class
= DW_ADDR_none
;
16973 /* If the pointer size or address class is different than the
16974 default, create a type variant marked as such and set the
16975 length accordingly. */
16976 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
16978 if (gdbarch_address_class_type_flags_p (gdbarch
))
16982 type_flags
= gdbarch_address_class_type_flags
16983 (gdbarch
, byte_size
, addr_class
);
16984 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16986 type
= make_type_with_address_space (type
, type_flags
);
16988 else if (TYPE_LENGTH (type
) != byte_size
)
16990 complaint (&symfile_complaints
,
16991 _("invalid pointer size %d"), byte_size
);
16995 /* Should we also complain about unhandled address classes? */
16999 TYPE_LENGTH (type
) = byte_size
;
17000 return set_die_type (die
, type
, cu
);
17003 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17004 the user defined type vector. */
17006 static struct type
*
17007 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17010 struct type
*to_type
;
17011 struct type
*domain
;
17013 to_type
= die_type (die
, cu
);
17014 domain
= die_containing_type (die
, cu
);
17016 /* The calls above may have already set the type for this DIE. */
17017 type
= get_die_type (die
, cu
);
17021 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17022 type
= lookup_methodptr_type (to_type
);
17023 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17025 struct type
*new_type
17026 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17028 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17029 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17030 TYPE_VARARGS (to_type
));
17031 type
= lookup_methodptr_type (new_type
);
17034 type
= lookup_memberptr_type (to_type
, domain
);
17036 return set_die_type (die
, type
, cu
);
17039 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17040 the user defined type vector. */
17042 static struct type
*
17043 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17044 enum type_code refcode
)
17046 struct comp_unit_head
*cu_header
= &cu
->header
;
17047 struct type
*type
, *target_type
;
17048 struct attribute
*attr
;
17050 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17052 target_type
= die_type (die
, cu
);
17054 /* The die_type call above may have already set the type for this DIE. */
17055 type
= get_die_type (die
, cu
);
17059 type
= lookup_reference_type (target_type
, refcode
);
17060 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17063 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17067 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17069 return set_die_type (die
, type
, cu
);
17072 /* Add the given cv-qualifiers to the element type of the array. GCC
17073 outputs DWARF type qualifiers that apply to an array, not the
17074 element type. But GDB relies on the array element type to carry
17075 the cv-qualifiers. This mimics section 6.7.3 of the C99
17078 static struct type
*
17079 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17080 struct type
*base_type
, int cnst
, int voltl
)
17082 struct type
*el_type
, *inner_array
;
17084 base_type
= copy_type (base_type
);
17085 inner_array
= base_type
;
17087 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17089 TYPE_TARGET_TYPE (inner_array
) =
17090 copy_type (TYPE_TARGET_TYPE (inner_array
));
17091 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17094 el_type
= TYPE_TARGET_TYPE (inner_array
);
17095 cnst
|= TYPE_CONST (el_type
);
17096 voltl
|= TYPE_VOLATILE (el_type
);
17097 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17099 return set_die_type (die
, base_type
, cu
);
17102 static struct type
*
17103 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17105 struct type
*base_type
, *cv_type
;
17107 base_type
= die_type (die
, cu
);
17109 /* The die_type call above may have already set the type for this DIE. */
17110 cv_type
= get_die_type (die
, cu
);
17114 /* In case the const qualifier is applied to an array type, the element type
17115 is so qualified, not the array type (section 6.7.3 of C99). */
17116 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17117 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17119 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17120 return set_die_type (die
, cv_type
, cu
);
17123 static struct type
*
17124 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17126 struct type
*base_type
, *cv_type
;
17128 base_type
= die_type (die
, cu
);
17130 /* The die_type call above may have already set the type for this DIE. */
17131 cv_type
= get_die_type (die
, cu
);
17135 /* In case the volatile qualifier is applied to an array type, the
17136 element type is so qualified, not the array type (section 6.7.3
17138 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17139 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17141 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17142 return set_die_type (die
, cv_type
, cu
);
17145 /* Handle DW_TAG_restrict_type. */
17147 static struct type
*
17148 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17150 struct type
*base_type
, *cv_type
;
17152 base_type
= die_type (die
, cu
);
17154 /* The die_type call above may have already set the type for this DIE. */
17155 cv_type
= get_die_type (die
, cu
);
17159 cv_type
= make_restrict_type (base_type
);
17160 return set_die_type (die
, cv_type
, cu
);
17163 /* Handle DW_TAG_atomic_type. */
17165 static struct type
*
17166 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17168 struct type
*base_type
, *cv_type
;
17170 base_type
= die_type (die
, cu
);
17172 /* The die_type call above may have already set the type for this DIE. */
17173 cv_type
= get_die_type (die
, cu
);
17177 cv_type
= make_atomic_type (base_type
);
17178 return set_die_type (die
, cv_type
, cu
);
17181 /* Extract all information from a DW_TAG_string_type DIE and add to
17182 the user defined type vector. It isn't really a user defined type,
17183 but it behaves like one, with other DIE's using an AT_user_def_type
17184 attribute to reference it. */
17186 static struct type
*
17187 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17189 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17190 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17191 struct type
*type
, *range_type
, *index_type
, *char_type
;
17192 struct attribute
*attr
;
17193 unsigned int length
;
17195 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17198 length
= DW_UNSND (attr
);
17202 /* Check for the DW_AT_byte_size attribute. */
17203 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17206 length
= DW_UNSND (attr
);
17214 index_type
= objfile_type (objfile
)->builtin_int
;
17215 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17216 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17217 type
= create_string_type (NULL
, char_type
, range_type
);
17219 return set_die_type (die
, type
, cu
);
17222 /* Assuming that DIE corresponds to a function, returns nonzero
17223 if the function is prototyped. */
17226 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17228 struct attribute
*attr
;
17230 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17231 if (attr
&& (DW_UNSND (attr
) != 0))
17234 /* The DWARF standard implies that the DW_AT_prototyped attribute
17235 is only meaninful for C, but the concept also extends to other
17236 languages that allow unprototyped functions (Eg: Objective C).
17237 For all other languages, assume that functions are always
17239 if (cu
->language
!= language_c
17240 && cu
->language
!= language_objc
17241 && cu
->language
!= language_opencl
)
17244 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17245 prototyped and unprototyped functions; default to prototyped,
17246 since that is more common in modern code (and RealView warns
17247 about unprototyped functions). */
17248 if (producer_is_realview (cu
->producer
))
17254 /* Handle DIES due to C code like:
17258 int (*funcp)(int a, long l);
17262 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17264 static struct type
*
17265 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17267 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17268 struct type
*type
; /* Type that this function returns. */
17269 struct type
*ftype
; /* Function that returns above type. */
17270 struct attribute
*attr
;
17272 type
= die_type (die
, cu
);
17274 /* The die_type call above may have already set the type for this DIE. */
17275 ftype
= get_die_type (die
, cu
);
17279 ftype
= lookup_function_type (type
);
17281 if (prototyped_function_p (die
, cu
))
17282 TYPE_PROTOTYPED (ftype
) = 1;
17284 /* Store the calling convention in the type if it's available in
17285 the subroutine die. Otherwise set the calling convention to
17286 the default value DW_CC_normal. */
17287 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17289 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17290 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17291 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17293 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17295 /* Record whether the function returns normally to its caller or not
17296 if the DWARF producer set that information. */
17297 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17298 if (attr
&& (DW_UNSND (attr
) != 0))
17299 TYPE_NO_RETURN (ftype
) = 1;
17301 /* We need to add the subroutine type to the die immediately so
17302 we don't infinitely recurse when dealing with parameters
17303 declared as the same subroutine type. */
17304 set_die_type (die
, ftype
, cu
);
17306 if (die
->child
!= NULL
)
17308 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17309 struct die_info
*child_die
;
17310 int nparams
, iparams
;
17312 /* Count the number of parameters.
17313 FIXME: GDB currently ignores vararg functions, but knows about
17314 vararg member functions. */
17316 child_die
= die
->child
;
17317 while (child_die
&& child_die
->tag
)
17319 if (child_die
->tag
== DW_TAG_formal_parameter
)
17321 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17322 TYPE_VARARGS (ftype
) = 1;
17323 child_die
= sibling_die (child_die
);
17326 /* Allocate storage for parameters and fill them in. */
17327 TYPE_NFIELDS (ftype
) = nparams
;
17328 TYPE_FIELDS (ftype
) = (struct field
*)
17329 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17331 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17332 even if we error out during the parameters reading below. */
17333 for (iparams
= 0; iparams
< nparams
; iparams
++)
17334 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17337 child_die
= die
->child
;
17338 while (child_die
&& child_die
->tag
)
17340 if (child_die
->tag
== DW_TAG_formal_parameter
)
17342 struct type
*arg_type
;
17344 /* DWARF version 2 has no clean way to discern C++
17345 static and non-static member functions. G++ helps
17346 GDB by marking the first parameter for non-static
17347 member functions (which is the this pointer) as
17348 artificial. We pass this information to
17349 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17351 DWARF version 3 added DW_AT_object_pointer, which GCC
17352 4.5 does not yet generate. */
17353 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17355 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17357 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17358 arg_type
= die_type (child_die
, cu
);
17360 /* RealView does not mark THIS as const, which the testsuite
17361 expects. GCC marks THIS as const in method definitions,
17362 but not in the class specifications (GCC PR 43053). */
17363 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17364 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17367 struct dwarf2_cu
*arg_cu
= cu
;
17368 const char *name
= dwarf2_name (child_die
, cu
);
17370 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17373 /* If the compiler emits this, use it. */
17374 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17377 else if (name
&& strcmp (name
, "this") == 0)
17378 /* Function definitions will have the argument names. */
17380 else if (name
== NULL
&& iparams
== 0)
17381 /* Declarations may not have the names, so like
17382 elsewhere in GDB, assume an artificial first
17383 argument is "this". */
17387 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17391 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17394 child_die
= sibling_die (child_die
);
17401 static struct type
*
17402 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17404 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17405 const char *name
= NULL
;
17406 struct type
*this_type
, *target_type
;
17408 name
= dwarf2_full_name (NULL
, die
, cu
);
17409 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17410 TYPE_TARGET_STUB (this_type
) = 1;
17411 set_die_type (die
, this_type
, cu
);
17412 target_type
= die_type (die
, cu
);
17413 if (target_type
!= this_type
)
17414 TYPE_TARGET_TYPE (this_type
) = target_type
;
17417 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17418 spec and cause infinite loops in GDB. */
17419 complaint (&symfile_complaints
,
17420 _("Self-referential DW_TAG_typedef "
17421 "- DIE at %s [in module %s]"),
17422 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17423 TYPE_TARGET_TYPE (this_type
) = NULL
;
17428 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17429 (which may be different from NAME) to the architecture back-end to allow
17430 it to guess the correct format if necessary. */
17432 static struct type
*
17433 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17434 const char *name_hint
)
17436 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17437 const struct floatformat
**format
;
17440 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17442 type
= init_float_type (objfile
, bits
, name
, format
);
17444 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17449 /* Find a representation of a given base type and install
17450 it in the TYPE field of the die. */
17452 static struct type
*
17453 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17455 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17457 struct attribute
*attr
;
17458 int encoding
= 0, bits
= 0;
17461 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17464 encoding
= DW_UNSND (attr
);
17466 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17469 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17471 name
= dwarf2_name (die
, cu
);
17474 complaint (&symfile_complaints
,
17475 _("DW_AT_name missing from DW_TAG_base_type"));
17480 case DW_ATE_address
:
17481 /* Turn DW_ATE_address into a void * pointer. */
17482 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17483 type
= init_pointer_type (objfile
, bits
, name
, type
);
17485 case DW_ATE_boolean
:
17486 type
= init_boolean_type (objfile
, bits
, 1, name
);
17488 case DW_ATE_complex_float
:
17489 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17490 type
= init_complex_type (objfile
, name
, type
);
17492 case DW_ATE_decimal_float
:
17493 type
= init_decfloat_type (objfile
, bits
, name
);
17496 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17498 case DW_ATE_signed
:
17499 type
= init_integer_type (objfile
, bits
, 0, name
);
17501 case DW_ATE_unsigned
:
17502 if (cu
->language
== language_fortran
17504 && startswith (name
, "character("))
17505 type
= init_character_type (objfile
, bits
, 1, name
);
17507 type
= init_integer_type (objfile
, bits
, 1, name
);
17509 case DW_ATE_signed_char
:
17510 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17511 || cu
->language
== language_pascal
17512 || cu
->language
== language_fortran
)
17513 type
= init_character_type (objfile
, bits
, 0, name
);
17515 type
= init_integer_type (objfile
, bits
, 0, name
);
17517 case DW_ATE_unsigned_char
:
17518 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17519 || cu
->language
== language_pascal
17520 || cu
->language
== language_fortran
17521 || cu
->language
== language_rust
)
17522 type
= init_character_type (objfile
, bits
, 1, name
);
17524 type
= init_integer_type (objfile
, bits
, 1, name
);
17528 gdbarch
*arch
= get_objfile_arch (objfile
);
17531 type
= builtin_type (arch
)->builtin_char16
;
17532 else if (bits
== 32)
17533 type
= builtin_type (arch
)->builtin_char32
;
17536 complaint (&symfile_complaints
,
17537 _("unsupported DW_ATE_UTF bit size: '%d'"),
17539 type
= init_integer_type (objfile
, bits
, 1, name
);
17541 return set_die_type (die
, type
, cu
);
17546 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17547 dwarf_type_encoding_name (encoding
));
17548 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17552 if (name
&& strcmp (name
, "char") == 0)
17553 TYPE_NOSIGN (type
) = 1;
17555 return set_die_type (die
, type
, cu
);
17558 /* Parse dwarf attribute if it's a block, reference or constant and put the
17559 resulting value of the attribute into struct bound_prop.
17560 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17563 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17564 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17566 struct dwarf2_property_baton
*baton
;
17567 struct obstack
*obstack
17568 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17570 if (attr
== NULL
|| prop
== NULL
)
17573 if (attr_form_is_block (attr
))
17575 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17576 baton
->referenced_type
= NULL
;
17577 baton
->locexpr
.per_cu
= cu
->per_cu
;
17578 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17579 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17580 prop
->data
.baton
= baton
;
17581 prop
->kind
= PROP_LOCEXPR
;
17582 gdb_assert (prop
->data
.baton
!= NULL
);
17584 else if (attr_form_is_ref (attr
))
17586 struct dwarf2_cu
*target_cu
= cu
;
17587 struct die_info
*target_die
;
17588 struct attribute
*target_attr
;
17590 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17591 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17592 if (target_attr
== NULL
)
17593 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17595 if (target_attr
== NULL
)
17598 switch (target_attr
->name
)
17600 case DW_AT_location
:
17601 if (attr_form_is_section_offset (target_attr
))
17603 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17604 baton
->referenced_type
= die_type (target_die
, target_cu
);
17605 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17606 prop
->data
.baton
= baton
;
17607 prop
->kind
= PROP_LOCLIST
;
17608 gdb_assert (prop
->data
.baton
!= NULL
);
17610 else if (attr_form_is_block (target_attr
))
17612 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17613 baton
->referenced_type
= die_type (target_die
, target_cu
);
17614 baton
->locexpr
.per_cu
= cu
->per_cu
;
17615 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17616 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17617 prop
->data
.baton
= baton
;
17618 prop
->kind
= PROP_LOCEXPR
;
17619 gdb_assert (prop
->data
.baton
!= NULL
);
17623 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17624 "dynamic property");
17628 case DW_AT_data_member_location
:
17632 if (!handle_data_member_location (target_die
, target_cu
,
17636 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17637 baton
->referenced_type
= read_type_die (target_die
->parent
,
17639 baton
->offset_info
.offset
= offset
;
17640 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17641 prop
->data
.baton
= baton
;
17642 prop
->kind
= PROP_ADDR_OFFSET
;
17647 else if (attr_form_is_constant (attr
))
17649 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17650 prop
->kind
= PROP_CONST
;
17654 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17655 dwarf2_name (die
, cu
));
17662 /* Read the given DW_AT_subrange DIE. */
17664 static struct type
*
17665 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17667 struct type
*base_type
, *orig_base_type
;
17668 struct type
*range_type
;
17669 struct attribute
*attr
;
17670 struct dynamic_prop low
, high
;
17671 int low_default_is_valid
;
17672 int high_bound_is_count
= 0;
17674 LONGEST negative_mask
;
17676 orig_base_type
= die_type (die
, cu
);
17677 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17678 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17679 creating the range type, but we use the result of check_typedef
17680 when examining properties of the type. */
17681 base_type
= check_typedef (orig_base_type
);
17683 /* The die_type call above may have already set the type for this DIE. */
17684 range_type
= get_die_type (die
, cu
);
17688 low
.kind
= PROP_CONST
;
17689 high
.kind
= PROP_CONST
;
17690 high
.data
.const_val
= 0;
17692 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17693 omitting DW_AT_lower_bound. */
17694 switch (cu
->language
)
17697 case language_cplus
:
17698 low
.data
.const_val
= 0;
17699 low_default_is_valid
= 1;
17701 case language_fortran
:
17702 low
.data
.const_val
= 1;
17703 low_default_is_valid
= 1;
17706 case language_objc
:
17707 case language_rust
:
17708 low
.data
.const_val
= 0;
17709 low_default_is_valid
= (cu
->header
.version
>= 4);
17713 case language_pascal
:
17714 low
.data
.const_val
= 1;
17715 low_default_is_valid
= (cu
->header
.version
>= 4);
17718 low
.data
.const_val
= 0;
17719 low_default_is_valid
= 0;
17723 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17725 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
17726 else if (!low_default_is_valid
)
17727 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
17728 "- DIE at %s [in module %s]"),
17729 sect_offset_str (die
->sect_off
),
17730 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17732 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17733 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17735 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
17736 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
17738 /* If bounds are constant do the final calculation here. */
17739 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17740 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17742 high_bound_is_count
= 1;
17746 /* Dwarf-2 specifications explicitly allows to create subrange types
17747 without specifying a base type.
17748 In that case, the base type must be set to the type of
17749 the lower bound, upper bound or count, in that order, if any of these
17750 three attributes references an object that has a type.
17751 If no base type is found, the Dwarf-2 specifications say that
17752 a signed integer type of size equal to the size of an address should
17754 For the following C code: `extern char gdb_int [];'
17755 GCC produces an empty range DIE.
17756 FIXME: muller/2010-05-28: Possible references to object for low bound,
17757 high bound or count are not yet handled by this code. */
17758 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
17760 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17761 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17762 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
17763 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
17765 /* Test "int", "long int", and "long long int" objfile types,
17766 and select the first one having a size above or equal to the
17767 architecture address size. */
17768 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17769 base_type
= int_type
;
17772 int_type
= objfile_type (objfile
)->builtin_long
;
17773 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17774 base_type
= int_type
;
17777 int_type
= objfile_type (objfile
)->builtin_long_long
;
17778 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
17779 base_type
= int_type
;
17784 /* Normally, the DWARF producers are expected to use a signed
17785 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17786 But this is unfortunately not always the case, as witnessed
17787 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17788 is used instead. To work around that ambiguity, we treat
17789 the bounds as signed, and thus sign-extend their values, when
17790 the base type is signed. */
17792 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17793 if (low
.kind
== PROP_CONST
17794 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17795 low
.data
.const_val
|= negative_mask
;
17796 if (high
.kind
== PROP_CONST
17797 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17798 high
.data
.const_val
|= negative_mask
;
17800 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
17802 if (high_bound_is_count
)
17803 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17805 /* Ada expects an empty array on no boundary attributes. */
17806 if (attr
== NULL
&& cu
->language
!= language_ada
)
17807 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17809 name
= dwarf2_name (die
, cu
);
17811 TYPE_NAME (range_type
) = name
;
17813 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17815 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17817 set_die_type (die
, range_type
, cu
);
17819 /* set_die_type should be already done. */
17820 set_descriptive_type (range_type
, die
, cu
);
17825 static struct type
*
17826 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17830 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17832 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17834 /* In Ada, an unspecified type is typically used when the description
17835 of the type is defered to a different unit. When encountering
17836 such a type, we treat it as a stub, and try to resolve it later on,
17838 if (cu
->language
== language_ada
)
17839 TYPE_STUB (type
) = 1;
17841 return set_die_type (die
, type
, cu
);
17844 /* Read a single die and all its descendents. Set the die's sibling
17845 field to NULL; set other fields in the die correctly, and set all
17846 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17847 location of the info_ptr after reading all of those dies. PARENT
17848 is the parent of the die in question. */
17850 static struct die_info
*
17851 read_die_and_children (const struct die_reader_specs
*reader
,
17852 const gdb_byte
*info_ptr
,
17853 const gdb_byte
**new_info_ptr
,
17854 struct die_info
*parent
)
17856 struct die_info
*die
;
17857 const gdb_byte
*cur_ptr
;
17860 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
17863 *new_info_ptr
= cur_ptr
;
17866 store_in_ref_table (die
, reader
->cu
);
17869 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17873 *new_info_ptr
= cur_ptr
;
17876 die
->sibling
= NULL
;
17877 die
->parent
= parent
;
17881 /* Read a die, all of its descendents, and all of its siblings; set
17882 all of the fields of all of the dies correctly. Arguments are as
17883 in read_die_and_children. */
17885 static struct die_info
*
17886 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17887 const gdb_byte
*info_ptr
,
17888 const gdb_byte
**new_info_ptr
,
17889 struct die_info
*parent
)
17891 struct die_info
*first_die
, *last_sibling
;
17892 const gdb_byte
*cur_ptr
;
17894 cur_ptr
= info_ptr
;
17895 first_die
= last_sibling
= NULL
;
17899 struct die_info
*die
17900 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17904 *new_info_ptr
= cur_ptr
;
17911 last_sibling
->sibling
= die
;
17913 last_sibling
= die
;
17917 /* Read a die, all of its descendents, and all of its siblings; set
17918 all of the fields of all of the dies correctly. Arguments are as
17919 in read_die_and_children.
17920 This the main entry point for reading a DIE and all its children. */
17922 static struct die_info
*
17923 read_die_and_siblings (const struct die_reader_specs
*reader
,
17924 const gdb_byte
*info_ptr
,
17925 const gdb_byte
**new_info_ptr
,
17926 struct die_info
*parent
)
17928 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17929 new_info_ptr
, parent
);
17931 if (dwarf_die_debug
)
17933 fprintf_unfiltered (gdb_stdlog
,
17934 "Read die from %s@0x%x of %s:\n",
17935 get_section_name (reader
->die_section
),
17936 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17937 bfd_get_filename (reader
->abfd
));
17938 dump_die (die
, dwarf_die_debug
);
17944 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17946 The caller is responsible for filling in the extra attributes
17947 and updating (*DIEP)->num_attrs.
17948 Set DIEP to point to a newly allocated die with its information,
17949 except for its child, sibling, and parent fields.
17950 Set HAS_CHILDREN to tell whether the die has children or not. */
17952 static const gdb_byte
*
17953 read_full_die_1 (const struct die_reader_specs
*reader
,
17954 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17955 int *has_children
, int num_extra_attrs
)
17957 unsigned int abbrev_number
, bytes_read
, i
;
17958 struct abbrev_info
*abbrev
;
17959 struct die_info
*die
;
17960 struct dwarf2_cu
*cu
= reader
->cu
;
17961 bfd
*abfd
= reader
->abfd
;
17963 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17964 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17965 info_ptr
+= bytes_read
;
17966 if (!abbrev_number
)
17973 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17975 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17977 bfd_get_filename (abfd
));
17979 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17980 die
->sect_off
= sect_off
;
17981 die
->tag
= abbrev
->tag
;
17982 die
->abbrev
= abbrev_number
;
17984 /* Make the result usable.
17985 The caller needs to update num_attrs after adding the extra
17987 die
->num_attrs
= abbrev
->num_attrs
;
17989 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17990 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17994 *has_children
= abbrev
->has_children
;
17998 /* Read a die and all its attributes.
17999 Set DIEP to point to a newly allocated die with its information,
18000 except for its child, sibling, and parent fields.
18001 Set HAS_CHILDREN to tell whether the die has children or not. */
18003 static const gdb_byte
*
18004 read_full_die (const struct die_reader_specs
*reader
,
18005 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18008 const gdb_byte
*result
;
18010 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18012 if (dwarf_die_debug
)
18014 fprintf_unfiltered (gdb_stdlog
,
18015 "Read die from %s@0x%x of %s:\n",
18016 get_section_name (reader
->die_section
),
18017 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18018 bfd_get_filename (reader
->abfd
));
18019 dump_die (*diep
, dwarf_die_debug
);
18025 /* Abbreviation tables.
18027 In DWARF version 2, the description of the debugging information is
18028 stored in a separate .debug_abbrev section. Before we read any
18029 dies from a section we read in all abbreviations and install them
18030 in a hash table. */
18032 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18034 struct abbrev_info
*
18035 abbrev_table::alloc_abbrev ()
18037 struct abbrev_info
*abbrev
;
18039 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18040 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18045 /* Add an abbreviation to the table. */
18048 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18049 struct abbrev_info
*abbrev
)
18051 unsigned int hash_number
;
18053 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18054 abbrev
->next
= m_abbrevs
[hash_number
];
18055 m_abbrevs
[hash_number
] = abbrev
;
18058 /* Look up an abbrev in the table.
18059 Returns NULL if the abbrev is not found. */
18061 struct abbrev_info
*
18062 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18064 unsigned int hash_number
;
18065 struct abbrev_info
*abbrev
;
18067 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18068 abbrev
= m_abbrevs
[hash_number
];
18072 if (abbrev
->number
== abbrev_number
)
18074 abbrev
= abbrev
->next
;
18079 /* Read in an abbrev table. */
18081 static abbrev_table_up
18082 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18083 struct dwarf2_section_info
*section
,
18084 sect_offset sect_off
)
18086 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18087 bfd
*abfd
= get_section_bfd_owner (section
);
18088 const gdb_byte
*abbrev_ptr
;
18089 struct abbrev_info
*cur_abbrev
;
18090 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18091 unsigned int abbrev_form
;
18092 struct attr_abbrev
*cur_attrs
;
18093 unsigned int allocated_attrs
;
18095 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18097 dwarf2_read_section (objfile
, section
);
18098 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18099 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18100 abbrev_ptr
+= bytes_read
;
18102 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18103 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18105 /* Loop until we reach an abbrev number of 0. */
18106 while (abbrev_number
)
18108 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18110 /* read in abbrev header */
18111 cur_abbrev
->number
= abbrev_number
;
18113 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18114 abbrev_ptr
+= bytes_read
;
18115 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18118 /* now read in declarations */
18121 LONGEST implicit_const
;
18123 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18124 abbrev_ptr
+= bytes_read
;
18125 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18126 abbrev_ptr
+= bytes_read
;
18127 if (abbrev_form
== DW_FORM_implicit_const
)
18129 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18131 abbrev_ptr
+= bytes_read
;
18135 /* Initialize it due to a false compiler warning. */
18136 implicit_const
= -1;
18139 if (abbrev_name
== 0)
18142 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18144 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18146 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18149 cur_attrs
[cur_abbrev
->num_attrs
].name
18150 = (enum dwarf_attribute
) abbrev_name
;
18151 cur_attrs
[cur_abbrev
->num_attrs
].form
18152 = (enum dwarf_form
) abbrev_form
;
18153 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18154 ++cur_abbrev
->num_attrs
;
18157 cur_abbrev
->attrs
=
18158 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18159 cur_abbrev
->num_attrs
);
18160 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18161 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18163 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18165 /* Get next abbreviation.
18166 Under Irix6 the abbreviations for a compilation unit are not
18167 always properly terminated with an abbrev number of 0.
18168 Exit loop if we encounter an abbreviation which we have
18169 already read (which means we are about to read the abbreviations
18170 for the next compile unit) or if the end of the abbreviation
18171 table is reached. */
18172 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18174 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18175 abbrev_ptr
+= bytes_read
;
18176 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18181 return abbrev_table
;
18184 /* Returns nonzero if TAG represents a type that we might generate a partial
18188 is_type_tag_for_partial (int tag
)
18193 /* Some types that would be reasonable to generate partial symbols for,
18194 that we don't at present. */
18195 case DW_TAG_array_type
:
18196 case DW_TAG_file_type
:
18197 case DW_TAG_ptr_to_member_type
:
18198 case DW_TAG_set_type
:
18199 case DW_TAG_string_type
:
18200 case DW_TAG_subroutine_type
:
18202 case DW_TAG_base_type
:
18203 case DW_TAG_class_type
:
18204 case DW_TAG_interface_type
:
18205 case DW_TAG_enumeration_type
:
18206 case DW_TAG_structure_type
:
18207 case DW_TAG_subrange_type
:
18208 case DW_TAG_typedef
:
18209 case DW_TAG_union_type
:
18216 /* Load all DIEs that are interesting for partial symbols into memory. */
18218 static struct partial_die_info
*
18219 load_partial_dies (const struct die_reader_specs
*reader
,
18220 const gdb_byte
*info_ptr
, int building_psymtab
)
18222 struct dwarf2_cu
*cu
= reader
->cu
;
18223 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18224 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18225 unsigned int bytes_read
;
18226 unsigned int load_all
= 0;
18227 int nesting_level
= 1;
18232 gdb_assert (cu
->per_cu
!= NULL
);
18233 if (cu
->per_cu
->load_all_dies
)
18237 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18241 &cu
->comp_unit_obstack
,
18242 hashtab_obstack_allocate
,
18243 dummy_obstack_deallocate
);
18247 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18249 /* A NULL abbrev means the end of a series of children. */
18250 if (abbrev
== NULL
)
18252 if (--nesting_level
== 0)
18255 info_ptr
+= bytes_read
;
18256 last_die
= parent_die
;
18257 parent_die
= parent_die
->die_parent
;
18261 /* Check for template arguments. We never save these; if
18262 they're seen, we just mark the parent, and go on our way. */
18263 if (parent_die
!= NULL
18264 && cu
->language
== language_cplus
18265 && (abbrev
->tag
== DW_TAG_template_type_param
18266 || abbrev
->tag
== DW_TAG_template_value_param
))
18268 parent_die
->has_template_arguments
= 1;
18272 /* We don't need a partial DIE for the template argument. */
18273 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18278 /* We only recurse into c++ subprograms looking for template arguments.
18279 Skip their other children. */
18281 && cu
->language
== language_cplus
18282 && parent_die
!= NULL
18283 && parent_die
->tag
== DW_TAG_subprogram
)
18285 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18289 /* Check whether this DIE is interesting enough to save. Normally
18290 we would not be interested in members here, but there may be
18291 later variables referencing them via DW_AT_specification (for
18292 static members). */
18294 && !is_type_tag_for_partial (abbrev
->tag
)
18295 && abbrev
->tag
!= DW_TAG_constant
18296 && abbrev
->tag
!= DW_TAG_enumerator
18297 && abbrev
->tag
!= DW_TAG_subprogram
18298 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18299 && abbrev
->tag
!= DW_TAG_lexical_block
18300 && abbrev
->tag
!= DW_TAG_variable
18301 && abbrev
->tag
!= DW_TAG_namespace
18302 && abbrev
->tag
!= DW_TAG_module
18303 && abbrev
->tag
!= DW_TAG_member
18304 && abbrev
->tag
!= DW_TAG_imported_unit
18305 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18307 /* Otherwise we skip to the next sibling, if any. */
18308 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18312 struct partial_die_info pdi
;
18314 memset (&pdi
, 0, sizeof (pdi
));
18315 info_ptr
= read_partial_die (reader
, &pdi
, *abbrev
, bytes_read
,
18318 /* This two-pass algorithm for processing partial symbols has a
18319 high cost in cache pressure. Thus, handle some simple cases
18320 here which cover the majority of C partial symbols. DIEs
18321 which neither have specification tags in them, nor could have
18322 specification tags elsewhere pointing at them, can simply be
18323 processed and discarded.
18325 This segment is also optional; scan_partial_symbols and
18326 add_partial_symbol will handle these DIEs if we chain
18327 them in normally. When compilers which do not emit large
18328 quantities of duplicate debug information are more common,
18329 this code can probably be removed. */
18331 /* Any complete simple types at the top level (pretty much all
18332 of them, for a language without namespaces), can be processed
18334 if (parent_die
== NULL
18335 && pdi
.has_specification
== 0
18336 && pdi
.is_declaration
== 0
18337 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18338 || pdi
.tag
== DW_TAG_base_type
18339 || pdi
.tag
== DW_TAG_subrange_type
))
18341 if (building_psymtab
&& pdi
.name
!= NULL
)
18342 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18343 VAR_DOMAIN
, LOC_TYPEDEF
,
18344 &objfile
->static_psymbols
,
18345 0, cu
->language
, objfile
);
18346 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18350 /* The exception for DW_TAG_typedef with has_children above is
18351 a workaround of GCC PR debug/47510. In the case of this complaint
18352 type_name_no_tag_or_error will error on such types later.
18354 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18355 it could not find the child DIEs referenced later, this is checked
18356 above. In correct DWARF DW_TAG_typedef should have no children. */
18358 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18359 complaint (&symfile_complaints
,
18360 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18361 "- DIE at %s [in module %s]"),
18362 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18364 /* If we're at the second level, and we're an enumerator, and
18365 our parent has no specification (meaning possibly lives in a
18366 namespace elsewhere), then we can add the partial symbol now
18367 instead of queueing it. */
18368 if (pdi
.tag
== DW_TAG_enumerator
18369 && parent_die
!= NULL
18370 && parent_die
->die_parent
== NULL
18371 && parent_die
->tag
== DW_TAG_enumeration_type
18372 && parent_die
->has_specification
== 0)
18374 if (pdi
.name
== NULL
)
18375 complaint (&symfile_complaints
,
18376 _("malformed enumerator DIE ignored"));
18377 else if (building_psymtab
)
18378 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18379 VAR_DOMAIN
, LOC_CONST
,
18380 cu
->language
== language_cplus
18381 ? &objfile
->global_psymbols
18382 : &objfile
->static_psymbols
,
18383 0, cu
->language
, objfile
);
18385 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18389 struct partial_die_info
*part_die
18390 = XOBNEW (&cu
->comp_unit_obstack
, struct partial_die_info
);
18392 memcpy (part_die
, &pdi
, sizeof (pdi
));
18393 /* We'll save this DIE so link it in. */
18394 part_die
->die_parent
= parent_die
;
18395 part_die
->die_sibling
= NULL
;
18396 part_die
->die_child
= NULL
;
18398 if (last_die
&& last_die
== parent_die
)
18399 last_die
->die_child
= part_die
;
18401 last_die
->die_sibling
= part_die
;
18403 last_die
= part_die
;
18405 if (first_die
== NULL
)
18406 first_die
= part_die
;
18408 /* Maybe add the DIE to the hash table. Not all DIEs that we
18409 find interesting need to be in the hash table, because we
18410 also have the parent/sibling/child chains; only those that we
18411 might refer to by offset later during partial symbol reading.
18413 For now this means things that might have be the target of a
18414 DW_AT_specification, DW_AT_abstract_origin, or
18415 DW_AT_extension. DW_AT_extension will refer only to
18416 namespaces; DW_AT_abstract_origin refers to functions (and
18417 many things under the function DIE, but we do not recurse
18418 into function DIEs during partial symbol reading) and
18419 possibly variables as well; DW_AT_specification refers to
18420 declarations. Declarations ought to have the DW_AT_declaration
18421 flag. It happens that GCC forgets to put it in sometimes, but
18422 only for functions, not for types.
18424 Adding more things than necessary to the hash table is harmless
18425 except for the performance cost. Adding too few will result in
18426 wasted time in find_partial_die, when we reread the compilation
18427 unit with load_all_dies set. */
18430 || abbrev
->tag
== DW_TAG_constant
18431 || abbrev
->tag
== DW_TAG_subprogram
18432 || abbrev
->tag
== DW_TAG_variable
18433 || abbrev
->tag
== DW_TAG_namespace
18434 || part_die
->is_declaration
)
18438 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18439 to_underlying (part_die
->sect_off
),
18444 /* For some DIEs we want to follow their children (if any). For C
18445 we have no reason to follow the children of structures; for other
18446 languages we have to, so that we can get at method physnames
18447 to infer fully qualified class names, for DW_AT_specification,
18448 and for C++ template arguments. For C++, we also look one level
18449 inside functions to find template arguments (if the name of the
18450 function does not already contain the template arguments).
18452 For Ada, we need to scan the children of subprograms and lexical
18453 blocks as well because Ada allows the definition of nested
18454 entities that could be interesting for the debugger, such as
18455 nested subprograms for instance. */
18456 if (last_die
->has_children
18458 || last_die
->tag
== DW_TAG_namespace
18459 || last_die
->tag
== DW_TAG_module
18460 || last_die
->tag
== DW_TAG_enumeration_type
18461 || (cu
->language
== language_cplus
18462 && last_die
->tag
== DW_TAG_subprogram
18463 && (last_die
->name
== NULL
18464 || strchr (last_die
->name
, '<') == NULL
))
18465 || (cu
->language
!= language_c
18466 && (last_die
->tag
== DW_TAG_class_type
18467 || last_die
->tag
== DW_TAG_interface_type
18468 || last_die
->tag
== DW_TAG_structure_type
18469 || last_die
->tag
== DW_TAG_union_type
))
18470 || (cu
->language
== language_ada
18471 && (last_die
->tag
== DW_TAG_subprogram
18472 || last_die
->tag
== DW_TAG_lexical_block
))))
18475 parent_die
= last_die
;
18479 /* Otherwise we skip to the next sibling, if any. */
18480 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18482 /* Back to the top, do it again. */
18486 /* Read a minimal amount of information into the minimal die structure. */
18488 static const gdb_byte
*
18489 read_partial_die (const struct die_reader_specs
*reader
,
18490 struct partial_die_info
*part_die
,
18491 const struct abbrev_info
&abbrev
, unsigned int abbrev_len
,
18492 const gdb_byte
*info_ptr
)
18494 struct dwarf2_cu
*cu
= reader
->cu
;
18495 struct dwarf2_per_objfile
*dwarf2_per_objfile
18496 = cu
->per_cu
->dwarf2_per_objfile
;
18497 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18498 const gdb_byte
*buffer
= reader
->buffer
;
18500 struct attribute attr
;
18501 int has_low_pc_attr
= 0;
18502 int has_high_pc_attr
= 0;
18503 int high_pc_relative
= 0;
18505 memset (part_die
, 0, sizeof (struct partial_die_info
));
18507 part_die
->sect_off
= (sect_offset
) (info_ptr
- buffer
);
18509 info_ptr
+= abbrev_len
;
18511 part_die
->tag
= abbrev
.tag
;
18512 part_die
->has_children
= abbrev
.has_children
;
18514 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18516 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18518 /* Store the data if it is of an attribute we want to keep in a
18519 partial symbol table. */
18523 switch (part_die
->tag
)
18525 case DW_TAG_compile_unit
:
18526 case DW_TAG_partial_unit
:
18527 case DW_TAG_type_unit
:
18528 /* Compilation units have a DW_AT_name that is a filename, not
18529 a source language identifier. */
18530 case DW_TAG_enumeration_type
:
18531 case DW_TAG_enumerator
:
18532 /* These tags always have simple identifiers already; no need
18533 to canonicalize them. */
18534 part_die
->name
= DW_STRING (&attr
);
18538 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18539 &objfile
->per_bfd
->storage_obstack
);
18543 case DW_AT_linkage_name
:
18544 case DW_AT_MIPS_linkage_name
:
18545 /* Note that both forms of linkage name might appear. We
18546 assume they will be the same, and we only store the last
18548 if (cu
->language
== language_ada
)
18549 part_die
->name
= DW_STRING (&attr
);
18550 part_die
->linkage_name
= DW_STRING (&attr
);
18553 has_low_pc_attr
= 1;
18554 part_die
->lowpc
= attr_value_as_address (&attr
);
18556 case DW_AT_high_pc
:
18557 has_high_pc_attr
= 1;
18558 part_die
->highpc
= attr_value_as_address (&attr
);
18559 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18560 high_pc_relative
= 1;
18562 case DW_AT_location
:
18563 /* Support the .debug_loc offsets. */
18564 if (attr_form_is_block (&attr
))
18566 part_die
->d
.locdesc
= DW_BLOCK (&attr
);
18568 else if (attr_form_is_section_offset (&attr
))
18570 dwarf2_complex_location_expr_complaint ();
18574 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18575 "partial symbol information");
18578 case DW_AT_external
:
18579 part_die
->is_external
= DW_UNSND (&attr
);
18581 case DW_AT_declaration
:
18582 part_die
->is_declaration
= DW_UNSND (&attr
);
18585 part_die
->has_type
= 1;
18587 case DW_AT_abstract_origin
:
18588 case DW_AT_specification
:
18589 case DW_AT_extension
:
18590 part_die
->has_specification
= 1;
18591 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18592 part_die
->spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18593 || cu
->per_cu
->is_dwz
);
18595 case DW_AT_sibling
:
18596 /* Ignore absolute siblings, they might point outside of
18597 the current compile unit. */
18598 if (attr
.form
== DW_FORM_ref_addr
)
18599 complaint (&symfile_complaints
,
18600 _("ignoring absolute DW_AT_sibling"));
18603 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18604 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18606 if (sibling_ptr
< info_ptr
)
18607 complaint (&symfile_complaints
,
18608 _("DW_AT_sibling points backwards"));
18609 else if (sibling_ptr
> reader
->buffer_end
)
18610 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18612 part_die
->sibling
= sibling_ptr
;
18615 case DW_AT_byte_size
:
18616 part_die
->has_byte_size
= 1;
18618 case DW_AT_const_value
:
18619 part_die
->has_const_value
= 1;
18621 case DW_AT_calling_convention
:
18622 /* DWARF doesn't provide a way to identify a program's source-level
18623 entry point. DW_AT_calling_convention attributes are only meant
18624 to describe functions' calling conventions.
18626 However, because it's a necessary piece of information in
18627 Fortran, and before DWARF 4 DW_CC_program was the only
18628 piece of debugging information whose definition refers to
18629 a 'main program' at all, several compilers marked Fortran
18630 main programs with DW_CC_program --- even when those
18631 functions use the standard calling conventions.
18633 Although DWARF now specifies a way to provide this
18634 information, we support this practice for backward
18636 if (DW_UNSND (&attr
) == DW_CC_program
18637 && cu
->language
== language_fortran
)
18638 part_die
->main_subprogram
= 1;
18641 if (DW_UNSND (&attr
) == DW_INL_inlined
18642 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18643 part_die
->may_be_inlined
= 1;
18647 if (part_die
->tag
== DW_TAG_imported_unit
)
18649 part_die
->d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18650 part_die
->is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18651 || cu
->per_cu
->is_dwz
);
18655 case DW_AT_main_subprogram
:
18656 part_die
->main_subprogram
= DW_UNSND (&attr
);
18664 if (high_pc_relative
)
18665 part_die
->highpc
+= part_die
->lowpc
;
18667 if (has_low_pc_attr
&& has_high_pc_attr
)
18669 /* When using the GNU linker, .gnu.linkonce. sections are used to
18670 eliminate duplicate copies of functions and vtables and such.
18671 The linker will arbitrarily choose one and discard the others.
18672 The AT_*_pc values for such functions refer to local labels in
18673 these sections. If the section from that file was discarded, the
18674 labels are not in the output, so the relocs get a value of 0.
18675 If this is a discarded function, mark the pc bounds as invalid,
18676 so that GDB will ignore it. */
18677 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18679 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18681 complaint (&symfile_complaints
,
18682 _("DW_AT_low_pc %s is zero "
18683 "for DIE at %s [in module %s]"),
18684 paddress (gdbarch
, part_die
->lowpc
),
18685 sect_offset_str (part_die
->sect_off
),
18686 objfile_name (objfile
));
18688 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18689 else if (part_die
->lowpc
>= part_die
->highpc
)
18691 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18693 complaint (&symfile_complaints
,
18694 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18695 "for DIE at %s [in module %s]"),
18696 paddress (gdbarch
, part_die
->lowpc
),
18697 paddress (gdbarch
, part_die
->highpc
),
18698 sect_offset_str (part_die
->sect_off
),
18699 objfile_name (objfile
));
18702 part_die
->has_pc_info
= 1;
18708 /* Find a cached partial DIE at OFFSET in CU. */
18710 struct partial_die_info
*
18711 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18713 struct partial_die_info
*lookup_die
= NULL
;
18714 struct partial_die_info part_die
;
18716 part_die
.sect_off
= sect_off
;
18717 lookup_die
= ((struct partial_die_info
*)
18718 htab_find_with_hash (partial_dies
, &part_die
,
18719 to_underlying (sect_off
)));
18724 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18725 except in the case of .debug_types DIEs which do not reference
18726 outside their CU (they do however referencing other types via
18727 DW_FORM_ref_sig8). */
18729 static struct partial_die_info
*
18730 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18732 struct dwarf2_per_objfile
*dwarf2_per_objfile
18733 = cu
->per_cu
->dwarf2_per_objfile
;
18734 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18735 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18736 struct partial_die_info
*pd
= NULL
;
18738 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18739 && offset_in_cu_p (&cu
->header
, sect_off
))
18741 pd
= cu
->find_partial_die (sect_off
);
18744 /* We missed recording what we needed.
18745 Load all dies and try again. */
18746 per_cu
= cu
->per_cu
;
18750 /* TUs don't reference other CUs/TUs (except via type signatures). */
18751 if (cu
->per_cu
->is_debug_types
)
18753 error (_("Dwarf Error: Type Unit at offset %s contains"
18754 " external reference to offset %s [in module %s].\n"),
18755 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18756 bfd_get_filename (objfile
->obfd
));
18758 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18759 dwarf2_per_objfile
);
18761 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18762 load_partial_comp_unit (per_cu
);
18764 per_cu
->cu
->last_used
= 0;
18765 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18768 /* If we didn't find it, and not all dies have been loaded,
18769 load them all and try again. */
18771 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18773 per_cu
->load_all_dies
= 1;
18775 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18776 THIS_CU->cu may already be in use. So we can't just free it and
18777 replace its DIEs with the ones we read in. Instead, we leave those
18778 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18779 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18781 load_partial_comp_unit (per_cu
);
18783 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18787 internal_error (__FILE__
, __LINE__
,
18788 _("could not find partial DIE %s "
18789 "in cache [from module %s]\n"),
18790 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18794 /* See if we can figure out if the class lives in a namespace. We do
18795 this by looking for a member function; its demangled name will
18796 contain namespace info, if there is any. */
18799 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18800 struct dwarf2_cu
*cu
)
18802 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18803 what template types look like, because the demangler
18804 frequently doesn't give the same name as the debug info. We
18805 could fix this by only using the demangled name to get the
18806 prefix (but see comment in read_structure_type). */
18808 struct partial_die_info
*real_pdi
;
18809 struct partial_die_info
*child_pdi
;
18811 /* If this DIE (this DIE's specification, if any) has a parent, then
18812 we should not do this. We'll prepend the parent's fully qualified
18813 name when we create the partial symbol. */
18815 real_pdi
= struct_pdi
;
18816 while (real_pdi
->has_specification
)
18817 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
18818 real_pdi
->spec_is_dwz
, cu
);
18820 if (real_pdi
->die_parent
!= NULL
)
18823 for (child_pdi
= struct_pdi
->die_child
;
18825 child_pdi
= child_pdi
->die_sibling
)
18827 if (child_pdi
->tag
== DW_TAG_subprogram
18828 && child_pdi
->linkage_name
!= NULL
)
18830 char *actual_class_name
18831 = language_class_name_from_physname (cu
->language_defn
,
18832 child_pdi
->linkage_name
);
18833 if (actual_class_name
!= NULL
)
18835 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18838 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18840 strlen (actual_class_name
)));
18841 xfree (actual_class_name
);
18848 /* Adjust PART_DIE before generating a symbol for it. This function
18849 may set the is_external flag or change the DIE's name. */
18852 fixup_partial_die (struct partial_die_info
*part_die
,
18853 struct dwarf2_cu
*cu
)
18855 /* Once we've fixed up a die, there's no point in doing so again.
18856 This also avoids a memory leak if we were to call
18857 guess_partial_die_structure_name multiple times. */
18858 if (part_die
->fixup_called
)
18861 /* If we found a reference attribute and the DIE has no name, try
18862 to find a name in the referred to DIE. */
18864 if (part_die
->name
== NULL
&& part_die
->has_specification
)
18866 struct partial_die_info
*spec_die
;
18868 spec_die
= find_partial_die (part_die
->spec_offset
,
18869 part_die
->spec_is_dwz
, cu
);
18871 fixup_partial_die (spec_die
, cu
);
18873 if (spec_die
->name
)
18875 part_die
->name
= spec_die
->name
;
18877 /* Copy DW_AT_external attribute if it is set. */
18878 if (spec_die
->is_external
)
18879 part_die
->is_external
= spec_die
->is_external
;
18883 /* Set default names for some unnamed DIEs. */
18885 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
18886 part_die
->name
= CP_ANONYMOUS_NAMESPACE_STR
;
18888 /* If there is no parent die to provide a namespace, and there are
18889 children, see if we can determine the namespace from their linkage
18891 if (cu
->language
== language_cplus
18892 && !VEC_empty (dwarf2_section_info_def
,
18893 cu
->per_cu
->dwarf2_per_objfile
->types
)
18894 && part_die
->die_parent
== NULL
18895 && part_die
->has_children
18896 && (part_die
->tag
== DW_TAG_class_type
18897 || part_die
->tag
== DW_TAG_structure_type
18898 || part_die
->tag
== DW_TAG_union_type
))
18899 guess_partial_die_structure_name (part_die
, cu
);
18901 /* GCC might emit a nameless struct or union that has a linkage
18902 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18903 if (part_die
->name
== NULL
18904 && (part_die
->tag
== DW_TAG_class_type
18905 || part_die
->tag
== DW_TAG_interface_type
18906 || part_die
->tag
== DW_TAG_structure_type
18907 || part_die
->tag
== DW_TAG_union_type
)
18908 && part_die
->linkage_name
!= NULL
)
18912 demangled
= gdb_demangle (part_die
->linkage_name
, DMGL_TYPES
);
18917 /* Strip any leading namespaces/classes, keep only the base name.
18918 DW_AT_name for named DIEs does not contain the prefixes. */
18919 base
= strrchr (demangled
, ':');
18920 if (base
&& base
> demangled
&& base
[-1] == ':')
18925 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18928 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
18929 base
, strlen (base
)));
18934 part_die
->fixup_called
= 1;
18937 /* Read an attribute value described by an attribute form. */
18939 static const gdb_byte
*
18940 read_attribute_value (const struct die_reader_specs
*reader
,
18941 struct attribute
*attr
, unsigned form
,
18942 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
18944 struct dwarf2_cu
*cu
= reader
->cu
;
18945 struct dwarf2_per_objfile
*dwarf2_per_objfile
18946 = cu
->per_cu
->dwarf2_per_objfile
;
18947 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18948 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18949 bfd
*abfd
= reader
->abfd
;
18950 struct comp_unit_head
*cu_header
= &cu
->header
;
18951 unsigned int bytes_read
;
18952 struct dwarf_block
*blk
;
18954 attr
->form
= (enum dwarf_form
) form
;
18957 case DW_FORM_ref_addr
:
18958 if (cu
->header
.version
== 2)
18959 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18961 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
18962 &cu
->header
, &bytes_read
);
18963 info_ptr
+= bytes_read
;
18965 case DW_FORM_GNU_ref_alt
:
18966 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
18967 info_ptr
+= bytes_read
;
18970 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
18971 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18972 info_ptr
+= bytes_read
;
18974 case DW_FORM_block2
:
18975 blk
= dwarf_alloc_block (cu
);
18976 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18978 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18979 info_ptr
+= blk
->size
;
18980 DW_BLOCK (attr
) = blk
;
18982 case DW_FORM_block4
:
18983 blk
= dwarf_alloc_block (cu
);
18984 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18986 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18987 info_ptr
+= blk
->size
;
18988 DW_BLOCK (attr
) = blk
;
18990 case DW_FORM_data2
:
18991 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18994 case DW_FORM_data4
:
18995 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18998 case DW_FORM_data8
:
18999 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19002 case DW_FORM_data16
:
19003 blk
= dwarf_alloc_block (cu
);
19005 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19007 DW_BLOCK (attr
) = blk
;
19009 case DW_FORM_sec_offset
:
19010 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19011 info_ptr
+= bytes_read
;
19013 case DW_FORM_string
:
19014 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19015 DW_STRING_IS_CANONICAL (attr
) = 0;
19016 info_ptr
+= bytes_read
;
19019 if (!cu
->per_cu
->is_dwz
)
19021 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19022 abfd
, info_ptr
, cu_header
,
19024 DW_STRING_IS_CANONICAL (attr
) = 0;
19025 info_ptr
+= bytes_read
;
19029 case DW_FORM_line_strp
:
19030 if (!cu
->per_cu
->is_dwz
)
19032 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19034 cu_header
, &bytes_read
);
19035 DW_STRING_IS_CANONICAL (attr
) = 0;
19036 info_ptr
+= bytes_read
;
19040 case DW_FORM_GNU_strp_alt
:
19042 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19043 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19046 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19048 DW_STRING_IS_CANONICAL (attr
) = 0;
19049 info_ptr
+= bytes_read
;
19052 case DW_FORM_exprloc
:
19053 case DW_FORM_block
:
19054 blk
= dwarf_alloc_block (cu
);
19055 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19056 info_ptr
+= bytes_read
;
19057 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19058 info_ptr
+= blk
->size
;
19059 DW_BLOCK (attr
) = blk
;
19061 case DW_FORM_block1
:
19062 blk
= dwarf_alloc_block (cu
);
19063 blk
->size
= read_1_byte (abfd
, info_ptr
);
19065 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19066 info_ptr
+= blk
->size
;
19067 DW_BLOCK (attr
) = blk
;
19069 case DW_FORM_data1
:
19070 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19074 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19077 case DW_FORM_flag_present
:
19078 DW_UNSND (attr
) = 1;
19080 case DW_FORM_sdata
:
19081 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19082 info_ptr
+= bytes_read
;
19084 case DW_FORM_udata
:
19085 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19086 info_ptr
+= bytes_read
;
19089 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19090 + read_1_byte (abfd
, info_ptr
));
19094 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19095 + read_2_bytes (abfd
, info_ptr
));
19099 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19100 + read_4_bytes (abfd
, info_ptr
));
19104 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19105 + read_8_bytes (abfd
, info_ptr
));
19108 case DW_FORM_ref_sig8
:
19109 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19112 case DW_FORM_ref_udata
:
19113 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19114 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19115 info_ptr
+= bytes_read
;
19117 case DW_FORM_indirect
:
19118 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19119 info_ptr
+= bytes_read
;
19120 if (form
== DW_FORM_implicit_const
)
19122 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19123 info_ptr
+= bytes_read
;
19125 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19128 case DW_FORM_implicit_const
:
19129 DW_SND (attr
) = implicit_const
;
19131 case DW_FORM_GNU_addr_index
:
19132 if (reader
->dwo_file
== NULL
)
19134 /* For now flag a hard error.
19135 Later we can turn this into a complaint. */
19136 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19137 dwarf_form_name (form
),
19138 bfd_get_filename (abfd
));
19140 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19141 info_ptr
+= bytes_read
;
19143 case DW_FORM_GNU_str_index
:
19144 if (reader
->dwo_file
== NULL
)
19146 /* For now flag a hard error.
19147 Later we can turn this into a complaint if warranted. */
19148 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19149 dwarf_form_name (form
),
19150 bfd_get_filename (abfd
));
19153 ULONGEST str_index
=
19154 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19156 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19157 DW_STRING_IS_CANONICAL (attr
) = 0;
19158 info_ptr
+= bytes_read
;
19162 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19163 dwarf_form_name (form
),
19164 bfd_get_filename (abfd
));
19168 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19169 attr
->form
= DW_FORM_GNU_ref_alt
;
19171 /* We have seen instances where the compiler tried to emit a byte
19172 size attribute of -1 which ended up being encoded as an unsigned
19173 0xffffffff. Although 0xffffffff is technically a valid size value,
19174 an object of this size seems pretty unlikely so we can relatively
19175 safely treat these cases as if the size attribute was invalid and
19176 treat them as zero by default. */
19177 if (attr
->name
== DW_AT_byte_size
19178 && form
== DW_FORM_data4
19179 && DW_UNSND (attr
) >= 0xffffffff)
19182 (&symfile_complaints
,
19183 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19184 hex_string (DW_UNSND (attr
)));
19185 DW_UNSND (attr
) = 0;
19191 /* Read an attribute described by an abbreviated attribute. */
19193 static const gdb_byte
*
19194 read_attribute (const struct die_reader_specs
*reader
,
19195 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19196 const gdb_byte
*info_ptr
)
19198 attr
->name
= abbrev
->name
;
19199 return read_attribute_value (reader
, attr
, abbrev
->form
,
19200 abbrev
->implicit_const
, info_ptr
);
19203 /* Read dwarf information from a buffer. */
19205 static unsigned int
19206 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19208 return bfd_get_8 (abfd
, buf
);
19212 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19214 return bfd_get_signed_8 (abfd
, buf
);
19217 static unsigned int
19218 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19220 return bfd_get_16 (abfd
, buf
);
19224 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19226 return bfd_get_signed_16 (abfd
, buf
);
19229 static unsigned int
19230 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19232 return bfd_get_32 (abfd
, buf
);
19236 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19238 return bfd_get_signed_32 (abfd
, buf
);
19242 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19244 return bfd_get_64 (abfd
, buf
);
19248 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19249 unsigned int *bytes_read
)
19251 struct comp_unit_head
*cu_header
= &cu
->header
;
19252 CORE_ADDR retval
= 0;
19254 if (cu_header
->signed_addr_p
)
19256 switch (cu_header
->addr_size
)
19259 retval
= bfd_get_signed_16 (abfd
, buf
);
19262 retval
= bfd_get_signed_32 (abfd
, buf
);
19265 retval
= bfd_get_signed_64 (abfd
, buf
);
19268 internal_error (__FILE__
, __LINE__
,
19269 _("read_address: bad switch, signed [in module %s]"),
19270 bfd_get_filename (abfd
));
19275 switch (cu_header
->addr_size
)
19278 retval
= bfd_get_16 (abfd
, buf
);
19281 retval
= bfd_get_32 (abfd
, buf
);
19284 retval
= bfd_get_64 (abfd
, buf
);
19287 internal_error (__FILE__
, __LINE__
,
19288 _("read_address: bad switch, "
19289 "unsigned [in module %s]"),
19290 bfd_get_filename (abfd
));
19294 *bytes_read
= cu_header
->addr_size
;
19298 /* Read the initial length from a section. The (draft) DWARF 3
19299 specification allows the initial length to take up either 4 bytes
19300 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19301 bytes describe the length and all offsets will be 8 bytes in length
19304 An older, non-standard 64-bit format is also handled by this
19305 function. The older format in question stores the initial length
19306 as an 8-byte quantity without an escape value. Lengths greater
19307 than 2^32 aren't very common which means that the initial 4 bytes
19308 is almost always zero. Since a length value of zero doesn't make
19309 sense for the 32-bit format, this initial zero can be considered to
19310 be an escape value which indicates the presence of the older 64-bit
19311 format. As written, the code can't detect (old format) lengths
19312 greater than 4GB. If it becomes necessary to handle lengths
19313 somewhat larger than 4GB, we could allow other small values (such
19314 as the non-sensical values of 1, 2, and 3) to also be used as
19315 escape values indicating the presence of the old format.
19317 The value returned via bytes_read should be used to increment the
19318 relevant pointer after calling read_initial_length().
19320 [ Note: read_initial_length() and read_offset() are based on the
19321 document entitled "DWARF Debugging Information Format", revision
19322 3, draft 8, dated November 19, 2001. This document was obtained
19325 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19327 This document is only a draft and is subject to change. (So beware.)
19329 Details regarding the older, non-standard 64-bit format were
19330 determined empirically by examining 64-bit ELF files produced by
19331 the SGI toolchain on an IRIX 6.5 machine.
19333 - Kevin, July 16, 2002
19337 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19339 LONGEST length
= bfd_get_32 (abfd
, buf
);
19341 if (length
== 0xffffffff)
19343 length
= bfd_get_64 (abfd
, buf
+ 4);
19346 else if (length
== 0)
19348 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19349 length
= bfd_get_64 (abfd
, buf
);
19360 /* Cover function for read_initial_length.
19361 Returns the length of the object at BUF, and stores the size of the
19362 initial length in *BYTES_READ and stores the size that offsets will be in
19364 If the initial length size is not equivalent to that specified in
19365 CU_HEADER then issue a complaint.
19366 This is useful when reading non-comp-unit headers. */
19369 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19370 const struct comp_unit_head
*cu_header
,
19371 unsigned int *bytes_read
,
19372 unsigned int *offset_size
)
19374 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19376 gdb_assert (cu_header
->initial_length_size
== 4
19377 || cu_header
->initial_length_size
== 8
19378 || cu_header
->initial_length_size
== 12);
19380 if (cu_header
->initial_length_size
!= *bytes_read
)
19381 complaint (&symfile_complaints
,
19382 _("intermixed 32-bit and 64-bit DWARF sections"));
19384 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19388 /* Read an offset from the data stream. The size of the offset is
19389 given by cu_header->offset_size. */
19392 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19393 const struct comp_unit_head
*cu_header
,
19394 unsigned int *bytes_read
)
19396 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19398 *bytes_read
= cu_header
->offset_size
;
19402 /* Read an offset from the data stream. */
19405 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19407 LONGEST retval
= 0;
19409 switch (offset_size
)
19412 retval
= bfd_get_32 (abfd
, buf
);
19415 retval
= bfd_get_64 (abfd
, buf
);
19418 internal_error (__FILE__
, __LINE__
,
19419 _("read_offset_1: bad switch [in module %s]"),
19420 bfd_get_filename (abfd
));
19426 static const gdb_byte
*
19427 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19429 /* If the size of a host char is 8 bits, we can return a pointer
19430 to the buffer, otherwise we have to copy the data to a buffer
19431 allocated on the temporary obstack. */
19432 gdb_assert (HOST_CHAR_BIT
== 8);
19436 static const char *
19437 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19438 unsigned int *bytes_read_ptr
)
19440 /* If the size of a host char is 8 bits, we can return a pointer
19441 to the string, otherwise we have to copy the string to a buffer
19442 allocated on the temporary obstack. */
19443 gdb_assert (HOST_CHAR_BIT
== 8);
19446 *bytes_read_ptr
= 1;
19449 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19450 return (const char *) buf
;
19453 /* Return pointer to string at section SECT offset STR_OFFSET with error
19454 reporting strings FORM_NAME and SECT_NAME. */
19456 static const char *
19457 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19458 bfd
*abfd
, LONGEST str_offset
,
19459 struct dwarf2_section_info
*sect
,
19460 const char *form_name
,
19461 const char *sect_name
)
19463 dwarf2_read_section (objfile
, sect
);
19464 if (sect
->buffer
== NULL
)
19465 error (_("%s used without %s section [in module %s]"),
19466 form_name
, sect_name
, bfd_get_filename (abfd
));
19467 if (str_offset
>= sect
->size
)
19468 error (_("%s pointing outside of %s section [in module %s]"),
19469 form_name
, sect_name
, bfd_get_filename (abfd
));
19470 gdb_assert (HOST_CHAR_BIT
== 8);
19471 if (sect
->buffer
[str_offset
] == '\0')
19473 return (const char *) (sect
->buffer
+ str_offset
);
19476 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19478 static const char *
19479 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19480 bfd
*abfd
, LONGEST str_offset
)
19482 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19484 &dwarf2_per_objfile
->str
,
19485 "DW_FORM_strp", ".debug_str");
19488 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19490 static const char *
19491 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19492 bfd
*abfd
, LONGEST str_offset
)
19494 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19496 &dwarf2_per_objfile
->line_str
,
19497 "DW_FORM_line_strp",
19498 ".debug_line_str");
19501 /* Read a string at offset STR_OFFSET in the .debug_str section from
19502 the .dwz file DWZ. Throw an error if the offset is too large. If
19503 the string consists of a single NUL byte, return NULL; otherwise
19504 return a pointer to the string. */
19506 static const char *
19507 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19508 LONGEST str_offset
)
19510 dwarf2_read_section (objfile
, &dwz
->str
);
19512 if (dwz
->str
.buffer
== NULL
)
19513 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19514 "section [in module %s]"),
19515 bfd_get_filename (dwz
->dwz_bfd
));
19516 if (str_offset
>= dwz
->str
.size
)
19517 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19518 ".debug_str section [in module %s]"),
19519 bfd_get_filename (dwz
->dwz_bfd
));
19520 gdb_assert (HOST_CHAR_BIT
== 8);
19521 if (dwz
->str
.buffer
[str_offset
] == '\0')
19523 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19526 /* Return pointer to string at .debug_str offset as read from BUF.
19527 BUF is assumed to be in a compilation unit described by CU_HEADER.
19528 Return *BYTES_READ_PTR count of bytes read from BUF. */
19530 static const char *
19531 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19532 const gdb_byte
*buf
,
19533 const struct comp_unit_head
*cu_header
,
19534 unsigned int *bytes_read_ptr
)
19536 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19538 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19541 /* Return pointer to string at .debug_line_str offset as read from BUF.
19542 BUF is assumed to be in a compilation unit described by CU_HEADER.
19543 Return *BYTES_READ_PTR count of bytes read from BUF. */
19545 static const char *
19546 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19547 bfd
*abfd
, const gdb_byte
*buf
,
19548 const struct comp_unit_head
*cu_header
,
19549 unsigned int *bytes_read_ptr
)
19551 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19553 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19558 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19559 unsigned int *bytes_read_ptr
)
19562 unsigned int num_read
;
19564 unsigned char byte
;
19571 byte
= bfd_get_8 (abfd
, buf
);
19574 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19575 if ((byte
& 128) == 0)
19581 *bytes_read_ptr
= num_read
;
19586 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19587 unsigned int *bytes_read_ptr
)
19590 int shift
, num_read
;
19591 unsigned char byte
;
19598 byte
= bfd_get_8 (abfd
, buf
);
19601 result
|= ((LONGEST
) (byte
& 127) << shift
);
19603 if ((byte
& 128) == 0)
19608 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19609 result
|= -(((LONGEST
) 1) << shift
);
19610 *bytes_read_ptr
= num_read
;
19614 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19615 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19616 ADDR_SIZE is the size of addresses from the CU header. */
19619 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19620 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19622 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19623 bfd
*abfd
= objfile
->obfd
;
19624 const gdb_byte
*info_ptr
;
19626 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19627 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19628 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19629 objfile_name (objfile
));
19630 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19631 error (_("DW_FORM_addr_index pointing outside of "
19632 ".debug_addr section [in module %s]"),
19633 objfile_name (objfile
));
19634 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19635 + addr_base
+ addr_index
* addr_size
);
19636 if (addr_size
== 4)
19637 return bfd_get_32 (abfd
, info_ptr
);
19639 return bfd_get_64 (abfd
, info_ptr
);
19642 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19645 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19647 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19648 cu
->addr_base
, cu
->header
.addr_size
);
19651 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19654 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19655 unsigned int *bytes_read
)
19657 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19658 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19660 return read_addr_index (cu
, addr_index
);
19663 /* Data structure to pass results from dwarf2_read_addr_index_reader
19664 back to dwarf2_read_addr_index. */
19666 struct dwarf2_read_addr_index_data
19668 ULONGEST addr_base
;
19672 /* die_reader_func for dwarf2_read_addr_index. */
19675 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19676 const gdb_byte
*info_ptr
,
19677 struct die_info
*comp_unit_die
,
19681 struct dwarf2_cu
*cu
= reader
->cu
;
19682 struct dwarf2_read_addr_index_data
*aidata
=
19683 (struct dwarf2_read_addr_index_data
*) data
;
19685 aidata
->addr_base
= cu
->addr_base
;
19686 aidata
->addr_size
= cu
->header
.addr_size
;
19689 /* Given an index in .debug_addr, fetch the value.
19690 NOTE: This can be called during dwarf expression evaluation,
19691 long after the debug information has been read, and thus per_cu->cu
19692 may no longer exist. */
19695 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19696 unsigned int addr_index
)
19698 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19699 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19700 struct dwarf2_cu
*cu
= per_cu
->cu
;
19701 ULONGEST addr_base
;
19704 /* We need addr_base and addr_size.
19705 If we don't have PER_CU->cu, we have to get it.
19706 Nasty, but the alternative is storing the needed info in PER_CU,
19707 which at this point doesn't seem justified: it's not clear how frequently
19708 it would get used and it would increase the size of every PER_CU.
19709 Entry points like dwarf2_per_cu_addr_size do a similar thing
19710 so we're not in uncharted territory here.
19711 Alas we need to be a bit more complicated as addr_base is contained
19714 We don't need to read the entire CU(/TU).
19715 We just need the header and top level die.
19717 IWBN to use the aging mechanism to let us lazily later discard the CU.
19718 For now we skip this optimization. */
19722 addr_base
= cu
->addr_base
;
19723 addr_size
= cu
->header
.addr_size
;
19727 struct dwarf2_read_addr_index_data aidata
;
19729 /* Note: We can't use init_cutu_and_read_dies_simple here,
19730 we need addr_base. */
19731 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
19732 dwarf2_read_addr_index_reader
, &aidata
);
19733 addr_base
= aidata
.addr_base
;
19734 addr_size
= aidata
.addr_size
;
19737 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19741 /* Given a DW_FORM_GNU_str_index, fetch the string.
19742 This is only used by the Fission support. */
19744 static const char *
19745 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19747 struct dwarf2_cu
*cu
= reader
->cu
;
19748 struct dwarf2_per_objfile
*dwarf2_per_objfile
19749 = cu
->per_cu
->dwarf2_per_objfile
;
19750 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19751 const char *objf_name
= objfile_name (objfile
);
19752 bfd
*abfd
= objfile
->obfd
;
19753 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
19754 struct dwarf2_section_info
*str_offsets_section
=
19755 &reader
->dwo_file
->sections
.str_offsets
;
19756 const gdb_byte
*info_ptr
;
19757 ULONGEST str_offset
;
19758 static const char form_name
[] = "DW_FORM_GNU_str_index";
19760 dwarf2_read_section (objfile
, str_section
);
19761 dwarf2_read_section (objfile
, str_offsets_section
);
19762 if (str_section
->buffer
== NULL
)
19763 error (_("%s used without .debug_str.dwo section"
19764 " in CU at offset %s [in module %s]"),
19765 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19766 if (str_offsets_section
->buffer
== NULL
)
19767 error (_("%s used without .debug_str_offsets.dwo section"
19768 " in CU at offset %s [in module %s]"),
19769 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19770 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
19771 error (_("%s pointing outside of .debug_str_offsets.dwo"
19772 " section in CU at offset %s [in module %s]"),
19773 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19774 info_ptr
= (str_offsets_section
->buffer
19775 + str_index
* cu
->header
.offset_size
);
19776 if (cu
->header
.offset_size
== 4)
19777 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19779 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19780 if (str_offset
>= str_section
->size
)
19781 error (_("Offset from %s pointing outside of"
19782 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19783 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19784 return (const char *) (str_section
->buffer
+ str_offset
);
19787 /* Return the length of an LEB128 number in BUF. */
19790 leb128_size (const gdb_byte
*buf
)
19792 const gdb_byte
*begin
= buf
;
19798 if ((byte
& 128) == 0)
19799 return buf
- begin
;
19804 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19813 cu
->language
= language_c
;
19816 case DW_LANG_C_plus_plus
:
19817 case DW_LANG_C_plus_plus_11
:
19818 case DW_LANG_C_plus_plus_14
:
19819 cu
->language
= language_cplus
;
19822 cu
->language
= language_d
;
19824 case DW_LANG_Fortran77
:
19825 case DW_LANG_Fortran90
:
19826 case DW_LANG_Fortran95
:
19827 case DW_LANG_Fortran03
:
19828 case DW_LANG_Fortran08
:
19829 cu
->language
= language_fortran
;
19832 cu
->language
= language_go
;
19834 case DW_LANG_Mips_Assembler
:
19835 cu
->language
= language_asm
;
19837 case DW_LANG_Ada83
:
19838 case DW_LANG_Ada95
:
19839 cu
->language
= language_ada
;
19841 case DW_LANG_Modula2
:
19842 cu
->language
= language_m2
;
19844 case DW_LANG_Pascal83
:
19845 cu
->language
= language_pascal
;
19848 cu
->language
= language_objc
;
19851 case DW_LANG_Rust_old
:
19852 cu
->language
= language_rust
;
19854 case DW_LANG_Cobol74
:
19855 case DW_LANG_Cobol85
:
19857 cu
->language
= language_minimal
;
19860 cu
->language_defn
= language_def (cu
->language
);
19863 /* Return the named attribute or NULL if not there. */
19865 static struct attribute
*
19866 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19871 struct attribute
*spec
= NULL
;
19873 for (i
= 0; i
< die
->num_attrs
; ++i
)
19875 if (die
->attrs
[i
].name
== name
)
19876 return &die
->attrs
[i
];
19877 if (die
->attrs
[i
].name
== DW_AT_specification
19878 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19879 spec
= &die
->attrs
[i
];
19885 die
= follow_die_ref (die
, spec
, &cu
);
19891 /* Return the named attribute or NULL if not there,
19892 but do not follow DW_AT_specification, etc.
19893 This is for use in contexts where we're reading .debug_types dies.
19894 Following DW_AT_specification, DW_AT_abstract_origin will take us
19895 back up the chain, and we want to go down. */
19897 static struct attribute
*
19898 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19902 for (i
= 0; i
< die
->num_attrs
; ++i
)
19903 if (die
->attrs
[i
].name
== name
)
19904 return &die
->attrs
[i
];
19909 /* Return the string associated with a string-typed attribute, or NULL if it
19910 is either not found or is of an incorrect type. */
19912 static const char *
19913 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19915 struct attribute
*attr
;
19916 const char *str
= NULL
;
19918 attr
= dwarf2_attr (die
, name
, cu
);
19922 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19923 || attr
->form
== DW_FORM_string
19924 || attr
->form
== DW_FORM_GNU_str_index
19925 || attr
->form
== DW_FORM_GNU_strp_alt
)
19926 str
= DW_STRING (attr
);
19928 complaint (&symfile_complaints
,
19929 _("string type expected for attribute %s for "
19930 "DIE at %s in module %s"),
19931 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19932 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19938 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19939 and holds a non-zero value. This function should only be used for
19940 DW_FORM_flag or DW_FORM_flag_present attributes. */
19943 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19945 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19947 return (attr
&& DW_UNSND (attr
));
19951 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19953 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19954 which value is non-zero. However, we have to be careful with
19955 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19956 (via dwarf2_flag_true_p) follows this attribute. So we may
19957 end up accidently finding a declaration attribute that belongs
19958 to a different DIE referenced by the specification attribute,
19959 even though the given DIE does not have a declaration attribute. */
19960 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19961 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19964 /* Return the die giving the specification for DIE, if there is
19965 one. *SPEC_CU is the CU containing DIE on input, and the CU
19966 containing the return value on output. If there is no
19967 specification, but there is an abstract origin, that is
19970 static struct die_info
*
19971 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19973 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19976 if (spec_attr
== NULL
)
19977 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19979 if (spec_attr
== NULL
)
19982 return follow_die_ref (die
, spec_attr
, spec_cu
);
19985 /* Stub for free_line_header to match void * callback types. */
19988 free_line_header_voidp (void *arg
)
19990 struct line_header
*lh
= (struct line_header
*) arg
;
19996 line_header::add_include_dir (const char *include_dir
)
19998 if (dwarf_line_debug
>= 2)
19999 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20000 include_dirs
.size () + 1, include_dir
);
20002 include_dirs
.push_back (include_dir
);
20006 line_header::add_file_name (const char *name
,
20008 unsigned int mod_time
,
20009 unsigned int length
)
20011 if (dwarf_line_debug
>= 2)
20012 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20013 (unsigned) file_names
.size () + 1, name
);
20015 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20018 /* A convenience function to find the proper .debug_line section for a CU. */
20020 static struct dwarf2_section_info
*
20021 get_debug_line_section (struct dwarf2_cu
*cu
)
20023 struct dwarf2_section_info
*section
;
20024 struct dwarf2_per_objfile
*dwarf2_per_objfile
20025 = cu
->per_cu
->dwarf2_per_objfile
;
20027 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20029 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20030 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20031 else if (cu
->per_cu
->is_dwz
)
20033 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20035 section
= &dwz
->line
;
20038 section
= &dwarf2_per_objfile
->line
;
20043 /* Read directory or file name entry format, starting with byte of
20044 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20045 entries count and the entries themselves in the described entry
20049 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20050 bfd
*abfd
, const gdb_byte
**bufp
,
20051 struct line_header
*lh
,
20052 const struct comp_unit_head
*cu_header
,
20053 void (*callback
) (struct line_header
*lh
,
20056 unsigned int mod_time
,
20057 unsigned int length
))
20059 gdb_byte format_count
, formati
;
20060 ULONGEST data_count
, datai
;
20061 const gdb_byte
*buf
= *bufp
;
20062 const gdb_byte
*format_header_data
;
20063 unsigned int bytes_read
;
20065 format_count
= read_1_byte (abfd
, buf
);
20067 format_header_data
= buf
;
20068 for (formati
= 0; formati
< format_count
; formati
++)
20070 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20072 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20076 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20078 for (datai
= 0; datai
< data_count
; datai
++)
20080 const gdb_byte
*format
= format_header_data
;
20081 struct file_entry fe
;
20083 for (formati
= 0; formati
< format_count
; formati
++)
20085 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20086 format
+= bytes_read
;
20088 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20089 format
+= bytes_read
;
20091 gdb::optional
<const char *> string
;
20092 gdb::optional
<unsigned int> uint
;
20096 case DW_FORM_string
:
20097 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20101 case DW_FORM_line_strp
:
20102 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20109 case DW_FORM_data1
:
20110 uint
.emplace (read_1_byte (abfd
, buf
));
20114 case DW_FORM_data2
:
20115 uint
.emplace (read_2_bytes (abfd
, buf
));
20119 case DW_FORM_data4
:
20120 uint
.emplace (read_4_bytes (abfd
, buf
));
20124 case DW_FORM_data8
:
20125 uint
.emplace (read_8_bytes (abfd
, buf
));
20129 case DW_FORM_udata
:
20130 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20134 case DW_FORM_block
:
20135 /* It is valid only for DW_LNCT_timestamp which is ignored by
20140 switch (content_type
)
20143 if (string
.has_value ())
20146 case DW_LNCT_directory_index
:
20147 if (uint
.has_value ())
20148 fe
.d_index
= (dir_index
) *uint
;
20150 case DW_LNCT_timestamp
:
20151 if (uint
.has_value ())
20152 fe
.mod_time
= *uint
;
20155 if (uint
.has_value ())
20161 complaint (&symfile_complaints
,
20162 _("Unknown format content type %s"),
20163 pulongest (content_type
));
20167 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20173 /* Read the statement program header starting at OFFSET in
20174 .debug_line, or .debug_line.dwo. Return a pointer
20175 to a struct line_header, allocated using xmalloc.
20176 Returns NULL if there is a problem reading the header, e.g., if it
20177 has a version we don't understand.
20179 NOTE: the strings in the include directory and file name tables of
20180 the returned object point into the dwarf line section buffer,
20181 and must not be freed. */
20183 static line_header_up
20184 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20186 const gdb_byte
*line_ptr
;
20187 unsigned int bytes_read
, offset_size
;
20189 const char *cur_dir
, *cur_file
;
20190 struct dwarf2_section_info
*section
;
20192 struct dwarf2_per_objfile
*dwarf2_per_objfile
20193 = cu
->per_cu
->dwarf2_per_objfile
;
20195 section
= get_debug_line_section (cu
);
20196 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20197 if (section
->buffer
== NULL
)
20199 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20200 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20202 complaint (&symfile_complaints
, _("missing .debug_line section"));
20206 /* We can't do this until we know the section is non-empty.
20207 Only then do we know we have such a section. */
20208 abfd
= get_section_bfd_owner (section
);
20210 /* Make sure that at least there's room for the total_length field.
20211 That could be 12 bytes long, but we're just going to fudge that. */
20212 if (to_underlying (sect_off
) + 4 >= section
->size
)
20214 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20218 line_header_up
lh (new line_header ());
20220 lh
->sect_off
= sect_off
;
20221 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20223 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20225 /* Read in the header. */
20227 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20228 &bytes_read
, &offset_size
);
20229 line_ptr
+= bytes_read
;
20230 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20232 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20235 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20236 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20238 if (lh
->version
> 5)
20240 /* This is a version we don't understand. The format could have
20241 changed in ways we don't handle properly so just punt. */
20242 complaint (&symfile_complaints
,
20243 _("unsupported version in .debug_line section"));
20246 if (lh
->version
>= 5)
20248 gdb_byte segment_selector_size
;
20250 /* Skip address size. */
20251 read_1_byte (abfd
, line_ptr
);
20254 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20256 if (segment_selector_size
!= 0)
20258 complaint (&symfile_complaints
,
20259 _("unsupported segment selector size %u "
20260 "in .debug_line section"),
20261 segment_selector_size
);
20265 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20266 line_ptr
+= offset_size
;
20267 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20269 if (lh
->version
>= 4)
20271 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20275 lh
->maximum_ops_per_instruction
= 1;
20277 if (lh
->maximum_ops_per_instruction
== 0)
20279 lh
->maximum_ops_per_instruction
= 1;
20280 complaint (&symfile_complaints
,
20281 _("invalid maximum_ops_per_instruction "
20282 "in `.debug_line' section"));
20285 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20287 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20289 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20291 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20293 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20295 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20296 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20298 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20302 if (lh
->version
>= 5)
20304 /* Read directory table. */
20305 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20307 [] (struct line_header
*lh
, const char *name
,
20308 dir_index d_index
, unsigned int mod_time
,
20309 unsigned int length
)
20311 lh
->add_include_dir (name
);
20314 /* Read file name table. */
20315 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20317 [] (struct line_header
*lh
, const char *name
,
20318 dir_index d_index
, unsigned int mod_time
,
20319 unsigned int length
)
20321 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20326 /* Read directory table. */
20327 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20329 line_ptr
+= bytes_read
;
20330 lh
->add_include_dir (cur_dir
);
20332 line_ptr
+= bytes_read
;
20334 /* Read file name table. */
20335 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20337 unsigned int mod_time
, length
;
20340 line_ptr
+= bytes_read
;
20341 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20342 line_ptr
+= bytes_read
;
20343 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20344 line_ptr
+= bytes_read
;
20345 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20346 line_ptr
+= bytes_read
;
20348 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20350 line_ptr
+= bytes_read
;
20352 lh
->statement_program_start
= line_ptr
;
20354 if (line_ptr
> (section
->buffer
+ section
->size
))
20355 complaint (&symfile_complaints
,
20356 _("line number info header doesn't "
20357 "fit in `.debug_line' section"));
20362 /* Subroutine of dwarf_decode_lines to simplify it.
20363 Return the file name of the psymtab for included file FILE_INDEX
20364 in line header LH of PST.
20365 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20366 If space for the result is malloc'd, *NAME_HOLDER will be set.
20367 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20369 static const char *
20370 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20371 const struct partial_symtab
*pst
,
20372 const char *comp_dir
,
20373 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20375 const file_entry
&fe
= lh
->file_names
[file_index
];
20376 const char *include_name
= fe
.name
;
20377 const char *include_name_to_compare
= include_name
;
20378 const char *pst_filename
;
20381 const char *dir_name
= fe
.include_dir (lh
);
20383 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20384 if (!IS_ABSOLUTE_PATH (include_name
)
20385 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20387 /* Avoid creating a duplicate psymtab for PST.
20388 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20389 Before we do the comparison, however, we need to account
20390 for DIR_NAME and COMP_DIR.
20391 First prepend dir_name (if non-NULL). If we still don't
20392 have an absolute path prepend comp_dir (if non-NULL).
20393 However, the directory we record in the include-file's
20394 psymtab does not contain COMP_DIR (to match the
20395 corresponding symtab(s)).
20400 bash$ gcc -g ./hello.c
20401 include_name = "hello.c"
20403 DW_AT_comp_dir = comp_dir = "/tmp"
20404 DW_AT_name = "./hello.c"
20408 if (dir_name
!= NULL
)
20410 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20411 include_name
, (char *) NULL
));
20412 include_name
= name_holder
->get ();
20413 include_name_to_compare
= include_name
;
20415 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20417 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20418 include_name
, (char *) NULL
));
20419 include_name_to_compare
= hold_compare
.get ();
20423 pst_filename
= pst
->filename
;
20424 gdb::unique_xmalloc_ptr
<char> copied_name
;
20425 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20427 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20428 pst_filename
, (char *) NULL
));
20429 pst_filename
= copied_name
.get ();
20432 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20436 return include_name
;
20439 /* State machine to track the state of the line number program. */
20441 class lnp_state_machine
20444 /* Initialize a machine state for the start of a line number
20446 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20448 file_entry
*current_file ()
20450 /* lh->file_names is 0-based, but the file name numbers in the
20451 statement program are 1-based. */
20452 return m_line_header
->file_name_at (m_file
);
20455 /* Record the line in the state machine. END_SEQUENCE is true if
20456 we're processing the end of a sequence. */
20457 void record_line (bool end_sequence
);
20459 /* Check address and if invalid nop-out the rest of the lines in this
20461 void check_line_address (struct dwarf2_cu
*cu
,
20462 const gdb_byte
*line_ptr
,
20463 CORE_ADDR lowpc
, CORE_ADDR address
);
20465 void handle_set_discriminator (unsigned int discriminator
)
20467 m_discriminator
= discriminator
;
20468 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20471 /* Handle DW_LNE_set_address. */
20472 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20475 address
+= baseaddr
;
20476 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20479 /* Handle DW_LNS_advance_pc. */
20480 void handle_advance_pc (CORE_ADDR adjust
);
20482 /* Handle a special opcode. */
20483 void handle_special_opcode (unsigned char op_code
);
20485 /* Handle DW_LNS_advance_line. */
20486 void handle_advance_line (int line_delta
)
20488 advance_line (line_delta
);
20491 /* Handle DW_LNS_set_file. */
20492 void handle_set_file (file_name_index file
);
20494 /* Handle DW_LNS_negate_stmt. */
20495 void handle_negate_stmt ()
20497 m_is_stmt
= !m_is_stmt
;
20500 /* Handle DW_LNS_const_add_pc. */
20501 void handle_const_add_pc ();
20503 /* Handle DW_LNS_fixed_advance_pc. */
20504 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20506 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20510 /* Handle DW_LNS_copy. */
20511 void handle_copy ()
20513 record_line (false);
20514 m_discriminator
= 0;
20517 /* Handle DW_LNE_end_sequence. */
20518 void handle_end_sequence ()
20520 m_record_line_callback
= ::record_line
;
20524 /* Advance the line by LINE_DELTA. */
20525 void advance_line (int line_delta
)
20527 m_line
+= line_delta
;
20529 if (line_delta
!= 0)
20530 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20533 gdbarch
*m_gdbarch
;
20535 /* True if we're recording lines.
20536 Otherwise we're building partial symtabs and are just interested in
20537 finding include files mentioned by the line number program. */
20538 bool m_record_lines_p
;
20540 /* The line number header. */
20541 line_header
*m_line_header
;
20543 /* These are part of the standard DWARF line number state machine,
20544 and initialized according to the DWARF spec. */
20546 unsigned char m_op_index
= 0;
20547 /* The line table index (1-based) of the current file. */
20548 file_name_index m_file
= (file_name_index
) 1;
20549 unsigned int m_line
= 1;
20551 /* These are initialized in the constructor. */
20553 CORE_ADDR m_address
;
20555 unsigned int m_discriminator
;
20557 /* Additional bits of state we need to track. */
20559 /* The last file that we called dwarf2_start_subfile for.
20560 This is only used for TLLs. */
20561 unsigned int m_last_file
= 0;
20562 /* The last file a line number was recorded for. */
20563 struct subfile
*m_last_subfile
= NULL
;
20565 /* The function to call to record a line. */
20566 record_line_ftype
*m_record_line_callback
= NULL
;
20568 /* The last line number that was recorded, used to coalesce
20569 consecutive entries for the same line. This can happen, for
20570 example, when discriminators are present. PR 17276. */
20571 unsigned int m_last_line
= 0;
20572 bool m_line_has_non_zero_discriminator
= false;
20576 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20578 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20579 / m_line_header
->maximum_ops_per_instruction
)
20580 * m_line_header
->minimum_instruction_length
);
20581 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20582 m_op_index
= ((m_op_index
+ adjust
)
20583 % m_line_header
->maximum_ops_per_instruction
);
20587 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20589 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20590 CORE_ADDR addr_adj
= (((m_op_index
20591 + (adj_opcode
/ m_line_header
->line_range
))
20592 / m_line_header
->maximum_ops_per_instruction
)
20593 * m_line_header
->minimum_instruction_length
);
20594 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20595 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20596 % m_line_header
->maximum_ops_per_instruction
);
20598 int line_delta
= (m_line_header
->line_base
20599 + (adj_opcode
% m_line_header
->line_range
));
20600 advance_line (line_delta
);
20601 record_line (false);
20602 m_discriminator
= 0;
20606 lnp_state_machine::handle_set_file (file_name_index file
)
20610 const file_entry
*fe
= current_file ();
20612 dwarf2_debug_line_missing_file_complaint ();
20613 else if (m_record_lines_p
)
20615 const char *dir
= fe
->include_dir (m_line_header
);
20617 m_last_subfile
= current_subfile
;
20618 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20619 dwarf2_start_subfile (fe
->name
, dir
);
20624 lnp_state_machine::handle_const_add_pc ()
20627 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20630 = (((m_op_index
+ adjust
)
20631 / m_line_header
->maximum_ops_per_instruction
)
20632 * m_line_header
->minimum_instruction_length
);
20634 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20635 m_op_index
= ((m_op_index
+ adjust
)
20636 % m_line_header
->maximum_ops_per_instruction
);
20639 /* Ignore this record_line request. */
20642 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
20647 /* Return non-zero if we should add LINE to the line number table.
20648 LINE is the line to add, LAST_LINE is the last line that was added,
20649 LAST_SUBFILE is the subfile for LAST_LINE.
20650 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20651 had a non-zero discriminator.
20653 We have to be careful in the presence of discriminators.
20654 E.g., for this line:
20656 for (i = 0; i < 100000; i++);
20658 clang can emit four line number entries for that one line,
20659 each with a different discriminator.
20660 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20662 However, we want gdb to coalesce all four entries into one.
20663 Otherwise the user could stepi into the middle of the line and
20664 gdb would get confused about whether the pc really was in the
20665 middle of the line.
20667 Things are further complicated by the fact that two consecutive
20668 line number entries for the same line is a heuristic used by gcc
20669 to denote the end of the prologue. So we can't just discard duplicate
20670 entries, we have to be selective about it. The heuristic we use is
20671 that we only collapse consecutive entries for the same line if at least
20672 one of those entries has a non-zero discriminator. PR 17276.
20674 Note: Addresses in the line number state machine can never go backwards
20675 within one sequence, thus this coalescing is ok. */
20678 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
20679 int line_has_non_zero_discriminator
,
20680 struct subfile
*last_subfile
)
20682 if (current_subfile
!= last_subfile
)
20684 if (line
!= last_line
)
20686 /* Same line for the same file that we've seen already.
20687 As a last check, for pr 17276, only record the line if the line
20688 has never had a non-zero discriminator. */
20689 if (!line_has_non_zero_discriminator
)
20694 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
20695 in the line table of subfile SUBFILE. */
20698 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20699 unsigned int line
, CORE_ADDR address
,
20700 record_line_ftype p_record_line
)
20702 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20704 if (dwarf_line_debug
)
20706 fprintf_unfiltered (gdb_stdlog
,
20707 "Recording line %u, file %s, address %s\n",
20708 line
, lbasename (subfile
->name
),
20709 paddress (gdbarch
, address
));
20712 (*p_record_line
) (subfile
, line
, addr
);
20715 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20716 Mark the end of a set of line number records.
20717 The arguments are the same as for dwarf_record_line_1.
20718 If SUBFILE is NULL the request is ignored. */
20721 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20722 CORE_ADDR address
, record_line_ftype p_record_line
)
20724 if (subfile
== NULL
)
20727 if (dwarf_line_debug
)
20729 fprintf_unfiltered (gdb_stdlog
,
20730 "Finishing current line, file %s, address %s\n",
20731 lbasename (subfile
->name
),
20732 paddress (gdbarch
, address
));
20735 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
20739 lnp_state_machine::record_line (bool end_sequence
)
20741 if (dwarf_line_debug
)
20743 fprintf_unfiltered (gdb_stdlog
,
20744 "Processing actual line %u: file %u,"
20745 " address %s, is_stmt %u, discrim %u\n",
20746 m_line
, to_underlying (m_file
),
20747 paddress (m_gdbarch
, m_address
),
20748 m_is_stmt
, m_discriminator
);
20751 file_entry
*fe
= current_file ();
20754 dwarf2_debug_line_missing_file_complaint ();
20755 /* For now we ignore lines not starting on an instruction boundary.
20756 But not when processing end_sequence for compatibility with the
20757 previous version of the code. */
20758 else if (m_op_index
== 0 || end_sequence
)
20760 fe
->included_p
= 1;
20761 if (m_record_lines_p
&& m_is_stmt
)
20763 if (m_last_subfile
!= current_subfile
|| end_sequence
)
20765 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
20766 m_address
, m_record_line_callback
);
20771 if (dwarf_record_line_p (m_line
, m_last_line
,
20772 m_line_has_non_zero_discriminator
,
20775 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
20777 m_record_line_callback
);
20779 m_last_subfile
= current_subfile
;
20780 m_last_line
= m_line
;
20786 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
20787 bool record_lines_p
)
20790 m_record_lines_p
= record_lines_p
;
20791 m_line_header
= lh
;
20793 m_record_line_callback
= ::record_line
;
20795 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20796 was a line entry for it so that the backend has a chance to adjust it
20797 and also record it in case it needs it. This is currently used by MIPS
20798 code, cf. `mips_adjust_dwarf2_line'. */
20799 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20800 m_is_stmt
= lh
->default_is_stmt
;
20801 m_discriminator
= 0;
20805 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20806 const gdb_byte
*line_ptr
,
20807 CORE_ADDR lowpc
, CORE_ADDR address
)
20809 /* If address < lowpc then it's not a usable value, it's outside the
20810 pc range of the CU. However, we restrict the test to only address
20811 values of zero to preserve GDB's previous behaviour which is to
20812 handle the specific case of a function being GC'd by the linker. */
20814 if (address
== 0 && address
< lowpc
)
20816 /* This line table is for a function which has been
20817 GCd by the linker. Ignore it. PR gdb/12528 */
20819 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20820 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20822 complaint (&symfile_complaints
,
20823 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20824 line_offset
, objfile_name (objfile
));
20825 m_record_line_callback
= noop_record_line
;
20826 /* Note: record_line_callback is left as noop_record_line until
20827 we see DW_LNE_end_sequence. */
20831 /* Subroutine of dwarf_decode_lines to simplify it.
20832 Process the line number information in LH.
20833 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20834 program in order to set included_p for every referenced header. */
20837 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20838 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20840 const gdb_byte
*line_ptr
, *extended_end
;
20841 const gdb_byte
*line_end
;
20842 unsigned int bytes_read
, extended_len
;
20843 unsigned char op_code
, extended_op
;
20844 CORE_ADDR baseaddr
;
20845 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20846 bfd
*abfd
= objfile
->obfd
;
20847 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20848 /* True if we're recording line info (as opposed to building partial
20849 symtabs and just interested in finding include files mentioned by
20850 the line number program). */
20851 bool record_lines_p
= !decode_for_pst_p
;
20853 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
20855 line_ptr
= lh
->statement_program_start
;
20856 line_end
= lh
->statement_program_end
;
20858 /* Read the statement sequences until there's nothing left. */
20859 while (line_ptr
< line_end
)
20861 /* The DWARF line number program state machine. Reset the state
20862 machine at the start of each sequence. */
20863 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
20864 bool end_sequence
= false;
20866 if (record_lines_p
)
20868 /* Start a subfile for the current file of the state
20870 const file_entry
*fe
= state_machine
.current_file ();
20873 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
20876 /* Decode the table. */
20877 while (line_ptr
< line_end
&& !end_sequence
)
20879 op_code
= read_1_byte (abfd
, line_ptr
);
20882 if (op_code
>= lh
->opcode_base
)
20884 /* Special opcode. */
20885 state_machine
.handle_special_opcode (op_code
);
20887 else switch (op_code
)
20889 case DW_LNS_extended_op
:
20890 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20892 line_ptr
+= bytes_read
;
20893 extended_end
= line_ptr
+ extended_len
;
20894 extended_op
= read_1_byte (abfd
, line_ptr
);
20896 switch (extended_op
)
20898 case DW_LNE_end_sequence
:
20899 state_machine
.handle_end_sequence ();
20900 end_sequence
= true;
20902 case DW_LNE_set_address
:
20905 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20906 line_ptr
+= bytes_read
;
20908 state_machine
.check_line_address (cu
, line_ptr
,
20910 state_machine
.handle_set_address (baseaddr
, address
);
20913 case DW_LNE_define_file
:
20915 const char *cur_file
;
20916 unsigned int mod_time
, length
;
20919 cur_file
= read_direct_string (abfd
, line_ptr
,
20921 line_ptr
+= bytes_read
;
20922 dindex
= (dir_index
)
20923 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20924 line_ptr
+= bytes_read
;
20926 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20927 line_ptr
+= bytes_read
;
20929 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20930 line_ptr
+= bytes_read
;
20931 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20934 case DW_LNE_set_discriminator
:
20936 /* The discriminator is not interesting to the
20937 debugger; just ignore it. We still need to
20938 check its value though:
20939 if there are consecutive entries for the same
20940 (non-prologue) line we want to coalesce them.
20943 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20944 line_ptr
+= bytes_read
;
20946 state_machine
.handle_set_discriminator (discr
);
20950 complaint (&symfile_complaints
,
20951 _("mangled .debug_line section"));
20954 /* Make sure that we parsed the extended op correctly. If e.g.
20955 we expected a different address size than the producer used,
20956 we may have read the wrong number of bytes. */
20957 if (line_ptr
!= extended_end
)
20959 complaint (&symfile_complaints
,
20960 _("mangled .debug_line section"));
20965 state_machine
.handle_copy ();
20967 case DW_LNS_advance_pc
:
20970 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20971 line_ptr
+= bytes_read
;
20973 state_machine
.handle_advance_pc (adjust
);
20976 case DW_LNS_advance_line
:
20979 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20980 line_ptr
+= bytes_read
;
20982 state_machine
.handle_advance_line (line_delta
);
20985 case DW_LNS_set_file
:
20987 file_name_index file
20988 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20990 line_ptr
+= bytes_read
;
20992 state_machine
.handle_set_file (file
);
20995 case DW_LNS_set_column
:
20996 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20997 line_ptr
+= bytes_read
;
20999 case DW_LNS_negate_stmt
:
21000 state_machine
.handle_negate_stmt ();
21002 case DW_LNS_set_basic_block
:
21004 /* Add to the address register of the state machine the
21005 address increment value corresponding to special opcode
21006 255. I.e., this value is scaled by the minimum
21007 instruction length since special opcode 255 would have
21008 scaled the increment. */
21009 case DW_LNS_const_add_pc
:
21010 state_machine
.handle_const_add_pc ();
21012 case DW_LNS_fixed_advance_pc
:
21014 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21017 state_machine
.handle_fixed_advance_pc (addr_adj
);
21022 /* Unknown standard opcode, ignore it. */
21025 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21027 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21028 line_ptr
+= bytes_read
;
21035 dwarf2_debug_line_missing_end_sequence_complaint ();
21037 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21038 in which case we still finish recording the last line). */
21039 state_machine
.record_line (true);
21043 /* Decode the Line Number Program (LNP) for the given line_header
21044 structure and CU. The actual information extracted and the type
21045 of structures created from the LNP depends on the value of PST.
21047 1. If PST is NULL, then this procedure uses the data from the program
21048 to create all necessary symbol tables, and their linetables.
21050 2. If PST is not NULL, this procedure reads the program to determine
21051 the list of files included by the unit represented by PST, and
21052 builds all the associated partial symbol tables.
21054 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21055 It is used for relative paths in the line table.
21056 NOTE: When processing partial symtabs (pst != NULL),
21057 comp_dir == pst->dirname.
21059 NOTE: It is important that psymtabs have the same file name (via strcmp)
21060 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21061 symtab we don't use it in the name of the psymtabs we create.
21062 E.g. expand_line_sal requires this when finding psymtabs to expand.
21063 A good testcase for this is mb-inline.exp.
21065 LOWPC is the lowest address in CU (or 0 if not known).
21067 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21068 for its PC<->lines mapping information. Otherwise only the filename
21069 table is read in. */
21072 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21073 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21074 CORE_ADDR lowpc
, int decode_mapping
)
21076 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21077 const int decode_for_pst_p
= (pst
!= NULL
);
21079 if (decode_mapping
)
21080 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21082 if (decode_for_pst_p
)
21086 /* Now that we're done scanning the Line Header Program, we can
21087 create the psymtab of each included file. */
21088 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21089 if (lh
->file_names
[file_index
].included_p
== 1)
21091 gdb::unique_xmalloc_ptr
<char> name_holder
;
21092 const char *include_name
=
21093 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21095 if (include_name
!= NULL
)
21096 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21101 /* Make sure a symtab is created for every file, even files
21102 which contain only variables (i.e. no code with associated
21104 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21107 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21109 file_entry
&fe
= lh
->file_names
[i
];
21111 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21113 if (current_subfile
->symtab
== NULL
)
21115 current_subfile
->symtab
21116 = allocate_symtab (cust
, current_subfile
->name
);
21118 fe
.symtab
= current_subfile
->symtab
;
21123 /* Start a subfile for DWARF. FILENAME is the name of the file and
21124 DIRNAME the name of the source directory which contains FILENAME
21125 or NULL if not known.
21126 This routine tries to keep line numbers from identical absolute and
21127 relative file names in a common subfile.
21129 Using the `list' example from the GDB testsuite, which resides in
21130 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21131 of /srcdir/list0.c yields the following debugging information for list0.c:
21133 DW_AT_name: /srcdir/list0.c
21134 DW_AT_comp_dir: /compdir
21135 files.files[0].name: list0.h
21136 files.files[0].dir: /srcdir
21137 files.files[1].name: list0.c
21138 files.files[1].dir: /srcdir
21140 The line number information for list0.c has to end up in a single
21141 subfile, so that `break /srcdir/list0.c:1' works as expected.
21142 start_subfile will ensure that this happens provided that we pass the
21143 concatenation of files.files[1].dir and files.files[1].name as the
21147 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21151 /* In order not to lose the line information directory,
21152 we concatenate it to the filename when it makes sense.
21153 Note that the Dwarf3 standard says (speaking of filenames in line
21154 information): ``The directory index is ignored for file names
21155 that represent full path names''. Thus ignoring dirname in the
21156 `else' branch below isn't an issue. */
21158 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21160 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21164 start_subfile (filename
);
21170 /* Start a symtab for DWARF.
21171 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21173 static struct compunit_symtab
*
21174 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21175 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21177 struct compunit_symtab
*cust
21178 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21179 low_pc
, cu
->language
);
21181 record_debugformat ("DWARF 2");
21182 record_producer (cu
->producer
);
21184 /* We assume that we're processing GCC output. */
21185 processing_gcc_compilation
= 2;
21187 cu
->processing_has_namespace_info
= 0;
21193 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21194 struct dwarf2_cu
*cu
)
21196 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21197 struct comp_unit_head
*cu_header
= &cu
->header
;
21199 /* NOTE drow/2003-01-30: There used to be a comment and some special
21200 code here to turn a symbol with DW_AT_external and a
21201 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21202 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21203 with some versions of binutils) where shared libraries could have
21204 relocations against symbols in their debug information - the
21205 minimal symbol would have the right address, but the debug info
21206 would not. It's no longer necessary, because we will explicitly
21207 apply relocations when we read in the debug information now. */
21209 /* A DW_AT_location attribute with no contents indicates that a
21210 variable has been optimized away. */
21211 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21213 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21217 /* Handle one degenerate form of location expression specially, to
21218 preserve GDB's previous behavior when section offsets are
21219 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21220 then mark this symbol as LOC_STATIC. */
21222 if (attr_form_is_block (attr
)
21223 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21224 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21225 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21226 && (DW_BLOCK (attr
)->size
21227 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21229 unsigned int dummy
;
21231 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21232 SYMBOL_VALUE_ADDRESS (sym
) =
21233 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21235 SYMBOL_VALUE_ADDRESS (sym
) =
21236 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21237 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21238 fixup_symbol_section (sym
, objfile
);
21239 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21240 SYMBOL_SECTION (sym
));
21244 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21245 expression evaluator, and use LOC_COMPUTED only when necessary
21246 (i.e. when the value of a register or memory location is
21247 referenced, or a thread-local block, etc.). Then again, it might
21248 not be worthwhile. I'm assuming that it isn't unless performance
21249 or memory numbers show me otherwise. */
21251 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21253 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21254 cu
->has_loclist
= 1;
21257 /* Given a pointer to a DWARF information entry, figure out if we need
21258 to make a symbol table entry for it, and if so, create a new entry
21259 and return a pointer to it.
21260 If TYPE is NULL, determine symbol type from the die, otherwise
21261 used the passed type.
21262 If SPACE is not NULL, use it to hold the new symbol. If it is
21263 NULL, allocate a new symbol on the objfile's obstack. */
21265 static struct symbol
*
21266 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21267 struct symbol
*space
)
21269 struct dwarf2_per_objfile
*dwarf2_per_objfile
21270 = cu
->per_cu
->dwarf2_per_objfile
;
21271 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21272 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21273 struct symbol
*sym
= NULL
;
21275 struct attribute
*attr
= NULL
;
21276 struct attribute
*attr2
= NULL
;
21277 CORE_ADDR baseaddr
;
21278 struct pending
**list_to_add
= NULL
;
21280 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21282 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21284 name
= dwarf2_name (die
, cu
);
21287 const char *linkagename
;
21288 int suppress_add
= 0;
21293 sym
= allocate_symbol (objfile
);
21294 OBJSTAT (objfile
, n_syms
++);
21296 /* Cache this symbol's name and the name's demangled form (if any). */
21297 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21298 linkagename
= dwarf2_physname (name
, die
, cu
);
21299 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21301 /* Fortran does not have mangling standard and the mangling does differ
21302 between gfortran, iFort etc. */
21303 if (cu
->language
== language_fortran
21304 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21305 symbol_set_demangled_name (&(sym
->ginfo
),
21306 dwarf2_full_name (name
, die
, cu
),
21309 /* Default assumptions.
21310 Use the passed type or decode it from the die. */
21311 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21312 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21314 SYMBOL_TYPE (sym
) = type
;
21316 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21317 attr
= dwarf2_attr (die
,
21318 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21322 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21325 attr
= dwarf2_attr (die
,
21326 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21330 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21331 struct file_entry
*fe
;
21333 if (cu
->line_header
!= NULL
)
21334 fe
= cu
->line_header
->file_name_at (file_index
);
21339 complaint (&symfile_complaints
,
21340 _("file index out of range"));
21342 symbol_set_symtab (sym
, fe
->symtab
);
21348 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21353 addr
= attr_value_as_address (attr
);
21354 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21355 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21357 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21358 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21359 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21360 add_symbol_to_list (sym
, cu
->list_in_scope
);
21362 case DW_TAG_subprogram
:
21363 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21365 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21366 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21367 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21368 || cu
->language
== language_ada
)
21370 /* Subprograms marked external are stored as a global symbol.
21371 Ada subprograms, whether marked external or not, are always
21372 stored as a global symbol, because we want to be able to
21373 access them globally. For instance, we want to be able
21374 to break on a nested subprogram without having to
21375 specify the context. */
21376 list_to_add
= &global_symbols
;
21380 list_to_add
= cu
->list_in_scope
;
21383 case DW_TAG_inlined_subroutine
:
21384 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21386 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21387 SYMBOL_INLINED (sym
) = 1;
21388 list_to_add
= cu
->list_in_scope
;
21390 case DW_TAG_template_value_param
:
21392 /* Fall through. */
21393 case DW_TAG_constant
:
21394 case DW_TAG_variable
:
21395 case DW_TAG_member
:
21396 /* Compilation with minimal debug info may result in
21397 variables with missing type entries. Change the
21398 misleading `void' type to something sensible. */
21399 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21400 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21402 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21403 /* In the case of DW_TAG_member, we should only be called for
21404 static const members. */
21405 if (die
->tag
== DW_TAG_member
)
21407 /* dwarf2_add_field uses die_is_declaration,
21408 so we do the same. */
21409 gdb_assert (die_is_declaration (die
, cu
));
21414 dwarf2_const_value (attr
, sym
, cu
);
21415 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21418 if (attr2
&& (DW_UNSND (attr2
) != 0))
21419 list_to_add
= &global_symbols
;
21421 list_to_add
= cu
->list_in_scope
;
21425 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21428 var_decode_location (attr
, sym
, cu
);
21429 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21431 /* Fortran explicitly imports any global symbols to the local
21432 scope by DW_TAG_common_block. */
21433 if (cu
->language
== language_fortran
&& die
->parent
21434 && die
->parent
->tag
== DW_TAG_common_block
)
21437 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21438 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21439 && !dwarf2_per_objfile
->has_section_at_zero
)
21441 /* When a static variable is eliminated by the linker,
21442 the corresponding debug information is not stripped
21443 out, but the variable address is set to null;
21444 do not add such variables into symbol table. */
21446 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21448 /* Workaround gfortran PR debug/40040 - it uses
21449 DW_AT_location for variables in -fPIC libraries which may
21450 get overriden by other libraries/executable and get
21451 a different address. Resolve it by the minimal symbol
21452 which may come from inferior's executable using copy
21453 relocation. Make this workaround only for gfortran as for
21454 other compilers GDB cannot guess the minimal symbol
21455 Fortran mangling kind. */
21456 if (cu
->language
== language_fortran
&& die
->parent
21457 && die
->parent
->tag
== DW_TAG_module
21459 && startswith (cu
->producer
, "GNU Fortran"))
21460 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21462 /* A variable with DW_AT_external is never static,
21463 but it may be block-scoped. */
21464 list_to_add
= (cu
->list_in_scope
== &file_symbols
21465 ? &global_symbols
: cu
->list_in_scope
);
21468 list_to_add
= cu
->list_in_scope
;
21472 /* We do not know the address of this symbol.
21473 If it is an external symbol and we have type information
21474 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21475 The address of the variable will then be determined from
21476 the minimal symbol table whenever the variable is
21478 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21480 /* Fortran explicitly imports any global symbols to the local
21481 scope by DW_TAG_common_block. */
21482 if (cu
->language
== language_fortran
&& die
->parent
21483 && die
->parent
->tag
== DW_TAG_common_block
)
21485 /* SYMBOL_CLASS doesn't matter here because
21486 read_common_block is going to reset it. */
21488 list_to_add
= cu
->list_in_scope
;
21490 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21491 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21493 /* A variable with DW_AT_external is never static, but it
21494 may be block-scoped. */
21495 list_to_add
= (cu
->list_in_scope
== &file_symbols
21496 ? &global_symbols
: cu
->list_in_scope
);
21498 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21500 else if (!die_is_declaration (die
, cu
))
21502 /* Use the default LOC_OPTIMIZED_OUT class. */
21503 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21505 list_to_add
= cu
->list_in_scope
;
21509 case DW_TAG_formal_parameter
:
21510 /* If we are inside a function, mark this as an argument. If
21511 not, we might be looking at an argument to an inlined function
21512 when we do not have enough information to show inlined frames;
21513 pretend it's a local variable in that case so that the user can
21515 if (context_stack_depth
> 0
21516 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21517 SYMBOL_IS_ARGUMENT (sym
) = 1;
21518 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21521 var_decode_location (attr
, sym
, cu
);
21523 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21526 dwarf2_const_value (attr
, sym
, cu
);
21529 list_to_add
= cu
->list_in_scope
;
21531 case DW_TAG_unspecified_parameters
:
21532 /* From varargs functions; gdb doesn't seem to have any
21533 interest in this information, so just ignore it for now.
21536 case DW_TAG_template_type_param
:
21538 /* Fall through. */
21539 case DW_TAG_class_type
:
21540 case DW_TAG_interface_type
:
21541 case DW_TAG_structure_type
:
21542 case DW_TAG_union_type
:
21543 case DW_TAG_set_type
:
21544 case DW_TAG_enumeration_type
:
21545 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21546 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21549 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21550 really ever be static objects: otherwise, if you try
21551 to, say, break of a class's method and you're in a file
21552 which doesn't mention that class, it won't work unless
21553 the check for all static symbols in lookup_symbol_aux
21554 saves you. See the OtherFileClass tests in
21555 gdb.c++/namespace.exp. */
21559 list_to_add
= (cu
->list_in_scope
== &file_symbols
21560 && cu
->language
== language_cplus
21561 ? &global_symbols
: cu
->list_in_scope
);
21563 /* The semantics of C++ state that "struct foo {
21564 ... }" also defines a typedef for "foo". */
21565 if (cu
->language
== language_cplus
21566 || cu
->language
== language_ada
21567 || cu
->language
== language_d
21568 || cu
->language
== language_rust
)
21570 /* The symbol's name is already allocated along
21571 with this objfile, so we don't need to
21572 duplicate it for the type. */
21573 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21574 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21579 case DW_TAG_typedef
:
21580 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21581 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21582 list_to_add
= cu
->list_in_scope
;
21584 case DW_TAG_base_type
:
21585 case DW_TAG_subrange_type
:
21586 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21587 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21588 list_to_add
= cu
->list_in_scope
;
21590 case DW_TAG_enumerator
:
21591 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21594 dwarf2_const_value (attr
, sym
, cu
);
21597 /* NOTE: carlton/2003-11-10: See comment above in the
21598 DW_TAG_class_type, etc. block. */
21600 list_to_add
= (cu
->list_in_scope
== &file_symbols
21601 && cu
->language
== language_cplus
21602 ? &global_symbols
: cu
->list_in_scope
);
21605 case DW_TAG_imported_declaration
:
21606 case DW_TAG_namespace
:
21607 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21608 list_to_add
= &global_symbols
;
21610 case DW_TAG_module
:
21611 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21612 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21613 list_to_add
= &global_symbols
;
21615 case DW_TAG_common_block
:
21616 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21617 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21618 add_symbol_to_list (sym
, cu
->list_in_scope
);
21621 /* Not a tag we recognize. Hopefully we aren't processing
21622 trash data, but since we must specifically ignore things
21623 we don't recognize, there is nothing else we should do at
21625 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
21626 dwarf_tag_name (die
->tag
));
21632 sym
->hash_next
= objfile
->template_symbols
;
21633 objfile
->template_symbols
= sym
;
21634 list_to_add
= NULL
;
21637 if (list_to_add
!= NULL
)
21638 add_symbol_to_list (sym
, list_to_add
);
21640 /* For the benefit of old versions of GCC, check for anonymous
21641 namespaces based on the demangled name. */
21642 if (!cu
->processing_has_namespace_info
21643 && cu
->language
== language_cplus
)
21644 cp_scan_for_anonymous_namespaces (sym
, objfile
);
21649 /* Given an attr with a DW_FORM_dataN value in host byte order,
21650 zero-extend it as appropriate for the symbol's type. The DWARF
21651 standard (v4) is not entirely clear about the meaning of using
21652 DW_FORM_dataN for a constant with a signed type, where the type is
21653 wider than the data. The conclusion of a discussion on the DWARF
21654 list was that this is unspecified. We choose to always zero-extend
21655 because that is the interpretation long in use by GCC. */
21658 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21659 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21661 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21662 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21663 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21664 LONGEST l
= DW_UNSND (attr
);
21666 if (bits
< sizeof (*value
) * 8)
21668 l
&= ((LONGEST
) 1 << bits
) - 1;
21671 else if (bits
== sizeof (*value
) * 8)
21675 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21676 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21683 /* Read a constant value from an attribute. Either set *VALUE, or if
21684 the value does not fit in *VALUE, set *BYTES - either already
21685 allocated on the objfile obstack, or newly allocated on OBSTACK,
21686 or, set *BATON, if we translated the constant to a location
21690 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21691 const char *name
, struct obstack
*obstack
,
21692 struct dwarf2_cu
*cu
,
21693 LONGEST
*value
, const gdb_byte
**bytes
,
21694 struct dwarf2_locexpr_baton
**baton
)
21696 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21697 struct comp_unit_head
*cu_header
= &cu
->header
;
21698 struct dwarf_block
*blk
;
21699 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21700 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21706 switch (attr
->form
)
21709 case DW_FORM_GNU_addr_index
:
21713 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21714 dwarf2_const_value_length_mismatch_complaint (name
,
21715 cu_header
->addr_size
,
21716 TYPE_LENGTH (type
));
21717 /* Symbols of this form are reasonably rare, so we just
21718 piggyback on the existing location code rather than writing
21719 a new implementation of symbol_computed_ops. */
21720 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21721 (*baton
)->per_cu
= cu
->per_cu
;
21722 gdb_assert ((*baton
)->per_cu
);
21724 (*baton
)->size
= 2 + cu_header
->addr_size
;
21725 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21726 (*baton
)->data
= data
;
21728 data
[0] = DW_OP_addr
;
21729 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21730 byte_order
, DW_ADDR (attr
));
21731 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21734 case DW_FORM_string
:
21736 case DW_FORM_GNU_str_index
:
21737 case DW_FORM_GNU_strp_alt
:
21738 /* DW_STRING is already allocated on the objfile obstack, point
21740 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21742 case DW_FORM_block1
:
21743 case DW_FORM_block2
:
21744 case DW_FORM_block4
:
21745 case DW_FORM_block
:
21746 case DW_FORM_exprloc
:
21747 case DW_FORM_data16
:
21748 blk
= DW_BLOCK (attr
);
21749 if (TYPE_LENGTH (type
) != blk
->size
)
21750 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21751 TYPE_LENGTH (type
));
21752 *bytes
= blk
->data
;
21755 /* The DW_AT_const_value attributes are supposed to carry the
21756 symbol's value "represented as it would be on the target
21757 architecture." By the time we get here, it's already been
21758 converted to host endianness, so we just need to sign- or
21759 zero-extend it as appropriate. */
21760 case DW_FORM_data1
:
21761 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21763 case DW_FORM_data2
:
21764 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21766 case DW_FORM_data4
:
21767 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21769 case DW_FORM_data8
:
21770 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21773 case DW_FORM_sdata
:
21774 case DW_FORM_implicit_const
:
21775 *value
= DW_SND (attr
);
21778 case DW_FORM_udata
:
21779 *value
= DW_UNSND (attr
);
21783 complaint (&symfile_complaints
,
21784 _("unsupported const value attribute form: '%s'"),
21785 dwarf_form_name (attr
->form
));
21792 /* Copy constant value from an attribute to a symbol. */
21795 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21796 struct dwarf2_cu
*cu
)
21798 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21800 const gdb_byte
*bytes
;
21801 struct dwarf2_locexpr_baton
*baton
;
21803 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21804 SYMBOL_PRINT_NAME (sym
),
21805 &objfile
->objfile_obstack
, cu
,
21806 &value
, &bytes
, &baton
);
21810 SYMBOL_LOCATION_BATON (sym
) = baton
;
21811 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21813 else if (bytes
!= NULL
)
21815 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21816 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21820 SYMBOL_VALUE (sym
) = value
;
21821 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21825 /* Return the type of the die in question using its DW_AT_type attribute. */
21827 static struct type
*
21828 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21830 struct attribute
*type_attr
;
21832 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21835 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21836 /* A missing DW_AT_type represents a void type. */
21837 return objfile_type (objfile
)->builtin_void
;
21840 return lookup_die_type (die
, type_attr
, cu
);
21843 /* True iff CU's producer generates GNAT Ada auxiliary information
21844 that allows to find parallel types through that information instead
21845 of having to do expensive parallel lookups by type name. */
21848 need_gnat_info (struct dwarf2_cu
*cu
)
21850 /* Assume that the Ada compiler was GNAT, which always produces
21851 the auxiliary information. */
21852 return (cu
->language
== language_ada
);
21855 /* Return the auxiliary type of the die in question using its
21856 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21857 attribute is not present. */
21859 static struct type
*
21860 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21862 struct attribute
*type_attr
;
21864 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21868 return lookup_die_type (die
, type_attr
, cu
);
21871 /* If DIE has a descriptive_type attribute, then set the TYPE's
21872 descriptive type accordingly. */
21875 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21876 struct dwarf2_cu
*cu
)
21878 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21880 if (descriptive_type
)
21882 ALLOCATE_GNAT_AUX_TYPE (type
);
21883 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21887 /* Return the containing type of the die in question using its
21888 DW_AT_containing_type attribute. */
21890 static struct type
*
21891 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21893 struct attribute
*type_attr
;
21894 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21896 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21898 error (_("Dwarf Error: Problem turning containing type into gdb type "
21899 "[in module %s]"), objfile_name (objfile
));
21901 return lookup_die_type (die
, type_attr
, cu
);
21904 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21906 static struct type
*
21907 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21909 struct dwarf2_per_objfile
*dwarf2_per_objfile
21910 = cu
->per_cu
->dwarf2_per_objfile
;
21911 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21912 char *message
, *saved
;
21914 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
21915 objfile_name (objfile
),
21916 sect_offset_str (cu
->header
.sect_off
),
21917 sect_offset_str (die
->sect_off
));
21918 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
21919 message
, strlen (message
));
21922 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21925 /* Look up the type of DIE in CU using its type attribute ATTR.
21926 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21927 DW_AT_containing_type.
21928 If there is no type substitute an error marker. */
21930 static struct type
*
21931 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21932 struct dwarf2_cu
*cu
)
21934 struct dwarf2_per_objfile
*dwarf2_per_objfile
21935 = cu
->per_cu
->dwarf2_per_objfile
;
21936 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21937 struct type
*this_type
;
21939 gdb_assert (attr
->name
== DW_AT_type
21940 || attr
->name
== DW_AT_GNAT_descriptive_type
21941 || attr
->name
== DW_AT_containing_type
);
21943 /* First see if we have it cached. */
21945 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21947 struct dwarf2_per_cu_data
*per_cu
;
21948 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21950 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21951 dwarf2_per_objfile
);
21952 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21954 else if (attr_form_is_ref (attr
))
21956 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21958 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21960 else if (attr
->form
== DW_FORM_ref_sig8
)
21962 ULONGEST signature
= DW_SIGNATURE (attr
);
21964 return get_signatured_type (die
, signature
, cu
);
21968 complaint (&symfile_complaints
,
21969 _("Dwarf Error: Bad type attribute %s in DIE"
21970 " at %s [in module %s]"),
21971 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21972 objfile_name (objfile
));
21973 return build_error_marker_type (cu
, die
);
21976 /* If not cached we need to read it in. */
21978 if (this_type
== NULL
)
21980 struct die_info
*type_die
= NULL
;
21981 struct dwarf2_cu
*type_cu
= cu
;
21983 if (attr_form_is_ref (attr
))
21984 type_die
= follow_die_ref (die
, attr
, &type_cu
);
21985 if (type_die
== NULL
)
21986 return build_error_marker_type (cu
, die
);
21987 /* If we find the type now, it's probably because the type came
21988 from an inter-CU reference and the type's CU got expanded before
21990 this_type
= read_type_die (type_die
, type_cu
);
21993 /* If we still don't have a type use an error marker. */
21995 if (this_type
== NULL
)
21996 return build_error_marker_type (cu
, die
);
22001 /* Return the type in DIE, CU.
22002 Returns NULL for invalid types.
22004 This first does a lookup in die_type_hash,
22005 and only reads the die in if necessary.
22007 NOTE: This can be called when reading in partial or full symbols. */
22009 static struct type
*
22010 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22012 struct type
*this_type
;
22014 this_type
= get_die_type (die
, cu
);
22018 return read_type_die_1 (die
, cu
);
22021 /* Read the type in DIE, CU.
22022 Returns NULL for invalid types. */
22024 static struct type
*
22025 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22027 struct type
*this_type
= NULL
;
22031 case DW_TAG_class_type
:
22032 case DW_TAG_interface_type
:
22033 case DW_TAG_structure_type
:
22034 case DW_TAG_union_type
:
22035 this_type
= read_structure_type (die
, cu
);
22037 case DW_TAG_enumeration_type
:
22038 this_type
= read_enumeration_type (die
, cu
);
22040 case DW_TAG_subprogram
:
22041 case DW_TAG_subroutine_type
:
22042 case DW_TAG_inlined_subroutine
:
22043 this_type
= read_subroutine_type (die
, cu
);
22045 case DW_TAG_array_type
:
22046 this_type
= read_array_type (die
, cu
);
22048 case DW_TAG_set_type
:
22049 this_type
= read_set_type (die
, cu
);
22051 case DW_TAG_pointer_type
:
22052 this_type
= read_tag_pointer_type (die
, cu
);
22054 case DW_TAG_ptr_to_member_type
:
22055 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22057 case DW_TAG_reference_type
:
22058 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22060 case DW_TAG_rvalue_reference_type
:
22061 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22063 case DW_TAG_const_type
:
22064 this_type
= read_tag_const_type (die
, cu
);
22066 case DW_TAG_volatile_type
:
22067 this_type
= read_tag_volatile_type (die
, cu
);
22069 case DW_TAG_restrict_type
:
22070 this_type
= read_tag_restrict_type (die
, cu
);
22072 case DW_TAG_string_type
:
22073 this_type
= read_tag_string_type (die
, cu
);
22075 case DW_TAG_typedef
:
22076 this_type
= read_typedef (die
, cu
);
22078 case DW_TAG_subrange_type
:
22079 this_type
= read_subrange_type (die
, cu
);
22081 case DW_TAG_base_type
:
22082 this_type
= read_base_type (die
, cu
);
22084 case DW_TAG_unspecified_type
:
22085 this_type
= read_unspecified_type (die
, cu
);
22087 case DW_TAG_namespace
:
22088 this_type
= read_namespace_type (die
, cu
);
22090 case DW_TAG_module
:
22091 this_type
= read_module_type (die
, cu
);
22093 case DW_TAG_atomic_type
:
22094 this_type
= read_tag_atomic_type (die
, cu
);
22097 complaint (&symfile_complaints
,
22098 _("unexpected tag in read_type_die: '%s'"),
22099 dwarf_tag_name (die
->tag
));
22106 /* See if we can figure out if the class lives in a namespace. We do
22107 this by looking for a member function; its demangled name will
22108 contain namespace info, if there is any.
22109 Return the computed name or NULL.
22110 Space for the result is allocated on the objfile's obstack.
22111 This is the full-die version of guess_partial_die_structure_name.
22112 In this case we know DIE has no useful parent. */
22115 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22117 struct die_info
*spec_die
;
22118 struct dwarf2_cu
*spec_cu
;
22119 struct die_info
*child
;
22120 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22123 spec_die
= die_specification (die
, &spec_cu
);
22124 if (spec_die
!= NULL
)
22130 for (child
= die
->child
;
22132 child
= child
->sibling
)
22134 if (child
->tag
== DW_TAG_subprogram
)
22136 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22138 if (linkage_name
!= NULL
)
22141 = language_class_name_from_physname (cu
->language_defn
,
22145 if (actual_name
!= NULL
)
22147 const char *die_name
= dwarf2_name (die
, cu
);
22149 if (die_name
!= NULL
22150 && strcmp (die_name
, actual_name
) != 0)
22152 /* Strip off the class name from the full name.
22153 We want the prefix. */
22154 int die_name_len
= strlen (die_name
);
22155 int actual_name_len
= strlen (actual_name
);
22157 /* Test for '::' as a sanity check. */
22158 if (actual_name_len
> die_name_len
+ 2
22159 && actual_name
[actual_name_len
22160 - die_name_len
- 1] == ':')
22161 name
= (char *) obstack_copy0 (
22162 &objfile
->per_bfd
->storage_obstack
,
22163 actual_name
, actual_name_len
- die_name_len
- 2);
22166 xfree (actual_name
);
22175 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22176 prefix part in such case. See
22177 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22179 static const char *
22180 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22182 struct attribute
*attr
;
22185 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22186 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22189 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22192 attr
= dw2_linkage_name_attr (die
, cu
);
22193 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22196 /* dwarf2_name had to be already called. */
22197 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22199 /* Strip the base name, keep any leading namespaces/classes. */
22200 base
= strrchr (DW_STRING (attr
), ':');
22201 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22204 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22205 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22207 &base
[-1] - DW_STRING (attr
));
22210 /* Return the name of the namespace/class that DIE is defined within,
22211 or "" if we can't tell. The caller should not xfree the result.
22213 For example, if we're within the method foo() in the following
22223 then determine_prefix on foo's die will return "N::C". */
22225 static const char *
22226 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22228 struct dwarf2_per_objfile
*dwarf2_per_objfile
22229 = cu
->per_cu
->dwarf2_per_objfile
;
22230 struct die_info
*parent
, *spec_die
;
22231 struct dwarf2_cu
*spec_cu
;
22232 struct type
*parent_type
;
22233 const char *retval
;
22235 if (cu
->language
!= language_cplus
22236 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22237 && cu
->language
!= language_rust
)
22240 retval
= anonymous_struct_prefix (die
, cu
);
22244 /* We have to be careful in the presence of DW_AT_specification.
22245 For example, with GCC 3.4, given the code
22249 // Definition of N::foo.
22253 then we'll have a tree of DIEs like this:
22255 1: DW_TAG_compile_unit
22256 2: DW_TAG_namespace // N
22257 3: DW_TAG_subprogram // declaration of N::foo
22258 4: DW_TAG_subprogram // definition of N::foo
22259 DW_AT_specification // refers to die #3
22261 Thus, when processing die #4, we have to pretend that we're in
22262 the context of its DW_AT_specification, namely the contex of die
22265 spec_die
= die_specification (die
, &spec_cu
);
22266 if (spec_die
== NULL
)
22267 parent
= die
->parent
;
22270 parent
= spec_die
->parent
;
22274 if (parent
== NULL
)
22276 else if (parent
->building_fullname
)
22279 const char *parent_name
;
22281 /* It has been seen on RealView 2.2 built binaries,
22282 DW_TAG_template_type_param types actually _defined_ as
22283 children of the parent class:
22286 template class <class Enum> Class{};
22287 Class<enum E> class_e;
22289 1: DW_TAG_class_type (Class)
22290 2: DW_TAG_enumeration_type (E)
22291 3: DW_TAG_enumerator (enum1:0)
22292 3: DW_TAG_enumerator (enum2:1)
22294 2: DW_TAG_template_type_param
22295 DW_AT_type DW_FORM_ref_udata (E)
22297 Besides being broken debug info, it can put GDB into an
22298 infinite loop. Consider:
22300 When we're building the full name for Class<E>, we'll start
22301 at Class, and go look over its template type parameters,
22302 finding E. We'll then try to build the full name of E, and
22303 reach here. We're now trying to build the full name of E,
22304 and look over the parent DIE for containing scope. In the
22305 broken case, if we followed the parent DIE of E, we'd again
22306 find Class, and once again go look at its template type
22307 arguments, etc., etc. Simply don't consider such parent die
22308 as source-level parent of this die (it can't be, the language
22309 doesn't allow it), and break the loop here. */
22310 name
= dwarf2_name (die
, cu
);
22311 parent_name
= dwarf2_name (parent
, cu
);
22312 complaint (&symfile_complaints
,
22313 _("template param type '%s' defined within parent '%s'"),
22314 name
? name
: "<unknown>",
22315 parent_name
? parent_name
: "<unknown>");
22319 switch (parent
->tag
)
22321 case DW_TAG_namespace
:
22322 parent_type
= read_type_die (parent
, cu
);
22323 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22324 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22325 Work around this problem here. */
22326 if (cu
->language
== language_cplus
22327 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22329 /* We give a name to even anonymous namespaces. */
22330 return TYPE_TAG_NAME (parent_type
);
22331 case DW_TAG_class_type
:
22332 case DW_TAG_interface_type
:
22333 case DW_TAG_structure_type
:
22334 case DW_TAG_union_type
:
22335 case DW_TAG_module
:
22336 parent_type
= read_type_die (parent
, cu
);
22337 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22338 return TYPE_TAG_NAME (parent_type
);
22340 /* An anonymous structure is only allowed non-static data
22341 members; no typedefs, no member functions, et cetera.
22342 So it does not need a prefix. */
22344 case DW_TAG_compile_unit
:
22345 case DW_TAG_partial_unit
:
22346 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22347 if (cu
->language
== language_cplus
22348 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22349 && die
->child
!= NULL
22350 && (die
->tag
== DW_TAG_class_type
22351 || die
->tag
== DW_TAG_structure_type
22352 || die
->tag
== DW_TAG_union_type
))
22354 char *name
= guess_full_die_structure_name (die
, cu
);
22359 case DW_TAG_enumeration_type
:
22360 parent_type
= read_type_die (parent
, cu
);
22361 if (TYPE_DECLARED_CLASS (parent_type
))
22363 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22364 return TYPE_TAG_NAME (parent_type
);
22367 /* Fall through. */
22369 return determine_prefix (parent
, cu
);
22373 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22374 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22375 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22376 an obconcat, otherwise allocate storage for the result. The CU argument is
22377 used to determine the language and hence, the appropriate separator. */
22379 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22382 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22383 int physname
, struct dwarf2_cu
*cu
)
22385 const char *lead
= "";
22388 if (suffix
== NULL
|| suffix
[0] == '\0'
22389 || prefix
== NULL
|| prefix
[0] == '\0')
22391 else if (cu
->language
== language_d
)
22393 /* For D, the 'main' function could be defined in any module, but it
22394 should never be prefixed. */
22395 if (strcmp (suffix
, "D main") == 0)
22403 else if (cu
->language
== language_fortran
&& physname
)
22405 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22406 DW_AT_MIPS_linkage_name is preferred and used instead. */
22414 if (prefix
== NULL
)
22416 if (suffix
== NULL
)
22423 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22425 strcpy (retval
, lead
);
22426 strcat (retval
, prefix
);
22427 strcat (retval
, sep
);
22428 strcat (retval
, suffix
);
22433 /* We have an obstack. */
22434 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22438 /* Return sibling of die, NULL if no sibling. */
22440 static struct die_info
*
22441 sibling_die (struct die_info
*die
)
22443 return die
->sibling
;
22446 /* Get name of a die, return NULL if not found. */
22448 static const char *
22449 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22450 struct obstack
*obstack
)
22452 if (name
&& cu
->language
== language_cplus
)
22454 std::string canon_name
= cp_canonicalize_string (name
);
22456 if (!canon_name
.empty ())
22458 if (canon_name
!= name
)
22459 name
= (const char *) obstack_copy0 (obstack
,
22460 canon_name
.c_str (),
22461 canon_name
.length ());
22468 /* Get name of a die, return NULL if not found.
22469 Anonymous namespaces are converted to their magic string. */
22471 static const char *
22472 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22474 struct attribute
*attr
;
22475 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22477 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22478 if ((!attr
|| !DW_STRING (attr
))
22479 && die
->tag
!= DW_TAG_namespace
22480 && die
->tag
!= DW_TAG_class_type
22481 && die
->tag
!= DW_TAG_interface_type
22482 && die
->tag
!= DW_TAG_structure_type
22483 && die
->tag
!= DW_TAG_union_type
)
22488 case DW_TAG_compile_unit
:
22489 case DW_TAG_partial_unit
:
22490 /* Compilation units have a DW_AT_name that is a filename, not
22491 a source language identifier. */
22492 case DW_TAG_enumeration_type
:
22493 case DW_TAG_enumerator
:
22494 /* These tags always have simple identifiers already; no need
22495 to canonicalize them. */
22496 return DW_STRING (attr
);
22498 case DW_TAG_namespace
:
22499 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22500 return DW_STRING (attr
);
22501 return CP_ANONYMOUS_NAMESPACE_STR
;
22503 case DW_TAG_class_type
:
22504 case DW_TAG_interface_type
:
22505 case DW_TAG_structure_type
:
22506 case DW_TAG_union_type
:
22507 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22508 structures or unions. These were of the form "._%d" in GCC 4.1,
22509 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22510 and GCC 4.4. We work around this problem by ignoring these. */
22511 if (attr
&& DW_STRING (attr
)
22512 && (startswith (DW_STRING (attr
), "._")
22513 || startswith (DW_STRING (attr
), "<anonymous")))
22516 /* GCC might emit a nameless typedef that has a linkage name. See
22517 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22518 if (!attr
|| DW_STRING (attr
) == NULL
)
22520 char *demangled
= NULL
;
22522 attr
= dw2_linkage_name_attr (die
, cu
);
22523 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22526 /* Avoid demangling DW_STRING (attr) the second time on a second
22527 call for the same DIE. */
22528 if (!DW_STRING_IS_CANONICAL (attr
))
22529 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22535 /* FIXME: we already did this for the partial symbol... */
22538 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22539 demangled
, strlen (demangled
)));
22540 DW_STRING_IS_CANONICAL (attr
) = 1;
22543 /* Strip any leading namespaces/classes, keep only the base name.
22544 DW_AT_name for named DIEs does not contain the prefixes. */
22545 base
= strrchr (DW_STRING (attr
), ':');
22546 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22549 return DW_STRING (attr
);
22558 if (!DW_STRING_IS_CANONICAL (attr
))
22561 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22562 &objfile
->per_bfd
->storage_obstack
);
22563 DW_STRING_IS_CANONICAL (attr
) = 1;
22565 return DW_STRING (attr
);
22568 /* Return the die that this die in an extension of, or NULL if there
22569 is none. *EXT_CU is the CU containing DIE on input, and the CU
22570 containing the return value on output. */
22572 static struct die_info
*
22573 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22575 struct attribute
*attr
;
22577 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22581 return follow_die_ref (die
, attr
, ext_cu
);
22584 /* Convert a DIE tag into its string name. */
22586 static const char *
22587 dwarf_tag_name (unsigned tag
)
22589 const char *name
= get_DW_TAG_name (tag
);
22592 return "DW_TAG_<unknown>";
22597 /* Convert a DWARF attribute code into its string name. */
22599 static const char *
22600 dwarf_attr_name (unsigned attr
)
22604 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22605 if (attr
== DW_AT_MIPS_fde
)
22606 return "DW_AT_MIPS_fde";
22608 if (attr
== DW_AT_HP_block_index
)
22609 return "DW_AT_HP_block_index";
22612 name
= get_DW_AT_name (attr
);
22615 return "DW_AT_<unknown>";
22620 /* Convert a DWARF value form code into its string name. */
22622 static const char *
22623 dwarf_form_name (unsigned form
)
22625 const char *name
= get_DW_FORM_name (form
);
22628 return "DW_FORM_<unknown>";
22633 static const char *
22634 dwarf_bool_name (unsigned mybool
)
22642 /* Convert a DWARF type code into its string name. */
22644 static const char *
22645 dwarf_type_encoding_name (unsigned enc
)
22647 const char *name
= get_DW_ATE_name (enc
);
22650 return "DW_ATE_<unknown>";
22656 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22660 print_spaces (indent
, f
);
22661 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22662 dwarf_tag_name (die
->tag
), die
->abbrev
,
22663 sect_offset_str (die
->sect_off
));
22665 if (die
->parent
!= NULL
)
22667 print_spaces (indent
, f
);
22668 fprintf_unfiltered (f
, " parent at offset: %s\n",
22669 sect_offset_str (die
->parent
->sect_off
));
22672 print_spaces (indent
, f
);
22673 fprintf_unfiltered (f
, " has children: %s\n",
22674 dwarf_bool_name (die
->child
!= NULL
));
22676 print_spaces (indent
, f
);
22677 fprintf_unfiltered (f
, " attributes:\n");
22679 for (i
= 0; i
< die
->num_attrs
; ++i
)
22681 print_spaces (indent
, f
);
22682 fprintf_unfiltered (f
, " %s (%s) ",
22683 dwarf_attr_name (die
->attrs
[i
].name
),
22684 dwarf_form_name (die
->attrs
[i
].form
));
22686 switch (die
->attrs
[i
].form
)
22689 case DW_FORM_GNU_addr_index
:
22690 fprintf_unfiltered (f
, "address: ");
22691 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22693 case DW_FORM_block2
:
22694 case DW_FORM_block4
:
22695 case DW_FORM_block
:
22696 case DW_FORM_block1
:
22697 fprintf_unfiltered (f
, "block: size %s",
22698 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22700 case DW_FORM_exprloc
:
22701 fprintf_unfiltered (f
, "expression: size %s",
22702 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22704 case DW_FORM_data16
:
22705 fprintf_unfiltered (f
, "constant of 16 bytes");
22707 case DW_FORM_ref_addr
:
22708 fprintf_unfiltered (f
, "ref address: ");
22709 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22711 case DW_FORM_GNU_ref_alt
:
22712 fprintf_unfiltered (f
, "alt ref address: ");
22713 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22719 case DW_FORM_ref_udata
:
22720 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22721 (long) (DW_UNSND (&die
->attrs
[i
])));
22723 case DW_FORM_data1
:
22724 case DW_FORM_data2
:
22725 case DW_FORM_data4
:
22726 case DW_FORM_data8
:
22727 case DW_FORM_udata
:
22728 case DW_FORM_sdata
:
22729 fprintf_unfiltered (f
, "constant: %s",
22730 pulongest (DW_UNSND (&die
->attrs
[i
])));
22732 case DW_FORM_sec_offset
:
22733 fprintf_unfiltered (f
, "section offset: %s",
22734 pulongest (DW_UNSND (&die
->attrs
[i
])));
22736 case DW_FORM_ref_sig8
:
22737 fprintf_unfiltered (f
, "signature: %s",
22738 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22740 case DW_FORM_string
:
22742 case DW_FORM_line_strp
:
22743 case DW_FORM_GNU_str_index
:
22744 case DW_FORM_GNU_strp_alt
:
22745 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22746 DW_STRING (&die
->attrs
[i
])
22747 ? DW_STRING (&die
->attrs
[i
]) : "",
22748 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22751 if (DW_UNSND (&die
->attrs
[i
]))
22752 fprintf_unfiltered (f
, "flag: TRUE");
22754 fprintf_unfiltered (f
, "flag: FALSE");
22756 case DW_FORM_flag_present
:
22757 fprintf_unfiltered (f
, "flag: TRUE");
22759 case DW_FORM_indirect
:
22760 /* The reader will have reduced the indirect form to
22761 the "base form" so this form should not occur. */
22762 fprintf_unfiltered (f
,
22763 "unexpected attribute form: DW_FORM_indirect");
22765 case DW_FORM_implicit_const
:
22766 fprintf_unfiltered (f
, "constant: %s",
22767 plongest (DW_SND (&die
->attrs
[i
])));
22770 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22771 die
->attrs
[i
].form
);
22774 fprintf_unfiltered (f
, "\n");
22779 dump_die_for_error (struct die_info
*die
)
22781 dump_die_shallow (gdb_stderr
, 0, die
);
22785 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22787 int indent
= level
* 4;
22789 gdb_assert (die
!= NULL
);
22791 if (level
>= max_level
)
22794 dump_die_shallow (f
, indent
, die
);
22796 if (die
->child
!= NULL
)
22798 print_spaces (indent
, f
);
22799 fprintf_unfiltered (f
, " Children:");
22800 if (level
+ 1 < max_level
)
22802 fprintf_unfiltered (f
, "\n");
22803 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22807 fprintf_unfiltered (f
,
22808 " [not printed, max nesting level reached]\n");
22812 if (die
->sibling
!= NULL
&& level
> 0)
22814 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22818 /* This is called from the pdie macro in gdbinit.in.
22819 It's not static so gcc will keep a copy callable from gdb. */
22822 dump_die (struct die_info
*die
, int max_level
)
22824 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22828 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22832 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22833 to_underlying (die
->sect_off
),
22839 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22843 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22845 if (attr_form_is_ref (attr
))
22846 return (sect_offset
) DW_UNSND (attr
);
22848 complaint (&symfile_complaints
,
22849 _("unsupported die ref attribute form: '%s'"),
22850 dwarf_form_name (attr
->form
));
22854 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22855 * the value held by the attribute is not constant. */
22858 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22860 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22861 return DW_SND (attr
);
22862 else if (attr
->form
== DW_FORM_udata
22863 || attr
->form
== DW_FORM_data1
22864 || attr
->form
== DW_FORM_data2
22865 || attr
->form
== DW_FORM_data4
22866 || attr
->form
== DW_FORM_data8
)
22867 return DW_UNSND (attr
);
22870 /* For DW_FORM_data16 see attr_form_is_constant. */
22871 complaint (&symfile_complaints
,
22872 _("Attribute value is not a constant (%s)"),
22873 dwarf_form_name (attr
->form
));
22874 return default_value
;
22878 /* Follow reference or signature attribute ATTR of SRC_DIE.
22879 On entry *REF_CU is the CU of SRC_DIE.
22880 On exit *REF_CU is the CU of the result. */
22882 static struct die_info
*
22883 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22884 struct dwarf2_cu
**ref_cu
)
22886 struct die_info
*die
;
22888 if (attr_form_is_ref (attr
))
22889 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22890 else if (attr
->form
== DW_FORM_ref_sig8
)
22891 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22894 dump_die_for_error (src_die
);
22895 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22896 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22902 /* Follow reference OFFSET.
22903 On entry *REF_CU is the CU of the source die referencing OFFSET.
22904 On exit *REF_CU is the CU of the result.
22905 Returns NULL if OFFSET is invalid. */
22907 static struct die_info
*
22908 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22909 struct dwarf2_cu
**ref_cu
)
22911 struct die_info temp_die
;
22912 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22913 struct dwarf2_per_objfile
*dwarf2_per_objfile
22914 = cu
->per_cu
->dwarf2_per_objfile
;
22915 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22917 gdb_assert (cu
->per_cu
!= NULL
);
22921 if (cu
->per_cu
->is_debug_types
)
22923 /* .debug_types CUs cannot reference anything outside their CU.
22924 If they need to, they have to reference a signatured type via
22925 DW_FORM_ref_sig8. */
22926 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22929 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22930 || !offset_in_cu_p (&cu
->header
, sect_off
))
22932 struct dwarf2_per_cu_data
*per_cu
;
22934 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22935 dwarf2_per_objfile
);
22937 /* If necessary, add it to the queue and load its DIEs. */
22938 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
22939 load_full_comp_unit (per_cu
, cu
->language
);
22941 target_cu
= per_cu
->cu
;
22943 else if (cu
->dies
== NULL
)
22945 /* We're loading full DIEs during partial symbol reading. */
22946 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
22947 load_full_comp_unit (cu
->per_cu
, language_minimal
);
22950 *ref_cu
= target_cu
;
22951 temp_die
.sect_off
= sect_off
;
22952 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
22954 to_underlying (sect_off
));
22957 /* Follow reference attribute ATTR of SRC_DIE.
22958 On entry *REF_CU is the CU of SRC_DIE.
22959 On exit *REF_CU is the CU of the result. */
22961 static struct die_info
*
22962 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
22963 struct dwarf2_cu
**ref_cu
)
22965 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22966 struct dwarf2_cu
*cu
= *ref_cu
;
22967 struct die_info
*die
;
22969 die
= follow_die_offset (sect_off
,
22970 (attr
->form
== DW_FORM_GNU_ref_alt
22971 || cu
->per_cu
->is_dwz
),
22974 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
22975 "at %s [in module %s]"),
22976 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
22977 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
22982 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
22983 Returned value is intended for DW_OP_call*. Returned
22984 dwarf2_locexpr_baton->data has lifetime of
22985 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
22987 struct dwarf2_locexpr_baton
22988 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
22989 struct dwarf2_per_cu_data
*per_cu
,
22990 CORE_ADDR (*get_frame_pc
) (void *baton
),
22993 struct dwarf2_cu
*cu
;
22994 struct die_info
*die
;
22995 struct attribute
*attr
;
22996 struct dwarf2_locexpr_baton retval
;
22997 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
22998 struct dwarf2_per_objfile
*dwarf2_per_objfile
22999 = get_dwarf2_per_objfile (objfile
);
23001 if (per_cu
->cu
== NULL
)
23006 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23007 Instead just throw an error, not much else we can do. */
23008 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23009 sect_offset_str (sect_off
), objfile_name (objfile
));
23012 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23014 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23015 sect_offset_str (sect_off
), objfile_name (objfile
));
23017 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23020 /* DWARF: "If there is no such attribute, then there is no effect.".
23021 DATA is ignored if SIZE is 0. */
23023 retval
.data
= NULL
;
23026 else if (attr_form_is_section_offset (attr
))
23028 struct dwarf2_loclist_baton loclist_baton
;
23029 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23032 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23034 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23036 retval
.size
= size
;
23040 if (!attr_form_is_block (attr
))
23041 error (_("Dwarf Error: DIE at %s referenced in module %s "
23042 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23043 sect_offset_str (sect_off
), objfile_name (objfile
));
23045 retval
.data
= DW_BLOCK (attr
)->data
;
23046 retval
.size
= DW_BLOCK (attr
)->size
;
23048 retval
.per_cu
= cu
->per_cu
;
23050 age_cached_comp_units (dwarf2_per_objfile
);
23055 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23058 struct dwarf2_locexpr_baton
23059 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23060 struct dwarf2_per_cu_data
*per_cu
,
23061 CORE_ADDR (*get_frame_pc
) (void *baton
),
23064 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23066 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23069 /* Write a constant of a given type as target-ordered bytes into
23072 static const gdb_byte
*
23073 write_constant_as_bytes (struct obstack
*obstack
,
23074 enum bfd_endian byte_order
,
23081 *len
= TYPE_LENGTH (type
);
23082 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23083 store_unsigned_integer (result
, *len
, byte_order
, value
);
23088 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23089 pointer to the constant bytes and set LEN to the length of the
23090 data. If memory is needed, allocate it on OBSTACK. If the DIE
23091 does not have a DW_AT_const_value, return NULL. */
23094 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23095 struct dwarf2_per_cu_data
*per_cu
,
23096 struct obstack
*obstack
,
23099 struct dwarf2_cu
*cu
;
23100 struct die_info
*die
;
23101 struct attribute
*attr
;
23102 const gdb_byte
*result
= NULL
;
23105 enum bfd_endian byte_order
;
23106 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23108 if (per_cu
->cu
== NULL
)
23113 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23114 Instead just throw an error, not much else we can do. */
23115 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23116 sect_offset_str (sect_off
), objfile_name (objfile
));
23119 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23121 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23122 sect_offset_str (sect_off
), objfile_name (objfile
));
23124 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23128 byte_order
= (bfd_big_endian (objfile
->obfd
)
23129 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23131 switch (attr
->form
)
23134 case DW_FORM_GNU_addr_index
:
23138 *len
= cu
->header
.addr_size
;
23139 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23140 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23144 case DW_FORM_string
:
23146 case DW_FORM_GNU_str_index
:
23147 case DW_FORM_GNU_strp_alt
:
23148 /* DW_STRING is already allocated on the objfile obstack, point
23150 result
= (const gdb_byte
*) DW_STRING (attr
);
23151 *len
= strlen (DW_STRING (attr
));
23153 case DW_FORM_block1
:
23154 case DW_FORM_block2
:
23155 case DW_FORM_block4
:
23156 case DW_FORM_block
:
23157 case DW_FORM_exprloc
:
23158 case DW_FORM_data16
:
23159 result
= DW_BLOCK (attr
)->data
;
23160 *len
= DW_BLOCK (attr
)->size
;
23163 /* The DW_AT_const_value attributes are supposed to carry the
23164 symbol's value "represented as it would be on the target
23165 architecture." By the time we get here, it's already been
23166 converted to host endianness, so we just need to sign- or
23167 zero-extend it as appropriate. */
23168 case DW_FORM_data1
:
23169 type
= die_type (die
, cu
);
23170 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23171 if (result
== NULL
)
23172 result
= write_constant_as_bytes (obstack
, byte_order
,
23175 case DW_FORM_data2
:
23176 type
= die_type (die
, cu
);
23177 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23178 if (result
== NULL
)
23179 result
= write_constant_as_bytes (obstack
, byte_order
,
23182 case DW_FORM_data4
:
23183 type
= die_type (die
, cu
);
23184 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23185 if (result
== NULL
)
23186 result
= write_constant_as_bytes (obstack
, byte_order
,
23189 case DW_FORM_data8
:
23190 type
= die_type (die
, cu
);
23191 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23192 if (result
== NULL
)
23193 result
= write_constant_as_bytes (obstack
, byte_order
,
23197 case DW_FORM_sdata
:
23198 case DW_FORM_implicit_const
:
23199 type
= die_type (die
, cu
);
23200 result
= write_constant_as_bytes (obstack
, byte_order
,
23201 type
, DW_SND (attr
), len
);
23204 case DW_FORM_udata
:
23205 type
= die_type (die
, cu
);
23206 result
= write_constant_as_bytes (obstack
, byte_order
,
23207 type
, DW_UNSND (attr
), len
);
23211 complaint (&symfile_complaints
,
23212 _("unsupported const value attribute form: '%s'"),
23213 dwarf_form_name (attr
->form
));
23220 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23221 valid type for this die is found. */
23224 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23225 struct dwarf2_per_cu_data
*per_cu
)
23227 struct dwarf2_cu
*cu
;
23228 struct die_info
*die
;
23230 if (per_cu
->cu
== NULL
)
23236 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23240 return die_type (die
, cu
);
23243 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23247 dwarf2_get_die_type (cu_offset die_offset
,
23248 struct dwarf2_per_cu_data
*per_cu
)
23250 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23251 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23254 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23255 On entry *REF_CU is the CU of SRC_DIE.
23256 On exit *REF_CU is the CU of the result.
23257 Returns NULL if the referenced DIE isn't found. */
23259 static struct die_info
*
23260 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23261 struct dwarf2_cu
**ref_cu
)
23263 struct die_info temp_die
;
23264 struct dwarf2_cu
*sig_cu
;
23265 struct die_info
*die
;
23267 /* While it might be nice to assert sig_type->type == NULL here,
23268 we can get here for DW_AT_imported_declaration where we need
23269 the DIE not the type. */
23271 /* If necessary, add it to the queue and load its DIEs. */
23273 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23274 read_signatured_type (sig_type
);
23276 sig_cu
= sig_type
->per_cu
.cu
;
23277 gdb_assert (sig_cu
!= NULL
);
23278 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23279 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23280 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23281 to_underlying (temp_die
.sect_off
));
23284 struct dwarf2_per_objfile
*dwarf2_per_objfile
23285 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23287 /* For .gdb_index version 7 keep track of included TUs.
23288 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23289 if (dwarf2_per_objfile
->index_table
!= NULL
23290 && dwarf2_per_objfile
->index_table
->version
<= 7)
23292 VEC_safe_push (dwarf2_per_cu_ptr
,
23293 (*ref_cu
)->per_cu
->imported_symtabs
,
23304 /* Follow signatured type referenced by ATTR in SRC_DIE.
23305 On entry *REF_CU is the CU of SRC_DIE.
23306 On exit *REF_CU is the CU of the result.
23307 The result is the DIE of the type.
23308 If the referenced type cannot be found an error is thrown. */
23310 static struct die_info
*
23311 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23312 struct dwarf2_cu
**ref_cu
)
23314 ULONGEST signature
= DW_SIGNATURE (attr
);
23315 struct signatured_type
*sig_type
;
23316 struct die_info
*die
;
23318 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23320 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23321 /* sig_type will be NULL if the signatured type is missing from
23323 if (sig_type
== NULL
)
23325 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23326 " from DIE at %s [in module %s]"),
23327 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23328 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23331 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23334 dump_die_for_error (src_die
);
23335 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23336 " from DIE at %s [in module %s]"),
23337 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23338 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23344 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23345 reading in and processing the type unit if necessary. */
23347 static struct type
*
23348 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23349 struct dwarf2_cu
*cu
)
23351 struct dwarf2_per_objfile
*dwarf2_per_objfile
23352 = cu
->per_cu
->dwarf2_per_objfile
;
23353 struct signatured_type
*sig_type
;
23354 struct dwarf2_cu
*type_cu
;
23355 struct die_info
*type_die
;
23358 sig_type
= lookup_signatured_type (cu
, signature
);
23359 /* sig_type will be NULL if the signatured type is missing from
23361 if (sig_type
== NULL
)
23363 complaint (&symfile_complaints
,
23364 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23365 " from DIE at %s [in module %s]"),
23366 hex_string (signature
), sect_offset_str (die
->sect_off
),
23367 objfile_name (dwarf2_per_objfile
->objfile
));
23368 return build_error_marker_type (cu
, die
);
23371 /* If we already know the type we're done. */
23372 if (sig_type
->type
!= NULL
)
23373 return sig_type
->type
;
23376 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23377 if (type_die
!= NULL
)
23379 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23380 is created. This is important, for example, because for c++ classes
23381 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23382 type
= read_type_die (type_die
, type_cu
);
23385 complaint (&symfile_complaints
,
23386 _("Dwarf Error: Cannot build signatured type %s"
23387 " referenced from DIE at %s [in module %s]"),
23388 hex_string (signature
), sect_offset_str (die
->sect_off
),
23389 objfile_name (dwarf2_per_objfile
->objfile
));
23390 type
= build_error_marker_type (cu
, die
);
23395 complaint (&symfile_complaints
,
23396 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23397 " from DIE at %s [in module %s]"),
23398 hex_string (signature
), sect_offset_str (die
->sect_off
),
23399 objfile_name (dwarf2_per_objfile
->objfile
));
23400 type
= build_error_marker_type (cu
, die
);
23402 sig_type
->type
= type
;
23407 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23408 reading in and processing the type unit if necessary. */
23410 static struct type
*
23411 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23412 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23414 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23415 if (attr_form_is_ref (attr
))
23417 struct dwarf2_cu
*type_cu
= cu
;
23418 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23420 return read_type_die (type_die
, type_cu
);
23422 else if (attr
->form
== DW_FORM_ref_sig8
)
23424 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23428 struct dwarf2_per_objfile
*dwarf2_per_objfile
23429 = cu
->per_cu
->dwarf2_per_objfile
;
23431 complaint (&symfile_complaints
,
23432 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23433 " at %s [in module %s]"),
23434 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23435 objfile_name (dwarf2_per_objfile
->objfile
));
23436 return build_error_marker_type (cu
, die
);
23440 /* Load the DIEs associated with type unit PER_CU into memory. */
23443 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23445 struct signatured_type
*sig_type
;
23447 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23448 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23450 /* We have the per_cu, but we need the signatured_type.
23451 Fortunately this is an easy translation. */
23452 gdb_assert (per_cu
->is_debug_types
);
23453 sig_type
= (struct signatured_type
*) per_cu
;
23455 gdb_assert (per_cu
->cu
== NULL
);
23457 read_signatured_type (sig_type
);
23459 gdb_assert (per_cu
->cu
!= NULL
);
23462 /* die_reader_func for read_signatured_type.
23463 This is identical to load_full_comp_unit_reader,
23464 but is kept separate for now. */
23467 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23468 const gdb_byte
*info_ptr
,
23469 struct die_info
*comp_unit_die
,
23473 struct dwarf2_cu
*cu
= reader
->cu
;
23475 gdb_assert (cu
->die_hash
== NULL
);
23477 htab_create_alloc_ex (cu
->header
.length
/ 12,
23481 &cu
->comp_unit_obstack
,
23482 hashtab_obstack_allocate
,
23483 dummy_obstack_deallocate
);
23486 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23487 &info_ptr
, comp_unit_die
);
23488 cu
->dies
= comp_unit_die
;
23489 /* comp_unit_die is not stored in die_hash, no need. */
23491 /* We try not to read any attributes in this function, because not
23492 all CUs needed for references have been loaded yet, and symbol
23493 table processing isn't initialized. But we have to set the CU language,
23494 or we won't be able to build types correctly.
23495 Similarly, if we do not read the producer, we can not apply
23496 producer-specific interpretation. */
23497 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23500 /* Read in a signatured type and build its CU and DIEs.
23501 If the type is a stub for the real type in a DWO file,
23502 read in the real type from the DWO file as well. */
23505 read_signatured_type (struct signatured_type
*sig_type
)
23507 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23509 gdb_assert (per_cu
->is_debug_types
);
23510 gdb_assert (per_cu
->cu
== NULL
);
23512 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23513 read_signatured_type_reader
, NULL
);
23514 sig_type
->per_cu
.tu_read
= 1;
23517 /* Decode simple location descriptions.
23518 Given a pointer to a dwarf block that defines a location, compute
23519 the location and return the value.
23521 NOTE drow/2003-11-18: This function is called in two situations
23522 now: for the address of static or global variables (partial symbols
23523 only) and for offsets into structures which are expected to be
23524 (more or less) constant. The partial symbol case should go away,
23525 and only the constant case should remain. That will let this
23526 function complain more accurately. A few special modes are allowed
23527 without complaint for global variables (for instance, global
23528 register values and thread-local values).
23530 A location description containing no operations indicates that the
23531 object is optimized out. The return value is 0 for that case.
23532 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23533 callers will only want a very basic result and this can become a
23536 Note that stack[0] is unused except as a default error return. */
23539 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23541 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23543 size_t size
= blk
->size
;
23544 const gdb_byte
*data
= blk
->data
;
23545 CORE_ADDR stack
[64];
23547 unsigned int bytes_read
, unsnd
;
23553 stack
[++stacki
] = 0;
23592 stack
[++stacki
] = op
- DW_OP_lit0
;
23627 stack
[++stacki
] = op
- DW_OP_reg0
;
23629 dwarf2_complex_location_expr_complaint ();
23633 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23635 stack
[++stacki
] = unsnd
;
23637 dwarf2_complex_location_expr_complaint ();
23641 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23646 case DW_OP_const1u
:
23647 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23651 case DW_OP_const1s
:
23652 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23656 case DW_OP_const2u
:
23657 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23661 case DW_OP_const2s
:
23662 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23666 case DW_OP_const4u
:
23667 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23671 case DW_OP_const4s
:
23672 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23676 case DW_OP_const8u
:
23677 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23682 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23688 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23693 stack
[stacki
+ 1] = stack
[stacki
];
23698 stack
[stacki
- 1] += stack
[stacki
];
23702 case DW_OP_plus_uconst
:
23703 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23709 stack
[stacki
- 1] -= stack
[stacki
];
23714 /* If we're not the last op, then we definitely can't encode
23715 this using GDB's address_class enum. This is valid for partial
23716 global symbols, although the variable's address will be bogus
23719 dwarf2_complex_location_expr_complaint ();
23722 case DW_OP_GNU_push_tls_address
:
23723 case DW_OP_form_tls_address
:
23724 /* The top of the stack has the offset from the beginning
23725 of the thread control block at which the variable is located. */
23726 /* Nothing should follow this operator, so the top of stack would
23728 /* This is valid for partial global symbols, but the variable's
23729 address will be bogus in the psymtab. Make it always at least
23730 non-zero to not look as a variable garbage collected by linker
23731 which have DW_OP_addr 0. */
23733 dwarf2_complex_location_expr_complaint ();
23737 case DW_OP_GNU_uninit
:
23740 case DW_OP_GNU_addr_index
:
23741 case DW_OP_GNU_const_index
:
23742 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23749 const char *name
= get_DW_OP_name (op
);
23752 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
23755 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
23759 return (stack
[stacki
]);
23762 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23763 outside of the allocated space. Also enforce minimum>0. */
23764 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23766 complaint (&symfile_complaints
,
23767 _("location description stack overflow"));
23773 complaint (&symfile_complaints
,
23774 _("location description stack underflow"));
23778 return (stack
[stacki
]);
23781 /* memory allocation interface */
23783 static struct dwarf_block
*
23784 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23786 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23789 static struct die_info
*
23790 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23792 struct die_info
*die
;
23793 size_t size
= sizeof (struct die_info
);
23796 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23798 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23799 memset (die
, 0, sizeof (struct die_info
));
23804 /* Macro support. */
23806 /* Return file name relative to the compilation directory of file number I in
23807 *LH's file name table. The result is allocated using xmalloc; the caller is
23808 responsible for freeing it. */
23811 file_file_name (int file
, struct line_header
*lh
)
23813 /* Is the file number a valid index into the line header's file name
23814 table? Remember that file numbers start with one, not zero. */
23815 if (1 <= file
&& file
<= lh
->file_names
.size ())
23817 const file_entry
&fe
= lh
->file_names
[file
- 1];
23819 if (!IS_ABSOLUTE_PATH (fe
.name
))
23821 const char *dir
= fe
.include_dir (lh
);
23823 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
23825 return xstrdup (fe
.name
);
23829 /* The compiler produced a bogus file number. We can at least
23830 record the macro definitions made in the file, even if we
23831 won't be able to find the file by name. */
23832 char fake_name
[80];
23834 xsnprintf (fake_name
, sizeof (fake_name
),
23835 "<bad macro file number %d>", file
);
23837 complaint (&symfile_complaints
,
23838 _("bad file number in macro information (%d)"),
23841 return xstrdup (fake_name
);
23845 /* Return the full name of file number I in *LH's file name table.
23846 Use COMP_DIR as the name of the current directory of the
23847 compilation. The result is allocated using xmalloc; the caller is
23848 responsible for freeing it. */
23850 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23852 /* Is the file number a valid index into the line header's file name
23853 table? Remember that file numbers start with one, not zero. */
23854 if (1 <= file
&& file
<= lh
->file_names
.size ())
23856 char *relative
= file_file_name (file
, lh
);
23858 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23860 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23861 relative
, (char *) NULL
);
23864 return file_file_name (file
, lh
);
23868 static struct macro_source_file
*
23869 macro_start_file (int file
, int line
,
23870 struct macro_source_file
*current_file
,
23871 struct line_header
*lh
)
23873 /* File name relative to the compilation directory of this source file. */
23874 char *file_name
= file_file_name (file
, lh
);
23876 if (! current_file
)
23878 /* Note: We don't create a macro table for this compilation unit
23879 at all until we actually get a filename. */
23880 struct macro_table
*macro_table
= get_macro_table ();
23882 /* If we have no current file, then this must be the start_file
23883 directive for the compilation unit's main source file. */
23884 current_file
= macro_set_main (macro_table
, file_name
);
23885 macro_define_special (macro_table
);
23888 current_file
= macro_include (current_file
, line
, file_name
);
23892 return current_file
;
23895 static const char *
23896 consume_improper_spaces (const char *p
, const char *body
)
23900 complaint (&symfile_complaints
,
23901 _("macro definition contains spaces "
23902 "in formal argument list:\n`%s'"),
23914 parse_macro_definition (struct macro_source_file
*file
, int line
,
23919 /* The body string takes one of two forms. For object-like macro
23920 definitions, it should be:
23922 <macro name> " " <definition>
23924 For function-like macro definitions, it should be:
23926 <macro name> "() " <definition>
23928 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
23930 Spaces may appear only where explicitly indicated, and in the
23933 The Dwarf 2 spec says that an object-like macro's name is always
23934 followed by a space, but versions of GCC around March 2002 omit
23935 the space when the macro's definition is the empty string.
23937 The Dwarf 2 spec says that there should be no spaces between the
23938 formal arguments in a function-like macro's formal argument list,
23939 but versions of GCC around March 2002 include spaces after the
23943 /* Find the extent of the macro name. The macro name is terminated
23944 by either a space or null character (for an object-like macro) or
23945 an opening paren (for a function-like macro). */
23946 for (p
= body
; *p
; p
++)
23947 if (*p
== ' ' || *p
== '(')
23950 if (*p
== ' ' || *p
== '\0')
23952 /* It's an object-like macro. */
23953 int name_len
= p
- body
;
23954 char *name
= savestring (body
, name_len
);
23955 const char *replacement
;
23958 replacement
= body
+ name_len
+ 1;
23961 dwarf2_macro_malformed_definition_complaint (body
);
23962 replacement
= body
+ name_len
;
23965 macro_define_object (file
, line
, name
, replacement
);
23969 else if (*p
== '(')
23971 /* It's a function-like macro. */
23972 char *name
= savestring (body
, p
- body
);
23975 char **argv
= XNEWVEC (char *, argv_size
);
23979 p
= consume_improper_spaces (p
, body
);
23981 /* Parse the formal argument list. */
23982 while (*p
&& *p
!= ')')
23984 /* Find the extent of the current argument name. */
23985 const char *arg_start
= p
;
23987 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
23990 if (! *p
|| p
== arg_start
)
23991 dwarf2_macro_malformed_definition_complaint (body
);
23994 /* Make sure argv has room for the new argument. */
23995 if (argc
>= argv_size
)
23998 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24001 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24004 p
= consume_improper_spaces (p
, body
);
24006 /* Consume the comma, if present. */
24011 p
= consume_improper_spaces (p
, body
);
24020 /* Perfectly formed definition, no complaints. */
24021 macro_define_function (file
, line
, name
,
24022 argc
, (const char **) argv
,
24024 else if (*p
== '\0')
24026 /* Complain, but do define it. */
24027 dwarf2_macro_malformed_definition_complaint (body
);
24028 macro_define_function (file
, line
, name
,
24029 argc
, (const char **) argv
,
24033 /* Just complain. */
24034 dwarf2_macro_malformed_definition_complaint (body
);
24037 /* Just complain. */
24038 dwarf2_macro_malformed_definition_complaint (body
);
24044 for (i
= 0; i
< argc
; i
++)
24050 dwarf2_macro_malformed_definition_complaint (body
);
24053 /* Skip some bytes from BYTES according to the form given in FORM.
24054 Returns the new pointer. */
24056 static const gdb_byte
*
24057 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24058 enum dwarf_form form
,
24059 unsigned int offset_size
,
24060 struct dwarf2_section_info
*section
)
24062 unsigned int bytes_read
;
24066 case DW_FORM_data1
:
24071 case DW_FORM_data2
:
24075 case DW_FORM_data4
:
24079 case DW_FORM_data8
:
24083 case DW_FORM_data16
:
24087 case DW_FORM_string
:
24088 read_direct_string (abfd
, bytes
, &bytes_read
);
24089 bytes
+= bytes_read
;
24092 case DW_FORM_sec_offset
:
24094 case DW_FORM_GNU_strp_alt
:
24095 bytes
+= offset_size
;
24098 case DW_FORM_block
:
24099 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24100 bytes
+= bytes_read
;
24103 case DW_FORM_block1
:
24104 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24106 case DW_FORM_block2
:
24107 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24109 case DW_FORM_block4
:
24110 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24113 case DW_FORM_sdata
:
24114 case DW_FORM_udata
:
24115 case DW_FORM_GNU_addr_index
:
24116 case DW_FORM_GNU_str_index
:
24117 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24120 dwarf2_section_buffer_overflow_complaint (section
);
24125 case DW_FORM_implicit_const
:
24130 complaint (&symfile_complaints
,
24131 _("invalid form 0x%x in `%s'"),
24132 form
, get_section_name (section
));
24140 /* A helper for dwarf_decode_macros that handles skipping an unknown
24141 opcode. Returns an updated pointer to the macro data buffer; or,
24142 on error, issues a complaint and returns NULL. */
24144 static const gdb_byte
*
24145 skip_unknown_opcode (unsigned int opcode
,
24146 const gdb_byte
**opcode_definitions
,
24147 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24149 unsigned int offset_size
,
24150 struct dwarf2_section_info
*section
)
24152 unsigned int bytes_read
, i
;
24154 const gdb_byte
*defn
;
24156 if (opcode_definitions
[opcode
] == NULL
)
24158 complaint (&symfile_complaints
,
24159 _("unrecognized DW_MACFINO opcode 0x%x"),
24164 defn
= opcode_definitions
[opcode
];
24165 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24166 defn
+= bytes_read
;
24168 for (i
= 0; i
< arg
; ++i
)
24170 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24171 (enum dwarf_form
) defn
[i
], offset_size
,
24173 if (mac_ptr
== NULL
)
24175 /* skip_form_bytes already issued the complaint. */
24183 /* A helper function which parses the header of a macro section.
24184 If the macro section is the extended (for now called "GNU") type,
24185 then this updates *OFFSET_SIZE. Returns a pointer to just after
24186 the header, or issues a complaint and returns NULL on error. */
24188 static const gdb_byte
*
24189 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24191 const gdb_byte
*mac_ptr
,
24192 unsigned int *offset_size
,
24193 int section_is_gnu
)
24195 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24197 if (section_is_gnu
)
24199 unsigned int version
, flags
;
24201 version
= read_2_bytes (abfd
, mac_ptr
);
24202 if (version
!= 4 && version
!= 5)
24204 complaint (&symfile_complaints
,
24205 _("unrecognized version `%d' in .debug_macro section"),
24211 flags
= read_1_byte (abfd
, mac_ptr
);
24213 *offset_size
= (flags
& 1) ? 8 : 4;
24215 if ((flags
& 2) != 0)
24216 /* We don't need the line table offset. */
24217 mac_ptr
+= *offset_size
;
24219 /* Vendor opcode descriptions. */
24220 if ((flags
& 4) != 0)
24222 unsigned int i
, count
;
24224 count
= read_1_byte (abfd
, mac_ptr
);
24226 for (i
= 0; i
< count
; ++i
)
24228 unsigned int opcode
, bytes_read
;
24231 opcode
= read_1_byte (abfd
, mac_ptr
);
24233 opcode_definitions
[opcode
] = mac_ptr
;
24234 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24235 mac_ptr
+= bytes_read
;
24244 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24245 including DW_MACRO_import. */
24248 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24250 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24251 struct macro_source_file
*current_file
,
24252 struct line_header
*lh
,
24253 struct dwarf2_section_info
*section
,
24254 int section_is_gnu
, int section_is_dwz
,
24255 unsigned int offset_size
,
24256 htab_t include_hash
)
24258 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24259 enum dwarf_macro_record_type macinfo_type
;
24260 int at_commandline
;
24261 const gdb_byte
*opcode_definitions
[256];
24263 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24264 &offset_size
, section_is_gnu
);
24265 if (mac_ptr
== NULL
)
24267 /* We already issued a complaint. */
24271 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24272 GDB is still reading the definitions from command line. First
24273 DW_MACINFO_start_file will need to be ignored as it was already executed
24274 to create CURRENT_FILE for the main source holding also the command line
24275 definitions. On first met DW_MACINFO_start_file this flag is reset to
24276 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24278 at_commandline
= 1;
24282 /* Do we at least have room for a macinfo type byte? */
24283 if (mac_ptr
>= mac_end
)
24285 dwarf2_section_buffer_overflow_complaint (section
);
24289 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24292 /* Note that we rely on the fact that the corresponding GNU and
24293 DWARF constants are the same. */
24295 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24296 switch (macinfo_type
)
24298 /* A zero macinfo type indicates the end of the macro
24303 case DW_MACRO_define
:
24304 case DW_MACRO_undef
:
24305 case DW_MACRO_define_strp
:
24306 case DW_MACRO_undef_strp
:
24307 case DW_MACRO_define_sup
:
24308 case DW_MACRO_undef_sup
:
24310 unsigned int bytes_read
;
24315 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24316 mac_ptr
+= bytes_read
;
24318 if (macinfo_type
== DW_MACRO_define
24319 || macinfo_type
== DW_MACRO_undef
)
24321 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24322 mac_ptr
+= bytes_read
;
24326 LONGEST str_offset
;
24328 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24329 mac_ptr
+= offset_size
;
24331 if (macinfo_type
== DW_MACRO_define_sup
24332 || macinfo_type
== DW_MACRO_undef_sup
24335 struct dwz_file
*dwz
24336 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24338 body
= read_indirect_string_from_dwz (objfile
,
24342 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24346 is_define
= (macinfo_type
== DW_MACRO_define
24347 || macinfo_type
== DW_MACRO_define_strp
24348 || macinfo_type
== DW_MACRO_define_sup
);
24349 if (! current_file
)
24351 /* DWARF violation as no main source is present. */
24352 complaint (&symfile_complaints
,
24353 _("debug info with no main source gives macro %s "
24355 is_define
? _("definition") : _("undefinition"),
24359 if ((line
== 0 && !at_commandline
)
24360 || (line
!= 0 && at_commandline
))
24361 complaint (&symfile_complaints
,
24362 _("debug info gives %s macro %s with %s line %d: %s"),
24363 at_commandline
? _("command-line") : _("in-file"),
24364 is_define
? _("definition") : _("undefinition"),
24365 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24368 parse_macro_definition (current_file
, line
, body
);
24371 gdb_assert (macinfo_type
== DW_MACRO_undef
24372 || macinfo_type
== DW_MACRO_undef_strp
24373 || macinfo_type
== DW_MACRO_undef_sup
);
24374 macro_undef (current_file
, line
, body
);
24379 case DW_MACRO_start_file
:
24381 unsigned int bytes_read
;
24384 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24385 mac_ptr
+= bytes_read
;
24386 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24387 mac_ptr
+= bytes_read
;
24389 if ((line
== 0 && !at_commandline
)
24390 || (line
!= 0 && at_commandline
))
24391 complaint (&symfile_complaints
,
24392 _("debug info gives source %d included "
24393 "from %s at %s line %d"),
24394 file
, at_commandline
? _("command-line") : _("file"),
24395 line
== 0 ? _("zero") : _("non-zero"), line
);
24397 if (at_commandline
)
24399 /* This DW_MACRO_start_file was executed in the
24401 at_commandline
= 0;
24404 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24408 case DW_MACRO_end_file
:
24409 if (! current_file
)
24410 complaint (&symfile_complaints
,
24411 _("macro debug info has an unmatched "
24412 "`close_file' directive"));
24415 current_file
= current_file
->included_by
;
24416 if (! current_file
)
24418 enum dwarf_macro_record_type next_type
;
24420 /* GCC circa March 2002 doesn't produce the zero
24421 type byte marking the end of the compilation
24422 unit. Complain if it's not there, but exit no
24425 /* Do we at least have room for a macinfo type byte? */
24426 if (mac_ptr
>= mac_end
)
24428 dwarf2_section_buffer_overflow_complaint (section
);
24432 /* We don't increment mac_ptr here, so this is just
24435 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24437 if (next_type
!= 0)
24438 complaint (&symfile_complaints
,
24439 _("no terminating 0-type entry for "
24440 "macros in `.debug_macinfo' section"));
24447 case DW_MACRO_import
:
24448 case DW_MACRO_import_sup
:
24452 bfd
*include_bfd
= abfd
;
24453 struct dwarf2_section_info
*include_section
= section
;
24454 const gdb_byte
*include_mac_end
= mac_end
;
24455 int is_dwz
= section_is_dwz
;
24456 const gdb_byte
*new_mac_ptr
;
24458 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24459 mac_ptr
+= offset_size
;
24461 if (macinfo_type
== DW_MACRO_import_sup
)
24463 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24465 dwarf2_read_section (objfile
, &dwz
->macro
);
24467 include_section
= &dwz
->macro
;
24468 include_bfd
= get_section_bfd_owner (include_section
);
24469 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24473 new_mac_ptr
= include_section
->buffer
+ offset
;
24474 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24478 /* This has actually happened; see
24479 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24480 complaint (&symfile_complaints
,
24481 _("recursive DW_MACRO_import in "
24482 ".debug_macro section"));
24486 *slot
= (void *) new_mac_ptr
;
24488 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24489 include_bfd
, new_mac_ptr
,
24490 include_mac_end
, current_file
, lh
,
24491 section
, section_is_gnu
, is_dwz
,
24492 offset_size
, include_hash
);
24494 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24499 case DW_MACINFO_vendor_ext
:
24500 if (!section_is_gnu
)
24502 unsigned int bytes_read
;
24504 /* This reads the constant, but since we don't recognize
24505 any vendor extensions, we ignore it. */
24506 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24507 mac_ptr
+= bytes_read
;
24508 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24509 mac_ptr
+= bytes_read
;
24511 /* We don't recognize any vendor extensions. */
24517 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24518 mac_ptr
, mac_end
, abfd
, offset_size
,
24520 if (mac_ptr
== NULL
)
24525 } while (macinfo_type
!= 0);
24529 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24530 int section_is_gnu
)
24532 struct dwarf2_per_objfile
*dwarf2_per_objfile
24533 = cu
->per_cu
->dwarf2_per_objfile
;
24534 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24535 struct line_header
*lh
= cu
->line_header
;
24537 const gdb_byte
*mac_ptr
, *mac_end
;
24538 struct macro_source_file
*current_file
= 0;
24539 enum dwarf_macro_record_type macinfo_type
;
24540 unsigned int offset_size
= cu
->header
.offset_size
;
24541 const gdb_byte
*opcode_definitions
[256];
24543 struct dwarf2_section_info
*section
;
24544 const char *section_name
;
24546 if (cu
->dwo_unit
!= NULL
)
24548 if (section_is_gnu
)
24550 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24551 section_name
= ".debug_macro.dwo";
24555 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24556 section_name
= ".debug_macinfo.dwo";
24561 if (section_is_gnu
)
24563 section
= &dwarf2_per_objfile
->macro
;
24564 section_name
= ".debug_macro";
24568 section
= &dwarf2_per_objfile
->macinfo
;
24569 section_name
= ".debug_macinfo";
24573 dwarf2_read_section (objfile
, section
);
24574 if (section
->buffer
== NULL
)
24576 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24579 abfd
= get_section_bfd_owner (section
);
24581 /* First pass: Find the name of the base filename.
24582 This filename is needed in order to process all macros whose definition
24583 (or undefinition) comes from the command line. These macros are defined
24584 before the first DW_MACINFO_start_file entry, and yet still need to be
24585 associated to the base file.
24587 To determine the base file name, we scan the macro definitions until we
24588 reach the first DW_MACINFO_start_file entry. We then initialize
24589 CURRENT_FILE accordingly so that any macro definition found before the
24590 first DW_MACINFO_start_file can still be associated to the base file. */
24592 mac_ptr
= section
->buffer
+ offset
;
24593 mac_end
= section
->buffer
+ section
->size
;
24595 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24596 &offset_size
, section_is_gnu
);
24597 if (mac_ptr
== NULL
)
24599 /* We already issued a complaint. */
24605 /* Do we at least have room for a macinfo type byte? */
24606 if (mac_ptr
>= mac_end
)
24608 /* Complaint is printed during the second pass as GDB will probably
24609 stop the first pass earlier upon finding
24610 DW_MACINFO_start_file. */
24614 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24617 /* Note that we rely on the fact that the corresponding GNU and
24618 DWARF constants are the same. */
24620 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24621 switch (macinfo_type
)
24623 /* A zero macinfo type indicates the end of the macro
24628 case DW_MACRO_define
:
24629 case DW_MACRO_undef
:
24630 /* Only skip the data by MAC_PTR. */
24632 unsigned int bytes_read
;
24634 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24635 mac_ptr
+= bytes_read
;
24636 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24637 mac_ptr
+= bytes_read
;
24641 case DW_MACRO_start_file
:
24643 unsigned int bytes_read
;
24646 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24647 mac_ptr
+= bytes_read
;
24648 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24649 mac_ptr
+= bytes_read
;
24651 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24655 case DW_MACRO_end_file
:
24656 /* No data to skip by MAC_PTR. */
24659 case DW_MACRO_define_strp
:
24660 case DW_MACRO_undef_strp
:
24661 case DW_MACRO_define_sup
:
24662 case DW_MACRO_undef_sup
:
24664 unsigned int bytes_read
;
24666 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24667 mac_ptr
+= bytes_read
;
24668 mac_ptr
+= offset_size
;
24672 case DW_MACRO_import
:
24673 case DW_MACRO_import_sup
:
24674 /* Note that, according to the spec, a transparent include
24675 chain cannot call DW_MACRO_start_file. So, we can just
24676 skip this opcode. */
24677 mac_ptr
+= offset_size
;
24680 case DW_MACINFO_vendor_ext
:
24681 /* Only skip the data by MAC_PTR. */
24682 if (!section_is_gnu
)
24684 unsigned int bytes_read
;
24686 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24687 mac_ptr
+= bytes_read
;
24688 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24689 mac_ptr
+= bytes_read
;
24694 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24695 mac_ptr
, mac_end
, abfd
, offset_size
,
24697 if (mac_ptr
== NULL
)
24702 } while (macinfo_type
!= 0 && current_file
== NULL
);
24704 /* Second pass: Process all entries.
24706 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24707 command-line macro definitions/undefinitions. This flag is unset when we
24708 reach the first DW_MACINFO_start_file entry. */
24710 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24712 NULL
, xcalloc
, xfree
));
24713 mac_ptr
= section
->buffer
+ offset
;
24714 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24715 *slot
= (void *) mac_ptr
;
24716 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24717 abfd
, mac_ptr
, mac_end
,
24718 current_file
, lh
, section
,
24719 section_is_gnu
, 0, offset_size
,
24720 include_hash
.get ());
24723 /* Check if the attribute's form is a DW_FORM_block*
24724 if so return true else false. */
24727 attr_form_is_block (const struct attribute
*attr
)
24729 return (attr
== NULL
? 0 :
24730 attr
->form
== DW_FORM_block1
24731 || attr
->form
== DW_FORM_block2
24732 || attr
->form
== DW_FORM_block4
24733 || attr
->form
== DW_FORM_block
24734 || attr
->form
== DW_FORM_exprloc
);
24737 /* Return non-zero if ATTR's value is a section offset --- classes
24738 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24739 You may use DW_UNSND (attr) to retrieve such offsets.
24741 Section 7.5.4, "Attribute Encodings", explains that no attribute
24742 may have a value that belongs to more than one of these classes; it
24743 would be ambiguous if we did, because we use the same forms for all
24747 attr_form_is_section_offset (const struct attribute
*attr
)
24749 return (attr
->form
== DW_FORM_data4
24750 || attr
->form
== DW_FORM_data8
24751 || attr
->form
== DW_FORM_sec_offset
);
24754 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24755 zero otherwise. When this function returns true, you can apply
24756 dwarf2_get_attr_constant_value to it.
24758 However, note that for some attributes you must check
24759 attr_form_is_section_offset before using this test. DW_FORM_data4
24760 and DW_FORM_data8 are members of both the constant class, and of
24761 the classes that contain offsets into other debug sections
24762 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24763 that, if an attribute's can be either a constant or one of the
24764 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24765 taken as section offsets, not constants.
24767 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24768 cannot handle that. */
24771 attr_form_is_constant (const struct attribute
*attr
)
24773 switch (attr
->form
)
24775 case DW_FORM_sdata
:
24776 case DW_FORM_udata
:
24777 case DW_FORM_data1
:
24778 case DW_FORM_data2
:
24779 case DW_FORM_data4
:
24780 case DW_FORM_data8
:
24781 case DW_FORM_implicit_const
:
24789 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24790 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24793 attr_form_is_ref (const struct attribute
*attr
)
24795 switch (attr
->form
)
24797 case DW_FORM_ref_addr
:
24802 case DW_FORM_ref_udata
:
24803 case DW_FORM_GNU_ref_alt
:
24810 /* Return the .debug_loc section to use for CU.
24811 For DWO files use .debug_loc.dwo. */
24813 static struct dwarf2_section_info
*
24814 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24816 struct dwarf2_per_objfile
*dwarf2_per_objfile
24817 = cu
->per_cu
->dwarf2_per_objfile
;
24821 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24823 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24825 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24826 : &dwarf2_per_objfile
->loc
);
24829 /* A helper function that fills in a dwarf2_loclist_baton. */
24832 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24833 struct dwarf2_loclist_baton
*baton
,
24834 const struct attribute
*attr
)
24836 struct dwarf2_per_objfile
*dwarf2_per_objfile
24837 = cu
->per_cu
->dwarf2_per_objfile
;
24838 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24840 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
24842 baton
->per_cu
= cu
->per_cu
;
24843 gdb_assert (baton
->per_cu
);
24844 /* We don't know how long the location list is, but make sure we
24845 don't run off the edge of the section. */
24846 baton
->size
= section
->size
- DW_UNSND (attr
);
24847 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24848 baton
->base_address
= cu
->base_address
;
24849 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24853 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24854 struct dwarf2_cu
*cu
, int is_block
)
24856 struct dwarf2_per_objfile
*dwarf2_per_objfile
24857 = cu
->per_cu
->dwarf2_per_objfile
;
24858 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24859 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24861 if (attr_form_is_section_offset (attr
)
24862 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24863 the section. If so, fall through to the complaint in the
24865 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24867 struct dwarf2_loclist_baton
*baton
;
24869 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24871 fill_in_loclist_baton (cu
, baton
, attr
);
24873 if (cu
->base_known
== 0)
24874 complaint (&symfile_complaints
,
24875 _("Location list used without "
24876 "specifying the CU base address."));
24878 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24879 ? dwarf2_loclist_block_index
24880 : dwarf2_loclist_index
);
24881 SYMBOL_LOCATION_BATON (sym
) = baton
;
24885 struct dwarf2_locexpr_baton
*baton
;
24887 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24888 baton
->per_cu
= cu
->per_cu
;
24889 gdb_assert (baton
->per_cu
);
24891 if (attr_form_is_block (attr
))
24893 /* Note that we're just copying the block's data pointer
24894 here, not the actual data. We're still pointing into the
24895 info_buffer for SYM's objfile; right now we never release
24896 that buffer, but when we do clean up properly this may
24898 baton
->size
= DW_BLOCK (attr
)->size
;
24899 baton
->data
= DW_BLOCK (attr
)->data
;
24903 dwarf2_invalid_attrib_class_complaint ("location description",
24904 SYMBOL_NATURAL_NAME (sym
));
24908 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24909 ? dwarf2_locexpr_block_index
24910 : dwarf2_locexpr_index
);
24911 SYMBOL_LOCATION_BATON (sym
) = baton
;
24915 /* Return the OBJFILE associated with the compilation unit CU. If CU
24916 came from a separate debuginfo file, then the master objfile is
24920 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
24922 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
24924 /* Return the master objfile, so that we can report and look up the
24925 correct file containing this variable. */
24926 if (objfile
->separate_debug_objfile_backlink
)
24927 objfile
= objfile
->separate_debug_objfile_backlink
;
24932 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
24933 (CU_HEADERP is unused in such case) or prepare a temporary copy at
24934 CU_HEADERP first. */
24936 static const struct comp_unit_head
*
24937 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
24938 struct dwarf2_per_cu_data
*per_cu
)
24940 const gdb_byte
*info_ptr
;
24943 return &per_cu
->cu
->header
;
24945 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
24947 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
24948 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
24949 rcuh_kind::COMPILE
);
24954 /* Return the address size given in the compilation unit header for CU. */
24957 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24959 struct comp_unit_head cu_header_local
;
24960 const struct comp_unit_head
*cu_headerp
;
24962 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24964 return cu_headerp
->addr_size
;
24967 /* Return the offset size given in the compilation unit header for CU. */
24970 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
24972 struct comp_unit_head cu_header_local
;
24973 const struct comp_unit_head
*cu_headerp
;
24975 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24977 return cu_headerp
->offset_size
;
24980 /* See its dwarf2loc.h declaration. */
24983 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
24985 struct comp_unit_head cu_header_local
;
24986 const struct comp_unit_head
*cu_headerp
;
24988 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
24990 if (cu_headerp
->version
== 2)
24991 return cu_headerp
->addr_size
;
24993 return cu_headerp
->offset_size
;
24996 /* Return the text offset of the CU. The returned offset comes from
24997 this CU's objfile. If this objfile came from a separate debuginfo
24998 file, then the offset may be different from the corresponding
24999 offset in the parent objfile. */
25002 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25004 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25006 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25009 /* Return DWARF version number of PER_CU. */
25012 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25014 return per_cu
->dwarf_version
;
25017 /* Locate the .debug_info compilation unit from CU's objfile which contains
25018 the DIE at OFFSET. Raises an error on failure. */
25020 static struct dwarf2_per_cu_data
*
25021 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25022 unsigned int offset_in_dwz
,
25023 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25025 struct dwarf2_per_cu_data
*this_cu
;
25027 const sect_offset
*cu_off
;
25030 high
= dwarf2_per_objfile
->n_comp_units
- 1;
25033 struct dwarf2_per_cu_data
*mid_cu
;
25034 int mid
= low
+ (high
- low
) / 2;
25036 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25037 cu_off
= &mid_cu
->sect_off
;
25038 if (mid_cu
->is_dwz
> offset_in_dwz
25039 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25044 gdb_assert (low
== high
);
25045 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25046 cu_off
= &this_cu
->sect_off
;
25047 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25049 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25050 error (_("Dwarf Error: could not find partial DIE containing "
25051 "offset %s [in module %s]"),
25052 sect_offset_str (sect_off
),
25053 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25055 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25057 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25061 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25062 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25063 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25064 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25065 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25070 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25072 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25073 : per_cu (per_cu_
),
25076 checked_producer (0),
25077 producer_is_gxx_lt_4_6 (0),
25078 producer_is_gcc_lt_4_3 (0),
25079 producer_is_icc_lt_14 (0),
25080 processing_has_namespace_info (0)
25085 /* Destroy a dwarf2_cu. */
25087 dwarf2_cu::~dwarf2_cu ()
25092 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25095 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25096 enum language pretend_language
)
25098 struct attribute
*attr
;
25100 /* Set the language we're debugging. */
25101 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25103 set_cu_language (DW_UNSND (attr
), cu
);
25106 cu
->language
= pretend_language
;
25107 cu
->language_defn
= language_def (cu
->language
);
25110 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25113 /* Free all cached compilation units. */
25116 free_cached_comp_units (void *data
)
25118 struct dwarf2_per_objfile
*dwarf2_per_objfile
25119 = (struct dwarf2_per_objfile
*) data
;
25121 dwarf2_per_objfile
->free_cached_comp_units ();
25124 /* Increase the age counter on each cached compilation unit, and free
25125 any that are too old. */
25128 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25130 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25132 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25133 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25134 while (per_cu
!= NULL
)
25136 per_cu
->cu
->last_used
++;
25137 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25138 dwarf2_mark (per_cu
->cu
);
25139 per_cu
= per_cu
->cu
->read_in_chain
;
25142 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25143 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25144 while (per_cu
!= NULL
)
25146 struct dwarf2_per_cu_data
*next_cu
;
25148 next_cu
= per_cu
->cu
->read_in_chain
;
25150 if (!per_cu
->cu
->mark
)
25153 *last_chain
= next_cu
;
25156 last_chain
= &per_cu
->cu
->read_in_chain
;
25162 /* Remove a single compilation unit from the cache. */
25165 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25167 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25168 struct dwarf2_per_objfile
*dwarf2_per_objfile
25169 = target_per_cu
->dwarf2_per_objfile
;
25171 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25172 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25173 while (per_cu
!= NULL
)
25175 struct dwarf2_per_cu_data
*next_cu
;
25177 next_cu
= per_cu
->cu
->read_in_chain
;
25179 if (per_cu
== target_per_cu
)
25183 *last_chain
= next_cu
;
25187 last_chain
= &per_cu
->cu
->read_in_chain
;
25193 /* Release all extra memory associated with OBJFILE. */
25196 dwarf2_free_objfile (struct objfile
*objfile
)
25198 struct dwarf2_per_objfile
*dwarf2_per_objfile
25199 = get_dwarf2_per_objfile (objfile
);
25201 delete dwarf2_per_objfile
;
25204 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25205 We store these in a hash table separate from the DIEs, and preserve them
25206 when the DIEs are flushed out of cache.
25208 The CU "per_cu" pointer is needed because offset alone is not enough to
25209 uniquely identify the type. A file may have multiple .debug_types sections,
25210 or the type may come from a DWO file. Furthermore, while it's more logical
25211 to use per_cu->section+offset, with Fission the section with the data is in
25212 the DWO file but we don't know that section at the point we need it.
25213 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25214 because we can enter the lookup routine, get_die_type_at_offset, from
25215 outside this file, and thus won't necessarily have PER_CU->cu.
25216 Fortunately, PER_CU is stable for the life of the objfile. */
25218 struct dwarf2_per_cu_offset_and_type
25220 const struct dwarf2_per_cu_data
*per_cu
;
25221 sect_offset sect_off
;
25225 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25228 per_cu_offset_and_type_hash (const void *item
)
25230 const struct dwarf2_per_cu_offset_and_type
*ofs
25231 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25233 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25236 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25239 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25241 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25242 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25243 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25244 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25246 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25247 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25250 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25251 table if necessary. For convenience, return TYPE.
25253 The DIEs reading must have careful ordering to:
25254 * Not cause infite loops trying to read in DIEs as a prerequisite for
25255 reading current DIE.
25256 * Not trying to dereference contents of still incompletely read in types
25257 while reading in other DIEs.
25258 * Enable referencing still incompletely read in types just by a pointer to
25259 the type without accessing its fields.
25261 Therefore caller should follow these rules:
25262 * Try to fetch any prerequisite types we may need to build this DIE type
25263 before building the type and calling set_die_type.
25264 * After building type call set_die_type for current DIE as soon as
25265 possible before fetching more types to complete the current type.
25266 * Make the type as complete as possible before fetching more types. */
25268 static struct type
*
25269 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25271 struct dwarf2_per_objfile
*dwarf2_per_objfile
25272 = cu
->per_cu
->dwarf2_per_objfile
;
25273 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25274 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25275 struct attribute
*attr
;
25276 struct dynamic_prop prop
;
25278 /* For Ada types, make sure that the gnat-specific data is always
25279 initialized (if not already set). There are a few types where
25280 we should not be doing so, because the type-specific area is
25281 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25282 where the type-specific area is used to store the floatformat).
25283 But this is not a problem, because the gnat-specific information
25284 is actually not needed for these types. */
25285 if (need_gnat_info (cu
)
25286 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25287 && TYPE_CODE (type
) != TYPE_CODE_FLT
25288 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25289 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25290 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25291 && !HAVE_GNAT_AUX_INFO (type
))
25292 INIT_GNAT_SPECIFIC (type
);
25294 /* Read DW_AT_allocated and set in type. */
25295 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25296 if (attr_form_is_block (attr
))
25298 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25299 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25301 else if (attr
!= NULL
)
25303 complaint (&symfile_complaints
,
25304 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25305 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25306 sect_offset_str (die
->sect_off
));
25309 /* Read DW_AT_associated and set in type. */
25310 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25311 if (attr_form_is_block (attr
))
25313 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25314 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25316 else if (attr
!= NULL
)
25318 complaint (&symfile_complaints
,
25319 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25320 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25321 sect_offset_str (die
->sect_off
));
25324 /* Read DW_AT_data_location and set in type. */
25325 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25326 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25327 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25329 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25331 dwarf2_per_objfile
->die_type_hash
=
25332 htab_create_alloc_ex (127,
25333 per_cu_offset_and_type_hash
,
25334 per_cu_offset_and_type_eq
,
25336 &objfile
->objfile_obstack
,
25337 hashtab_obstack_allocate
,
25338 dummy_obstack_deallocate
);
25341 ofs
.per_cu
= cu
->per_cu
;
25342 ofs
.sect_off
= die
->sect_off
;
25344 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25345 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25347 complaint (&symfile_complaints
,
25348 _("A problem internal to GDB: DIE %s has type already set"),
25349 sect_offset_str (die
->sect_off
));
25350 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25351 struct dwarf2_per_cu_offset_and_type
);
25356 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25357 or return NULL if the die does not have a saved type. */
25359 static struct type
*
25360 get_die_type_at_offset (sect_offset sect_off
,
25361 struct dwarf2_per_cu_data
*per_cu
)
25363 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25364 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25366 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25369 ofs
.per_cu
= per_cu
;
25370 ofs
.sect_off
= sect_off
;
25371 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25372 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25379 /* Look up the type for DIE in CU in die_type_hash,
25380 or return NULL if DIE does not have a saved type. */
25382 static struct type
*
25383 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25385 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25388 /* Add a dependence relationship from CU to REF_PER_CU. */
25391 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25392 struct dwarf2_per_cu_data
*ref_per_cu
)
25396 if (cu
->dependencies
== NULL
)
25398 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25399 NULL
, &cu
->comp_unit_obstack
,
25400 hashtab_obstack_allocate
,
25401 dummy_obstack_deallocate
);
25403 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25405 *slot
= ref_per_cu
;
25408 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25409 Set the mark field in every compilation unit in the
25410 cache that we must keep because we are keeping CU. */
25413 dwarf2_mark_helper (void **slot
, void *data
)
25415 struct dwarf2_per_cu_data
*per_cu
;
25417 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25419 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25420 reading of the chain. As such dependencies remain valid it is not much
25421 useful to track and undo them during QUIT cleanups. */
25422 if (per_cu
->cu
== NULL
)
25425 if (per_cu
->cu
->mark
)
25427 per_cu
->cu
->mark
= 1;
25429 if (per_cu
->cu
->dependencies
!= NULL
)
25430 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25435 /* Set the mark field in CU and in every other compilation unit in the
25436 cache that we must keep because we are keeping CU. */
25439 dwarf2_mark (struct dwarf2_cu
*cu
)
25444 if (cu
->dependencies
!= NULL
)
25445 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25449 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25453 per_cu
->cu
->mark
= 0;
25454 per_cu
= per_cu
->cu
->read_in_chain
;
25458 /* Trivial hash function for partial_die_info: the hash value of a DIE
25459 is its offset in .debug_info for this objfile. */
25462 partial_die_hash (const void *item
)
25464 const struct partial_die_info
*part_die
25465 = (const struct partial_die_info
*) item
;
25467 return to_underlying (part_die
->sect_off
);
25470 /* Trivial comparison function for partial_die_info structures: two DIEs
25471 are equal if they have the same offset. */
25474 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25476 const struct partial_die_info
*part_die_lhs
25477 = (const struct partial_die_info
*) item_lhs
;
25478 const struct partial_die_info
*part_die_rhs
25479 = (const struct partial_die_info
*) item_rhs
;
25481 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25484 static struct cmd_list_element
*set_dwarf_cmdlist
;
25485 static struct cmd_list_element
*show_dwarf_cmdlist
;
25488 set_dwarf_cmd (const char *args
, int from_tty
)
25490 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25495 show_dwarf_cmd (const char *args
, int from_tty
)
25497 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25500 /* The "save gdb-index" command. */
25502 /* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
25506 file_write (FILE *file
, const void *data
, size_t size
)
25508 if (fwrite (data
, 1, size
, file
) != size
)
25509 error (_("couldn't data write to file"));
25512 /* Write the contents of VEC to FILE, with error checking. */
25514 template<typename Elem
, typename Alloc
>
25516 file_write (FILE *file
, const std::vector
<Elem
, Alloc
> &vec
)
25518 file_write (file
, vec
.data (), vec
.size () * sizeof (vec
[0]));
25521 /* In-memory buffer to prepare data to be written later to a file. */
25525 /* Copy DATA to the end of the buffer. */
25526 template<typename T
>
25527 void append_data (const T
&data
)
25529 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
25530 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
25531 grow (sizeof (data
)));
25534 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
25535 terminating zero is appended too. */
25536 void append_cstr0 (const char *cstr
)
25538 const size_t size
= strlen (cstr
) + 1;
25539 std::copy (cstr
, cstr
+ size
, grow (size
));
25542 /* Store INPUT as ULEB128 to the end of buffer. */
25543 void append_unsigned_leb128 (ULONGEST input
)
25547 gdb_byte output
= input
& 0x7f;
25551 append_data (output
);
25557 /* Accept a host-format integer in VAL and append it to the buffer
25558 as a target-format integer which is LEN bytes long. */
25559 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
25561 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
25564 /* Return the size of the buffer. */
25565 size_t size () const
25567 return m_vec
.size ();
25570 /* Return true iff the buffer is empty. */
25571 bool empty () const
25573 return m_vec
.empty ();
25576 /* Write the buffer to FILE. */
25577 void file_write (FILE *file
) const
25579 ::file_write (file
, m_vec
);
25583 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
25584 the start of the new block. */
25585 gdb_byte
*grow (size_t size
)
25587 m_vec
.resize (m_vec
.size () + size
);
25588 return &*m_vec
.end () - size
;
25591 gdb::byte_vector m_vec
;
25594 /* An entry in the symbol table. */
25595 struct symtab_index_entry
25597 /* The name of the symbol. */
25599 /* The offset of the name in the constant pool. */
25600 offset_type index_offset
;
25601 /* A sorted vector of the indices of all the CUs that hold an object
25603 std::vector
<offset_type
> cu_indices
;
25606 /* The symbol table. This is a power-of-2-sized hash table. */
25607 struct mapped_symtab
25611 data
.resize (1024);
25614 offset_type n_elements
= 0;
25615 std::vector
<symtab_index_entry
> data
;
25618 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
25621 Function is used only during write_hash_table so no index format backward
25622 compatibility is needed. */
25624 static symtab_index_entry
&
25625 find_slot (struct mapped_symtab
*symtab
, const char *name
)
25627 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
25629 index
= hash
& (symtab
->data
.size () - 1);
25630 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
25634 if (symtab
->data
[index
].name
== NULL
25635 || strcmp (name
, symtab
->data
[index
].name
) == 0)
25636 return symtab
->data
[index
];
25637 index
= (index
+ step
) & (symtab
->data
.size () - 1);
25641 /* Expand SYMTAB's hash table. */
25644 hash_expand (struct mapped_symtab
*symtab
)
25646 auto old_entries
= std::move (symtab
->data
);
25648 symtab
->data
.clear ();
25649 symtab
->data
.resize (old_entries
.size () * 2);
25651 for (auto &it
: old_entries
)
25652 if (it
.name
!= NULL
)
25654 auto &ref
= find_slot (symtab
, it
.name
);
25655 ref
= std::move (it
);
25659 /* Add an entry to SYMTAB. NAME is the name of the symbol.
25660 CU_INDEX is the index of the CU in which the symbol appears.
25661 IS_STATIC is one if the symbol is static, otherwise zero (global). */
25664 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
25665 int is_static
, gdb_index_symbol_kind kind
,
25666 offset_type cu_index
)
25668 offset_type cu_index_and_attrs
;
25670 ++symtab
->n_elements
;
25671 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
25672 hash_expand (symtab
);
25674 symtab_index_entry
&slot
= find_slot (symtab
, name
);
25675 if (slot
.name
== NULL
)
25678 /* index_offset is set later. */
25681 cu_index_and_attrs
= 0;
25682 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
25683 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
25684 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
25686 /* We don't want to record an index value twice as we want to avoid the
25688 We process all global symbols and then all static symbols
25689 (which would allow us to avoid the duplication by only having to check
25690 the last entry pushed), but a symbol could have multiple kinds in one CU.
25691 To keep things simple we don't worry about the duplication here and
25692 sort and uniqufy the list after we've processed all symbols. */
25693 slot
.cu_indices
.push_back (cu_index_and_attrs
);
25696 /* Sort and remove duplicates of all symbols' cu_indices lists. */
25699 uniquify_cu_indices (struct mapped_symtab
*symtab
)
25701 for (auto &entry
: symtab
->data
)
25703 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
25705 auto &cu_indices
= entry
.cu_indices
;
25706 std::sort (cu_indices
.begin (), cu_indices
.end ());
25707 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
25708 cu_indices
.erase (from
, cu_indices
.end ());
25713 /* A form of 'const char *' suitable for container keys. Only the
25714 pointer is stored. The strings themselves are compared, not the
25719 c_str_view (const char *cstr
)
25723 bool operator== (const c_str_view
&other
) const
25725 return strcmp (m_cstr
, other
.m_cstr
) == 0;
25728 /* Return the underlying C string. Note, the returned string is
25729 only a reference with lifetime of this object. */
25730 const char *c_str () const
25736 friend class c_str_view_hasher
;
25737 const char *const m_cstr
;
25740 /* A std::unordered_map::hasher for c_str_view that uses the right
25741 hash function for strings in a mapped index. */
25742 class c_str_view_hasher
25745 size_t operator () (const c_str_view
&x
) const
25747 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
25751 /* A std::unordered_map::hasher for std::vector<>. */
25752 template<typename T
>
25753 class vector_hasher
25756 size_t operator () (const std::vector
<T
> &key
) const
25758 return iterative_hash (key
.data (),
25759 sizeof (key
.front ()) * key
.size (), 0);
25763 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
25764 constant pool entries going into the data buffer CPOOL. */
25767 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
25770 /* Elements are sorted vectors of the indices of all the CUs that
25771 hold an object of this name. */
25772 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
25773 vector_hasher
<offset_type
>>
25776 /* We add all the index vectors to the constant pool first, to
25777 ensure alignment is ok. */
25778 for (symtab_index_entry
&entry
: symtab
->data
)
25780 if (entry
.name
== NULL
)
25782 gdb_assert (entry
.index_offset
== 0);
25784 /* Finding before inserting is faster than always trying to
25785 insert, because inserting always allocates a node, does the
25786 lookup, and then destroys the new node if another node
25787 already had the same key. C++17 try_emplace will avoid
25790 = symbol_hash_table
.find (entry
.cu_indices
);
25791 if (found
!= symbol_hash_table
.end ())
25793 entry
.index_offset
= found
->second
;
25797 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
25798 entry
.index_offset
= cpool
.size ();
25799 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
25800 for (const auto index
: entry
.cu_indices
)
25801 cpool
.append_data (MAYBE_SWAP (index
));
25805 /* Now write out the hash table. */
25806 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
25807 for (const auto &entry
: symtab
->data
)
25809 offset_type str_off
, vec_off
;
25811 if (entry
.name
!= NULL
)
25813 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
25814 if (insertpair
.second
)
25815 cpool
.append_cstr0 (entry
.name
);
25816 str_off
= insertpair
.first
->second
;
25817 vec_off
= entry
.index_offset
;
25821 /* While 0 is a valid constant pool index, it is not valid
25822 to have 0 for both offsets. */
25827 output
.append_data (MAYBE_SWAP (str_off
));
25828 output
.append_data (MAYBE_SWAP (vec_off
));
25832 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
25834 /* Helper struct for building the address table. */
25835 struct addrmap_index_data
25837 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
25838 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
25841 struct objfile
*objfile
;
25842 data_buf
&addr_vec
;
25843 psym_index_map
&cu_index_htab
;
25845 /* Non-zero if the previous_* fields are valid.
25846 We can't write an entry until we see the next entry (since it is only then
25847 that we know the end of the entry). */
25848 int previous_valid
;
25849 /* Index of the CU in the table of all CUs in the index file. */
25850 unsigned int previous_cu_index
;
25851 /* Start address of the CU. */
25852 CORE_ADDR previous_cu_start
;
25855 /* Write an address entry to ADDR_VEC. */
25858 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
25859 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
25861 CORE_ADDR baseaddr
;
25863 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25865 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
25866 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
25867 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
25870 /* Worker function for traversing an addrmap to build the address table. */
25873 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
25875 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
25876 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
25878 if (data
->previous_valid
)
25879 add_address_entry (data
->objfile
, data
->addr_vec
,
25880 data
->previous_cu_start
, start_addr
,
25881 data
->previous_cu_index
);
25883 data
->previous_cu_start
= start_addr
;
25886 const auto it
= data
->cu_index_htab
.find (pst
);
25887 gdb_assert (it
!= data
->cu_index_htab
.cend ());
25888 data
->previous_cu_index
= it
->second
;
25889 data
->previous_valid
= 1;
25892 data
->previous_valid
= 0;
25897 /* Write OBJFILE's address map to ADDR_VEC.
25898 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
25899 in the index file. */
25902 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
25903 psym_index_map
&cu_index_htab
)
25905 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
25907 /* When writing the address table, we have to cope with the fact that
25908 the addrmap iterator only provides the start of a region; we have to
25909 wait until the next invocation to get the start of the next region. */
25911 addrmap_index_data
.objfile
= objfile
;
25912 addrmap_index_data
.previous_valid
= 0;
25914 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
25915 &addrmap_index_data
);
25917 /* It's highly unlikely the last entry (end address = 0xff...ff)
25918 is valid, but we should still handle it.
25919 The end address is recorded as the start of the next region, but that
25920 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
25922 if (addrmap_index_data
.previous_valid
)
25923 add_address_entry (objfile
, addr_vec
,
25924 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
25925 addrmap_index_data
.previous_cu_index
);
25928 /* Return the symbol kind of PSYM. */
25930 static gdb_index_symbol_kind
25931 symbol_kind (struct partial_symbol
*psym
)
25933 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
25934 enum address_class aclass
= PSYMBOL_CLASS (psym
);
25942 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
25944 return GDB_INDEX_SYMBOL_KIND_TYPE
;
25946 case LOC_CONST_BYTES
:
25947 case LOC_OPTIMIZED_OUT
:
25949 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
25951 /* Note: It's currently impossible to recognize psyms as enum values
25952 short of reading the type info. For now punt. */
25953 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
25955 /* There are other LOC_FOO values that one might want to classify
25956 as variables, but dwarf2read.c doesn't currently use them. */
25957 return GDB_INDEX_SYMBOL_KIND_OTHER
;
25959 case STRUCT_DOMAIN
:
25960 return GDB_INDEX_SYMBOL_KIND_TYPE
;
25962 return GDB_INDEX_SYMBOL_KIND_OTHER
;
25966 /* Add a list of partial symbols to SYMTAB. */
25969 write_psymbols (struct mapped_symtab
*symtab
,
25970 std::unordered_set
<partial_symbol
*> &psyms_seen
,
25971 struct partial_symbol
**psymp
,
25973 offset_type cu_index
,
25976 for (; count
-- > 0; ++psymp
)
25978 struct partial_symbol
*psym
= *psymp
;
25980 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
25981 error (_("Ada is not currently supported by the index"));
25983 /* Only add a given psymbol once. */
25984 if (psyms_seen
.insert (psym
).second
)
25986 gdb_index_symbol_kind kind
= symbol_kind (psym
);
25988 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
25989 is_static
, kind
, cu_index
);
25994 /* A helper struct used when iterating over debug_types. */
25995 struct signatured_type_index_data
25997 signatured_type_index_data (data_buf
&types_list_
,
25998 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
25999 : types_list (types_list_
), psyms_seen (psyms_seen_
)
26002 struct objfile
*objfile
;
26003 struct mapped_symtab
*symtab
;
26004 data_buf
&types_list
;
26005 std::unordered_set
<partial_symbol
*> &psyms_seen
;
26009 /* A helper function that writes a single signatured_type to an
26013 write_one_signatured_type (void **slot
, void *d
)
26015 struct signatured_type_index_data
*info
26016 = (struct signatured_type_index_data
*) d
;
26017 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26018 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26020 write_psymbols (info
->symtab
,
26022 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26023 psymtab
->n_global_syms
, info
->cu_index
,
26025 write_psymbols (info
->symtab
,
26027 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26028 psymtab
->n_static_syms
, info
->cu_index
,
26031 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26032 to_underlying (entry
->per_cu
.sect_off
));
26033 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26034 to_underlying (entry
->type_offset_in_tu
));
26035 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
26042 /* Recurse into all "included" dependencies and count their symbols as
26043 if they appeared in this psymtab. */
26046 recursively_count_psymbols (struct partial_symtab
*psymtab
,
26047 size_t &psyms_seen
)
26049 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26050 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26051 recursively_count_psymbols (psymtab
->dependencies
[i
],
26054 psyms_seen
+= psymtab
->n_global_syms
;
26055 psyms_seen
+= psymtab
->n_static_syms
;
26058 /* Recurse into all "included" dependencies and write their symbols as
26059 if they appeared in this psymtab. */
26062 recursively_write_psymbols (struct objfile
*objfile
,
26063 struct partial_symtab
*psymtab
,
26064 struct mapped_symtab
*symtab
,
26065 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26066 offset_type cu_index
)
26070 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26071 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26072 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26073 symtab
, psyms_seen
, cu_index
);
26075 write_psymbols (symtab
,
26077 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26078 psymtab
->n_global_syms
, cu_index
,
26080 write_psymbols (symtab
,
26082 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26083 psymtab
->n_static_syms
, cu_index
,
26087 /* DWARF-5 .debug_names builder. */
26091 debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bool is_dwarf64
,
26092 bfd_endian dwarf5_byte_order
)
26093 : m_dwarf5_byte_order (dwarf5_byte_order
),
26094 m_dwarf32 (dwarf5_byte_order
),
26095 m_dwarf64 (dwarf5_byte_order
),
26096 m_dwarf (is_dwarf64
26097 ? static_cast<dwarf
&> (m_dwarf64
)
26098 : static_cast<dwarf
&> (m_dwarf32
)),
26099 m_name_table_string_offs (m_dwarf
.name_table_string_offs
),
26100 m_name_table_entry_offs (m_dwarf
.name_table_entry_offs
),
26101 m_debugstrlookup (dwarf2_per_objfile
)
26104 int dwarf5_offset_size () const
26106 const bool dwarf5_is_dwarf64
= &m_dwarf
== &m_dwarf64
;
26107 return dwarf5_is_dwarf64
? 8 : 4;
26110 /* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
26111 enum class unit_kind
{ cu
, tu
};
26113 /* Insert one symbol. */
26114 void insert (const partial_symbol
*psym
, int cu_index
, bool is_static
,
26117 const int dwarf_tag
= psymbol_tag (psym
);
26118 if (dwarf_tag
== 0)
26120 const char *const name
= SYMBOL_SEARCH_NAME (psym
);
26121 const auto insertpair
26122 = m_name_to_value_set
.emplace (c_str_view (name
),
26123 std::set
<symbol_value
> ());
26124 std::set
<symbol_value
> &value_set
= insertpair
.first
->second
;
26125 value_set
.emplace (symbol_value (dwarf_tag
, cu_index
, is_static
, kind
));
26128 /* Build all the tables. All symbols must be already inserted.
26129 This function does not call file_write, caller has to do it
26133 /* Verify the build method has not be called twice. */
26134 gdb_assert (m_abbrev_table
.empty ());
26135 const size_t name_count
= m_name_to_value_set
.size ();
26136 m_bucket_table
.resize
26137 (std::pow (2, std::ceil (std::log2 (name_count
* 4 / 3))));
26138 m_hash_table
.reserve (name_count
);
26139 m_name_table_string_offs
.reserve (name_count
);
26140 m_name_table_entry_offs
.reserve (name_count
);
26142 /* Map each hash of symbol to its name and value. */
26143 struct hash_it_pair
26146 decltype (m_name_to_value_set
)::const_iterator it
;
26148 std::vector
<std::forward_list
<hash_it_pair
>> bucket_hash
;
26149 bucket_hash
.resize (m_bucket_table
.size ());
26150 for (decltype (m_name_to_value_set
)::const_iterator it
26151 = m_name_to_value_set
.cbegin ();
26152 it
!= m_name_to_value_set
.cend ();
26155 const char *const name
= it
->first
.c_str ();
26156 const uint32_t hash
= dwarf5_djb_hash (name
);
26157 hash_it_pair hashitpair
;
26158 hashitpair
.hash
= hash
;
26159 hashitpair
.it
= it
;
26160 auto &slot
= bucket_hash
[hash
% bucket_hash
.size()];
26161 slot
.push_front (std::move (hashitpair
));
26163 for (size_t bucket_ix
= 0; bucket_ix
< bucket_hash
.size (); ++bucket_ix
)
26165 const std::forward_list
<hash_it_pair
> &hashitlist
26166 = bucket_hash
[bucket_ix
];
26167 if (hashitlist
.empty ())
26169 uint32_t &bucket_slot
= m_bucket_table
[bucket_ix
];
26170 /* The hashes array is indexed starting at 1. */
26171 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&bucket_slot
),
26172 sizeof (bucket_slot
), m_dwarf5_byte_order
,
26173 m_hash_table
.size () + 1);
26174 for (const hash_it_pair
&hashitpair
: hashitlist
)
26176 m_hash_table
.push_back (0);
26177 store_unsigned_integer (reinterpret_cast<gdb_byte
*>
26178 (&m_hash_table
.back ()),
26179 sizeof (m_hash_table
.back ()),
26180 m_dwarf5_byte_order
, hashitpair
.hash
);
26181 const c_str_view
&name
= hashitpair
.it
->first
;
26182 const std::set
<symbol_value
> &value_set
= hashitpair
.it
->second
;
26183 m_name_table_string_offs
.push_back_reorder
26184 (m_debugstrlookup
.lookup (name
.c_str ()));
26185 m_name_table_entry_offs
.push_back_reorder (m_entry_pool
.size ());
26186 gdb_assert (!value_set
.empty ());
26187 for (const symbol_value
&value
: value_set
)
26189 int &idx
= m_indexkey_to_idx
[index_key (value
.dwarf_tag
,
26194 idx
= m_idx_next
++;
26195 m_abbrev_table
.append_unsigned_leb128 (idx
);
26196 m_abbrev_table
.append_unsigned_leb128 (value
.dwarf_tag
);
26197 m_abbrev_table
.append_unsigned_leb128
26198 (value
.kind
== unit_kind::cu
? DW_IDX_compile_unit
26199 : DW_IDX_type_unit
);
26200 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_udata
);
26201 m_abbrev_table
.append_unsigned_leb128 (value
.is_static
26202 ? DW_IDX_GNU_internal
26203 : DW_IDX_GNU_external
);
26204 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_flag_present
);
26206 /* Terminate attributes list. */
26207 m_abbrev_table
.append_unsigned_leb128 (0);
26208 m_abbrev_table
.append_unsigned_leb128 (0);
26211 m_entry_pool
.append_unsigned_leb128 (idx
);
26212 m_entry_pool
.append_unsigned_leb128 (value
.cu_index
);
26215 /* Terminate the list of CUs. */
26216 m_entry_pool
.append_unsigned_leb128 (0);
26219 gdb_assert (m_hash_table
.size () == name_count
);
26221 /* Terminate tags list. */
26222 m_abbrev_table
.append_unsigned_leb128 (0);
26225 /* Return .debug_names bucket count. This must be called only after
26226 calling the build method. */
26227 uint32_t bucket_count () const
26229 /* Verify the build method has been already called. */
26230 gdb_assert (!m_abbrev_table
.empty ());
26231 const uint32_t retval
= m_bucket_table
.size ();
26233 /* Check for overflow. */
26234 gdb_assert (retval
== m_bucket_table
.size ());
26238 /* Return .debug_names names count. This must be called only after
26239 calling the build method. */
26240 uint32_t name_count () const
26242 /* Verify the build method has been already called. */
26243 gdb_assert (!m_abbrev_table
.empty ());
26244 const uint32_t retval
= m_hash_table
.size ();
26246 /* Check for overflow. */
26247 gdb_assert (retval
== m_hash_table
.size ());
26251 /* Return number of bytes of .debug_names abbreviation table. This
26252 must be called only after calling the build method. */
26253 uint32_t abbrev_table_bytes () const
26255 gdb_assert (!m_abbrev_table
.empty ());
26256 return m_abbrev_table
.size ();
26259 /* Recurse into all "included" dependencies and store their symbols
26260 as if they appeared in this psymtab. */
26261 void recursively_write_psymbols
26262 (struct objfile
*objfile
,
26263 struct partial_symtab
*psymtab
,
26264 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26267 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26268 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26269 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26270 psyms_seen
, cu_index
);
26272 write_psymbols (psyms_seen
,
26273 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26274 psymtab
->n_global_syms
, cu_index
, false, unit_kind::cu
);
26275 write_psymbols (psyms_seen
,
26276 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26277 psymtab
->n_static_syms
, cu_index
, true, unit_kind::cu
);
26280 /* Return number of bytes the .debug_names section will have. This
26281 must be called only after calling the build method. */
26282 size_t bytes () const
26284 /* Verify the build method has been already called. */
26285 gdb_assert (!m_abbrev_table
.empty ());
26286 size_t expected_bytes
= 0;
26287 expected_bytes
+= m_bucket_table
.size () * sizeof (m_bucket_table
[0]);
26288 expected_bytes
+= m_hash_table
.size () * sizeof (m_hash_table
[0]);
26289 expected_bytes
+= m_name_table_string_offs
.bytes ();
26290 expected_bytes
+= m_name_table_entry_offs
.bytes ();
26291 expected_bytes
+= m_abbrev_table
.size ();
26292 expected_bytes
+= m_entry_pool
.size ();
26293 return expected_bytes
;
26296 /* Write .debug_names to FILE_NAMES and .debug_str addition to
26297 FILE_STR. This must be called only after calling the build
26299 void file_write (FILE *file_names
, FILE *file_str
) const
26301 /* Verify the build method has been already called. */
26302 gdb_assert (!m_abbrev_table
.empty ());
26303 ::file_write (file_names
, m_bucket_table
);
26304 ::file_write (file_names
, m_hash_table
);
26305 m_name_table_string_offs
.file_write (file_names
);
26306 m_name_table_entry_offs
.file_write (file_names
);
26307 m_abbrev_table
.file_write (file_names
);
26308 m_entry_pool
.file_write (file_names
);
26309 m_debugstrlookup
.file_write (file_str
);
26312 /* A helper user data for write_one_signatured_type. */
26313 class write_one_signatured_type_data
26316 write_one_signatured_type_data (debug_names
&nametable_
,
26317 signatured_type_index_data
&&info_
)
26318 : nametable (nametable_
), info (std::move (info_
))
26320 debug_names
&nametable
;
26321 struct signatured_type_index_data info
;
26324 /* A helper function to pass write_one_signatured_type to
26325 htab_traverse_noresize. */
26327 write_one_signatured_type (void **slot
, void *d
)
26329 write_one_signatured_type_data
*data
= (write_one_signatured_type_data
*) d
;
26330 struct signatured_type_index_data
*info
= &data
->info
;
26331 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26333 data
->nametable
.write_one_signatured_type (entry
, info
);
26340 /* Storage for symbol names mapping them to their .debug_str section
26342 class debug_str_lookup
26346 /* Object costructor to be called for current DWARF2_PER_OBJFILE.
26347 All .debug_str section strings are automatically stored. */
26348 debug_str_lookup (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26349 : m_abfd (dwarf2_per_objfile
->objfile
->obfd
),
26350 m_dwarf2_per_objfile (dwarf2_per_objfile
)
26352 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
26353 &dwarf2_per_objfile
->str
);
26354 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
26356 for (const gdb_byte
*data
= dwarf2_per_objfile
->str
.buffer
;
26357 data
< (dwarf2_per_objfile
->str
.buffer
26358 + dwarf2_per_objfile
->str
.size
);)
26360 const char *const s
= reinterpret_cast<const char *> (data
);
26361 const auto insertpair
26362 = m_str_table
.emplace (c_str_view (s
),
26363 data
- dwarf2_per_objfile
->str
.buffer
);
26364 if (!insertpair
.second
)
26365 complaint (&symfile_complaints
,
26366 _("Duplicate string \"%s\" in "
26367 ".debug_str section [in module %s]"),
26368 s
, bfd_get_filename (m_abfd
));
26369 data
+= strlen (s
) + 1;
26373 /* Return offset of symbol name S in the .debug_str section. Add
26374 such symbol to the section's end if it does not exist there
26376 size_t lookup (const char *s
)
26378 const auto it
= m_str_table
.find (c_str_view (s
));
26379 if (it
!= m_str_table
.end ())
26381 const size_t offset
= (m_dwarf2_per_objfile
->str
.size
26382 + m_str_add_buf
.size ());
26383 m_str_table
.emplace (c_str_view (s
), offset
);
26384 m_str_add_buf
.append_cstr0 (s
);
26388 /* Append the end of the .debug_str section to FILE. */
26389 void file_write (FILE *file
) const
26391 m_str_add_buf
.file_write (file
);
26395 std::unordered_map
<c_str_view
, size_t, c_str_view_hasher
> m_str_table
;
26397 struct dwarf2_per_objfile
*m_dwarf2_per_objfile
;
26399 /* Data to add at the end of .debug_str for new needed symbol names. */
26400 data_buf m_str_add_buf
;
26403 /* Container to map used DWARF tags to their .debug_names abbreviation
26408 index_key (int dwarf_tag_
, bool is_static_
, unit_kind kind_
)
26409 : dwarf_tag (dwarf_tag_
), is_static (is_static_
), kind (kind_
)
26414 operator== (const index_key
&other
) const
26416 return (dwarf_tag
== other
.dwarf_tag
&& is_static
== other
.is_static
26417 && kind
== other
.kind
);
26420 const int dwarf_tag
;
26421 const bool is_static
;
26422 const unit_kind kind
;
26425 /* Provide std::unordered_map::hasher for index_key. */
26426 class index_key_hasher
26430 operator () (const index_key
&key
) const
26432 return (std::hash
<int>() (key
.dwarf_tag
) << 1) | key
.is_static
;
26436 /* Parameters of one symbol entry. */
26440 const int dwarf_tag
, cu_index
;
26441 const bool is_static
;
26442 const unit_kind kind
;
26444 symbol_value (int dwarf_tag_
, int cu_index_
, bool is_static_
,
26446 : dwarf_tag (dwarf_tag_
), cu_index (cu_index_
), is_static (is_static_
),
26451 operator< (const symbol_value
&other
) const
26471 /* Abstract base class to unify DWARF-32 and DWARF-64 name table
26476 const bfd_endian dwarf5_byte_order
;
26478 explicit offset_vec (bfd_endian dwarf5_byte_order_
)
26479 : dwarf5_byte_order (dwarf5_byte_order_
)
26482 /* Call std::vector::reserve for NELEM elements. */
26483 virtual void reserve (size_t nelem
) = 0;
26485 /* Call std::vector::push_back with store_unsigned_integer byte
26486 reordering for ELEM. */
26487 virtual void push_back_reorder (size_t elem
) = 0;
26489 /* Return expected output size in bytes. */
26490 virtual size_t bytes () const = 0;
26492 /* Write name table to FILE. */
26493 virtual void file_write (FILE *file
) const = 0;
26496 /* Template to unify DWARF-32 and DWARF-64 output. */
26497 template<typename OffsetSize
>
26498 class offset_vec_tmpl
: public offset_vec
26501 explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_
)
26502 : offset_vec (dwarf5_byte_order_
)
26505 /* Implement offset_vec::reserve. */
26506 void reserve (size_t nelem
) override
26508 m_vec
.reserve (nelem
);
26511 /* Implement offset_vec::push_back_reorder. */
26512 void push_back_reorder (size_t elem
) override
26514 m_vec
.push_back (elem
);
26515 /* Check for overflow. */
26516 gdb_assert (m_vec
.back () == elem
);
26517 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&m_vec
.back ()),
26518 sizeof (m_vec
.back ()), dwarf5_byte_order
, elem
);
26521 /* Implement offset_vec::bytes. */
26522 size_t bytes () const override
26524 return m_vec
.size () * sizeof (m_vec
[0]);
26527 /* Implement offset_vec::file_write. */
26528 void file_write (FILE *file
) const override
26530 ::file_write (file
, m_vec
);
26534 std::vector
<OffsetSize
> m_vec
;
26537 /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
26538 respecting name table width. */
26542 offset_vec
&name_table_string_offs
, &name_table_entry_offs
;
26544 dwarf (offset_vec
&name_table_string_offs_
,
26545 offset_vec
&name_table_entry_offs_
)
26546 : name_table_string_offs (name_table_string_offs_
),
26547 name_table_entry_offs (name_table_entry_offs_
)
26552 /* Template to unify DWARF-32 and DWARF-64 .debug_names output
26553 respecting name table width. */
26554 template<typename OffsetSize
>
26555 class dwarf_tmpl
: public dwarf
26558 explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_
)
26559 : dwarf (m_name_table_string_offs
, m_name_table_entry_offs
),
26560 m_name_table_string_offs (dwarf5_byte_order_
),
26561 m_name_table_entry_offs (dwarf5_byte_order_
)
26565 offset_vec_tmpl
<OffsetSize
> m_name_table_string_offs
;
26566 offset_vec_tmpl
<OffsetSize
> m_name_table_entry_offs
;
26569 /* Try to reconstruct original DWARF tag for given partial_symbol.
26570 This function is not DWARF-5 compliant but it is sufficient for
26571 GDB as a DWARF-5 index consumer. */
26572 static int psymbol_tag (const struct partial_symbol
*psym
)
26574 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26575 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26583 return DW_TAG_subprogram
;
26585 return DW_TAG_typedef
;
26587 case LOC_CONST_BYTES
:
26588 case LOC_OPTIMIZED_OUT
:
26590 return DW_TAG_variable
;
26592 /* Note: It's currently impossible to recognize psyms as enum values
26593 short of reading the type info. For now punt. */
26594 return DW_TAG_variable
;
26596 /* There are other LOC_FOO values that one might want to classify
26597 as variables, but dwarf2read.c doesn't currently use them. */
26598 return DW_TAG_variable
;
26600 case STRUCT_DOMAIN
:
26601 return DW_TAG_structure_type
;
26607 /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
26608 void write_psymbols (std::unordered_set
<partial_symbol
*> &psyms_seen
,
26609 struct partial_symbol
**psymp
, int count
, int cu_index
,
26610 bool is_static
, unit_kind kind
)
26612 for (; count
-- > 0; ++psymp
)
26614 struct partial_symbol
*psym
= *psymp
;
26616 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
26617 error (_("Ada is not currently supported by the index"));
26619 /* Only add a given psymbol once. */
26620 if (psyms_seen
.insert (psym
).second
)
26621 insert (psym
, cu_index
, is_static
, kind
);
26625 /* A helper function that writes a single signatured_type
26626 to a debug_names. */
26628 write_one_signatured_type (struct signatured_type
*entry
,
26629 struct signatured_type_index_data
*info
)
26631 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26633 write_psymbols (info
->psyms_seen
,
26634 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26635 psymtab
->n_global_syms
, info
->cu_index
, false,
26637 write_psymbols (info
->psyms_seen
,
26638 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26639 psymtab
->n_static_syms
, info
->cu_index
, true,
26642 info
->types_list
.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order
,
26643 to_underlying (entry
->per_cu
.sect_off
));
26648 /* Store value of each symbol. */
26649 std::unordered_map
<c_str_view
, std::set
<symbol_value
>, c_str_view_hasher
>
26650 m_name_to_value_set
;
26652 /* Tables of DWARF-5 .debug_names. They are in object file byte
26654 std::vector
<uint32_t> m_bucket_table
;
26655 std::vector
<uint32_t> m_hash_table
;
26657 const bfd_endian m_dwarf5_byte_order
;
26658 dwarf_tmpl
<uint32_t> m_dwarf32
;
26659 dwarf_tmpl
<uint64_t> m_dwarf64
;
26661 offset_vec
&m_name_table_string_offs
, &m_name_table_entry_offs
;
26662 debug_str_lookup m_debugstrlookup
;
26664 /* Map each used .debug_names abbreviation tag parameter to its
26666 std::unordered_map
<index_key
, int, index_key_hasher
> m_indexkey_to_idx
;
26668 /* Next unused .debug_names abbreviation tag for
26669 m_indexkey_to_idx. */
26670 int m_idx_next
= 1;
26672 /* .debug_names abbreviation table. */
26673 data_buf m_abbrev_table
;
26675 /* .debug_names entry pool. */
26676 data_buf m_entry_pool
;
26679 /* Return iff any of the needed offsets does not fit into 32-bit
26680 .debug_names section. */
26683 check_dwarf64_offsets (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26685 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26687 const dwarf2_per_cu_data
&per_cu
= *dwarf2_per_objfile
->all_comp_units
[i
];
26689 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
26692 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
26694 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
26695 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
26697 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
26703 /* The psyms_seen set is potentially going to be largish (~40k
26704 elements when indexing a -g3 build of GDB itself). Estimate the
26705 number of elements in order to avoid too many rehashes, which
26706 require rebuilding buckets and thus many trips to
26710 psyms_seen_size (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26712 size_t psyms_count
= 0;
26713 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26715 struct dwarf2_per_cu_data
*per_cu
26716 = dwarf2_per_objfile
->all_comp_units
[i
];
26717 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26719 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
26720 recursively_count_psymbols (psymtab
, psyms_count
);
26722 /* Generating an index for gdb itself shows a ratio of
26723 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
26724 return psyms_count
/ 4;
26727 /* Write new .gdb_index section for OBJFILE into OUT_FILE.
26728 Return how many bytes were expected to be written into OUT_FILE. */
26731 write_gdbindex (struct dwarf2_per_objfile
*dwarf2_per_objfile
, FILE *out_file
)
26733 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
26734 mapped_symtab symtab
;
26737 /* While we're scanning CU's create a table that maps a psymtab pointer
26738 (which is what addrmap records) to its index (which is what is recorded
26739 in the index file). This will later be needed to write the address
26741 psym_index_map cu_index_htab
;
26742 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
26744 /* The CU list is already sorted, so we don't need to do additional
26745 work here. Also, the debug_types entries do not appear in
26746 all_comp_units, but only in their own hash table. */
26748 std::unordered_set
<partial_symbol
*> psyms_seen
26749 (psyms_seen_size (dwarf2_per_objfile
));
26750 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26752 struct dwarf2_per_cu_data
*per_cu
26753 = dwarf2_per_objfile
->all_comp_units
[i
];
26754 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26756 /* CU of a shared file from 'dwz -m' may be unused by this main file.
26757 It may be referenced from a local scope but in such case it does not
26758 need to be present in .gdb_index. */
26759 if (psymtab
== NULL
)
26762 if (psymtab
->user
== NULL
)
26763 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
26766 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
26767 gdb_assert (insertpair
.second
);
26769 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26770 to_underlying (per_cu
->sect_off
));
26771 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
26774 /* Dump the address map. */
26776 write_address_map (objfile
, addr_vec
, cu_index_htab
);
26778 /* Write out the .debug_type entries, if any. */
26779 data_buf types_cu_list
;
26780 if (dwarf2_per_objfile
->signatured_types
)
26782 signatured_type_index_data
sig_data (types_cu_list
,
26785 sig_data
.objfile
= objfile
;
26786 sig_data
.symtab
= &symtab
;
26787 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
26788 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
26789 write_one_signatured_type
, &sig_data
);
26792 /* Now that we've processed all symbols we can shrink their cu_indices
26794 uniquify_cu_indices (&symtab
);
26796 data_buf symtab_vec
, constant_pool
;
26797 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
26800 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
26801 offset_type total_len
= size_of_contents
;
26803 /* The version number. */
26804 contents
.append_data (MAYBE_SWAP (8));
26806 /* The offset of the CU list from the start of the file. */
26807 contents
.append_data (MAYBE_SWAP (total_len
));
26808 total_len
+= cu_list
.size ();
26810 /* The offset of the types CU list from the start of the file. */
26811 contents
.append_data (MAYBE_SWAP (total_len
));
26812 total_len
+= types_cu_list
.size ();
26814 /* The offset of the address table from the start of the file. */
26815 contents
.append_data (MAYBE_SWAP (total_len
));
26816 total_len
+= addr_vec
.size ();
26818 /* The offset of the symbol table from the start of the file. */
26819 contents
.append_data (MAYBE_SWAP (total_len
));
26820 total_len
+= symtab_vec
.size ();
26822 /* The offset of the constant pool from the start of the file. */
26823 contents
.append_data (MAYBE_SWAP (total_len
));
26824 total_len
+= constant_pool
.size ();
26826 gdb_assert (contents
.size () == size_of_contents
);
26828 contents
.file_write (out_file
);
26829 cu_list
.file_write (out_file
);
26830 types_cu_list
.file_write (out_file
);
26831 addr_vec
.file_write (out_file
);
26832 symtab_vec
.file_write (out_file
);
26833 constant_pool
.file_write (out_file
);
26838 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
26839 static const gdb_byte dwarf5_gdb_augmentation
[] = { 'G', 'D', 'B', 0 };
26841 /* Write a new .debug_names section for OBJFILE into OUT_FILE, write
26842 needed addition to .debug_str section to OUT_FILE_STR. Return how
26843 many bytes were expected to be written into OUT_FILE. */
26846 write_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
26847 FILE *out_file
, FILE *out_file_str
)
26849 const bool dwarf5_is_dwarf64
= check_dwarf64_offsets (dwarf2_per_objfile
);
26850 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
26851 const enum bfd_endian dwarf5_byte_order
26852 = gdbarch_byte_order (get_objfile_arch (objfile
));
26854 /* The CU list is already sorted, so we don't need to do additional
26855 work here. Also, the debug_types entries do not appear in
26856 all_comp_units, but only in their own hash table. */
26858 debug_names
nametable (dwarf2_per_objfile
, dwarf5_is_dwarf64
,
26859 dwarf5_byte_order
);
26860 std::unordered_set
<partial_symbol
*>
26861 psyms_seen (psyms_seen_size (dwarf2_per_objfile
));
26862 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
26864 const dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
26865 partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
26867 /* CU of a shared file from 'dwz -m' may be unused by this main
26868 file. It may be referenced from a local scope but in such
26869 case it does not need to be present in .debug_names. */
26870 if (psymtab
== NULL
)
26873 if (psymtab
->user
== NULL
)
26874 nametable
.recursively_write_psymbols (objfile
, psymtab
, psyms_seen
, i
);
26876 cu_list
.append_uint (nametable
.dwarf5_offset_size (), dwarf5_byte_order
,
26877 to_underlying (per_cu
->sect_off
));
26880 /* Write out the .debug_type entries, if any. */
26881 data_buf types_cu_list
;
26882 if (dwarf2_per_objfile
->signatured_types
)
26884 debug_names::write_one_signatured_type_data
sig_data (nametable
,
26885 signatured_type_index_data (types_cu_list
, psyms_seen
));
26887 sig_data
.info
.objfile
= objfile
;
26888 /* It is used only for gdb_index. */
26889 sig_data
.info
.symtab
= nullptr;
26890 sig_data
.info
.cu_index
= 0;
26891 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
26892 debug_names::write_one_signatured_type
,
26896 nametable
.build ();
26898 /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
26900 const offset_type bytes_of_header
26901 = ((dwarf5_is_dwarf64
? 12 : 4)
26903 + sizeof (dwarf5_gdb_augmentation
));
26904 size_t expected_bytes
= 0;
26905 expected_bytes
+= bytes_of_header
;
26906 expected_bytes
+= cu_list
.size ();
26907 expected_bytes
+= types_cu_list
.size ();
26908 expected_bytes
+= nametable
.bytes ();
26911 if (!dwarf5_is_dwarf64
)
26913 const uint64_t size64
= expected_bytes
- 4;
26914 gdb_assert (size64
< 0xfffffff0);
26915 header
.append_uint (4, dwarf5_byte_order
, size64
);
26919 header
.append_uint (4, dwarf5_byte_order
, 0xffffffff);
26920 header
.append_uint (8, dwarf5_byte_order
, expected_bytes
- 12);
26923 /* The version number. */
26924 header
.append_uint (2, dwarf5_byte_order
, 5);
26927 header
.append_uint (2, dwarf5_byte_order
, 0);
26929 /* comp_unit_count - The number of CUs in the CU list. */
26930 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_comp_units
);
26932 /* local_type_unit_count - The number of TUs in the local TU
26934 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_type_units
);
26936 /* foreign_type_unit_count - The number of TUs in the foreign TU
26938 header
.append_uint (4, dwarf5_byte_order
, 0);
26940 /* bucket_count - The number of hash buckets in the hash lookup
26942 header
.append_uint (4, dwarf5_byte_order
, nametable
.bucket_count ());
26944 /* name_count - The number of unique names in the index. */
26945 header
.append_uint (4, dwarf5_byte_order
, nametable
.name_count ());
26947 /* abbrev_table_size - The size in bytes of the abbreviations
26949 header
.append_uint (4, dwarf5_byte_order
, nametable
.abbrev_table_bytes ());
26951 /* augmentation_string_size - The size in bytes of the augmentation
26952 string. This value is rounded up to a multiple of 4. */
26953 static_assert (sizeof (dwarf5_gdb_augmentation
) % 4 == 0, "");
26954 header
.append_uint (4, dwarf5_byte_order
, sizeof (dwarf5_gdb_augmentation
));
26955 header
.append_data (dwarf5_gdb_augmentation
);
26957 gdb_assert (header
.size () == bytes_of_header
);
26959 header
.file_write (out_file
);
26960 cu_list
.file_write (out_file
);
26961 types_cu_list
.file_write (out_file
);
26962 nametable
.file_write (out_file
, out_file_str
);
26964 return expected_bytes
;
26967 /* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
26968 position is at the end of the file. */
26971 assert_file_size (FILE *file
, const char *filename
, size_t expected_size
)
26973 const auto file_size
= ftell (file
);
26974 if (file_size
== -1)
26975 error (_("Can't get `%s' size"), filename
);
26976 gdb_assert (file_size
== expected_size
);
26979 /* Create an index file for OBJFILE in the directory DIR. */
26982 write_psymtabs_to_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
26984 dw_index_kind index_kind
)
26986 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
26988 if (dwarf2_per_objfile
->using_index
)
26989 error (_("Cannot use an index to create the index"));
26991 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
26992 error (_("Cannot make an index when the file has multiple .debug_types sections"));
26994 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
26998 if (stat (objfile_name (objfile
), &st
) < 0)
26999 perror_with_name (objfile_name (objfile
));
27001 std::string
filename (std::string (dir
) + SLASH_STRING
27002 + lbasename (objfile_name (objfile
))
27003 + (index_kind
== dw_index_kind::DEBUG_NAMES
27004 ? INDEX5_SUFFIX
: INDEX4_SUFFIX
));
27006 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
27008 error (_("Can't open `%s' for writing"), filename
.c_str ());
27010 /* Order matters here; we want FILE to be closed before FILENAME is
27011 unlinked, because on MS-Windows one cannot delete a file that is
27012 still open. (Don't call anything here that might throw until
27013 file_closer is created.) */
27014 gdb::unlinker
unlink_file (filename
.c_str ());
27015 gdb_file_up
close_out_file (out_file
);
27017 if (index_kind
== dw_index_kind::DEBUG_NAMES
)
27019 std::string
filename_str (std::string (dir
) + SLASH_STRING
27020 + lbasename (objfile_name (objfile
))
27021 + DEBUG_STR_SUFFIX
);
27023 = gdb_fopen_cloexec (filename_str
.c_str (), "wb").release ();
27025 error (_("Can't open `%s' for writing"), filename_str
.c_str ());
27026 gdb::unlinker
unlink_file_str (filename_str
.c_str ());
27027 gdb_file_up
close_out_file_str (out_file_str
);
27029 const size_t total_len
27030 = write_debug_names (dwarf2_per_objfile
, out_file
, out_file_str
);
27031 assert_file_size (out_file
, filename
.c_str (), total_len
);
27033 /* We want to keep the file .debug_str file too. */
27034 unlink_file_str
.keep ();
27038 const size_t total_len
27039 = write_gdbindex (dwarf2_per_objfile
, out_file
);
27040 assert_file_size (out_file
, filename
.c_str (), total_len
);
27043 /* We want to keep the file. */
27044 unlink_file
.keep ();
27047 /* Implementation of the `save gdb-index' command.
27049 Note that the .gdb_index file format used by this command is
27050 documented in the GDB manual. Any changes here must be documented
27054 save_gdb_index_command (const char *arg
, int from_tty
)
27056 struct objfile
*objfile
;
27057 const char dwarf5space
[] = "-dwarf-5 ";
27058 dw_index_kind index_kind
= dw_index_kind::GDB_INDEX
;
27063 arg
= skip_spaces (arg
);
27064 if (strncmp (arg
, dwarf5space
, strlen (dwarf5space
)) == 0)
27066 index_kind
= dw_index_kind::DEBUG_NAMES
;
27067 arg
+= strlen (dwarf5space
);
27068 arg
= skip_spaces (arg
);
27072 error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
27074 ALL_OBJFILES (objfile
)
27078 /* If the objfile does not correspond to an actual file, skip it. */
27079 if (stat (objfile_name (objfile
), &st
) < 0)
27082 struct dwarf2_per_objfile
*dwarf2_per_objfile
27083 = get_dwarf2_per_objfile (objfile
);
27085 if (dwarf2_per_objfile
!= NULL
)
27089 write_psymtabs_to_index (dwarf2_per_objfile
, arg
, index_kind
);
27091 CATCH (except
, RETURN_MASK_ERROR
)
27093 exception_fprintf (gdb_stderr
, except
,
27094 _("Error while writing index for `%s': "),
27095 objfile_name (objfile
));
27105 int dwarf_always_disassemble
;
27108 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
27109 struct cmd_list_element
*c
, const char *value
)
27111 fprintf_filtered (file
,
27112 _("Whether to always disassemble "
27113 "DWARF expressions is %s.\n"),
27118 show_check_physname (struct ui_file
*file
, int from_tty
,
27119 struct cmd_list_element
*c
, const char *value
)
27121 fprintf_filtered (file
,
27122 _("Whether to check \"physname\" is %s.\n"),
27127 _initialize_dwarf2_read (void)
27129 struct cmd_list_element
*c
;
27131 dwarf2_objfile_data_key
= register_objfile_data ();
27133 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
27134 Set DWARF specific variables.\n\
27135 Configure DWARF variables such as the cache size"),
27136 &set_dwarf_cmdlist
, "maintenance set dwarf ",
27137 0/*allow-unknown*/, &maintenance_set_cmdlist
);
27139 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
27140 Show DWARF specific variables\n\
27141 Show DWARF variables such as the cache size"),
27142 &show_dwarf_cmdlist
, "maintenance show dwarf ",
27143 0/*allow-unknown*/, &maintenance_show_cmdlist
);
27145 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
27146 &dwarf_max_cache_age
, _("\
27147 Set the upper bound on the age of cached DWARF compilation units."), _("\
27148 Show the upper bound on the age of cached DWARF compilation units."), _("\
27149 A higher limit means that cached compilation units will be stored\n\
27150 in memory longer, and more total memory will be used. Zero disables\n\
27151 caching, which can slow down startup."),
27153 show_dwarf_max_cache_age
,
27154 &set_dwarf_cmdlist
,
27155 &show_dwarf_cmdlist
);
27157 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
27158 &dwarf_always_disassemble
, _("\
27159 Set whether `info address' always disassembles DWARF expressions."), _("\
27160 Show whether `info address' always disassembles DWARF expressions."), _("\
27161 When enabled, DWARF expressions are always printed in an assembly-like\n\
27162 syntax. When disabled, expressions will be printed in a more\n\
27163 conversational style, when possible."),
27165 show_dwarf_always_disassemble
,
27166 &set_dwarf_cmdlist
,
27167 &show_dwarf_cmdlist
);
27169 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
27170 Set debugging of the DWARF reader."), _("\
27171 Show debugging of the DWARF reader."), _("\
27172 When enabled (non-zero), debugging messages are printed during DWARF\n\
27173 reading and symtab expansion. A value of 1 (one) provides basic\n\
27174 information. A value greater than 1 provides more verbose information."),
27177 &setdebuglist
, &showdebuglist
);
27179 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
27180 Set debugging of the DWARF DIE reader."), _("\
27181 Show debugging of the DWARF DIE reader."), _("\
27182 When enabled (non-zero), DIEs are dumped after they are read in.\n\
27183 The value is the maximum depth to print."),
27186 &setdebuglist
, &showdebuglist
);
27188 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
27189 Set debugging of the dwarf line reader."), _("\
27190 Show debugging of the dwarf line reader."), _("\
27191 When enabled (non-zero), line number entries are dumped as they are read in.\n\
27192 A value of 1 (one) provides basic information.\n\
27193 A value greater than 1 provides more verbose information."),
27196 &setdebuglist
, &showdebuglist
);
27198 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
27199 Set cross-checking of \"physname\" code against demangler."), _("\
27200 Show cross-checking of \"physname\" code against demangler."), _("\
27201 When enabled, GDB's internal \"physname\" code is checked against\n\
27203 NULL
, show_check_physname
,
27204 &setdebuglist
, &showdebuglist
);
27206 add_setshow_boolean_cmd ("use-deprecated-index-sections",
27207 no_class
, &use_deprecated_index_sections
, _("\
27208 Set whether to use deprecated gdb_index sections."), _("\
27209 Show whether to use deprecated gdb_index sections."), _("\
27210 When enabled, deprecated .gdb_index sections are used anyway.\n\
27211 Normally they are ignored either because of a missing feature or\n\
27212 performance issue.\n\
27213 Warning: This option must be enabled before gdb reads the file."),
27216 &setlist
, &showlist
);
27218 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
27220 Save a gdb-index file.\n\
27221 Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
27223 No options create one file with .gdb-index extension for pre-DWARF-5\n\
27224 compatible .gdb_index section. With -dwarf-5 creates two files with\n\
27225 extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
27227 set_cmd_completer (c
, filename_completer
);
27229 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27230 &dwarf2_locexpr_funcs
);
27231 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27232 &dwarf2_loclist_funcs
);
27234 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27235 &dwarf2_block_frame_base_locexpr_funcs
);
27236 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27237 &dwarf2_block_frame_base_loclist_funcs
);
27240 selftests::register_test ("dw2_expand_symtabs_matching",
27241 selftests::dw2_expand_symtabs_matching::run_test
);