1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2018 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
40 #include "gdb-demangle.h"
41 #include "expression.h"
42 #include "filenames.h" /* for DOSish file names */
45 #include "complaints.h"
47 #include "dwarf2expr.h"
48 #include "dwarf2loc.h"
49 #include "cp-support.h"
55 #include "typeprint.h"
58 #include "completer.h"
63 #include "gdbcore.h" /* for gnutarget */
64 #include "gdb/gdb-index.h"
69 #include "filestuff.h"
71 #include "namespace.h"
72 #include "common/gdb_unlinker.h"
73 #include "common/function-view.h"
74 #include "common/gdb_optional.h"
75 #include "common/underlying.h"
76 #include "common/byte-vector.h"
77 #include "common/hash_enum.h"
78 #include "filename-seen-cache.h"
81 #include <sys/types.h>
83 #include <unordered_set>
84 #include <unordered_map>
88 #include <forward_list>
89 #include "rust-lang.h"
90 #include "common/pathstuff.h"
92 /* When == 1, print basic high level tracing messages.
93 When > 1, be more verbose.
94 This is in contrast to the low level DIE reading of dwarf_die_debug. */
95 static unsigned int dwarf_read_debug
= 0;
97 /* When non-zero, dump DIEs after they are read in. */
98 static unsigned int dwarf_die_debug
= 0;
100 /* When non-zero, dump line number entries as they are read in. */
101 static unsigned int dwarf_line_debug
= 0;
103 /* When non-zero, cross-check physname against demangler. */
104 static int check_physname
= 0;
106 /* When non-zero, do not reject deprecated .gdb_index sections. */
107 static int use_deprecated_index_sections
= 0;
109 static const struct objfile_data
*dwarf2_objfile_data_key
;
111 /* The "aclass" indices for various kinds of computed DWARF symbols. */
113 static int dwarf2_locexpr_index
;
114 static int dwarf2_loclist_index
;
115 static int dwarf2_locexpr_block_index
;
116 static int dwarf2_loclist_block_index
;
118 /* A descriptor for dwarf sections.
120 S.ASECTION, SIZE are typically initialized when the objfile is first
121 scanned. BUFFER, READIN are filled in later when the section is read.
122 If the section contained compressed data then SIZE is updated to record
123 the uncompressed size of the section.
125 DWP file format V2 introduces a wrinkle that is easiest to handle by
126 creating the concept of virtual sections contained within a real section.
127 In DWP V2 the sections of the input DWO files are concatenated together
128 into one section, but section offsets are kept relative to the original
130 If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
131 the real section this "virtual" section is contained in, and BUFFER,SIZE
132 describe the virtual section. */
134 struct dwarf2_section_info
138 /* If this is a real section, the bfd section. */
140 /* If this is a virtual section, pointer to the containing ("real")
142 struct dwarf2_section_info
*containing_section
;
144 /* Pointer to section data, only valid if readin. */
145 const gdb_byte
*buffer
;
146 /* The size of the section, real or virtual. */
148 /* If this is a virtual section, the offset in the real section.
149 Only valid if is_virtual. */
150 bfd_size_type virtual_offset
;
151 /* True if we have tried to read this section. */
153 /* True if this is a virtual section, False otherwise.
154 This specifies which of s.section and s.containing_section to use. */
158 typedef struct dwarf2_section_info dwarf2_section_info_def
;
159 DEF_VEC_O (dwarf2_section_info_def
);
161 /* All offsets in the index are of this type. It must be
162 architecture-independent. */
163 typedef uint32_t offset_type
;
165 DEF_VEC_I (offset_type
);
167 /* Ensure only legit values are used. */
168 #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \
170 gdb_assert ((unsigned int) (value) <= 1); \
171 GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \
174 /* Ensure only legit values are used. */
175 #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \
177 gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \
178 && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \
179 GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \
182 /* Ensure we don't use more than the alloted nuber of bits for the CU. */
183 #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \
185 gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \
186 GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \
191 /* Convert VALUE between big- and little-endian. */
194 byte_swap (offset_type value
)
198 result
= (value
& 0xff) << 24;
199 result
|= (value
& 0xff00) << 8;
200 result
|= (value
& 0xff0000) >> 8;
201 result
|= (value
& 0xff000000) >> 24;
205 #define MAYBE_SWAP(V) byte_swap (V)
208 #define MAYBE_SWAP(V) static_cast<offset_type> (V)
209 #endif /* WORDS_BIGENDIAN */
211 /* An index into a (C++) symbol name component in a symbol name as
212 recorded in the mapped_index's symbol table. For each C++ symbol
213 in the symbol table, we record one entry for the start of each
214 component in the symbol in a table of name components, and then
215 sort the table, in order to be able to binary search symbol names,
216 ignoring leading namespaces, both completion and regular look up.
217 For example, for symbol "A::B::C", we'll have an entry that points
218 to "A::B::C", another that points to "B::C", and another for "C".
219 Note that function symbols in GDB index have no parameter
220 information, just the function/method names. You can convert a
221 name_component to a "const char *" using the
222 'mapped_index::symbol_name_at(offset_type)' method. */
224 struct name_component
226 /* Offset in the symbol name where the component starts. Stored as
227 a (32-bit) offset instead of a pointer to save memory and improve
228 locality on 64-bit architectures. */
229 offset_type name_offset
;
231 /* The symbol's index in the symbol and constant pool tables of a
236 /* Base class containing bits shared by both .gdb_index and
237 .debug_name indexes. */
239 struct mapped_index_base
241 /* The name_component table (a sorted vector). See name_component's
242 description above. */
243 std::vector
<name_component
> name_components
;
245 /* How NAME_COMPONENTS is sorted. */
246 enum case_sensitivity name_components_casing
;
248 /* Return the number of names in the symbol table. */
249 virtual size_t symbol_name_count () const = 0;
251 /* Get the name of the symbol at IDX in the symbol table. */
252 virtual const char *symbol_name_at (offset_type idx
) const = 0;
254 /* Return whether the name at IDX in the symbol table should be
256 virtual bool symbol_name_slot_invalid (offset_type idx
) const
261 /* Build the symbol name component sorted vector, if we haven't
263 void build_name_components ();
265 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
266 possible matches for LN_NO_PARAMS in the name component
268 std::pair
<std::vector
<name_component
>::const_iterator
,
269 std::vector
<name_component
>::const_iterator
>
270 find_name_components_bounds (const lookup_name_info
&ln_no_params
) const;
272 /* Prevent deleting/destroying via a base class pointer. */
274 ~mapped_index_base() = default;
277 /* A description of the mapped index. The file format is described in
278 a comment by the code that writes the index. */
279 struct mapped_index final
: public mapped_index_base
281 /* A slot/bucket in the symbol table hash. */
282 struct symbol_table_slot
284 const offset_type name
;
285 const offset_type vec
;
288 /* Index data format version. */
291 /* The total length of the buffer. */
294 /* The address table data. */
295 gdb::array_view
<const gdb_byte
> address_table
;
297 /* The symbol table, implemented as a hash table. */
298 gdb::array_view
<symbol_table_slot
> symbol_table
;
300 /* A pointer to the constant pool. */
301 const char *constant_pool
;
303 bool symbol_name_slot_invalid (offset_type idx
) const override
305 const auto &bucket
= this->symbol_table
[idx
];
306 return bucket
.name
== 0 && bucket
.vec
;
309 /* Convenience method to get at the name of the symbol at IDX in the
311 const char *symbol_name_at (offset_type idx
) const override
312 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
314 size_t symbol_name_count () const override
315 { return this->symbol_table
.size (); }
318 /* A description of the mapped .debug_names.
319 Uninitialized map has CU_COUNT 0. */
320 struct mapped_debug_names final
: public mapped_index_base
322 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
323 : dwarf2_per_objfile (dwarf2_per_objfile_
)
326 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
327 bfd_endian dwarf5_byte_order
;
328 bool dwarf5_is_dwarf64
;
329 bool augmentation_is_gdb
;
331 uint32_t cu_count
= 0;
332 uint32_t tu_count
, bucket_count
, name_count
;
333 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
334 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
335 const gdb_byte
*name_table_string_offs_reordered
;
336 const gdb_byte
*name_table_entry_offs_reordered
;
337 const gdb_byte
*entry_pool
;
344 /* Attribute name DW_IDX_*. */
347 /* Attribute form DW_FORM_*. */
350 /* Value if FORM is DW_FORM_implicit_const. */
351 LONGEST implicit_const
;
353 std::vector
<attr
> attr_vec
;
356 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
358 const char *namei_to_name (uint32_t namei
) const;
360 /* Implementation of the mapped_index_base virtual interface, for
361 the name_components cache. */
363 const char *symbol_name_at (offset_type idx
) const override
364 { return namei_to_name (idx
); }
366 size_t symbol_name_count () const override
367 { return this->name_count
; }
370 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_ptr
;
371 DEF_VEC_P (dwarf2_per_cu_ptr
);
375 int nr_uniq_abbrev_tables
;
377 int nr_symtab_sharers
;
378 int nr_stmt_less_type_units
;
379 int nr_all_type_units_reallocs
;
382 /* Collection of data recorded per objfile.
383 This hangs off of dwarf2_objfile_data_key. */
385 struct dwarf2_per_objfile
: public allocate_on_obstack
387 /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the
388 dwarf2 section names, or is NULL if the standard ELF names are
390 dwarf2_per_objfile (struct objfile
*objfile
,
391 const dwarf2_debug_sections
*names
);
393 ~dwarf2_per_objfile ();
395 DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile
);
397 /* Free all cached compilation units. */
398 void free_cached_comp_units ();
400 /* This function is mapped across the sections and remembers the
401 offset and size of each of the debugging sections we are
403 void locate_sections (bfd
*abfd
, asection
*sectp
,
404 const dwarf2_debug_sections
&names
);
407 dwarf2_section_info info
{};
408 dwarf2_section_info abbrev
{};
409 dwarf2_section_info line
{};
410 dwarf2_section_info loc
{};
411 dwarf2_section_info loclists
{};
412 dwarf2_section_info macinfo
{};
413 dwarf2_section_info macro
{};
414 dwarf2_section_info str
{};
415 dwarf2_section_info line_str
{};
416 dwarf2_section_info ranges
{};
417 dwarf2_section_info rnglists
{};
418 dwarf2_section_info addr
{};
419 dwarf2_section_info frame
{};
420 dwarf2_section_info eh_frame
{};
421 dwarf2_section_info gdb_index
{};
422 dwarf2_section_info debug_names
{};
423 dwarf2_section_info debug_aranges
{};
425 VEC (dwarf2_section_info_def
) *types
= NULL
;
428 struct objfile
*objfile
= NULL
;
430 /* Table of all the compilation units. This is used to locate
431 the target compilation unit of a particular reference. */
432 struct dwarf2_per_cu_data
**all_comp_units
= NULL
;
434 /* The number of compilation units in ALL_COMP_UNITS. */
435 int n_comp_units
= 0;
437 /* The number of .debug_types-related CUs. */
438 int n_type_units
= 0;
440 /* The number of elements allocated in all_type_units.
441 If there are skeleton-less TUs, we add them to all_type_units lazily. */
442 int n_allocated_type_units
= 0;
444 /* The .debug_types-related CUs (TUs).
445 This is stored in malloc space because we may realloc it. */
446 struct signatured_type
**all_type_units
= NULL
;
448 /* Table of struct type_unit_group objects.
449 The hash key is the DW_AT_stmt_list value. */
450 htab_t type_unit_groups
{};
452 /* A table mapping .debug_types signatures to its signatured_type entry.
453 This is NULL if the .debug_types section hasn't been read in yet. */
454 htab_t signatured_types
{};
456 /* Type unit statistics, to see how well the scaling improvements
458 struct tu_stats tu_stats
{};
460 /* A chain of compilation units that are currently read in, so that
461 they can be freed later. */
462 dwarf2_per_cu_data
*read_in_chain
= NULL
;
464 /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
465 This is NULL if the table hasn't been allocated yet. */
468 /* True if we've checked for whether there is a DWP file. */
469 bool dwp_checked
= false;
471 /* The DWP file if there is one, or NULL. */
472 struct dwp_file
*dwp_file
= NULL
;
474 /* The shared '.dwz' file, if one exists. This is used when the
475 original data was compressed using 'dwz -m'. */
476 struct dwz_file
*dwz_file
= NULL
;
478 /* A flag indicating whether this objfile has a section loaded at a
480 bool has_section_at_zero
= false;
482 /* True if we are using the mapped index,
483 or we are faking it for OBJF_READNOW's sake. */
484 bool using_index
= false;
486 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
487 mapped_index
*index_table
= NULL
;
489 /* The mapped index, or NULL if .debug_names is missing or not being used. */
490 std::unique_ptr
<mapped_debug_names
> debug_names_table
;
492 /* When using index_table, this keeps track of all quick_file_names entries.
493 TUs typically share line table entries with a CU, so we maintain a
494 separate table of all line table entries to support the sharing.
495 Note that while there can be way more TUs than CUs, we've already
496 sorted all the TUs into "type unit groups", grouped by their
497 DW_AT_stmt_list value. Therefore the only sharing done here is with a
498 CU and its associated TU group if there is one. */
499 htab_t quick_file_names_table
{};
501 /* Set during partial symbol reading, to prevent queueing of full
503 bool reading_partial_symbols
= false;
505 /* Table mapping type DIEs to their struct type *.
506 This is NULL if not allocated yet.
507 The mapping is done via (CU/TU + DIE offset) -> type. */
508 htab_t die_type_hash
{};
510 /* The CUs we recently read. */
511 VEC (dwarf2_per_cu_ptr
) *just_read_cus
= NULL
;
513 /* Table containing line_header indexed by offset and offset_in_dwz. */
514 htab_t line_header_hash
{};
516 /* Table containing all filenames. This is an optional because the
517 table is lazily constructed on first access. */
518 gdb::optional
<filename_seen_cache
> filenames_cache
;
521 /* Get the dwarf2_per_objfile associated to OBJFILE. */
523 struct dwarf2_per_objfile
*
524 get_dwarf2_per_objfile (struct objfile
*objfile
)
526 return ((struct dwarf2_per_objfile
*)
527 objfile_data (objfile
, dwarf2_objfile_data_key
));
530 /* Set the dwarf2_per_objfile associated to OBJFILE. */
533 set_dwarf2_per_objfile (struct objfile
*objfile
,
534 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
536 gdb_assert (get_dwarf2_per_objfile (objfile
) == NULL
);
537 set_objfile_data (objfile
, dwarf2_objfile_data_key
, dwarf2_per_objfile
);
540 /* Default names of the debugging sections. */
542 /* Note that if the debugging section has been compressed, it might
543 have a name like .zdebug_info. */
545 static const struct dwarf2_debug_sections dwarf2_elf_names
=
547 { ".debug_info", ".zdebug_info" },
548 { ".debug_abbrev", ".zdebug_abbrev" },
549 { ".debug_line", ".zdebug_line" },
550 { ".debug_loc", ".zdebug_loc" },
551 { ".debug_loclists", ".zdebug_loclists" },
552 { ".debug_macinfo", ".zdebug_macinfo" },
553 { ".debug_macro", ".zdebug_macro" },
554 { ".debug_str", ".zdebug_str" },
555 { ".debug_line_str", ".zdebug_line_str" },
556 { ".debug_ranges", ".zdebug_ranges" },
557 { ".debug_rnglists", ".zdebug_rnglists" },
558 { ".debug_types", ".zdebug_types" },
559 { ".debug_addr", ".zdebug_addr" },
560 { ".debug_frame", ".zdebug_frame" },
561 { ".eh_frame", NULL
},
562 { ".gdb_index", ".zgdb_index" },
563 { ".debug_names", ".zdebug_names" },
564 { ".debug_aranges", ".zdebug_aranges" },
568 /* List of DWO/DWP sections. */
570 static const struct dwop_section_names
572 struct dwarf2_section_names abbrev_dwo
;
573 struct dwarf2_section_names info_dwo
;
574 struct dwarf2_section_names line_dwo
;
575 struct dwarf2_section_names loc_dwo
;
576 struct dwarf2_section_names loclists_dwo
;
577 struct dwarf2_section_names macinfo_dwo
;
578 struct dwarf2_section_names macro_dwo
;
579 struct dwarf2_section_names str_dwo
;
580 struct dwarf2_section_names str_offsets_dwo
;
581 struct dwarf2_section_names types_dwo
;
582 struct dwarf2_section_names cu_index
;
583 struct dwarf2_section_names tu_index
;
587 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
588 { ".debug_info.dwo", ".zdebug_info.dwo" },
589 { ".debug_line.dwo", ".zdebug_line.dwo" },
590 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
591 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
592 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
593 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
594 { ".debug_str.dwo", ".zdebug_str.dwo" },
595 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
596 { ".debug_types.dwo", ".zdebug_types.dwo" },
597 { ".debug_cu_index", ".zdebug_cu_index" },
598 { ".debug_tu_index", ".zdebug_tu_index" },
601 /* local data types */
603 /* The data in a compilation unit header, after target2host
604 translation, looks like this. */
605 struct comp_unit_head
609 unsigned char addr_size
;
610 unsigned char signed_addr_p
;
611 sect_offset abbrev_sect_off
;
613 /* Size of file offsets; either 4 or 8. */
614 unsigned int offset_size
;
616 /* Size of the length field; either 4 or 12. */
617 unsigned int initial_length_size
;
619 enum dwarf_unit_type unit_type
;
621 /* Offset to the first byte of this compilation unit header in the
622 .debug_info section, for resolving relative reference dies. */
623 sect_offset sect_off
;
625 /* Offset to first die in this cu from the start of the cu.
626 This will be the first byte following the compilation unit header. */
627 cu_offset first_die_cu_offset
;
629 /* 64-bit signature of this type unit - it is valid only for
630 UNIT_TYPE DW_UT_type. */
633 /* For types, offset in the type's DIE of the type defined by this TU. */
634 cu_offset type_cu_offset_in_tu
;
637 /* Type used for delaying computation of method physnames.
638 See comments for compute_delayed_physnames. */
639 struct delayed_method_info
641 /* The type to which the method is attached, i.e., its parent class. */
644 /* The index of the method in the type's function fieldlists. */
647 /* The index of the method in the fieldlist. */
650 /* The name of the DIE. */
653 /* The DIE associated with this method. */
654 struct die_info
*die
;
657 /* Internal state when decoding a particular compilation unit. */
660 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
663 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
665 /* The header of the compilation unit. */
666 struct comp_unit_head header
{};
668 /* Base address of this compilation unit. */
669 CORE_ADDR base_address
= 0;
671 /* Non-zero if base_address has been set. */
674 /* The language we are debugging. */
675 enum language language
= language_unknown
;
676 const struct language_defn
*language_defn
= nullptr;
678 const char *producer
= nullptr;
680 /* The generic symbol table building routines have separate lists for
681 file scope symbols and all all other scopes (local scopes). So
682 we need to select the right one to pass to add_symbol_to_list().
683 We do it by keeping a pointer to the correct list in list_in_scope.
685 FIXME: The original dwarf code just treated the file scope as the
686 first local scope, and all other local scopes as nested local
687 scopes, and worked fine. Check to see if we really need to
688 distinguish these in buildsym.c. */
689 struct pending
**list_in_scope
= nullptr;
691 /* Hash table holding all the loaded partial DIEs
692 with partial_die->offset.SECT_OFF as hash. */
693 htab_t partial_dies
= nullptr;
695 /* Storage for things with the same lifetime as this read-in compilation
696 unit, including partial DIEs. */
697 auto_obstack comp_unit_obstack
;
699 /* When multiple dwarf2_cu structures are living in memory, this field
700 chains them all together, so that they can be released efficiently.
701 We will probably also want a generation counter so that most-recently-used
702 compilation units are cached... */
703 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
705 /* Backlink to our per_cu entry. */
706 struct dwarf2_per_cu_data
*per_cu
;
708 /* How many compilation units ago was this CU last referenced? */
711 /* A hash table of DIE cu_offset for following references with
712 die_info->offset.sect_off as hash. */
713 htab_t die_hash
= nullptr;
715 /* Full DIEs if read in. */
716 struct die_info
*dies
= nullptr;
718 /* A set of pointers to dwarf2_per_cu_data objects for compilation
719 units referenced by this one. Only set during full symbol processing;
720 partial symbol tables do not have dependencies. */
721 htab_t dependencies
= nullptr;
723 /* Header data from the line table, during full symbol processing. */
724 struct line_header
*line_header
= nullptr;
725 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
726 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
727 this is the DW_TAG_compile_unit die for this CU. We'll hold on
728 to the line header as long as this DIE is being processed. See
729 process_die_scope. */
730 die_info
*line_header_die_owner
= nullptr;
732 /* A list of methods which need to have physnames computed
733 after all type information has been read. */
734 std::vector
<delayed_method_info
> method_list
;
736 /* To be copied to symtab->call_site_htab. */
737 htab_t call_site_htab
= nullptr;
739 /* Non-NULL if this CU came from a DWO file.
740 There is an invariant here that is important to remember:
741 Except for attributes copied from the top level DIE in the "main"
742 (or "stub") file in preparation for reading the DWO file
743 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
744 Either there isn't a DWO file (in which case this is NULL and the point
745 is moot), or there is and either we're not going to read it (in which
746 case this is NULL) or there is and we are reading it (in which case this
748 struct dwo_unit
*dwo_unit
= nullptr;
750 /* The DW_AT_addr_base attribute if present, zero otherwise
751 (zero is a valid value though).
752 Note this value comes from the Fission stub CU/TU's DIE. */
753 ULONGEST addr_base
= 0;
755 /* The DW_AT_ranges_base attribute if present, zero otherwise
756 (zero is a valid value though).
757 Note this value comes from the Fission stub CU/TU's DIE.
758 Also note that the value is zero in the non-DWO case so this value can
759 be used without needing to know whether DWO files are in use or not.
760 N.B. This does not apply to DW_AT_ranges appearing in
761 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
762 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
763 DW_AT_ranges_base *would* have to be applied, and we'd have to care
764 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
765 ULONGEST ranges_base
= 0;
767 /* When reading debug info generated by older versions of rustc, we
768 have to rewrite some union types to be struct types with a
769 variant part. This rewriting must be done after the CU is fully
770 read in, because otherwise at the point of rewriting some struct
771 type might not have been fully processed. So, we keep a list of
772 all such types here and process them after expansion. */
773 std::vector
<struct type
*> rust_unions
;
775 /* Mark used when releasing cached dies. */
776 unsigned int mark
: 1;
778 /* This CU references .debug_loc. See the symtab->locations_valid field.
779 This test is imperfect as there may exist optimized debug code not using
780 any location list and still facing inlining issues if handled as
781 unoptimized code. For a future better test see GCC PR other/32998. */
782 unsigned int has_loclist
: 1;
784 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set
785 if all the producer_is_* fields are valid. This information is cached
786 because profiling CU expansion showed excessive time spent in
787 producer_is_gxx_lt_4_6. */
788 unsigned int checked_producer
: 1;
789 unsigned int producer_is_gxx_lt_4_6
: 1;
790 unsigned int producer_is_gcc_lt_4_3
: 1;
791 unsigned int producer_is_icc_lt_14
: 1;
793 /* When set, the file that we're processing is known to have
794 debugging info for C++ namespaces. GCC 3.3.x did not produce
795 this information, but later versions do. */
797 unsigned int processing_has_namespace_info
: 1;
799 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
802 /* Persistent data held for a compilation unit, even when not
803 processing it. We put a pointer to this structure in the
804 read_symtab_private field of the psymtab. */
806 struct dwarf2_per_cu_data
808 /* The start offset and length of this compilation unit.
809 NOTE: Unlike comp_unit_head.length, this length includes
811 If the DIE refers to a DWO file, this is always of the original die,
813 sect_offset sect_off
;
816 /* DWARF standard version this data has been read from (such as 4 or 5). */
819 /* Flag indicating this compilation unit will be read in before
820 any of the current compilation units are processed. */
821 unsigned int queued
: 1;
823 /* This flag will be set when reading partial DIEs if we need to load
824 absolutely all DIEs for this compilation unit, instead of just the ones
825 we think are interesting. It gets set if we look for a DIE in the
826 hash table and don't find it. */
827 unsigned int load_all_dies
: 1;
829 /* Non-zero if this CU is from .debug_types.
830 Struct dwarf2_per_cu_data is contained in struct signatured_type iff
832 unsigned int is_debug_types
: 1;
834 /* Non-zero if this CU is from the .dwz file. */
835 unsigned int is_dwz
: 1;
837 /* Non-zero if reading a TU directly from a DWO file, bypassing the stub.
838 This flag is only valid if is_debug_types is true.
839 We can't read a CU directly from a DWO file: There are required
840 attributes in the stub. */
841 unsigned int reading_dwo_directly
: 1;
843 /* Non-zero if the TU has been read.
844 This is used to assist the "Stay in DWO Optimization" for Fission:
845 When reading a DWO, it's faster to read TUs from the DWO instead of
846 fetching them from random other DWOs (due to comdat folding).
847 If the TU has already been read, the optimization is unnecessary
848 (and unwise - we don't want to change where gdb thinks the TU lives
850 This flag is only valid if is_debug_types is true. */
851 unsigned int tu_read
: 1;
853 /* The section this CU/TU lives in.
854 If the DIE refers to a DWO file, this is always the original die,
856 struct dwarf2_section_info
*section
;
858 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
859 of the CU cache it gets reset to NULL again. This is left as NULL for
860 dummy CUs (a CU header, but nothing else). */
861 struct dwarf2_cu
*cu
;
863 /* The corresponding dwarf2_per_objfile. */
864 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
866 /* When dwarf2_per_objfile->using_index is true, the 'quick' field
867 is active. Otherwise, the 'psymtab' field is active. */
870 /* The partial symbol table associated with this compilation unit,
871 or NULL for unread partial units. */
872 struct partial_symtab
*psymtab
;
874 /* Data needed by the "quick" functions. */
875 struct dwarf2_per_cu_quick_data
*quick
;
878 /* The CUs we import using DW_TAG_imported_unit. This is filled in
879 while reading psymtabs, used to compute the psymtab dependencies,
880 and then cleared. Then it is filled in again while reading full
881 symbols, and only deleted when the objfile is destroyed.
883 This is also used to work around a difference between the way gold
884 generates .gdb_index version <=7 and the way gdb does. Arguably this
885 is a gold bug. For symbols coming from TUs, gold records in the index
886 the CU that includes the TU instead of the TU itself. This breaks
887 dw2_lookup_symbol: It assumes that if the index says symbol X lives
888 in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
889 will find X. Alas TUs live in their own symtab, so after expanding CU Y
890 we need to look in TU Z to find X. Fortunately, this is akin to
891 DW_TAG_imported_unit, so we just use the same mechanism: For
892 .gdb_index version <=7 this also records the TUs that the CU referred
893 to. Concurrently with this change gdb was modified to emit version 8
894 indices so we only pay a price for gold generated indices.
895 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
896 VEC (dwarf2_per_cu_ptr
) *imported_symtabs
;
899 /* Entry in the signatured_types hash table. */
901 struct signatured_type
903 /* The "per_cu" object of this type.
904 This struct is used iff per_cu.is_debug_types.
905 N.B.: This is the first member so that it's easy to convert pointers
907 struct dwarf2_per_cu_data per_cu
;
909 /* The type's signature. */
912 /* Offset in the TU of the type's DIE, as read from the TU header.
913 If this TU is a DWO stub and the definition lives in a DWO file
914 (specified by DW_AT_GNU_dwo_name), this value is unusable. */
915 cu_offset type_offset_in_tu
;
917 /* Offset in the section of the type's DIE.
918 If the definition lives in a DWO file, this is the offset in the
919 .debug_types.dwo section.
920 The value is zero until the actual value is known.
921 Zero is otherwise not a valid section offset. */
922 sect_offset type_offset_in_section
;
924 /* Type units are grouped by their DW_AT_stmt_list entry so that they
925 can share them. This points to the containing symtab. */
926 struct type_unit_group
*type_unit_group
;
929 The first time we encounter this type we fully read it in and install it
930 in the symbol tables. Subsequent times we only need the type. */
933 /* Containing DWO unit.
934 This field is valid iff per_cu.reading_dwo_directly. */
935 struct dwo_unit
*dwo_unit
;
938 typedef struct signatured_type
*sig_type_ptr
;
939 DEF_VEC_P (sig_type_ptr
);
941 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
942 This includes type_unit_group and quick_file_names. */
944 struct stmt_list_hash
946 /* The DWO unit this table is from or NULL if there is none. */
947 struct dwo_unit
*dwo_unit
;
949 /* Offset in .debug_line or .debug_line.dwo. */
950 sect_offset line_sect_off
;
953 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
954 an object of this type. */
956 struct type_unit_group
958 /* dwarf2read.c's main "handle" on a TU symtab.
959 To simplify things we create an artificial CU that "includes" all the
960 type units using this stmt_list so that the rest of the code still has
961 a "per_cu" handle on the symtab.
962 This PER_CU is recognized by having no section. */
963 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
964 struct dwarf2_per_cu_data per_cu
;
966 /* The TUs that share this DW_AT_stmt_list entry.
967 This is added to while parsing type units to build partial symtabs,
968 and is deleted afterwards and not used again. */
969 VEC (sig_type_ptr
) *tus
;
971 /* The compunit symtab.
972 Type units in a group needn't all be defined in the same source file,
973 so we create an essentially anonymous symtab as the compunit symtab. */
974 struct compunit_symtab
*compunit_symtab
;
976 /* The data used to construct the hash key. */
977 struct stmt_list_hash hash
;
979 /* The number of symtabs from the line header.
980 The value here must match line_header.num_file_names. */
981 unsigned int num_symtabs
;
983 /* The symbol tables for this TU (obtained from the files listed in
985 WARNING: The order of entries here must match the order of entries
986 in the line header. After the first TU using this type_unit_group, the
987 line header for the subsequent TUs is recreated from this. This is done
988 because we need to use the same symtabs for each TU using the same
989 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
990 there's no guarantee the line header doesn't have duplicate entries. */
991 struct symtab
**symtabs
;
994 /* These sections are what may appear in a (real or virtual) DWO file. */
998 struct dwarf2_section_info abbrev
;
999 struct dwarf2_section_info line
;
1000 struct dwarf2_section_info loc
;
1001 struct dwarf2_section_info loclists
;
1002 struct dwarf2_section_info macinfo
;
1003 struct dwarf2_section_info macro
;
1004 struct dwarf2_section_info str
;
1005 struct dwarf2_section_info str_offsets
;
1006 /* In the case of a virtual DWO file, these two are unused. */
1007 struct dwarf2_section_info info
;
1008 VEC (dwarf2_section_info_def
) *types
;
1011 /* CUs/TUs in DWP/DWO files. */
1015 /* Backlink to the containing struct dwo_file. */
1016 struct dwo_file
*dwo_file
;
1018 /* The "id" that distinguishes this CU/TU.
1019 .debug_info calls this "dwo_id", .debug_types calls this "signature".
1020 Since signatures came first, we stick with it for consistency. */
1023 /* The section this CU/TU lives in, in the DWO file. */
1024 struct dwarf2_section_info
*section
;
1026 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
1027 sect_offset sect_off
;
1028 unsigned int length
;
1030 /* For types, offset in the type's DIE of the type defined by this TU. */
1031 cu_offset type_offset_in_tu
;
1034 /* include/dwarf2.h defines the DWP section codes.
1035 It defines a max value but it doesn't define a min value, which we
1036 use for error checking, so provide one. */
1038 enum dwp_v2_section_ids
1043 /* Data for one DWO file.
1045 This includes virtual DWO files (a virtual DWO file is a DWO file as it
1046 appears in a DWP file). DWP files don't really have DWO files per se -
1047 comdat folding of types "loses" the DWO file they came from, and from
1048 a high level view DWP files appear to contain a mass of random types.
1049 However, to maintain consistency with the non-DWP case we pretend DWP
1050 files contain virtual DWO files, and we assign each TU with one virtual
1051 DWO file (generally based on the line and abbrev section offsets -
1052 a heuristic that seems to work in practice). */
1056 /* The DW_AT_GNU_dwo_name attribute.
1057 For virtual DWO files the name is constructed from the section offsets
1058 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
1059 from related CU+TUs. */
1060 const char *dwo_name
;
1062 /* The DW_AT_comp_dir attribute. */
1063 const char *comp_dir
;
1065 /* The bfd, when the file is open. Otherwise this is NULL.
1066 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
1069 /* The sections that make up this DWO file.
1070 Remember that for virtual DWO files in DWP V2, these are virtual
1071 sections (for lack of a better name). */
1072 struct dwo_sections sections
;
1074 /* The CUs in the file.
1075 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
1076 an extension to handle LLVM's Link Time Optimization output (where
1077 multiple source files may be compiled into a single object/dwo pair). */
1080 /* Table of TUs in the file.
1081 Each element is a struct dwo_unit. */
1085 /* These sections are what may appear in a DWP file. */
1089 /* These are used by both DWP version 1 and 2. */
1090 struct dwarf2_section_info str
;
1091 struct dwarf2_section_info cu_index
;
1092 struct dwarf2_section_info tu_index
;
1094 /* These are only used by DWP version 2 files.
1095 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
1096 sections are referenced by section number, and are not recorded here.
1097 In DWP version 2 there is at most one copy of all these sections, each
1098 section being (effectively) comprised of the concatenation of all of the
1099 individual sections that exist in the version 1 format.
1100 To keep the code simple we treat each of these concatenated pieces as a
1101 section itself (a virtual section?). */
1102 struct dwarf2_section_info abbrev
;
1103 struct dwarf2_section_info info
;
1104 struct dwarf2_section_info line
;
1105 struct dwarf2_section_info loc
;
1106 struct dwarf2_section_info macinfo
;
1107 struct dwarf2_section_info macro
;
1108 struct dwarf2_section_info str_offsets
;
1109 struct dwarf2_section_info types
;
1112 /* These sections are what may appear in a virtual DWO file in DWP version 1.
1113 A virtual DWO file is a DWO file as it appears in a DWP file. */
1115 struct virtual_v1_dwo_sections
1117 struct dwarf2_section_info abbrev
;
1118 struct dwarf2_section_info line
;
1119 struct dwarf2_section_info loc
;
1120 struct dwarf2_section_info macinfo
;
1121 struct dwarf2_section_info macro
;
1122 struct dwarf2_section_info str_offsets
;
1123 /* Each DWP hash table entry records one CU or one TU.
1124 That is recorded here, and copied to dwo_unit.section. */
1125 struct dwarf2_section_info info_or_types
;
1128 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
1129 In version 2, the sections of the DWO files are concatenated together
1130 and stored in one section of that name. Thus each ELF section contains
1131 several "virtual" sections. */
1133 struct virtual_v2_dwo_sections
1135 bfd_size_type abbrev_offset
;
1136 bfd_size_type abbrev_size
;
1138 bfd_size_type line_offset
;
1139 bfd_size_type line_size
;
1141 bfd_size_type loc_offset
;
1142 bfd_size_type loc_size
;
1144 bfd_size_type macinfo_offset
;
1145 bfd_size_type macinfo_size
;
1147 bfd_size_type macro_offset
;
1148 bfd_size_type macro_size
;
1150 bfd_size_type str_offsets_offset
;
1151 bfd_size_type str_offsets_size
;
1153 /* Each DWP hash table entry records one CU or one TU.
1154 That is recorded here, and copied to dwo_unit.section. */
1155 bfd_size_type info_or_types_offset
;
1156 bfd_size_type info_or_types_size
;
1159 /* Contents of DWP hash tables. */
1161 struct dwp_hash_table
1163 uint32_t version
, nr_columns
;
1164 uint32_t nr_units
, nr_slots
;
1165 const gdb_byte
*hash_table
, *unit_table
;
1170 const gdb_byte
*indices
;
1174 /* This is indexed by column number and gives the id of the section
1176 #define MAX_NR_V2_DWO_SECTIONS \
1177 (1 /* .debug_info or .debug_types */ \
1178 + 1 /* .debug_abbrev */ \
1179 + 1 /* .debug_line */ \
1180 + 1 /* .debug_loc */ \
1181 + 1 /* .debug_str_offsets */ \
1182 + 1 /* .debug_macro or .debug_macinfo */)
1183 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
1184 const gdb_byte
*offsets
;
1185 const gdb_byte
*sizes
;
1190 /* Data for one DWP file. */
1194 /* Name of the file. */
1197 /* File format version. */
1203 /* Section info for this file. */
1204 struct dwp_sections sections
;
1206 /* Table of CUs in the file. */
1207 const struct dwp_hash_table
*cus
;
1209 /* Table of TUs in the file. */
1210 const struct dwp_hash_table
*tus
;
1212 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
1216 /* Table to map ELF section numbers to their sections.
1217 This is only needed for the DWP V1 file format. */
1218 unsigned int num_sections
;
1219 asection
**elf_sections
;
1222 /* This represents a '.dwz' file. */
1226 /* A dwz file can only contain a few sections. */
1227 struct dwarf2_section_info abbrev
;
1228 struct dwarf2_section_info info
;
1229 struct dwarf2_section_info str
;
1230 struct dwarf2_section_info line
;
1231 struct dwarf2_section_info macro
;
1232 struct dwarf2_section_info gdb_index
;
1233 struct dwarf2_section_info debug_names
;
1235 /* The dwz's BFD. */
1239 /* Struct used to pass misc. parameters to read_die_and_children, et
1240 al. which are used for both .debug_info and .debug_types dies.
1241 All parameters here are unchanging for the life of the call. This
1242 struct exists to abstract away the constant parameters of die reading. */
1244 struct die_reader_specs
1246 /* The bfd of die_section. */
1249 /* The CU of the DIE we are parsing. */
1250 struct dwarf2_cu
*cu
;
1252 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
1253 struct dwo_file
*dwo_file
;
1255 /* The section the die comes from.
1256 This is either .debug_info or .debug_types, or the .dwo variants. */
1257 struct dwarf2_section_info
*die_section
;
1259 /* die_section->buffer. */
1260 const gdb_byte
*buffer
;
1262 /* The end of the buffer. */
1263 const gdb_byte
*buffer_end
;
1265 /* The value of the DW_AT_comp_dir attribute. */
1266 const char *comp_dir
;
1268 /* The abbreviation table to use when reading the DIEs. */
1269 struct abbrev_table
*abbrev_table
;
1272 /* Type of function passed to init_cutu_and_read_dies, et.al. */
1273 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
1274 const gdb_byte
*info_ptr
,
1275 struct die_info
*comp_unit_die
,
1279 /* A 1-based directory index. This is a strong typedef to prevent
1280 accidentally using a directory index as a 0-based index into an
1282 enum class dir_index
: unsigned int {};
1284 /* Likewise, a 1-based file name index. */
1285 enum class file_name_index
: unsigned int {};
1289 file_entry () = default;
1291 file_entry (const char *name_
, dir_index d_index_
,
1292 unsigned int mod_time_
, unsigned int length_
)
1295 mod_time (mod_time_
),
1299 /* Return the include directory at D_INDEX stored in LH. Returns
1300 NULL if D_INDEX is out of bounds. */
1301 const char *include_dir (const line_header
*lh
) const;
1303 /* The file name. Note this is an observing pointer. The memory is
1304 owned by debug_line_buffer. */
1305 const char *name
{};
1307 /* The directory index (1-based). */
1308 dir_index d_index
{};
1310 unsigned int mod_time
{};
1312 unsigned int length
{};
1314 /* True if referenced by the Line Number Program. */
1317 /* The associated symbol table, if any. */
1318 struct symtab
*symtab
{};
1321 /* The line number information for a compilation unit (found in the
1322 .debug_line section) begins with a "statement program header",
1323 which contains the following information. */
1330 /* Add an entry to the include directory table. */
1331 void add_include_dir (const char *include_dir
);
1333 /* Add an entry to the file name table. */
1334 void add_file_name (const char *name
, dir_index d_index
,
1335 unsigned int mod_time
, unsigned int length
);
1337 /* Return the include dir at INDEX (1-based). Returns NULL if INDEX
1338 is out of bounds. */
1339 const char *include_dir_at (dir_index index
) const
1341 /* Convert directory index number (1-based) to vector index
1343 size_t vec_index
= to_underlying (index
) - 1;
1345 if (vec_index
>= include_dirs
.size ())
1347 return include_dirs
[vec_index
];
1350 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
1351 is out of bounds. */
1352 file_entry
*file_name_at (file_name_index index
)
1354 /* Convert file name index number (1-based) to vector index
1356 size_t vec_index
= to_underlying (index
) - 1;
1358 if (vec_index
>= file_names
.size ())
1360 return &file_names
[vec_index
];
1363 /* Const version of the above. */
1364 const file_entry
*file_name_at (unsigned int index
) const
1366 if (index
>= file_names
.size ())
1368 return &file_names
[index
];
1371 /* Offset of line number information in .debug_line section. */
1372 sect_offset sect_off
{};
1374 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1375 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1377 unsigned int total_length
{};
1378 unsigned short version
{};
1379 unsigned int header_length
{};
1380 unsigned char minimum_instruction_length
{};
1381 unsigned char maximum_ops_per_instruction
{};
1382 unsigned char default_is_stmt
{};
1384 unsigned char line_range
{};
1385 unsigned char opcode_base
{};
1387 /* standard_opcode_lengths[i] is the number of operands for the
1388 standard opcode whose value is i. This means that
1389 standard_opcode_lengths[0] is unused, and the last meaningful
1390 element is standard_opcode_lengths[opcode_base - 1]. */
1391 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1393 /* The include_directories table. Note these are observing
1394 pointers. The memory is owned by debug_line_buffer. */
1395 std::vector
<const char *> include_dirs
;
1397 /* The file_names table. */
1398 std::vector
<file_entry
> file_names
;
1400 /* The start and end of the statement program following this
1401 header. These point into dwarf2_per_objfile->line_buffer. */
1402 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1405 typedef std::unique_ptr
<line_header
> line_header_up
;
1408 file_entry::include_dir (const line_header
*lh
) const
1410 return lh
->include_dir_at (d_index
);
1413 /* When we construct a partial symbol table entry we only
1414 need this much information. */
1415 struct partial_die_info
: public allocate_on_obstack
1417 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1419 /* Disable assign but still keep copy ctor, which is needed
1420 load_partial_dies. */
1421 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1423 /* Adjust the partial die before generating a symbol for it. This
1424 function may set the is_external flag or change the DIE's
1426 void fixup (struct dwarf2_cu
*cu
);
1428 /* Read a minimal amount of information into the minimal die
1430 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1431 const struct abbrev_info
&abbrev
,
1432 const gdb_byte
*info_ptr
);
1434 /* Offset of this DIE. */
1435 const sect_offset sect_off
;
1437 /* DWARF-2 tag for this DIE. */
1438 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1440 /* Assorted flags describing the data found in this DIE. */
1441 const unsigned int has_children
: 1;
1443 unsigned int is_external
: 1;
1444 unsigned int is_declaration
: 1;
1445 unsigned int has_type
: 1;
1446 unsigned int has_specification
: 1;
1447 unsigned int has_pc_info
: 1;
1448 unsigned int may_be_inlined
: 1;
1450 /* This DIE has been marked DW_AT_main_subprogram. */
1451 unsigned int main_subprogram
: 1;
1453 /* Flag set if the SCOPE field of this structure has been
1455 unsigned int scope_set
: 1;
1457 /* Flag set if the DIE has a byte_size attribute. */
1458 unsigned int has_byte_size
: 1;
1460 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1461 unsigned int has_const_value
: 1;
1463 /* Flag set if any of the DIE's children are template arguments. */
1464 unsigned int has_template_arguments
: 1;
1466 /* Flag set if fixup has been called on this die. */
1467 unsigned int fixup_called
: 1;
1469 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1470 unsigned int is_dwz
: 1;
1472 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1473 unsigned int spec_is_dwz
: 1;
1475 /* The name of this DIE. Normally the value of DW_AT_name, but
1476 sometimes a default name for unnamed DIEs. */
1477 const char *name
= nullptr;
1479 /* The linkage name, if present. */
1480 const char *linkage_name
= nullptr;
1482 /* The scope to prepend to our children. This is generally
1483 allocated on the comp_unit_obstack, so will disappear
1484 when this compilation unit leaves the cache. */
1485 const char *scope
= nullptr;
1487 /* Some data associated with the partial DIE. The tag determines
1488 which field is live. */
1491 /* The location description associated with this DIE, if any. */
1492 struct dwarf_block
*locdesc
;
1493 /* The offset of an import, for DW_TAG_imported_unit. */
1494 sect_offset sect_off
;
1497 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1498 CORE_ADDR lowpc
= 0;
1499 CORE_ADDR highpc
= 0;
1501 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1502 DW_AT_sibling, if any. */
1503 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1504 could return DW_AT_sibling values to its caller load_partial_dies. */
1505 const gdb_byte
*sibling
= nullptr;
1507 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1508 DW_AT_specification (or DW_AT_abstract_origin or
1509 DW_AT_extension). */
1510 sect_offset spec_offset
{};
1512 /* Pointers to this DIE's parent, first child, and next sibling,
1514 struct partial_die_info
*die_parent
= nullptr;
1515 struct partial_die_info
*die_child
= nullptr;
1516 struct partial_die_info
*die_sibling
= nullptr;
1518 friend struct partial_die_info
*
1519 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1522 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1523 partial_die_info (sect_offset sect_off
)
1524 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1528 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1530 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1535 has_specification
= 0;
1538 main_subprogram
= 0;
1541 has_const_value
= 0;
1542 has_template_arguments
= 0;
1549 /* This data structure holds the information of an abbrev. */
1552 unsigned int number
; /* number identifying abbrev */
1553 enum dwarf_tag tag
; /* dwarf tag */
1554 unsigned short has_children
; /* boolean */
1555 unsigned short num_attrs
; /* number of attributes */
1556 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1557 struct abbrev_info
*next
; /* next in chain */
1562 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1563 ENUM_BITFIELD(dwarf_form
) form
: 16;
1565 /* It is valid only if FORM is DW_FORM_implicit_const. */
1566 LONGEST implicit_const
;
1569 /* Size of abbrev_table.abbrev_hash_table. */
1570 #define ABBREV_HASH_SIZE 121
1572 /* Top level data structure to contain an abbreviation table. */
1576 explicit abbrev_table (sect_offset off
)
1580 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1581 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1584 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1586 /* Allocate space for a struct abbrev_info object in
1588 struct abbrev_info
*alloc_abbrev ();
1590 /* Add an abbreviation to the table. */
1591 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1593 /* Look up an abbrev in the table.
1594 Returns NULL if the abbrev is not found. */
1596 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1599 /* Where the abbrev table came from.
1600 This is used as a sanity check when the table is used. */
1601 const sect_offset sect_off
;
1603 /* Storage for the abbrev table. */
1604 auto_obstack abbrev_obstack
;
1608 /* Hash table of abbrevs.
1609 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1610 It could be statically allocated, but the previous code didn't so we
1612 struct abbrev_info
**m_abbrevs
;
1615 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1617 /* Attributes have a name and a value. */
1620 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1621 ENUM_BITFIELD(dwarf_form
) form
: 15;
1623 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1624 field should be in u.str (existing only for DW_STRING) but it is kept
1625 here for better struct attribute alignment. */
1626 unsigned int string_is_canonical
: 1;
1631 struct dwarf_block
*blk
;
1640 /* This data structure holds a complete die structure. */
1643 /* DWARF-2 tag for this DIE. */
1644 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1646 /* Number of attributes */
1647 unsigned char num_attrs
;
1649 /* True if we're presently building the full type name for the
1650 type derived from this DIE. */
1651 unsigned char building_fullname
: 1;
1653 /* True if this die is in process. PR 16581. */
1654 unsigned char in_process
: 1;
1657 unsigned int abbrev
;
1659 /* Offset in .debug_info or .debug_types section. */
1660 sect_offset sect_off
;
1662 /* The dies in a compilation unit form an n-ary tree. PARENT
1663 points to this die's parent; CHILD points to the first child of
1664 this node; and all the children of a given node are chained
1665 together via their SIBLING fields. */
1666 struct die_info
*child
; /* Its first child, if any. */
1667 struct die_info
*sibling
; /* Its next sibling, if any. */
1668 struct die_info
*parent
; /* Its parent, if any. */
1670 /* An array of attributes, with NUM_ATTRS elements. There may be
1671 zero, but it's not common and zero-sized arrays are not
1672 sufficiently portable C. */
1673 struct attribute attrs
[1];
1676 /* Get at parts of an attribute structure. */
1678 #define DW_STRING(attr) ((attr)->u.str)
1679 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1680 #define DW_UNSND(attr) ((attr)->u.unsnd)
1681 #define DW_BLOCK(attr) ((attr)->u.blk)
1682 #define DW_SND(attr) ((attr)->u.snd)
1683 #define DW_ADDR(attr) ((attr)->u.addr)
1684 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1686 /* Blocks are a bunch of untyped bytes. */
1691 /* Valid only if SIZE is not zero. */
1692 const gdb_byte
*data
;
1695 #ifndef ATTR_ALLOC_CHUNK
1696 #define ATTR_ALLOC_CHUNK 4
1699 /* Allocate fields for structs, unions and enums in this size. */
1700 #ifndef DW_FIELD_ALLOC_CHUNK
1701 #define DW_FIELD_ALLOC_CHUNK 4
1704 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1705 but this would require a corresponding change in unpack_field_as_long
1707 static int bits_per_byte
= 8;
1709 /* When reading a variant or variant part, we track a bit more
1710 information about the field, and store it in an object of this
1713 struct variant_field
1715 /* If we see a DW_TAG_variant, then this will be the discriminant
1717 ULONGEST discriminant_value
;
1718 /* If we see a DW_TAG_variant, then this will be set if this is the
1720 bool default_branch
;
1721 /* While reading a DW_TAG_variant_part, this will be set if this
1722 field is the discriminant. */
1723 bool is_discriminant
;
1728 int accessibility
= 0;
1730 /* Extra information to describe a variant or variant part. */
1731 struct variant_field variant
{};
1732 struct field field
{};
1737 const char *name
= nullptr;
1738 std::vector
<struct fn_field
> fnfields
;
1741 /* The routines that read and process dies for a C struct or C++ class
1742 pass lists of data member fields and lists of member function fields
1743 in an instance of a field_info structure, as defined below. */
1746 /* List of data member and baseclasses fields. */
1747 std::vector
<struct nextfield
> fields
;
1748 std::vector
<struct nextfield
> baseclasses
;
1750 /* Number of fields (including baseclasses). */
1753 /* Set if the accesibility of one of the fields is not public. */
1754 int non_public_fields
= 0;
1756 /* Member function fieldlist array, contains name of possibly overloaded
1757 member function, number of overloaded member functions and a pointer
1758 to the head of the member function field chain. */
1759 std::vector
<struct fnfieldlist
> fnfieldlists
;
1761 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1762 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1763 std::vector
<struct decl_field
> typedef_field_list
;
1765 /* Nested types defined by this class and the number of elements in this
1767 std::vector
<struct decl_field
> nested_types_list
;
1770 /* One item on the queue of compilation units to read in full symbols
1772 struct dwarf2_queue_item
1774 struct dwarf2_per_cu_data
*per_cu
;
1775 enum language pretend_language
;
1776 struct dwarf2_queue_item
*next
;
1779 /* The current queue. */
1780 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1782 /* Loaded secondary compilation units are kept in memory until they
1783 have not been referenced for the processing of this many
1784 compilation units. Set this to zero to disable caching. Cache
1785 sizes of up to at least twenty will improve startup time for
1786 typical inter-CU-reference binaries, at an obvious memory cost. */
1787 static int dwarf_max_cache_age
= 5;
1789 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1790 struct cmd_list_element
*c
, const char *value
)
1792 fprintf_filtered (file
, _("The upper bound on the age of cached "
1793 "DWARF compilation units is %s.\n"),
1797 /* local function prototypes */
1799 static const char *get_section_name (const struct dwarf2_section_info
*);
1801 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1803 static void dwarf2_find_base_address (struct die_info
*die
,
1804 struct dwarf2_cu
*cu
);
1806 static struct partial_symtab
*create_partial_symtab
1807 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1809 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1810 const gdb_byte
*info_ptr
,
1811 struct die_info
*type_unit_die
,
1812 int has_children
, void *data
);
1814 static void dwarf2_build_psymtabs_hard
1815 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1817 static void scan_partial_symbols (struct partial_die_info
*,
1818 CORE_ADDR
*, CORE_ADDR
*,
1819 int, struct dwarf2_cu
*);
1821 static void add_partial_symbol (struct partial_die_info
*,
1822 struct dwarf2_cu
*);
1824 static void add_partial_namespace (struct partial_die_info
*pdi
,
1825 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1826 int set_addrmap
, struct dwarf2_cu
*cu
);
1828 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1829 CORE_ADDR
*highpc
, int set_addrmap
,
1830 struct dwarf2_cu
*cu
);
1832 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1833 struct dwarf2_cu
*cu
);
1835 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1836 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1837 int need_pc
, struct dwarf2_cu
*cu
);
1839 static void dwarf2_read_symtab (struct partial_symtab
*,
1842 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1844 static abbrev_table_up abbrev_table_read_table
1845 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1848 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1850 static struct partial_die_info
*load_partial_dies
1851 (const struct die_reader_specs
*, const gdb_byte
*, int);
1853 static struct partial_die_info
*find_partial_die (sect_offset
, int,
1854 struct dwarf2_cu
*);
1856 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1857 struct attribute
*, struct attr_abbrev
*,
1860 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1862 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1864 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1866 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1868 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1870 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1873 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1875 static LONGEST read_checked_initial_length_and_offset
1876 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1877 unsigned int *, unsigned int *);
1879 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1880 const struct comp_unit_head
*,
1883 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1885 static sect_offset read_abbrev_offset
1886 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1887 struct dwarf2_section_info
*, sect_offset
);
1889 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1891 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1893 static const char *read_indirect_string
1894 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1895 const struct comp_unit_head
*, unsigned int *);
1897 static const char *read_indirect_line_string
1898 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1899 const struct comp_unit_head
*, unsigned int *);
1901 static const char *read_indirect_string_at_offset
1902 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1903 LONGEST str_offset
);
1905 static const char *read_indirect_string_from_dwz
1906 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1908 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1910 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1914 static const char *read_str_index (const struct die_reader_specs
*reader
,
1915 ULONGEST str_index
);
1917 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1919 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1920 struct dwarf2_cu
*);
1922 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1925 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1926 struct dwarf2_cu
*cu
);
1928 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1929 struct dwarf2_cu
*cu
);
1931 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1933 static struct die_info
*die_specification (struct die_info
*die
,
1934 struct dwarf2_cu
**);
1936 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1937 struct dwarf2_cu
*cu
);
1939 static void dwarf_decode_lines (struct line_header
*, const char *,
1940 struct dwarf2_cu
*, struct partial_symtab
*,
1941 CORE_ADDR
, int decode_mapping
);
1943 static void dwarf2_start_subfile (const char *, const char *);
1945 static struct compunit_symtab
*dwarf2_start_symtab (struct dwarf2_cu
*,
1946 const char *, const char *,
1949 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1950 struct dwarf2_cu
*, struct symbol
* = NULL
);
1952 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1953 struct dwarf2_cu
*);
1955 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1958 struct obstack
*obstack
,
1959 struct dwarf2_cu
*cu
, LONGEST
*value
,
1960 const gdb_byte
**bytes
,
1961 struct dwarf2_locexpr_baton
**baton
);
1963 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1965 static int need_gnat_info (struct dwarf2_cu
*);
1967 static struct type
*die_descriptive_type (struct die_info
*,
1968 struct dwarf2_cu
*);
1970 static void set_descriptive_type (struct type
*, struct die_info
*,
1971 struct dwarf2_cu
*);
1973 static struct type
*die_containing_type (struct die_info
*,
1974 struct dwarf2_cu
*);
1976 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1977 struct dwarf2_cu
*);
1979 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1981 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1983 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1985 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1986 const char *suffix
, int physname
,
1987 struct dwarf2_cu
*cu
);
1989 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1991 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1993 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1995 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1997 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1999 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
2001 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
2002 struct dwarf2_cu
*, struct partial_symtab
*);
2004 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
2005 values. Keep the items ordered with increasing constraints compliance. */
2008 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
2009 PC_BOUNDS_NOT_PRESENT
,
2011 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
2012 were present but they do not form a valid range of PC addresses. */
2015 /* Discontiguous range was found - that is DW_AT_ranges was found. */
2018 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
2022 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
2023 CORE_ADDR
*, CORE_ADDR
*,
2025 struct partial_symtab
*);
2027 static void get_scope_pc_bounds (struct die_info
*,
2028 CORE_ADDR
*, CORE_ADDR
*,
2029 struct dwarf2_cu
*);
2031 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
2032 CORE_ADDR
, struct dwarf2_cu
*);
2034 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
2035 struct dwarf2_cu
*);
2037 static void dwarf2_attach_fields_to_type (struct field_info
*,
2038 struct type
*, struct dwarf2_cu
*);
2040 static void dwarf2_add_member_fn (struct field_info
*,
2041 struct die_info
*, struct type
*,
2042 struct dwarf2_cu
*);
2044 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
2046 struct dwarf2_cu
*);
2048 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
2050 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
2052 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
2054 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
2056 static struct using_direct
**using_directives (enum language
);
2058 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
2060 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
2062 static struct type
*read_module_type (struct die_info
*die
,
2063 struct dwarf2_cu
*cu
);
2065 static const char *namespace_name (struct die_info
*die
,
2066 int *is_anonymous
, struct dwarf2_cu
*);
2068 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
2070 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
2072 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
2073 struct dwarf2_cu
*);
2075 static struct die_info
*read_die_and_siblings_1
2076 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
2079 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
2080 const gdb_byte
*info_ptr
,
2081 const gdb_byte
**new_info_ptr
,
2082 struct die_info
*parent
);
2084 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
2085 struct die_info
**, const gdb_byte
*,
2088 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
2089 struct die_info
**, const gdb_byte
*,
2092 static void process_die (struct die_info
*, struct dwarf2_cu
*);
2094 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
2097 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
2099 static const char *dwarf2_full_name (const char *name
,
2100 struct die_info
*die
,
2101 struct dwarf2_cu
*cu
);
2103 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
2104 struct dwarf2_cu
*cu
);
2106 static struct die_info
*dwarf2_extension (struct die_info
*die
,
2107 struct dwarf2_cu
**);
2109 static const char *dwarf_tag_name (unsigned int);
2111 static const char *dwarf_attr_name (unsigned int);
2113 static const char *dwarf_form_name (unsigned int);
2115 static const char *dwarf_bool_name (unsigned int);
2117 static const char *dwarf_type_encoding_name (unsigned int);
2119 static struct die_info
*sibling_die (struct die_info
*);
2121 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
2123 static void dump_die_for_error (struct die_info
*);
2125 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
2128 /*static*/ void dump_die (struct die_info
*, int max_level
);
2130 static void store_in_ref_table (struct die_info
*,
2131 struct dwarf2_cu
*);
2133 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
2135 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
2137 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
2138 const struct attribute
*,
2139 struct dwarf2_cu
**);
2141 static struct die_info
*follow_die_ref (struct die_info
*,
2142 const struct attribute
*,
2143 struct dwarf2_cu
**);
2145 static struct die_info
*follow_die_sig (struct die_info
*,
2146 const struct attribute
*,
2147 struct dwarf2_cu
**);
2149 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
2150 struct dwarf2_cu
*);
2152 static struct type
*get_DW_AT_signature_type (struct die_info
*,
2153 const struct attribute
*,
2154 struct dwarf2_cu
*);
2156 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
2158 static void read_signatured_type (struct signatured_type
*);
2160 static int attr_to_dynamic_prop (const struct attribute
*attr
,
2161 struct die_info
*die
, struct dwarf2_cu
*cu
,
2162 struct dynamic_prop
*prop
);
2164 /* memory allocation interface */
2166 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
2168 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
2170 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
2172 static int attr_form_is_block (const struct attribute
*);
2174 static int attr_form_is_section_offset (const struct attribute
*);
2176 static int attr_form_is_constant (const struct attribute
*);
2178 static int attr_form_is_ref (const struct attribute
*);
2180 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
2181 struct dwarf2_loclist_baton
*baton
,
2182 const struct attribute
*attr
);
2184 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
2186 struct dwarf2_cu
*cu
,
2189 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
2190 const gdb_byte
*info_ptr
,
2191 struct abbrev_info
*abbrev
);
2193 static hashval_t
partial_die_hash (const void *item
);
2195 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
2197 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
2198 (sect_offset sect_off
, unsigned int offset_in_dwz
,
2199 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2201 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
2202 struct die_info
*comp_unit_die
,
2203 enum language pretend_language
);
2205 static void free_cached_comp_units (void *);
2207 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2209 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
2211 static struct type
*set_die_type (struct die_info
*, struct type
*,
2212 struct dwarf2_cu
*);
2214 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2216 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2218 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
2221 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
2224 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
2227 static void dwarf2_add_dependence (struct dwarf2_cu
*,
2228 struct dwarf2_per_cu_data
*);
2230 static void dwarf2_mark (struct dwarf2_cu
*);
2232 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
2234 static struct type
*get_die_type_at_offset (sect_offset
,
2235 struct dwarf2_per_cu_data
*);
2237 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
2239 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
2240 enum language pretend_language
);
2242 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2244 /* Class, the destructor of which frees all allocated queue entries. This
2245 will only have work to do if an error was thrown while processing the
2246 dwarf. If no error was thrown then the queue entries should have all
2247 been processed, and freed, as we went along. */
2249 class dwarf2_queue_guard
2252 dwarf2_queue_guard () = default;
2254 /* Free any entries remaining on the queue. There should only be
2255 entries left if we hit an error while processing the dwarf. */
2256 ~dwarf2_queue_guard ()
2258 struct dwarf2_queue_item
*item
, *last
;
2260 item
= dwarf2_queue
;
2263 /* Anything still marked queued is likely to be in an
2264 inconsistent state, so discard it. */
2265 if (item
->per_cu
->queued
)
2267 if (item
->per_cu
->cu
!= NULL
)
2268 free_one_cached_comp_unit (item
->per_cu
);
2269 item
->per_cu
->queued
= 0;
2277 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2281 /* The return type of find_file_and_directory. Note, the enclosed
2282 string pointers are only valid while this object is valid. */
2284 struct file_and_directory
2286 /* The filename. This is never NULL. */
2289 /* The compilation directory. NULL if not known. If we needed to
2290 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2291 points directly to the DW_AT_comp_dir string attribute owned by
2292 the obstack that owns the DIE. */
2293 const char *comp_dir
;
2295 /* If we needed to build a new string for comp_dir, this is what
2296 owns the storage. */
2297 std::string comp_dir_storage
;
2300 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2301 struct dwarf2_cu
*cu
);
2303 static char *file_full_name (int file
, struct line_header
*lh
,
2304 const char *comp_dir
);
2306 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2307 enum class rcuh_kind
{ COMPILE
, TYPE
};
2309 static const gdb_byte
*read_and_check_comp_unit_head
2310 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2311 struct comp_unit_head
*header
,
2312 struct dwarf2_section_info
*section
,
2313 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2314 rcuh_kind section_kind
);
2316 static void init_cutu_and_read_dies
2317 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
2318 int use_existing_cu
, int keep
,
2319 die_reader_func_ftype
*die_reader_func
, void *data
);
2321 static void init_cutu_and_read_dies_simple
2322 (struct dwarf2_per_cu_data
*this_cu
,
2323 die_reader_func_ftype
*die_reader_func
, void *data
);
2325 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2327 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2329 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2330 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2331 struct dwp_file
*dwp_file
, const char *comp_dir
,
2332 ULONGEST signature
, int is_debug_types
);
2334 static struct dwp_file
*get_dwp_file
2335 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2337 static struct dwo_unit
*lookup_dwo_comp_unit
2338 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2340 static struct dwo_unit
*lookup_dwo_type_unit
2341 (struct signatured_type
*, const char *, const char *);
2343 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2345 static void free_dwo_file_cleanup (void *);
2347 struct free_dwo_file_cleanup_data
2349 struct dwo_file
*dwo_file
;
2350 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
2353 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2355 static void check_producer (struct dwarf2_cu
*cu
);
2357 static void free_line_header_voidp (void *arg
);
2359 /* Various complaints about symbol reading that don't abort the process. */
2362 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2364 complaint (&symfile_complaints
,
2365 _("statement list doesn't fit in .debug_line section"));
2369 dwarf2_debug_line_missing_file_complaint (void)
2371 complaint (&symfile_complaints
,
2372 _(".debug_line section has line data without a file"));
2376 dwarf2_debug_line_missing_end_sequence_complaint (void)
2378 complaint (&symfile_complaints
,
2379 _(".debug_line section has line "
2380 "program sequence without an end"));
2384 dwarf2_complex_location_expr_complaint (void)
2386 complaint (&symfile_complaints
, _("location expression too complex"));
2390 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2393 complaint (&symfile_complaints
,
2394 _("const value length mismatch for '%s', got %d, expected %d"),
2399 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2401 complaint (&symfile_complaints
,
2402 _("debug info runs off end of %s section"
2404 get_section_name (section
),
2405 get_section_file_name (section
));
2409 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2411 complaint (&symfile_complaints
,
2412 _("macro debug info contains a "
2413 "malformed macro definition:\n`%s'"),
2418 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2420 complaint (&symfile_complaints
,
2421 _("invalid attribute class or form for '%s' in '%s'"),
2425 /* Hash function for line_header_hash. */
2428 line_header_hash (const struct line_header
*ofs
)
2430 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2433 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2436 line_header_hash_voidp (const void *item
)
2438 const struct line_header
*ofs
= (const struct line_header
*) item
;
2440 return line_header_hash (ofs
);
2443 /* Equality function for line_header_hash. */
2446 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2448 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2449 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2451 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2452 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2457 /* Read the given attribute value as an address, taking the attribute's
2458 form into account. */
2461 attr_value_as_address (struct attribute
*attr
)
2465 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_GNU_addr_index
)
2467 /* Aside from a few clearly defined exceptions, attributes that
2468 contain an address must always be in DW_FORM_addr form.
2469 Unfortunately, some compilers happen to be violating this
2470 requirement by encoding addresses using other forms, such
2471 as DW_FORM_data4 for example. For those broken compilers,
2472 we try to do our best, without any guarantee of success,
2473 to interpret the address correctly. It would also be nice
2474 to generate a complaint, but that would require us to maintain
2475 a list of legitimate cases where a non-address form is allowed,
2476 as well as update callers to pass in at least the CU's DWARF
2477 version. This is more overhead than what we're willing to
2478 expand for a pretty rare case. */
2479 addr
= DW_UNSND (attr
);
2482 addr
= DW_ADDR (attr
);
2487 /* The suffix for an index file. */
2488 #define INDEX4_SUFFIX ".gdb-index"
2489 #define INDEX5_SUFFIX ".debug_names"
2490 #define DEBUG_STR_SUFFIX ".debug_str"
2492 /* See declaration. */
2494 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2495 const dwarf2_debug_sections
*names
)
2496 : objfile (objfile_
)
2499 names
= &dwarf2_elf_names
;
2501 bfd
*obfd
= objfile
->obfd
;
2503 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2504 locate_sections (obfd
, sec
, *names
);
2507 static void free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
);
2509 dwarf2_per_objfile::~dwarf2_per_objfile ()
2511 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2512 free_cached_comp_units ();
2514 if (quick_file_names_table
)
2515 htab_delete (quick_file_names_table
);
2517 if (line_header_hash
)
2518 htab_delete (line_header_hash
);
2520 for (int ix
= 0; ix
< n_comp_units
; ++ix
)
2521 VEC_free (dwarf2_per_cu_ptr
, all_comp_units
[ix
]->imported_symtabs
);
2523 for (int ix
= 0; ix
< n_type_units
; ++ix
)
2524 VEC_free (dwarf2_per_cu_ptr
,
2525 all_type_units
[ix
]->per_cu
.imported_symtabs
);
2526 xfree (all_type_units
);
2528 VEC_free (dwarf2_section_info_def
, types
);
2530 if (dwo_files
!= NULL
)
2531 free_dwo_files (dwo_files
, objfile
);
2532 if (dwp_file
!= NULL
)
2533 gdb_bfd_unref (dwp_file
->dbfd
);
2535 if (dwz_file
!= NULL
&& dwz_file
->dwz_bfd
)
2536 gdb_bfd_unref (dwz_file
->dwz_bfd
);
2538 if (index_table
!= NULL
)
2539 index_table
->~mapped_index ();
2541 /* Everything else should be on the objfile obstack. */
2544 /* See declaration. */
2547 dwarf2_per_objfile::free_cached_comp_units ()
2549 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2550 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2551 while (per_cu
!= NULL
)
2553 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2556 *last_chain
= next_cu
;
2561 /* Try to locate the sections we need for DWARF 2 debugging
2562 information and return true if we have enough to do something.
2563 NAMES points to the dwarf2 section names, or is NULL if the standard
2564 ELF names are used. */
2567 dwarf2_has_info (struct objfile
*objfile
,
2568 const struct dwarf2_debug_sections
*names
)
2570 if (objfile
->flags
& OBJF_READNEVER
)
2573 struct dwarf2_per_objfile
*dwarf2_per_objfile
2574 = get_dwarf2_per_objfile (objfile
);
2576 if (dwarf2_per_objfile
== NULL
)
2578 /* Initialize per-objfile state. */
2580 = new (&objfile
->objfile_obstack
) struct dwarf2_per_objfile (objfile
,
2582 set_dwarf2_per_objfile (objfile
, dwarf2_per_objfile
);
2584 return (!dwarf2_per_objfile
->info
.is_virtual
2585 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2586 && !dwarf2_per_objfile
->abbrev
.is_virtual
2587 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2590 /* Return the containing section of virtual section SECTION. */
2592 static struct dwarf2_section_info
*
2593 get_containing_section (const struct dwarf2_section_info
*section
)
2595 gdb_assert (section
->is_virtual
);
2596 return section
->s
.containing_section
;
2599 /* Return the bfd owner of SECTION. */
2602 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2604 if (section
->is_virtual
)
2606 section
= get_containing_section (section
);
2607 gdb_assert (!section
->is_virtual
);
2609 return section
->s
.section
->owner
;
2612 /* Return the bfd section of SECTION.
2613 Returns NULL if the section is not present. */
2616 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2618 if (section
->is_virtual
)
2620 section
= get_containing_section (section
);
2621 gdb_assert (!section
->is_virtual
);
2623 return section
->s
.section
;
2626 /* Return the name of SECTION. */
2629 get_section_name (const struct dwarf2_section_info
*section
)
2631 asection
*sectp
= get_section_bfd_section (section
);
2633 gdb_assert (sectp
!= NULL
);
2634 return bfd_section_name (get_section_bfd_owner (section
), sectp
);
2637 /* Return the name of the file SECTION is in. */
2640 get_section_file_name (const struct dwarf2_section_info
*section
)
2642 bfd
*abfd
= get_section_bfd_owner (section
);
2644 return bfd_get_filename (abfd
);
2647 /* Return the id of SECTION.
2648 Returns 0 if SECTION doesn't exist. */
2651 get_section_id (const struct dwarf2_section_info
*section
)
2653 asection
*sectp
= get_section_bfd_section (section
);
2660 /* Return the flags of SECTION.
2661 SECTION (or containing section if this is a virtual section) must exist. */
2664 get_section_flags (const struct dwarf2_section_info
*section
)
2666 asection
*sectp
= get_section_bfd_section (section
);
2668 gdb_assert (sectp
!= NULL
);
2669 return bfd_get_section_flags (sectp
->owner
, sectp
);
2672 /* When loading sections, we look either for uncompressed section or for
2673 compressed section names. */
2676 section_is_p (const char *section_name
,
2677 const struct dwarf2_section_names
*names
)
2679 if (names
->normal
!= NULL
2680 && strcmp (section_name
, names
->normal
) == 0)
2682 if (names
->compressed
!= NULL
2683 && strcmp (section_name
, names
->compressed
) == 0)
2688 /* See declaration. */
2691 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2692 const dwarf2_debug_sections
&names
)
2694 flagword aflag
= bfd_get_section_flags (abfd
, sectp
);
2696 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2699 else if (section_is_p (sectp
->name
, &names
.info
))
2701 this->info
.s
.section
= sectp
;
2702 this->info
.size
= bfd_get_section_size (sectp
);
2704 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2706 this->abbrev
.s
.section
= sectp
;
2707 this->abbrev
.size
= bfd_get_section_size (sectp
);
2709 else if (section_is_p (sectp
->name
, &names
.line
))
2711 this->line
.s
.section
= sectp
;
2712 this->line
.size
= bfd_get_section_size (sectp
);
2714 else if (section_is_p (sectp
->name
, &names
.loc
))
2716 this->loc
.s
.section
= sectp
;
2717 this->loc
.size
= bfd_get_section_size (sectp
);
2719 else if (section_is_p (sectp
->name
, &names
.loclists
))
2721 this->loclists
.s
.section
= sectp
;
2722 this->loclists
.size
= bfd_get_section_size (sectp
);
2724 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2726 this->macinfo
.s
.section
= sectp
;
2727 this->macinfo
.size
= bfd_get_section_size (sectp
);
2729 else if (section_is_p (sectp
->name
, &names
.macro
))
2731 this->macro
.s
.section
= sectp
;
2732 this->macro
.size
= bfd_get_section_size (sectp
);
2734 else if (section_is_p (sectp
->name
, &names
.str
))
2736 this->str
.s
.section
= sectp
;
2737 this->str
.size
= bfd_get_section_size (sectp
);
2739 else if (section_is_p (sectp
->name
, &names
.line_str
))
2741 this->line_str
.s
.section
= sectp
;
2742 this->line_str
.size
= bfd_get_section_size (sectp
);
2744 else if (section_is_p (sectp
->name
, &names
.addr
))
2746 this->addr
.s
.section
= sectp
;
2747 this->addr
.size
= bfd_get_section_size (sectp
);
2749 else if (section_is_p (sectp
->name
, &names
.frame
))
2751 this->frame
.s
.section
= sectp
;
2752 this->frame
.size
= bfd_get_section_size (sectp
);
2754 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2756 this->eh_frame
.s
.section
= sectp
;
2757 this->eh_frame
.size
= bfd_get_section_size (sectp
);
2759 else if (section_is_p (sectp
->name
, &names
.ranges
))
2761 this->ranges
.s
.section
= sectp
;
2762 this->ranges
.size
= bfd_get_section_size (sectp
);
2764 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2766 this->rnglists
.s
.section
= sectp
;
2767 this->rnglists
.size
= bfd_get_section_size (sectp
);
2769 else if (section_is_p (sectp
->name
, &names
.types
))
2771 struct dwarf2_section_info type_section
;
2773 memset (&type_section
, 0, sizeof (type_section
));
2774 type_section
.s
.section
= sectp
;
2775 type_section
.size
= bfd_get_section_size (sectp
);
2777 VEC_safe_push (dwarf2_section_info_def
, this->types
,
2780 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2782 this->gdb_index
.s
.section
= sectp
;
2783 this->gdb_index
.size
= bfd_get_section_size (sectp
);
2785 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2787 this->debug_names
.s
.section
= sectp
;
2788 this->debug_names
.size
= bfd_get_section_size (sectp
);
2790 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2792 this->debug_aranges
.s
.section
= sectp
;
2793 this->debug_aranges
.size
= bfd_get_section_size (sectp
);
2796 if ((bfd_get_section_flags (abfd
, sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2797 && bfd_section_vma (abfd
, sectp
) == 0)
2798 this->has_section_at_zero
= true;
2801 /* A helper function that decides whether a section is empty,
2805 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2807 if (section
->is_virtual
)
2808 return section
->size
== 0;
2809 return section
->s
.section
== NULL
|| section
->size
== 0;
2812 /* Read the contents of the section INFO.
2813 OBJFILE is the main object file, but not necessarily the file where
2814 the section comes from. E.g., for DWO files the bfd of INFO is the bfd
2816 If the section is compressed, uncompress it before returning. */
2819 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
2823 gdb_byte
*buf
, *retbuf
;
2827 info
->buffer
= NULL
;
2830 if (dwarf2_section_empty_p (info
))
2833 sectp
= get_section_bfd_section (info
);
2835 /* If this is a virtual section we need to read in the real one first. */
2836 if (info
->is_virtual
)
2838 struct dwarf2_section_info
*containing_section
=
2839 get_containing_section (info
);
2841 gdb_assert (sectp
!= NULL
);
2842 if ((sectp
->flags
& SEC_RELOC
) != 0)
2844 error (_("Dwarf Error: DWP format V2 with relocations is not"
2845 " supported in section %s [in module %s]"),
2846 get_section_name (info
), get_section_file_name (info
));
2848 dwarf2_read_section (objfile
, containing_section
);
2849 /* Other code should have already caught virtual sections that don't
2851 gdb_assert (info
->virtual_offset
+ info
->size
2852 <= containing_section
->size
);
2853 /* If the real section is empty or there was a problem reading the
2854 section we shouldn't get here. */
2855 gdb_assert (containing_section
->buffer
!= NULL
);
2856 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2860 /* If the section has relocations, we must read it ourselves.
2861 Otherwise we attach it to the BFD. */
2862 if ((sectp
->flags
& SEC_RELOC
) == 0)
2864 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2868 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2871 /* When debugging .o files, we may need to apply relocations; see
2872 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2873 We never compress sections in .o files, so we only need to
2874 try this when the section is not compressed. */
2875 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2878 info
->buffer
= retbuf
;
2882 abfd
= get_section_bfd_owner (info
);
2883 gdb_assert (abfd
!= NULL
);
2885 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2886 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2888 error (_("Dwarf Error: Can't read DWARF data"
2889 " in section %s [in module %s]"),
2890 bfd_section_name (abfd
, sectp
), bfd_get_filename (abfd
));
2894 /* A helper function that returns the size of a section in a safe way.
2895 If you are positive that the section has been read before using the
2896 size, then it is safe to refer to the dwarf2_section_info object's
2897 "size" field directly. In other cases, you must call this
2898 function, because for compressed sections the size field is not set
2899 correctly until the section has been read. */
2901 static bfd_size_type
2902 dwarf2_section_size (struct objfile
*objfile
,
2903 struct dwarf2_section_info
*info
)
2906 dwarf2_read_section (objfile
, info
);
2910 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2914 dwarf2_get_section_info (struct objfile
*objfile
,
2915 enum dwarf2_section_enum sect
,
2916 asection
**sectp
, const gdb_byte
**bufp
,
2917 bfd_size_type
*sizep
)
2919 struct dwarf2_per_objfile
*data
2920 = (struct dwarf2_per_objfile
*) objfile_data (objfile
,
2921 dwarf2_objfile_data_key
);
2922 struct dwarf2_section_info
*info
;
2924 /* We may see an objfile without any DWARF, in which case we just
2935 case DWARF2_DEBUG_FRAME
:
2936 info
= &data
->frame
;
2938 case DWARF2_EH_FRAME
:
2939 info
= &data
->eh_frame
;
2942 gdb_assert_not_reached ("unexpected section");
2945 dwarf2_read_section (objfile
, info
);
2947 *sectp
= get_section_bfd_section (info
);
2948 *bufp
= info
->buffer
;
2949 *sizep
= info
->size
;
2952 /* A helper function to find the sections for a .dwz file. */
2955 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2957 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2959 /* Note that we only support the standard ELF names, because .dwz
2960 is ELF-only (at the time of writing). */
2961 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2963 dwz_file
->abbrev
.s
.section
= sectp
;
2964 dwz_file
->abbrev
.size
= bfd_get_section_size (sectp
);
2966 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2968 dwz_file
->info
.s
.section
= sectp
;
2969 dwz_file
->info
.size
= bfd_get_section_size (sectp
);
2971 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2973 dwz_file
->str
.s
.section
= sectp
;
2974 dwz_file
->str
.size
= bfd_get_section_size (sectp
);
2976 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2978 dwz_file
->line
.s
.section
= sectp
;
2979 dwz_file
->line
.size
= bfd_get_section_size (sectp
);
2981 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2983 dwz_file
->macro
.s
.section
= sectp
;
2984 dwz_file
->macro
.size
= bfd_get_section_size (sectp
);
2986 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2988 dwz_file
->gdb_index
.s
.section
= sectp
;
2989 dwz_file
->gdb_index
.size
= bfd_get_section_size (sectp
);
2991 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2993 dwz_file
->debug_names
.s
.section
= sectp
;
2994 dwz_file
->debug_names
.size
= bfd_get_section_size (sectp
);
2998 /* Open the separate '.dwz' debug file, if needed. Return NULL if
2999 there is no .gnu_debugaltlink section in the file. Error if there
3000 is such a section but the file cannot be found. */
3002 static struct dwz_file
*
3003 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
3005 const char *filename
;
3006 struct dwz_file
*result
;
3007 bfd_size_type buildid_len_arg
;
3011 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
3012 return dwarf2_per_objfile
->dwz_file
;
3014 bfd_set_error (bfd_error_no_error
);
3015 gdb::unique_xmalloc_ptr
<char> data
3016 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
3017 &buildid_len_arg
, &buildid
));
3020 if (bfd_get_error () == bfd_error_no_error
)
3022 error (_("could not read '.gnu_debugaltlink' section: %s"),
3023 bfd_errmsg (bfd_get_error ()));
3026 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
3028 buildid_len
= (size_t) buildid_len_arg
;
3030 filename
= data
.get ();
3032 std::string abs_storage
;
3033 if (!IS_ABSOLUTE_PATH (filename
))
3035 gdb::unique_xmalloc_ptr
<char> abs
3036 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
3038 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
3039 filename
= abs_storage
.c_str ();
3042 /* First try the file name given in the section. If that doesn't
3043 work, try to use the build-id instead. */
3044 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
3045 if (dwz_bfd
!= NULL
)
3047 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
3051 if (dwz_bfd
== NULL
)
3052 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
3054 if (dwz_bfd
== NULL
)
3055 error (_("could not find '.gnu_debugaltlink' file for %s"),
3056 objfile_name (dwarf2_per_objfile
->objfile
));
3058 result
= OBSTACK_ZALLOC (&dwarf2_per_objfile
->objfile
->objfile_obstack
,
3060 result
->dwz_bfd
= dwz_bfd
.release ();
3062 bfd_map_over_sections (result
->dwz_bfd
, locate_dwz_sections
, result
);
3064 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, result
->dwz_bfd
);
3065 dwarf2_per_objfile
->dwz_file
= result
;
3069 /* DWARF quick_symbols_functions support. */
3071 /* TUs can share .debug_line entries, and there can be a lot more TUs than
3072 unique line tables, so we maintain a separate table of all .debug_line
3073 derived entries to support the sharing.
3074 All the quick functions need is the list of file names. We discard the
3075 line_header when we're done and don't need to record it here. */
3076 struct quick_file_names
3078 /* The data used to construct the hash key. */
3079 struct stmt_list_hash hash
;
3081 /* The number of entries in file_names, real_names. */
3082 unsigned int num_file_names
;
3084 /* The file names from the line table, after being run through
3086 const char **file_names
;
3088 /* The file names from the line table after being run through
3089 gdb_realpath. These are computed lazily. */
3090 const char **real_names
;
3093 /* When using the index (and thus not using psymtabs), each CU has an
3094 object of this type. This is used to hold information needed by
3095 the various "quick" methods. */
3096 struct dwarf2_per_cu_quick_data
3098 /* The file table. This can be NULL if there was no file table
3099 or it's currently not read in.
3100 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
3101 struct quick_file_names
*file_names
;
3103 /* The corresponding symbol table. This is NULL if symbols for this
3104 CU have not yet been read. */
3105 struct compunit_symtab
*compunit_symtab
;
3107 /* A temporary mark bit used when iterating over all CUs in
3108 expand_symtabs_matching. */
3109 unsigned int mark
: 1;
3111 /* True if we've tried to read the file table and found there isn't one.
3112 There will be no point in trying to read it again next time. */
3113 unsigned int no_file_data
: 1;
3116 /* Utility hash function for a stmt_list_hash. */
3119 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
3123 if (stmt_list_hash
->dwo_unit
!= NULL
)
3124 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
3125 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
3129 /* Utility equality function for a stmt_list_hash. */
3132 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
3133 const struct stmt_list_hash
*rhs
)
3135 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
3137 if (lhs
->dwo_unit
!= NULL
3138 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
3141 return lhs
->line_sect_off
== rhs
->line_sect_off
;
3144 /* Hash function for a quick_file_names. */
3147 hash_file_name_entry (const void *e
)
3149 const struct quick_file_names
*file_data
3150 = (const struct quick_file_names
*) e
;
3152 return hash_stmt_list_entry (&file_data
->hash
);
3155 /* Equality function for a quick_file_names. */
3158 eq_file_name_entry (const void *a
, const void *b
)
3160 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
3161 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
3163 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
3166 /* Delete function for a quick_file_names. */
3169 delete_file_name_entry (void *e
)
3171 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
3174 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3176 xfree ((void*) file_data
->file_names
[i
]);
3177 if (file_data
->real_names
)
3178 xfree ((void*) file_data
->real_names
[i
]);
3181 /* The space for the struct itself lives on objfile_obstack,
3182 so we don't free it here. */
3185 /* Create a quick_file_names hash table. */
3188 create_quick_file_names_table (unsigned int nr_initial_entries
)
3190 return htab_create_alloc (nr_initial_entries
,
3191 hash_file_name_entry
, eq_file_name_entry
,
3192 delete_file_name_entry
, xcalloc
, xfree
);
3195 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
3196 have to be created afterwards. You should call age_cached_comp_units after
3197 processing PER_CU->CU. dw2_setup must have been already called. */
3200 load_cu (struct dwarf2_per_cu_data
*per_cu
)
3202 if (per_cu
->is_debug_types
)
3203 load_full_type_unit (per_cu
);
3205 load_full_comp_unit (per_cu
, language_minimal
);
3207 if (per_cu
->cu
== NULL
)
3208 return; /* Dummy CU. */
3210 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
3213 /* Read in the symbols for PER_CU. */
3216 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3218 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3220 /* Skip type_unit_groups, reading the type units they contain
3221 is handled elsewhere. */
3222 if (IS_TYPE_UNIT_GROUP (per_cu
))
3225 /* The destructor of dwarf2_queue_guard frees any entries left on
3226 the queue. After this point we're guaranteed to leave this function
3227 with the dwarf queue empty. */
3228 dwarf2_queue_guard q_guard
;
3230 if (dwarf2_per_objfile
->using_index
3231 ? per_cu
->v
.quick
->compunit_symtab
== NULL
3232 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
3234 queue_comp_unit (per_cu
, language_minimal
);
3237 /* If we just loaded a CU from a DWO, and we're working with an index
3238 that may badly handle TUs, load all the TUs in that DWO as well.
3239 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
3240 if (!per_cu
->is_debug_types
3241 && per_cu
->cu
!= NULL
3242 && per_cu
->cu
->dwo_unit
!= NULL
3243 && dwarf2_per_objfile
->index_table
!= NULL
3244 && dwarf2_per_objfile
->index_table
->version
<= 7
3245 /* DWP files aren't supported yet. */
3246 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
3247 queue_and_load_all_dwo_tus (per_cu
);
3250 process_queue (dwarf2_per_objfile
);
3252 /* Age the cache, releasing compilation units that have not
3253 been used recently. */
3254 age_cached_comp_units (dwarf2_per_objfile
);
3257 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
3258 the objfile from which this CU came. Returns the resulting symbol
3261 static struct compunit_symtab
*
3262 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
)
3264 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
3266 gdb_assert (dwarf2_per_objfile
->using_index
);
3267 if (!per_cu
->v
.quick
->compunit_symtab
)
3269 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
,
3270 dwarf2_per_objfile
);
3271 scoped_restore decrementer
= increment_reading_symtab ();
3272 dw2_do_instantiate_symtab (per_cu
);
3273 process_cu_includes (dwarf2_per_objfile
);
3274 do_cleanups (back_to
);
3277 return per_cu
->v
.quick
->compunit_symtab
;
3280 /* Return the CU/TU given its index.
3282 This is intended for loops like:
3284 for (i = 0; i < (dwarf2_per_objfile->n_comp_units
3285 + dwarf2_per_objfile->n_type_units); ++i)
3287 struct dwarf2_per_cu_data *per_cu = dw2_get_cutu (i);
3293 static struct dwarf2_per_cu_data
*
3294 dw2_get_cutu (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3297 if (index
>= dwarf2_per_objfile
->n_comp_units
)
3299 index
-= dwarf2_per_objfile
->n_comp_units
;
3300 gdb_assert (index
< dwarf2_per_objfile
->n_type_units
);
3301 return &dwarf2_per_objfile
->all_type_units
[index
]->per_cu
;
3304 return dwarf2_per_objfile
->all_comp_units
[index
];
3307 /* Return the CU given its index.
3308 This differs from dw2_get_cutu in that it's for when you know INDEX
3311 static struct dwarf2_per_cu_data
*
3312 dw2_get_cu (struct dwarf2_per_objfile
*dwarf2_per_objfile
, int index
)
3314 gdb_assert (index
>= 0 && index
< dwarf2_per_objfile
->n_comp_units
);
3316 return dwarf2_per_objfile
->all_comp_units
[index
];
3319 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3320 objfile_obstack, and constructed with the specified field
3323 static dwarf2_per_cu_data
*
3324 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3325 struct dwarf2_section_info
*section
,
3327 sect_offset sect_off
, ULONGEST length
)
3329 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3330 dwarf2_per_cu_data
*the_cu
3331 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3332 struct dwarf2_per_cu_data
);
3333 the_cu
->sect_off
= sect_off
;
3334 the_cu
->length
= length
;
3335 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3336 the_cu
->section
= section
;
3337 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3338 struct dwarf2_per_cu_quick_data
);
3339 the_cu
->is_dwz
= is_dwz
;
3343 /* A helper for create_cus_from_index that handles a given list of
3347 create_cus_from_index_list (struct objfile
*objfile
,
3348 const gdb_byte
*cu_list
, offset_type n_elements
,
3349 struct dwarf2_section_info
*section
,
3354 struct dwarf2_per_objfile
*dwarf2_per_objfile
3355 = get_dwarf2_per_objfile (objfile
);
3357 for (i
= 0; i
< n_elements
; i
+= 2)
3359 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3361 sect_offset sect_off
3362 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3363 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3366 dwarf2_per_objfile
->all_comp_units
[base_offset
+ i
/ 2]
3367 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3372 /* Read the CU list from the mapped index, and use it to create all
3373 the CU objects for this objfile. */
3376 create_cus_from_index (struct objfile
*objfile
,
3377 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3378 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3380 struct dwz_file
*dwz
;
3381 struct dwarf2_per_objfile
*dwarf2_per_objfile
3382 = get_dwarf2_per_objfile (objfile
);
3384 dwarf2_per_objfile
->n_comp_units
= (cu_list_elements
+ dwz_elements
) / 2;
3385 dwarf2_per_objfile
->all_comp_units
=
3386 XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
3387 dwarf2_per_objfile
->n_comp_units
);
3389 create_cus_from_index_list (objfile
, cu_list
, cu_list_elements
,
3390 &dwarf2_per_objfile
->info
, 0, 0);
3392 if (dwz_elements
== 0)
3395 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3396 create_cus_from_index_list (objfile
, dwz_list
, dwz_elements
, &dwz
->info
, 1,
3397 cu_list_elements
/ 2);
3400 /* Create the signatured type hash table from the index. */
3403 create_signatured_type_table_from_index (struct objfile
*objfile
,
3404 struct dwarf2_section_info
*section
,
3405 const gdb_byte
*bytes
,
3406 offset_type elements
)
3409 htab_t sig_types_hash
;
3410 struct dwarf2_per_objfile
*dwarf2_per_objfile
3411 = get_dwarf2_per_objfile (objfile
);
3413 dwarf2_per_objfile
->n_type_units
3414 = dwarf2_per_objfile
->n_allocated_type_units
3416 dwarf2_per_objfile
->all_type_units
=
3417 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3419 sig_types_hash
= allocate_signatured_type_table (objfile
);
3421 for (i
= 0; i
< elements
; i
+= 3)
3423 struct signatured_type
*sig_type
;
3426 cu_offset type_offset_in_tu
;
3428 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3429 sect_offset sect_off
3430 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3432 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3434 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3437 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3438 struct signatured_type
);
3439 sig_type
->signature
= signature
;
3440 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3441 sig_type
->per_cu
.is_debug_types
= 1;
3442 sig_type
->per_cu
.section
= section
;
3443 sig_type
->per_cu
.sect_off
= sect_off
;
3444 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3445 sig_type
->per_cu
.v
.quick
3446 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3447 struct dwarf2_per_cu_quick_data
);
3449 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3452 dwarf2_per_objfile
->all_type_units
[i
/ 3] = sig_type
;
3455 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3458 /* Create the signatured type hash table from .debug_names. */
3461 create_signatured_type_table_from_debug_names
3462 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3463 const mapped_debug_names
&map
,
3464 struct dwarf2_section_info
*section
,
3465 struct dwarf2_section_info
*abbrev_section
)
3467 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3469 dwarf2_read_section (objfile
, section
);
3470 dwarf2_read_section (objfile
, abbrev_section
);
3472 dwarf2_per_objfile
->n_type_units
3473 = dwarf2_per_objfile
->n_allocated_type_units
3475 dwarf2_per_objfile
->all_type_units
3476 = XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
3478 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3480 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3482 struct signatured_type
*sig_type
;
3485 cu_offset type_offset_in_tu
;
3487 sect_offset sect_off
3488 = (sect_offset
) (extract_unsigned_integer
3489 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3491 map
.dwarf5_byte_order
));
3493 comp_unit_head cu_header
;
3494 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3496 section
->buffer
+ to_underlying (sect_off
),
3499 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3500 struct signatured_type
);
3501 sig_type
->signature
= cu_header
.signature
;
3502 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3503 sig_type
->per_cu
.is_debug_types
= 1;
3504 sig_type
->per_cu
.section
= section
;
3505 sig_type
->per_cu
.sect_off
= sect_off
;
3506 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3507 sig_type
->per_cu
.v
.quick
3508 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3509 struct dwarf2_per_cu_quick_data
);
3511 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3514 dwarf2_per_objfile
->all_type_units
[i
] = sig_type
;
3517 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3520 /* Read the address map data from the mapped index, and use it to
3521 populate the objfile's psymtabs_addrmap. */
3524 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3525 struct mapped_index
*index
)
3527 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3528 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3529 const gdb_byte
*iter
, *end
;
3530 struct addrmap
*mutable_map
;
3533 auto_obstack temp_obstack
;
3535 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3537 iter
= index
->address_table
.data ();
3538 end
= iter
+ index
->address_table
.size ();
3540 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3544 ULONGEST hi
, lo
, cu_index
;
3545 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3547 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3549 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3554 complaint (&symfile_complaints
,
3555 _(".gdb_index address table has invalid range (%s - %s)"),
3556 hex_string (lo
), hex_string (hi
));
3560 if (cu_index
>= dwarf2_per_objfile
->n_comp_units
)
3562 complaint (&symfile_complaints
,
3563 _(".gdb_index address table has invalid CU number %u"),
3564 (unsigned) cu_index
);
3568 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
);
3569 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
);
3570 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3571 dw2_get_cutu (dwarf2_per_objfile
, cu_index
));
3574 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3575 &objfile
->objfile_obstack
);
3578 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3579 populate the objfile's psymtabs_addrmap. */
3582 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3583 struct dwarf2_section_info
*section
)
3585 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3586 bfd
*abfd
= objfile
->obfd
;
3587 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3588 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3589 SECT_OFF_TEXT (objfile
));
3591 auto_obstack temp_obstack
;
3592 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3594 std::unordered_map
<sect_offset
,
3595 dwarf2_per_cu_data
*,
3596 gdb::hash_enum
<sect_offset
>>
3597 debug_info_offset_to_per_cu
;
3598 for (int cui
= 0; cui
< dwarf2_per_objfile
->n_comp_units
; ++cui
)
3600 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cui
);
3601 const auto insertpair
3602 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3603 if (!insertpair
.second
)
3605 warning (_("Section .debug_aranges in %s has duplicate "
3606 "debug_info_offset %s, ignoring .debug_aranges."),
3607 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3612 dwarf2_read_section (objfile
, section
);
3614 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3616 const gdb_byte
*addr
= section
->buffer
;
3618 while (addr
< section
->buffer
+ section
->size
)
3620 const gdb_byte
*const entry_addr
= addr
;
3621 unsigned int bytes_read
;
3623 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3627 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3628 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3629 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3630 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3632 warning (_("Section .debug_aranges in %s entry at offset %zu "
3633 "length %s exceeds section length %s, "
3634 "ignoring .debug_aranges."),
3635 objfile_name (objfile
), entry_addr
- section
->buffer
,
3636 plongest (bytes_read
+ entry_length
),
3637 pulongest (section
->size
));
3641 /* The version number. */
3642 const uint16_t version
= read_2_bytes (abfd
, addr
);
3646 warning (_("Section .debug_aranges in %s entry at offset %zu "
3647 "has unsupported version %d, ignoring .debug_aranges."),
3648 objfile_name (objfile
), entry_addr
- section
->buffer
,
3653 const uint64_t debug_info_offset
3654 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3655 addr
+= offset_size
;
3656 const auto per_cu_it
3657 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3658 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3660 warning (_("Section .debug_aranges in %s entry at offset %zu "
3661 "debug_info_offset %s does not exists, "
3662 "ignoring .debug_aranges."),
3663 objfile_name (objfile
), entry_addr
- section
->buffer
,
3664 pulongest (debug_info_offset
));
3667 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3669 const uint8_t address_size
= *addr
++;
3670 if (address_size
< 1 || address_size
> 8)
3672 warning (_("Section .debug_aranges in %s entry at offset %zu "
3673 "address_size %u is invalid, ignoring .debug_aranges."),
3674 objfile_name (objfile
), entry_addr
- section
->buffer
,
3679 const uint8_t segment_selector_size
= *addr
++;
3680 if (segment_selector_size
!= 0)
3682 warning (_("Section .debug_aranges in %s entry at offset %zu "
3683 "segment_selector_size %u is not supported, "
3684 "ignoring .debug_aranges."),
3685 objfile_name (objfile
), entry_addr
- section
->buffer
,
3686 segment_selector_size
);
3690 /* Must pad to an alignment boundary that is twice the address
3691 size. It is undocumented by the DWARF standard but GCC does
3693 for (size_t padding
= ((-(addr
- section
->buffer
))
3694 & (2 * address_size
- 1));
3695 padding
> 0; padding
--)
3698 warning (_("Section .debug_aranges in %s entry at offset %zu "
3699 "padding is not zero, ignoring .debug_aranges."),
3700 objfile_name (objfile
), entry_addr
- section
->buffer
);
3706 if (addr
+ 2 * address_size
> entry_end
)
3708 warning (_("Section .debug_aranges in %s entry at offset %zu "
3709 "address list is not properly terminated, "
3710 "ignoring .debug_aranges."),
3711 objfile_name (objfile
), entry_addr
- section
->buffer
);
3714 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3716 addr
+= address_size
;
3717 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3719 addr
+= address_size
;
3720 if (start
== 0 && length
== 0)
3722 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3724 /* Symbol was eliminated due to a COMDAT group. */
3727 ULONGEST end
= start
+ length
;
3728 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
);
3729 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
);
3730 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3734 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
3735 &objfile
->objfile_obstack
);
3738 /* The hash function for strings in the mapped index. This is the same as
3739 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
3740 implementation. This is necessary because the hash function is tied to the
3741 format of the mapped index file. The hash values do not have to match with
3744 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
3747 mapped_index_string_hash (int index_version
, const void *p
)
3749 const unsigned char *str
= (const unsigned char *) p
;
3753 while ((c
= *str
++) != 0)
3755 if (index_version
>= 5)
3757 r
= r
* 67 + c
- 113;
3763 /* Find a slot in the mapped index INDEX for the object named NAME.
3764 If NAME is found, set *VEC_OUT to point to the CU vector in the
3765 constant pool and return true. If NAME cannot be found, return
3769 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3770 offset_type
**vec_out
)
3773 offset_type slot
, step
;
3774 int (*cmp
) (const char *, const char *);
3776 gdb::unique_xmalloc_ptr
<char> without_params
;
3777 if (current_language
->la_language
== language_cplus
3778 || current_language
->la_language
== language_fortran
3779 || current_language
->la_language
== language_d
)
3781 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3784 if (strchr (name
, '(') != NULL
)
3786 without_params
= cp_remove_params (name
);
3788 if (without_params
!= NULL
)
3789 name
= without_params
.get ();
3793 /* Index version 4 did not support case insensitive searches. But the
3794 indices for case insensitive languages are built in lowercase, therefore
3795 simulate our NAME being searched is also lowercased. */
3796 hash
= mapped_index_string_hash ((index
->version
== 4
3797 && case_sensitivity
== case_sensitive_off
3798 ? 5 : index
->version
),
3801 slot
= hash
& (index
->symbol_table
.size () - 1);
3802 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3803 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3809 const auto &bucket
= index
->symbol_table
[slot
];
3810 if (bucket
.name
== 0 && bucket
.vec
== 0)
3813 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3814 if (!cmp (name
, str
))
3816 *vec_out
= (offset_type
*) (index
->constant_pool
3817 + MAYBE_SWAP (bucket
.vec
));
3821 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3825 /* A helper function that reads the .gdb_index from SECTION and fills
3826 in MAP. FILENAME is the name of the file containing the section;
3827 it is used for error reporting. DEPRECATED_OK is nonzero if it is
3828 ok to use deprecated sections.
3830 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3831 out parameters that are filled in with information about the CU and
3832 TU lists in the section.
3834 Returns 1 if all went well, 0 otherwise. */
3837 read_index_from_section (struct objfile
*objfile
,
3838 const char *filename
,
3840 struct dwarf2_section_info
*section
,
3841 struct mapped_index
*map
,
3842 const gdb_byte
**cu_list
,
3843 offset_type
*cu_list_elements
,
3844 const gdb_byte
**types_list
,
3845 offset_type
*types_list_elements
)
3847 const gdb_byte
*addr
;
3848 offset_type version
;
3849 offset_type
*metadata
;
3852 if (dwarf2_section_empty_p (section
))
3855 /* Older elfutils strip versions could keep the section in the main
3856 executable while splitting it for the separate debug info file. */
3857 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
3860 dwarf2_read_section (objfile
, section
);
3862 addr
= section
->buffer
;
3863 /* Version check. */
3864 version
= MAYBE_SWAP (*(offset_type
*) addr
);
3865 /* Versions earlier than 3 emitted every copy of a psymbol. This
3866 causes the index to behave very poorly for certain requests. Version 3
3867 contained incomplete addrmap. So, it seems better to just ignore such
3871 static int warning_printed
= 0;
3872 if (!warning_printed
)
3874 warning (_("Skipping obsolete .gdb_index section in %s."),
3876 warning_printed
= 1;
3880 /* Index version 4 uses a different hash function than index version
3883 Versions earlier than 6 did not emit psymbols for inlined
3884 functions. Using these files will cause GDB not to be able to
3885 set breakpoints on inlined functions by name, so we ignore these
3886 indices unless the user has done
3887 "set use-deprecated-index-sections on". */
3888 if (version
< 6 && !deprecated_ok
)
3890 static int warning_printed
= 0;
3891 if (!warning_printed
)
3894 Skipping deprecated .gdb_index section in %s.\n\
3895 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3896 to use the section anyway."),
3898 warning_printed
= 1;
3902 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3903 of the TU (for symbols coming from TUs),
3904 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3905 Plus gold-generated indices can have duplicate entries for global symbols,
3906 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3907 These are just performance bugs, and we can't distinguish gdb-generated
3908 indices from gold-generated ones, so issue no warning here. */
3910 /* Indexes with higher version than the one supported by GDB may be no
3911 longer backward compatible. */
3915 map
->version
= version
;
3916 map
->total_size
= section
->size
;
3918 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3921 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3922 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3926 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3927 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3928 - MAYBE_SWAP (metadata
[i
]))
3932 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3933 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3935 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3938 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3939 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3941 = gdb::array_view
<mapped_index::symbol_table_slot
>
3942 ((mapped_index::symbol_table_slot
*) symbol_table
,
3943 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3946 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3951 /* Read .gdb_index. If everything went ok, initialize the "quick"
3952 elements of all the CUs and return 1. Otherwise, return 0. */
3955 dwarf2_read_index (struct objfile
*objfile
)
3957 struct mapped_index local_map
, *map
;
3958 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3959 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3960 struct dwz_file
*dwz
;
3961 struct dwarf2_per_objfile
*dwarf2_per_objfile
3962 = get_dwarf2_per_objfile (objfile
);
3964 if (!read_index_from_section (objfile
, objfile_name (objfile
),
3965 use_deprecated_index_sections
,
3966 &dwarf2_per_objfile
->gdb_index
, &local_map
,
3967 &cu_list
, &cu_list_elements
,
3968 &types_list
, &types_list_elements
))
3971 /* Don't use the index if it's empty. */
3972 if (local_map
.symbol_table
.empty ())
3975 /* If there is a .dwz file, read it so we can get its CU list as
3977 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3980 struct mapped_index dwz_map
;
3981 const gdb_byte
*dwz_types_ignore
;
3982 offset_type dwz_types_elements_ignore
;
3984 if (!read_index_from_section (objfile
, bfd_get_filename (dwz
->dwz_bfd
),
3986 &dwz
->gdb_index
, &dwz_map
,
3987 &dwz_list
, &dwz_list_elements
,
3989 &dwz_types_elements_ignore
))
3991 warning (_("could not read '.gdb_index' section from %s; skipping"),
3992 bfd_get_filename (dwz
->dwz_bfd
));
3997 create_cus_from_index (objfile
, cu_list
, cu_list_elements
, dwz_list
,
4000 if (types_list_elements
)
4002 struct dwarf2_section_info
*section
;
4004 /* We can only handle a single .debug_types when we have an
4006 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
4009 section
= VEC_index (dwarf2_section_info_def
,
4010 dwarf2_per_objfile
->types
, 0);
4012 create_signatured_type_table_from_index (objfile
, section
, types_list
,
4013 types_list_elements
);
4016 create_addrmap_from_index (dwarf2_per_objfile
, &local_map
);
4018 map
= XOBNEW (&objfile
->objfile_obstack
, struct mapped_index
);
4019 map
= new (map
) mapped_index ();
4022 dwarf2_per_objfile
->index_table
= map
;
4023 dwarf2_per_objfile
->using_index
= 1;
4024 dwarf2_per_objfile
->quick_file_names_table
=
4025 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
4030 /* die_reader_func for dw2_get_file_names. */
4033 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
4034 const gdb_byte
*info_ptr
,
4035 struct die_info
*comp_unit_die
,
4039 struct dwarf2_cu
*cu
= reader
->cu
;
4040 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
4041 struct dwarf2_per_objfile
*dwarf2_per_objfile
4042 = cu
->per_cu
->dwarf2_per_objfile
;
4043 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4044 struct dwarf2_per_cu_data
*lh_cu
;
4045 struct attribute
*attr
;
4048 struct quick_file_names
*qfn
;
4050 gdb_assert (! this_cu
->is_debug_types
);
4052 /* Our callers never want to match partial units -- instead they
4053 will match the enclosing full CU. */
4054 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
4056 this_cu
->v
.quick
->no_file_data
= 1;
4064 sect_offset line_offset
{};
4066 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
4069 struct quick_file_names find_entry
;
4071 line_offset
= (sect_offset
) DW_UNSND (attr
);
4073 /* We may have already read in this line header (TU line header sharing).
4074 If we have we're done. */
4075 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
4076 find_entry
.hash
.line_sect_off
= line_offset
;
4077 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
4078 &find_entry
, INSERT
);
4081 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
4085 lh
= dwarf_decode_line_header (line_offset
, cu
);
4089 lh_cu
->v
.quick
->no_file_data
= 1;
4093 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
4094 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
4095 qfn
->hash
.line_sect_off
= line_offset
;
4096 gdb_assert (slot
!= NULL
);
4099 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
4101 qfn
->num_file_names
= lh
->file_names
.size ();
4103 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, lh
->file_names
.size ());
4104 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
4105 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
4106 qfn
->real_names
= NULL
;
4108 lh_cu
->v
.quick
->file_names
= qfn
;
4111 /* A helper for the "quick" functions which attempts to read the line
4112 table for THIS_CU. */
4114 static struct quick_file_names
*
4115 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
4117 /* This should never be called for TUs. */
4118 gdb_assert (! this_cu
->is_debug_types
);
4119 /* Nor type unit groups. */
4120 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
4122 if (this_cu
->v
.quick
->file_names
!= NULL
)
4123 return this_cu
->v
.quick
->file_names
;
4124 /* If we know there is no line data, no point in looking again. */
4125 if (this_cu
->v
.quick
->no_file_data
)
4128 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
4130 if (this_cu
->v
.quick
->no_file_data
)
4132 return this_cu
->v
.quick
->file_names
;
4135 /* A helper for the "quick" functions which computes and caches the
4136 real path for a given file name from the line table. */
4139 dw2_get_real_path (struct objfile
*objfile
,
4140 struct quick_file_names
*qfn
, int index
)
4142 if (qfn
->real_names
== NULL
)
4143 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
4144 qfn
->num_file_names
, const char *);
4146 if (qfn
->real_names
[index
] == NULL
)
4147 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
4149 return qfn
->real_names
[index
];
4152 static struct symtab
*
4153 dw2_find_last_source_symtab (struct objfile
*objfile
)
4155 struct dwarf2_per_objfile
*dwarf2_per_objfile
4156 = get_dwarf2_per_objfile (objfile
);
4157 int index
= dwarf2_per_objfile
->n_comp_units
- 1;
4158 dwarf2_per_cu_data
*dwarf_cu
= dw2_get_cutu (dwarf2_per_objfile
, index
);
4159 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
);
4164 return compunit_primary_filetab (cust
);
4167 /* Traversal function for dw2_forget_cached_source_info. */
4170 dw2_free_cached_file_names (void **slot
, void *info
)
4172 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
4174 if (file_data
->real_names
)
4178 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
4180 xfree ((void*) file_data
->real_names
[i
]);
4181 file_data
->real_names
[i
] = NULL
;
4189 dw2_forget_cached_source_info (struct objfile
*objfile
)
4191 struct dwarf2_per_objfile
*dwarf2_per_objfile
4192 = get_dwarf2_per_objfile (objfile
);
4194 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
4195 dw2_free_cached_file_names
, NULL
);
4198 /* Helper function for dw2_map_symtabs_matching_filename that expands
4199 the symtabs and calls the iterator. */
4202 dw2_map_expand_apply (struct objfile
*objfile
,
4203 struct dwarf2_per_cu_data
*per_cu
,
4204 const char *name
, const char *real_path
,
4205 gdb::function_view
<bool (symtab
*)> callback
)
4207 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
4209 /* Don't visit already-expanded CUs. */
4210 if (per_cu
->v
.quick
->compunit_symtab
)
4213 /* This may expand more than one symtab, and we want to iterate over
4215 dw2_instantiate_symtab (per_cu
);
4217 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
4218 last_made
, callback
);
4221 /* Implementation of the map_symtabs_matching_filename method. */
4224 dw2_map_symtabs_matching_filename
4225 (struct objfile
*objfile
, const char *name
, const char *real_path
,
4226 gdb::function_view
<bool (symtab
*)> callback
)
4229 const char *name_basename
= lbasename (name
);
4230 struct dwarf2_per_objfile
*dwarf2_per_objfile
4231 = get_dwarf2_per_objfile (objfile
);
4233 /* The rule is CUs specify all the files, including those used by
4234 any TU, so there's no need to scan TUs here. */
4236 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4239 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
4240 struct quick_file_names
*file_data
;
4242 /* We only need to look at symtabs not already expanded. */
4243 if (per_cu
->v
.quick
->compunit_symtab
)
4246 file_data
= dw2_get_file_names (per_cu
);
4247 if (file_data
== NULL
)
4250 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4252 const char *this_name
= file_data
->file_names
[j
];
4253 const char *this_real_name
;
4255 if (compare_filenames_for_search (this_name
, name
))
4257 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4263 /* Before we invoke realpath, which can get expensive when many
4264 files are involved, do a quick comparison of the basenames. */
4265 if (! basenames_may_differ
4266 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
4269 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4270 if (compare_filenames_for_search (this_real_name
, name
))
4272 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4278 if (real_path
!= NULL
)
4280 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
4281 gdb_assert (IS_ABSOLUTE_PATH (name
));
4282 if (this_real_name
!= NULL
4283 && FILENAME_CMP (real_path
, this_real_name
) == 0)
4285 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
4297 /* Struct used to manage iterating over all CUs looking for a symbol. */
4299 struct dw2_symtab_iterator
4301 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
4302 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
4303 /* If non-zero, only look for symbols that match BLOCK_INDEX. */
4304 int want_specific_block
;
4305 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
4306 Unused if !WANT_SPECIFIC_BLOCK. */
4308 /* The kind of symbol we're looking for. */
4310 /* The list of CUs from the index entry of the symbol,
4311 or NULL if not found. */
4313 /* The next element in VEC to look at. */
4315 /* The number of elements in VEC, or zero if there is no match. */
4317 /* Have we seen a global version of the symbol?
4318 If so we can ignore all further global instances.
4319 This is to work around gold/15646, inefficient gold-generated
4324 /* Initialize the index symtab iterator ITER.
4325 If WANT_SPECIFIC_BLOCK is non-zero, only look for symbols
4326 in block BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
4329 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
4330 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4331 int want_specific_block
,
4336 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
4337 iter
->want_specific_block
= want_specific_block
;
4338 iter
->block_index
= block_index
;
4339 iter
->domain
= domain
;
4341 iter
->global_seen
= 0;
4343 mapped_index
*index
= dwarf2_per_objfile
->index_table
;
4345 /* index is NULL if OBJF_READNOW. */
4346 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
4347 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4355 /* Return the next matching CU or NULL if there are no more. */
4357 static struct dwarf2_per_cu_data
*
4358 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4360 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4362 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4364 offset_type cu_index_and_attrs
=
4365 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4366 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4367 struct dwarf2_per_cu_data
*per_cu
;
4368 int want_static
= iter
->block_index
!= GLOBAL_BLOCK
;
4369 /* This value is only valid for index versions >= 7. */
4370 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4371 gdb_index_symbol_kind symbol_kind
=
4372 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4373 /* Only check the symbol attributes if they're present.
4374 Indices prior to version 7 don't record them,
4375 and indices >= 7 may elide them for certain symbols
4376 (gold does this). */
4378 (dwarf2_per_objfile
->index_table
->version
>= 7
4379 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4381 /* Don't crash on bad data. */
4382 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
4383 + dwarf2_per_objfile
->n_type_units
))
4385 complaint (&symfile_complaints
,
4386 _(".gdb_index entry has bad CU index"
4388 objfile_name (dwarf2_per_objfile
->objfile
));
4392 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
4394 /* Skip if already read in. */
4395 if (per_cu
->v
.quick
->compunit_symtab
)
4398 /* Check static vs global. */
4401 if (iter
->want_specific_block
4402 && want_static
!= is_static
)
4404 /* Work around gold/15646. */
4405 if (!is_static
&& iter
->global_seen
)
4408 iter
->global_seen
= 1;
4411 /* Only check the symbol's kind if it has one. */
4414 switch (iter
->domain
)
4417 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4418 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4419 /* Some types are also in VAR_DOMAIN. */
4420 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4424 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4428 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4443 static struct compunit_symtab
*
4444 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
4445 const char *name
, domain_enum domain
)
4447 struct compunit_symtab
*stab_best
= NULL
;
4448 struct dwarf2_per_objfile
*dwarf2_per_objfile
4449 = get_dwarf2_per_objfile (objfile
);
4451 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4453 struct dw2_symtab_iterator iter
;
4454 struct dwarf2_per_cu_data
*per_cu
;
4456 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 1, block_index
, domain
, name
);
4458 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4460 struct symbol
*sym
, *with_opaque
= NULL
;
4461 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
4462 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4463 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4465 sym
= block_find_symbol (block
, name
, domain
,
4466 block_find_non_opaque_type_preferred
,
4469 /* Some caution must be observed with overloaded functions
4470 and methods, since the index will not contain any overload
4471 information (but NAME might contain it). */
4474 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4476 if (with_opaque
!= NULL
4477 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4480 /* Keep looking through other CUs. */
4487 dw2_print_stats (struct objfile
*objfile
)
4489 struct dwarf2_per_objfile
*dwarf2_per_objfile
4490 = get_dwarf2_per_objfile (objfile
);
4491 int total
= dwarf2_per_objfile
->n_comp_units
+ dwarf2_per_objfile
->n_type_units
;
4494 for (int i
= 0; i
< total
; ++i
)
4496 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4498 if (!per_cu
->v
.quick
->compunit_symtab
)
4501 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4502 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4505 /* This dumps minimal information about the index.
4506 It is called via "mt print objfiles".
4507 One use is to verify .gdb_index has been loaded by the
4508 gdb.dwarf2/gdb-index.exp testcase. */
4511 dw2_dump (struct objfile
*objfile
)
4513 struct dwarf2_per_objfile
*dwarf2_per_objfile
4514 = get_dwarf2_per_objfile (objfile
);
4516 gdb_assert (dwarf2_per_objfile
->using_index
);
4517 printf_filtered (".gdb_index:");
4518 if (dwarf2_per_objfile
->index_table
!= NULL
)
4520 printf_filtered (" version %d\n",
4521 dwarf2_per_objfile
->index_table
->version
);
4524 printf_filtered (" faked for \"readnow\"\n");
4525 printf_filtered ("\n");
4529 dw2_relocate (struct objfile
*objfile
,
4530 const struct section_offsets
*new_offsets
,
4531 const struct section_offsets
*delta
)
4533 /* There's nothing to relocate here. */
4537 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4538 const char *func_name
)
4540 struct dwarf2_per_objfile
*dwarf2_per_objfile
4541 = get_dwarf2_per_objfile (objfile
);
4543 struct dw2_symtab_iterator iter
;
4544 struct dwarf2_per_cu_data
*per_cu
;
4546 /* Note: It doesn't matter what we pass for block_index here. */
4547 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, 0, GLOBAL_BLOCK
, VAR_DOMAIN
,
4550 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4551 dw2_instantiate_symtab (per_cu
);
4556 dw2_expand_all_symtabs (struct objfile
*objfile
)
4558 struct dwarf2_per_objfile
*dwarf2_per_objfile
4559 = get_dwarf2_per_objfile (objfile
);
4560 int total_units
= (dwarf2_per_objfile
->n_comp_units
4561 + dwarf2_per_objfile
->n_type_units
);
4563 for (int i
= 0; i
< total_units
; ++i
)
4565 struct dwarf2_per_cu_data
*per_cu
4566 = dw2_get_cutu (dwarf2_per_objfile
, i
);
4568 dw2_instantiate_symtab (per_cu
);
4573 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4574 const char *fullname
)
4576 struct dwarf2_per_objfile
*dwarf2_per_objfile
4577 = get_dwarf2_per_objfile (objfile
);
4579 /* We don't need to consider type units here.
4580 This is only called for examining code, e.g. expand_line_sal.
4581 There can be an order of magnitude (or more) more type units
4582 than comp units, and we avoid them if we can. */
4584 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
4587 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
4588 struct quick_file_names
*file_data
;
4590 /* We only need to look at symtabs not already expanded. */
4591 if (per_cu
->v
.quick
->compunit_symtab
)
4594 file_data
= dw2_get_file_names (per_cu
);
4595 if (file_data
== NULL
)
4598 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
4600 const char *this_fullname
= file_data
->file_names
[j
];
4602 if (filename_cmp (this_fullname
, fullname
) == 0)
4604 dw2_instantiate_symtab (per_cu
);
4612 dw2_map_matching_symbols (struct objfile
*objfile
,
4613 const char * name
, domain_enum domain
,
4615 int (*callback
) (struct block
*,
4616 struct symbol
*, void *),
4617 void *data
, symbol_name_match_type match
,
4618 symbol_compare_ftype
*ordered_compare
)
4620 /* Currently unimplemented; used for Ada. The function can be called if the
4621 current language is Ada for a non-Ada objfile using GNU index. As Ada
4622 does not look for non-Ada symbols this function should just return. */
4625 /* Symbol name matcher for .gdb_index names.
4627 Symbol names in .gdb_index have a few particularities:
4629 - There's no indication of which is the language of each symbol.
4631 Since each language has its own symbol name matching algorithm,
4632 and we don't know which language is the right one, we must match
4633 each symbol against all languages. This would be a potential
4634 performance problem if it were not mitigated by the
4635 mapped_index::name_components lookup table, which significantly
4636 reduces the number of times we need to call into this matcher,
4637 making it a non-issue.
4639 - Symbol names in the index have no overload (parameter)
4640 information. I.e., in C++, "foo(int)" and "foo(long)" both
4641 appear as "foo" in the index, for example.
4643 This means that the lookup names passed to the symbol name
4644 matcher functions must have no parameter information either
4645 because (e.g.) symbol search name "foo" does not match
4646 lookup-name "foo(int)" [while swapping search name for lookup
4649 class gdb_index_symbol_name_matcher
4652 /* Prepares the vector of comparison functions for LOOKUP_NAME. */
4653 gdb_index_symbol_name_matcher (const lookup_name_info
&lookup_name
);
4655 /* Walk all the matcher routines and match SYMBOL_NAME against them.
4656 Returns true if any matcher matches. */
4657 bool matches (const char *symbol_name
);
4660 /* A reference to the lookup name we're matching against. */
4661 const lookup_name_info
&m_lookup_name
;
4663 /* A vector holding all the different symbol name matchers, for all
4665 std::vector
<symbol_name_matcher_ftype
*> m_symbol_name_matcher_funcs
;
4668 gdb_index_symbol_name_matcher::gdb_index_symbol_name_matcher
4669 (const lookup_name_info
&lookup_name
)
4670 : m_lookup_name (lookup_name
)
4672 /* Prepare the vector of comparison functions upfront, to avoid
4673 doing the same work for each symbol. Care is taken to avoid
4674 matching with the same matcher more than once if/when multiple
4675 languages use the same matcher function. */
4676 auto &matchers
= m_symbol_name_matcher_funcs
;
4677 matchers
.reserve (nr_languages
);
4679 matchers
.push_back (default_symbol_name_matcher
);
4681 for (int i
= 0; i
< nr_languages
; i
++)
4683 const language_defn
*lang
= language_def ((enum language
) i
);
4684 symbol_name_matcher_ftype
*name_matcher
4685 = get_symbol_name_matcher (lang
, m_lookup_name
);
4687 /* Don't insert the same comparison routine more than once.
4688 Note that we do this linear walk instead of a seemingly
4689 cheaper sorted insert, or use a std::set or something like
4690 that, because relative order of function addresses is not
4691 stable. This is not a problem in practice because the number
4692 of supported languages is low, and the cost here is tiny
4693 compared to the number of searches we'll do afterwards using
4695 if (name_matcher
!= default_symbol_name_matcher
4696 && (std::find (matchers
.begin (), matchers
.end (), name_matcher
)
4697 == matchers
.end ()))
4698 matchers
.push_back (name_matcher
);
4703 gdb_index_symbol_name_matcher::matches (const char *symbol_name
)
4705 for (auto matches_name
: m_symbol_name_matcher_funcs
)
4706 if (matches_name (symbol_name
, m_lookup_name
, NULL
))
4712 /* Starting from a search name, return the string that finds the upper
4713 bound of all strings that start with SEARCH_NAME in a sorted name
4714 list. Returns the empty string to indicate that the upper bound is
4715 the end of the list. */
4718 make_sort_after_prefix_name (const char *search_name
)
4720 /* When looking to complete "func", we find the upper bound of all
4721 symbols that start with "func" by looking for where we'd insert
4722 the closest string that would follow "func" in lexicographical
4723 order. Usually, that's "func"-with-last-character-incremented,
4724 i.e. "fund". Mind non-ASCII characters, though. Usually those
4725 will be UTF-8 multi-byte sequences, but we can't be certain.
4726 Especially mind the 0xff character, which is a valid character in
4727 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4728 rule out compilers allowing it in identifiers. Note that
4729 conveniently, strcmp/strcasecmp are specified to compare
4730 characters interpreted as unsigned char. So what we do is treat
4731 the whole string as a base 256 number composed of a sequence of
4732 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4733 to 0, and carries 1 to the following more-significant position.
4734 If the very first character in SEARCH_NAME ends up incremented
4735 and carries/overflows, then the upper bound is the end of the
4736 list. The string after the empty string is also the empty
4739 Some examples of this operation:
4741 SEARCH_NAME => "+1" RESULT
4745 "\xff" "a" "\xff" => "\xff" "b"
4750 Then, with these symbols for example:
4756 completing "func" looks for symbols between "func" and
4757 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4758 which finds "func" and "func1", but not "fund".
4762 funcÿ (Latin1 'ÿ' [0xff])
4766 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4767 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4771 ÿÿ (Latin1 'ÿ' [0xff])
4774 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4775 the end of the list.
4777 std::string after
= search_name
;
4778 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4780 if (!after
.empty ())
4781 after
.back () = (unsigned char) after
.back () + 1;
4785 /* See declaration. */
4787 std::pair
<std::vector
<name_component
>::const_iterator
,
4788 std::vector
<name_component
>::const_iterator
>
4789 mapped_index_base::find_name_components_bounds
4790 (const lookup_name_info
&lookup_name_without_params
) const
4793 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4796 = lookup_name_without_params
.cplus ().lookup_name ().c_str ();
4798 /* Comparison function object for lower_bound that matches against a
4799 given symbol name. */
4800 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4803 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4804 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4805 return name_cmp (elem_name
, name
) < 0;
4808 /* Comparison function object for upper_bound that matches against a
4809 given symbol name. */
4810 auto lookup_compare_upper
= [&] (const char *name
,
4811 const name_component
&elem
)
4813 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4814 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4815 return name_cmp (name
, elem_name
) < 0;
4818 auto begin
= this->name_components
.begin ();
4819 auto end
= this->name_components
.end ();
4821 /* Find the lower bound. */
4824 if (lookup_name_without_params
.completion_mode () && cplus
[0] == '\0')
4827 return std::lower_bound (begin
, end
, cplus
, lookup_compare_lower
);
4830 /* Find the upper bound. */
4833 if (lookup_name_without_params
.completion_mode ())
4835 /* In completion mode, we want UPPER to point past all
4836 symbols names that have the same prefix. I.e., with
4837 these symbols, and completing "func":
4839 function << lower bound
4841 other_function << upper bound
4843 We find the upper bound by looking for the insertion
4844 point of "func"-with-last-character-incremented,
4846 std::string after
= make_sort_after_prefix_name (cplus
);
4849 return std::lower_bound (lower
, end
, after
.c_str (),
4850 lookup_compare_lower
);
4853 return std::upper_bound (lower
, end
, cplus
, lookup_compare_upper
);
4856 return {lower
, upper
};
4859 /* See declaration. */
4862 mapped_index_base::build_name_components ()
4864 if (!this->name_components
.empty ())
4867 this->name_components_casing
= case_sensitivity
;
4869 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4871 /* The code below only knows how to break apart components of C++
4872 symbol names (and other languages that use '::' as
4873 namespace/module separator). If we add support for wild matching
4874 to some language that uses some other operator (E.g., Ada, Go and
4875 D use '.'), then we'll need to try splitting the symbol name
4876 according to that language too. Note that Ada does support wild
4877 matching, but doesn't currently support .gdb_index. */
4878 auto count
= this->symbol_name_count ();
4879 for (offset_type idx
= 0; idx
< count
; idx
++)
4881 if (this->symbol_name_slot_invalid (idx
))
4884 const char *name
= this->symbol_name_at (idx
);
4886 /* Add each name component to the name component table. */
4887 unsigned int previous_len
= 0;
4888 for (unsigned int current_len
= cp_find_first_component (name
);
4889 name
[current_len
] != '\0';
4890 current_len
+= cp_find_first_component (name
+ current_len
))
4892 gdb_assert (name
[current_len
] == ':');
4893 this->name_components
.push_back ({previous_len
, idx
});
4894 /* Skip the '::'. */
4896 previous_len
= current_len
;
4898 this->name_components
.push_back ({previous_len
, idx
});
4901 /* Sort name_components elements by name. */
4902 auto name_comp_compare
= [&] (const name_component
&left
,
4903 const name_component
&right
)
4905 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4906 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4908 const char *left_name
= left_qualified
+ left
.name_offset
;
4909 const char *right_name
= right_qualified
+ right
.name_offset
;
4911 return name_cmp (left_name
, right_name
) < 0;
4914 std::sort (this->name_components
.begin (),
4915 this->name_components
.end (),
4919 /* Helper for dw2_expand_symtabs_matching that works with a
4920 mapped_index_base instead of the containing objfile. This is split
4921 to a separate function in order to be able to unit test the
4922 name_components matching using a mock mapped_index_base. For each
4923 symbol name that matches, calls MATCH_CALLBACK, passing it the
4924 symbol's index in the mapped_index_base symbol table. */
4927 dw2_expand_symtabs_matching_symbol
4928 (mapped_index_base
&index
,
4929 const lookup_name_info
&lookup_name_in
,
4930 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4931 enum search_domain kind
,
4932 gdb::function_view
<void (offset_type
)> match_callback
)
4934 lookup_name_info lookup_name_without_params
4935 = lookup_name_in
.make_ignore_params ();
4936 gdb_index_symbol_name_matcher lookup_name_matcher
4937 (lookup_name_without_params
);
4939 /* Build the symbol name component sorted vector, if we haven't
4941 index
.build_name_components ();
4943 auto bounds
= index
.find_name_components_bounds (lookup_name_without_params
);
4945 /* Now for each symbol name in range, check to see if we have a name
4946 match, and if so, call the MATCH_CALLBACK callback. */
4948 /* The same symbol may appear more than once in the range though.
4949 E.g., if we're looking for symbols that complete "w", and we have
4950 a symbol named "w1::w2", we'll find the two name components for
4951 that same symbol in the range. To be sure we only call the
4952 callback once per symbol, we first collect the symbol name
4953 indexes that matched in a temporary vector and ignore
4955 std::vector
<offset_type
> matches
;
4956 matches
.reserve (std::distance (bounds
.first
, bounds
.second
));
4958 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4960 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4962 if (!lookup_name_matcher
.matches (qualified
)
4963 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4966 matches
.push_back (bounds
.first
->idx
);
4969 std::sort (matches
.begin (), matches
.end ());
4971 /* Finally call the callback, once per match. */
4973 for (offset_type idx
: matches
)
4977 match_callback (idx
);
4982 /* Above we use a type wider than idx's for 'prev', since 0 and
4983 (offset_type)-1 are both possible values. */
4984 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4989 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4991 /* A mock .gdb_index/.debug_names-like name index table, enough to
4992 exercise dw2_expand_symtabs_matching_symbol, which works with the
4993 mapped_index_base interface. Builds an index from the symbol list
4994 passed as parameter to the constructor. */
4995 class mock_mapped_index
: public mapped_index_base
4998 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4999 : m_symbol_table (symbols
)
5002 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
5004 /* Return the number of names in the symbol table. */
5005 virtual size_t symbol_name_count () const
5007 return m_symbol_table
.size ();
5010 /* Get the name of the symbol at IDX in the symbol table. */
5011 virtual const char *symbol_name_at (offset_type idx
) const
5013 return m_symbol_table
[idx
];
5017 gdb::array_view
<const char *> m_symbol_table
;
5020 /* Convenience function that converts a NULL pointer to a "<null>"
5021 string, to pass to print routines. */
5024 string_or_null (const char *str
)
5026 return str
!= NULL
? str
: "<null>";
5029 /* Check if a lookup_name_info built from
5030 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
5031 index. EXPECTED_LIST is the list of expected matches, in expected
5032 matching order. If no match expected, then an empty list is
5033 specified. Returns true on success. On failure prints a warning
5034 indicating the file:line that failed, and returns false. */
5037 check_match (const char *file
, int line
,
5038 mock_mapped_index
&mock_index
,
5039 const char *name
, symbol_name_match_type match_type
,
5040 bool completion_mode
,
5041 std::initializer_list
<const char *> expected_list
)
5043 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
5045 bool matched
= true;
5047 auto mismatch
= [&] (const char *expected_str
,
5050 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
5051 "expected=\"%s\", got=\"%s\"\n"),
5053 (match_type
== symbol_name_match_type::FULL
5055 name
, string_or_null (expected_str
), string_or_null (got
));
5059 auto expected_it
= expected_list
.begin ();
5060 auto expected_end
= expected_list
.end ();
5062 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
5064 [&] (offset_type idx
)
5066 const char *matched_name
= mock_index
.symbol_name_at (idx
);
5067 const char *expected_str
5068 = expected_it
== expected_end
? NULL
: *expected_it
++;
5070 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
5071 mismatch (expected_str
, matched_name
);
5074 const char *expected_str
5075 = expected_it
== expected_end
? NULL
: *expected_it
++;
5076 if (expected_str
!= NULL
)
5077 mismatch (expected_str
, NULL
);
5082 /* The symbols added to the mock mapped_index for testing (in
5084 static const char *test_symbols
[] = {
5093 "ns2::tmpl<int>::foo2",
5094 "(anonymous namespace)::A::B::C",
5096 /* These are used to check that the increment-last-char in the
5097 matching algorithm for completion doesn't match "t1_fund" when
5098 completing "t1_func". */
5104 /* A UTF-8 name with multi-byte sequences to make sure that
5105 cp-name-parser understands this as a single identifier ("função"
5106 is "function" in PT). */
5109 /* \377 (0xff) is Latin1 'ÿ'. */
5112 /* \377 (0xff) is Latin1 'ÿ'. */
5116 /* A name with all sorts of complications. Starts with "z" to make
5117 it easier for the completion tests below. */
5118 #define Z_SYM_NAME \
5119 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
5120 "::tuple<(anonymous namespace)::ui*, " \
5121 "std::default_delete<(anonymous namespace)::ui>, void>"
5126 /* Returns true if the mapped_index_base::find_name_component_bounds
5127 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
5128 in completion mode. */
5131 check_find_bounds_finds (mapped_index_base
&index
,
5132 const char *search_name
,
5133 gdb::array_view
<const char *> expected_syms
)
5135 lookup_name_info
lookup_name (search_name
,
5136 symbol_name_match_type::FULL
, true);
5138 auto bounds
= index
.find_name_components_bounds (lookup_name
);
5140 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
5141 if (distance
!= expected_syms
.size ())
5144 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
5146 auto nc_elem
= bounds
.first
+ exp_elem
;
5147 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
5148 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
5155 /* Test the lower-level mapped_index::find_name_component_bounds
5159 test_mapped_index_find_name_component_bounds ()
5161 mock_mapped_index
mock_index (test_symbols
);
5163 mock_index
.build_name_components ();
5165 /* Test the lower-level mapped_index::find_name_component_bounds
5166 method in completion mode. */
5168 static const char *expected_syms
[] = {
5173 SELF_CHECK (check_find_bounds_finds (mock_index
,
5174 "t1_func", expected_syms
));
5177 /* Check that the increment-last-char in the name matching algorithm
5178 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
5180 static const char *expected_syms1
[] = {
5184 SELF_CHECK (check_find_bounds_finds (mock_index
,
5185 "\377", expected_syms1
));
5187 static const char *expected_syms2
[] = {
5190 SELF_CHECK (check_find_bounds_finds (mock_index
,
5191 "\377\377", expected_syms2
));
5195 /* Test dw2_expand_symtabs_matching_symbol. */
5198 test_dw2_expand_symtabs_matching_symbol ()
5200 mock_mapped_index
mock_index (test_symbols
);
5202 /* We let all tests run until the end even if some fails, for debug
5204 bool any_mismatch
= false;
5206 /* Create the expected symbols list (an initializer_list). Needed
5207 because lists have commas, and we need to pass them to CHECK,
5208 which is a macro. */
5209 #define EXPECT(...) { __VA_ARGS__ }
5211 /* Wrapper for check_match that passes down the current
5212 __FILE__/__LINE__. */
5213 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
5214 any_mismatch |= !check_match (__FILE__, __LINE__, \
5216 NAME, MATCH_TYPE, COMPLETION_MODE, \
5219 /* Identity checks. */
5220 for (const char *sym
: test_symbols
)
5222 /* Should be able to match all existing symbols. */
5223 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
5226 /* Should be able to match all existing symbols with
5228 std::string with_params
= std::string (sym
) + "(int)";
5229 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5232 /* Should be able to match all existing symbols with
5233 parameters and qualifiers. */
5234 with_params
= std::string (sym
) + " ( int ) const";
5235 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5238 /* This should really find sym, but cp-name-parser.y doesn't
5239 know about lvalue/rvalue qualifiers yet. */
5240 with_params
= std::string (sym
) + " ( int ) &&";
5241 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
5245 /* Check that the name matching algorithm for completion doesn't get
5246 confused with Latin1 'ÿ' / 0xff. */
5248 static const char str
[] = "\377";
5249 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5250 EXPECT ("\377", "\377\377123"));
5253 /* Check that the increment-last-char in the matching algorithm for
5254 completion doesn't match "t1_fund" when completing "t1_func". */
5256 static const char str
[] = "t1_func";
5257 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
5258 EXPECT ("t1_func", "t1_func1"));
5261 /* Check that completion mode works at each prefix of the expected
5264 static const char str
[] = "function(int)";
5265 size_t len
= strlen (str
);
5268 for (size_t i
= 1; i
< len
; i
++)
5270 lookup
.assign (str
, i
);
5271 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5272 EXPECT ("function"));
5276 /* While "w" is a prefix of both components, the match function
5277 should still only be called once. */
5279 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
5281 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
5285 /* Same, with a "complicated" symbol. */
5287 static const char str
[] = Z_SYM_NAME
;
5288 size_t len
= strlen (str
);
5291 for (size_t i
= 1; i
< len
; i
++)
5293 lookup
.assign (str
, i
);
5294 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
5295 EXPECT (Z_SYM_NAME
));
5299 /* In FULL mode, an incomplete symbol doesn't match. */
5301 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
5305 /* A complete symbol with parameters matches any overload, since the
5306 index has no overload info. */
5308 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
5309 EXPECT ("std::zfunction", "std::zfunction2"));
5310 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
5311 EXPECT ("std::zfunction", "std::zfunction2"));
5312 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
5313 EXPECT ("std::zfunction", "std::zfunction2"));
5316 /* Check that whitespace is ignored appropriately. A symbol with a
5317 template argument list. */
5319 static const char expected
[] = "ns::foo<int>";
5320 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
5322 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
5326 /* Check that whitespace is ignored appropriately. A symbol with a
5327 template argument list that includes a pointer. */
5329 static const char expected
[] = "ns::foo<char*>";
5330 /* Try both completion and non-completion modes. */
5331 static const bool completion_mode
[2] = {false, true};
5332 for (size_t i
= 0; i
< 2; i
++)
5334 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
5335 completion_mode
[i
], EXPECT (expected
));
5336 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
5337 completion_mode
[i
], EXPECT (expected
));
5339 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
5340 completion_mode
[i
], EXPECT (expected
));
5341 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
5342 completion_mode
[i
], EXPECT (expected
));
5347 /* Check method qualifiers are ignored. */
5348 static const char expected
[] = "ns::foo<char*>";
5349 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
5350 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5351 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
5352 symbol_name_match_type::FULL
, true, EXPECT (expected
));
5353 CHECK_MATCH ("foo < char * > ( int ) const",
5354 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5355 CHECK_MATCH ("foo < char * > ( int ) &&",
5356 symbol_name_match_type::WILD
, true, EXPECT (expected
));
5359 /* Test lookup names that don't match anything. */
5361 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
5364 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
5368 /* Some wild matching tests, exercising "(anonymous namespace)",
5369 which should not be confused with a parameter list. */
5371 static const char *syms
[] = {
5375 "A :: B :: C ( int )",
5380 for (const char *s
: syms
)
5382 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
5383 EXPECT ("(anonymous namespace)::A::B::C"));
5388 static const char expected
[] = "ns2::tmpl<int>::foo2";
5389 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5391 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5395 SELF_CHECK (!any_mismatch
);
5404 test_mapped_index_find_name_component_bounds ();
5405 test_dw2_expand_symtabs_matching_symbol ();
5408 }} // namespace selftests::dw2_expand_symtabs_matching
5410 #endif /* GDB_SELF_TEST */
5412 /* If FILE_MATCHER is NULL or if PER_CU has
5413 dwarf2_per_cu_quick_data::MARK set (see
5414 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5415 EXPANSION_NOTIFY on it. */
5418 dw2_expand_symtabs_matching_one
5419 (struct dwarf2_per_cu_data
*per_cu
,
5420 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5421 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5423 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5425 bool symtab_was_null
5426 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5428 dw2_instantiate_symtab (per_cu
);
5430 if (expansion_notify
!= NULL
5432 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5433 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5437 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5438 matched, to expand corresponding CUs that were marked. IDX is the
5439 index of the symbol name that matched. */
5442 dw2_expand_marked_cus
5443 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5444 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5445 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5448 offset_type
*vec
, vec_len
, vec_idx
;
5449 bool global_seen
= false;
5450 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5452 vec
= (offset_type
*) (index
.constant_pool
5453 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5454 vec_len
= MAYBE_SWAP (vec
[0]);
5455 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5457 struct dwarf2_per_cu_data
*per_cu
;
5458 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5459 /* This value is only valid for index versions >= 7. */
5460 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5461 gdb_index_symbol_kind symbol_kind
=
5462 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5463 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5464 /* Only check the symbol attributes if they're present.
5465 Indices prior to version 7 don't record them,
5466 and indices >= 7 may elide them for certain symbols
5467 (gold does this). */
5470 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5472 /* Work around gold/15646. */
5475 if (!is_static
&& global_seen
)
5481 /* Only check the symbol's kind if it has one. */
5486 case VARIABLES_DOMAIN
:
5487 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5490 case FUNCTIONS_DOMAIN
:
5491 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5495 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5503 /* Don't crash on bad data. */
5504 if (cu_index
>= (dwarf2_per_objfile
->n_comp_units
5505 + dwarf2_per_objfile
->n_type_units
))
5507 complaint (&symfile_complaints
,
5508 _(".gdb_index entry has bad CU index"
5510 objfile_name (dwarf2_per_objfile
->objfile
));
5514 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, cu_index
);
5515 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5520 /* If FILE_MATCHER is non-NULL, set all the
5521 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5522 that match FILE_MATCHER. */
5525 dw_expand_symtabs_matching_file_matcher
5526 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5527 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5529 if (file_matcher
== NULL
)
5532 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5534 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5536 NULL
, xcalloc
, xfree
));
5537 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5539 NULL
, xcalloc
, xfree
));
5541 /* The rule is CUs specify all the files, including those used by
5542 any TU, so there's no need to scan TUs here. */
5544 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5547 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5548 struct quick_file_names
*file_data
;
5553 per_cu
->v
.quick
->mark
= 0;
5555 /* We only need to look at symtabs not already expanded. */
5556 if (per_cu
->v
.quick
->compunit_symtab
)
5559 file_data
= dw2_get_file_names (per_cu
);
5560 if (file_data
== NULL
)
5563 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5565 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5567 per_cu
->v
.quick
->mark
= 1;
5571 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
5573 const char *this_real_name
;
5575 if (file_matcher (file_data
->file_names
[j
], false))
5577 per_cu
->v
.quick
->mark
= 1;
5581 /* Before we invoke realpath, which can get expensive when many
5582 files are involved, do a quick comparison of the basenames. */
5583 if (!basenames_may_differ
5584 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5588 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5589 if (file_matcher (this_real_name
, false))
5591 per_cu
->v
.quick
->mark
= 1;
5596 slot
= htab_find_slot (per_cu
->v
.quick
->mark
5597 ? visited_found
.get ()
5598 : visited_not_found
.get (),
5605 dw2_expand_symtabs_matching
5606 (struct objfile
*objfile
,
5607 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5608 const lookup_name_info
&lookup_name
,
5609 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5610 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5611 enum search_domain kind
)
5613 struct dwarf2_per_objfile
*dwarf2_per_objfile
5614 = get_dwarf2_per_objfile (objfile
);
5616 /* index_table is NULL if OBJF_READNOW. */
5617 if (!dwarf2_per_objfile
->index_table
)
5620 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5622 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5624 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5626 kind
, [&] (offset_type idx
)
5628 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5629 expansion_notify
, kind
);
5633 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5636 static struct compunit_symtab
*
5637 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5642 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5643 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5646 if (cust
->includes
== NULL
)
5649 for (i
= 0; cust
->includes
[i
]; ++i
)
5651 struct compunit_symtab
*s
= cust
->includes
[i
];
5653 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5661 static struct compunit_symtab
*
5662 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5663 struct bound_minimal_symbol msymbol
,
5665 struct obj_section
*section
,
5668 struct dwarf2_per_cu_data
*data
;
5669 struct compunit_symtab
*result
;
5671 if (!objfile
->psymtabs_addrmap
)
5674 data
= (struct dwarf2_per_cu_data
*) addrmap_find (objfile
->psymtabs_addrmap
,
5679 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5680 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5681 paddress (get_objfile_arch (objfile
), pc
));
5684 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
),
5686 gdb_assert (result
!= NULL
);
5691 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5692 void *data
, int need_fullname
)
5694 struct dwarf2_per_objfile
*dwarf2_per_objfile
5695 = get_dwarf2_per_objfile (objfile
);
5697 if (!dwarf2_per_objfile
->filenames_cache
)
5699 dwarf2_per_objfile
->filenames_cache
.emplace ();
5701 htab_up
visited (htab_create_alloc (10,
5702 htab_hash_pointer
, htab_eq_pointer
,
5703 NULL
, xcalloc
, xfree
));
5705 /* The rule is CUs specify all the files, including those used
5706 by any TU, so there's no need to scan TUs here. We can
5707 ignore file names coming from already-expanded CUs. */
5709 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5711 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
5713 if (per_cu
->v
.quick
->compunit_symtab
)
5715 void **slot
= htab_find_slot (visited
.get (),
5716 per_cu
->v
.quick
->file_names
,
5719 *slot
= per_cu
->v
.quick
->file_names
;
5723 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
5725 dwarf2_per_cu_data
*per_cu
= dw2_get_cu (dwarf2_per_objfile
, i
);
5726 struct quick_file_names
*file_data
;
5729 /* We only need to look at symtabs not already expanded. */
5730 if (per_cu
->v
.quick
->compunit_symtab
)
5733 file_data
= dw2_get_file_names (per_cu
);
5734 if (file_data
== NULL
)
5737 slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5740 /* Already visited. */
5745 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5747 const char *filename
= file_data
->file_names
[j
];
5748 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5753 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5755 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5758 this_real_name
= gdb_realpath (filename
);
5759 (*fun
) (filename
, this_real_name
.get (), data
);
5764 dw2_has_symbols (struct objfile
*objfile
)
5769 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5772 dw2_find_last_source_symtab
,
5773 dw2_forget_cached_source_info
,
5774 dw2_map_symtabs_matching_filename
,
5779 dw2_expand_symtabs_for_function
,
5780 dw2_expand_all_symtabs
,
5781 dw2_expand_symtabs_with_fullname
,
5782 dw2_map_matching_symbols
,
5783 dw2_expand_symtabs_matching
,
5784 dw2_find_pc_sect_compunit_symtab
,
5786 dw2_map_symbol_filenames
5789 /* DWARF-5 debug_names reader. */
5791 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5792 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5794 /* A helper function that reads the .debug_names section in SECTION
5795 and fills in MAP. FILENAME is the name of the file containing the
5796 section; it is used for error reporting.
5798 Returns true if all went well, false otherwise. */
5801 read_debug_names_from_section (struct objfile
*objfile
,
5802 const char *filename
,
5803 struct dwarf2_section_info
*section
,
5804 mapped_debug_names
&map
)
5806 if (dwarf2_section_empty_p (section
))
5809 /* Older elfutils strip versions could keep the section in the main
5810 executable while splitting it for the separate debug info file. */
5811 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5814 dwarf2_read_section (objfile
, section
);
5816 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5818 const gdb_byte
*addr
= section
->buffer
;
5820 bfd
*const abfd
= get_section_bfd_owner (section
);
5822 unsigned int bytes_read
;
5823 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5826 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5827 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5828 if (bytes_read
+ length
!= section
->size
)
5830 /* There may be multiple per-CU indices. */
5831 warning (_("Section .debug_names in %s length %s does not match "
5832 "section length %s, ignoring .debug_names."),
5833 filename
, plongest (bytes_read
+ length
),
5834 pulongest (section
->size
));
5838 /* The version number. */
5839 uint16_t version
= read_2_bytes (abfd
, addr
);
5843 warning (_("Section .debug_names in %s has unsupported version %d, "
5844 "ignoring .debug_names."),
5850 uint16_t padding
= read_2_bytes (abfd
, addr
);
5854 warning (_("Section .debug_names in %s has unsupported padding %d, "
5855 "ignoring .debug_names."),
5860 /* comp_unit_count - The number of CUs in the CU list. */
5861 map
.cu_count
= read_4_bytes (abfd
, addr
);
5864 /* local_type_unit_count - The number of TUs in the local TU
5866 map
.tu_count
= read_4_bytes (abfd
, addr
);
5869 /* foreign_type_unit_count - The number of TUs in the foreign TU
5871 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5873 if (foreign_tu_count
!= 0)
5875 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5876 "ignoring .debug_names."),
5877 filename
, static_cast<unsigned long> (foreign_tu_count
));
5881 /* bucket_count - The number of hash buckets in the hash lookup
5883 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5886 /* name_count - The number of unique names in the index. */
5887 map
.name_count
= read_4_bytes (abfd
, addr
);
5890 /* abbrev_table_size - The size in bytes of the abbreviations
5892 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5895 /* augmentation_string_size - The size in bytes of the augmentation
5896 string. This value is rounded up to a multiple of 4. */
5897 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5899 map
.augmentation_is_gdb
= ((augmentation_string_size
5900 == sizeof (dwarf5_augmentation
))
5901 && memcmp (addr
, dwarf5_augmentation
,
5902 sizeof (dwarf5_augmentation
)) == 0);
5903 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5904 addr
+= augmentation_string_size
;
5907 map
.cu_table_reordered
= addr
;
5908 addr
+= map
.cu_count
* map
.offset_size
;
5910 /* List of Local TUs */
5911 map
.tu_table_reordered
= addr
;
5912 addr
+= map
.tu_count
* map
.offset_size
;
5914 /* Hash Lookup Table */
5915 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5916 addr
+= map
.bucket_count
* 4;
5917 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5918 addr
+= map
.name_count
* 4;
5921 map
.name_table_string_offs_reordered
= addr
;
5922 addr
+= map
.name_count
* map
.offset_size
;
5923 map
.name_table_entry_offs_reordered
= addr
;
5924 addr
+= map
.name_count
* map
.offset_size
;
5926 const gdb_byte
*abbrev_table_start
= addr
;
5929 unsigned int bytes_read
;
5930 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5935 const auto insertpair
5936 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5937 if (!insertpair
.second
)
5939 warning (_("Section .debug_names in %s has duplicate index %s, "
5940 "ignoring .debug_names."),
5941 filename
, pulongest (index_num
));
5944 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5945 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5950 mapped_debug_names::index_val::attr attr
;
5951 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5953 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5955 if (attr
.form
== DW_FORM_implicit_const
)
5957 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5961 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5963 indexval
.attr_vec
.push_back (std::move (attr
));
5966 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5968 warning (_("Section .debug_names in %s has abbreviation_table "
5969 "of size %zu vs. written as %u, ignoring .debug_names."),
5970 filename
, addr
- abbrev_table_start
, abbrev_table_size
);
5973 map
.entry_pool
= addr
;
5978 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5982 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5983 const mapped_debug_names
&map
,
5984 dwarf2_section_info
§ion
,
5985 bool is_dwz
, int base_offset
)
5987 sect_offset sect_off_prev
;
5988 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5990 sect_offset sect_off_next
;
5991 if (i
< map
.cu_count
)
5994 = (sect_offset
) (extract_unsigned_integer
5995 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5997 map
.dwarf5_byte_order
));
6000 sect_off_next
= (sect_offset
) section
.size
;
6003 const ULONGEST length
= sect_off_next
- sect_off_prev
;
6004 dwarf2_per_objfile
->all_comp_units
[base_offset
+ (i
- 1)]
6005 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
6006 sect_off_prev
, length
);
6008 sect_off_prev
= sect_off_next
;
6012 /* Read the CU list from the mapped index, and use it to create all
6013 the CU objects for this dwarf2_per_objfile. */
6016 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6017 const mapped_debug_names
&map
,
6018 const mapped_debug_names
&dwz_map
)
6020 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6022 dwarf2_per_objfile
->n_comp_units
= map
.cu_count
+ dwz_map
.cu_count
;
6023 dwarf2_per_objfile
->all_comp_units
6024 = XOBNEWVEC (&objfile
->objfile_obstack
, struct dwarf2_per_cu_data
*,
6025 dwarf2_per_objfile
->n_comp_units
);
6027 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
6028 dwarf2_per_objfile
->info
,
6030 0 /* base_offset */);
6032 if (dwz_map
.cu_count
== 0)
6035 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
6036 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
6038 map
.cu_count
/* base_offset */);
6041 /* Read .debug_names. If everything went ok, initialize the "quick"
6042 elements of all the CUs and return true. Otherwise, return false. */
6045 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6047 mapped_debug_names
local_map (dwarf2_per_objfile
);
6048 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
6049 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6051 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
6052 &dwarf2_per_objfile
->debug_names
,
6056 /* Don't use the index if it's empty. */
6057 if (local_map
.name_count
== 0)
6060 /* If there is a .dwz file, read it so we can get its CU list as
6062 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
6065 if (!read_debug_names_from_section (objfile
,
6066 bfd_get_filename (dwz
->dwz_bfd
),
6067 &dwz
->debug_names
, dwz_map
))
6069 warning (_("could not read '.debug_names' section from %s; skipping"),
6070 bfd_get_filename (dwz
->dwz_bfd
));
6075 create_cus_from_debug_names (dwarf2_per_objfile
, local_map
, dwz_map
);
6077 if (local_map
.tu_count
!= 0)
6079 /* We can only handle a single .debug_types when we have an
6081 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) != 1)
6084 dwarf2_section_info
*section
= VEC_index (dwarf2_section_info_def
,
6085 dwarf2_per_objfile
->types
, 0);
6087 create_signatured_type_table_from_debug_names
6088 (dwarf2_per_objfile
, local_map
, section
, &dwarf2_per_objfile
->abbrev
);
6091 create_addrmap_from_aranges (dwarf2_per_objfile
,
6092 &dwarf2_per_objfile
->debug_aranges
);
6094 dwarf2_per_objfile
->debug_names_table
.reset
6095 (new mapped_debug_names (dwarf2_per_objfile
));
6096 *dwarf2_per_objfile
->debug_names_table
= std::move (local_map
);
6097 dwarf2_per_objfile
->using_index
= 1;
6098 dwarf2_per_objfile
->quick_file_names_table
=
6099 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6104 /* Symbol name hashing function as specified by DWARF-5. */
6107 dwarf5_djb_hash (const char *str_
)
6109 const unsigned char *str
= (const unsigned char *) str_
;
6111 /* Note: tolower here ignores UTF-8, which isn't fully compliant.
6112 See http://dwarfstd.org/ShowIssue.php?issue=161027.1. */
6114 uint32_t hash
= 5381;
6115 while (int c
= *str
++)
6116 hash
= hash
* 33 + tolower (c
);
6120 /* Type used to manage iterating over all CUs looking for a symbol for
6123 class dw2_debug_names_iterator
6126 /* If WANT_SPECIFIC_BLOCK is true, only look for symbols in block
6127 BLOCK_INDEX. Otherwise BLOCK_INDEX is ignored. */
6128 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6129 bool want_specific_block
,
6130 block_enum block_index
, domain_enum domain
,
6132 : m_map (map
), m_want_specific_block (want_specific_block
),
6133 m_block_index (block_index
), m_domain (domain
),
6134 m_addr (find_vec_in_debug_names (map
, name
))
6137 dw2_debug_names_iterator (const mapped_debug_names
&map
,
6138 search_domain search
, uint32_t namei
)
6141 m_addr (find_vec_in_debug_names (map
, namei
))
6144 /* Return the next matching CU or NULL if there are no more. */
6145 dwarf2_per_cu_data
*next ();
6148 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6150 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
6153 /* The internalized form of .debug_names. */
6154 const mapped_debug_names
&m_map
;
6156 /* If true, only look for symbols that match BLOCK_INDEX. */
6157 const bool m_want_specific_block
= false;
6159 /* One of GLOBAL_BLOCK or STATIC_BLOCK.
6160 Unused if !WANT_SPECIFIC_BLOCK - FIRST_LOCAL_BLOCK is an invalid
6162 const block_enum m_block_index
= FIRST_LOCAL_BLOCK
;
6164 /* The kind of symbol we're looking for. */
6165 const domain_enum m_domain
= UNDEF_DOMAIN
;
6166 const search_domain m_search
= ALL_DOMAIN
;
6168 /* The list of CUs from the index entry of the symbol, or NULL if
6170 const gdb_byte
*m_addr
;
6174 mapped_debug_names::namei_to_name (uint32_t namei
) const
6176 const ULONGEST namei_string_offs
6177 = extract_unsigned_integer ((name_table_string_offs_reordered
6178 + namei
* offset_size
),
6181 return read_indirect_string_at_offset
6182 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
6185 /* Find a slot in .debug_names for the object named NAME. If NAME is
6186 found, return pointer to its pool data. If NAME cannot be found,
6190 dw2_debug_names_iterator::find_vec_in_debug_names
6191 (const mapped_debug_names
&map
, const char *name
)
6193 int (*cmp
) (const char *, const char *);
6195 if (current_language
->la_language
== language_cplus
6196 || current_language
->la_language
== language_fortran
6197 || current_language
->la_language
== language_d
)
6199 /* NAME is already canonical. Drop any qualifiers as
6200 .debug_names does not contain any. */
6202 if (strchr (name
, '(') != NULL
)
6204 gdb::unique_xmalloc_ptr
<char> without_params
6205 = cp_remove_params (name
);
6207 if (without_params
!= NULL
)
6209 name
= without_params
.get();
6214 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
6216 const uint32_t full_hash
= dwarf5_djb_hash (name
);
6218 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6219 (map
.bucket_table_reordered
6220 + (full_hash
% map
.bucket_count
)), 4,
6221 map
.dwarf5_byte_order
);
6225 if (namei
>= map
.name_count
)
6227 complaint (&symfile_complaints
,
6228 _("Wrong .debug_names with name index %u but name_count=%u "
6230 namei
, map
.name_count
,
6231 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6237 const uint32_t namei_full_hash
6238 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
6239 (map
.hash_table_reordered
+ namei
), 4,
6240 map
.dwarf5_byte_order
);
6241 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
6244 if (full_hash
== namei_full_hash
)
6246 const char *const namei_string
= map
.namei_to_name (namei
);
6248 #if 0 /* An expensive sanity check. */
6249 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
6251 complaint (&symfile_complaints
,
6252 _("Wrong .debug_names hash for string at index %u "
6254 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
6259 if (cmp (namei_string
, name
) == 0)
6261 const ULONGEST namei_entry_offs
6262 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6263 + namei
* map
.offset_size
),
6264 map
.offset_size
, map
.dwarf5_byte_order
);
6265 return map
.entry_pool
+ namei_entry_offs
;
6270 if (namei
>= map
.name_count
)
6276 dw2_debug_names_iterator::find_vec_in_debug_names
6277 (const mapped_debug_names
&map
, uint32_t namei
)
6279 if (namei
>= map
.name_count
)
6281 complaint (&symfile_complaints
,
6282 _("Wrong .debug_names with name index %u but name_count=%u "
6284 namei
, map
.name_count
,
6285 objfile_name (map
.dwarf2_per_objfile
->objfile
));
6289 const ULONGEST namei_entry_offs
6290 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
6291 + namei
* map
.offset_size
),
6292 map
.offset_size
, map
.dwarf5_byte_order
);
6293 return map
.entry_pool
+ namei_entry_offs
;
6296 /* See dw2_debug_names_iterator. */
6298 dwarf2_per_cu_data
*
6299 dw2_debug_names_iterator::next ()
6304 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
6305 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6306 bfd
*const abfd
= objfile
->obfd
;
6310 unsigned int bytes_read
;
6311 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6312 m_addr
+= bytes_read
;
6316 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
6317 if (indexval_it
== m_map
.abbrev_map
.cend ())
6319 complaint (&symfile_complaints
,
6320 _("Wrong .debug_names undefined abbrev code %s "
6322 pulongest (abbrev
), objfile_name (objfile
));
6325 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
6326 bool have_is_static
= false;
6328 dwarf2_per_cu_data
*per_cu
= NULL
;
6329 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
6334 case DW_FORM_implicit_const
:
6335 ull
= attr
.implicit_const
;
6337 case DW_FORM_flag_present
:
6341 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
6342 m_addr
+= bytes_read
;
6345 complaint (&symfile_complaints
,
6346 _("Unsupported .debug_names form %s [in module %s]"),
6347 dwarf_form_name (attr
.form
),
6348 objfile_name (objfile
));
6351 switch (attr
.dw_idx
)
6353 case DW_IDX_compile_unit
:
6354 /* Don't crash on bad data. */
6355 if (ull
>= dwarf2_per_objfile
->n_comp_units
)
6357 complaint (&symfile_complaints
,
6358 _(".debug_names entry has bad CU index %s"
6361 objfile_name (dwarf2_per_objfile
->objfile
));
6364 per_cu
= dw2_get_cutu (dwarf2_per_objfile
, ull
);
6366 case DW_IDX_type_unit
:
6367 /* Don't crash on bad data. */
6368 if (ull
>= dwarf2_per_objfile
->n_type_units
)
6370 complaint (&symfile_complaints
,
6371 _(".debug_names entry has bad TU index %s"
6374 objfile_name (dwarf2_per_objfile
->objfile
));
6377 per_cu
= dw2_get_cutu (dwarf2_per_objfile
,
6378 dwarf2_per_objfile
->n_comp_units
+ ull
);
6380 case DW_IDX_GNU_internal
:
6381 if (!m_map
.augmentation_is_gdb
)
6383 have_is_static
= true;
6386 case DW_IDX_GNU_external
:
6387 if (!m_map
.augmentation_is_gdb
)
6389 have_is_static
= true;
6395 /* Skip if already read in. */
6396 if (per_cu
->v
.quick
->compunit_symtab
)
6399 /* Check static vs global. */
6402 const bool want_static
= m_block_index
!= GLOBAL_BLOCK
;
6403 if (m_want_specific_block
&& want_static
!= is_static
)
6407 /* Match dw2_symtab_iter_next, symbol_kind
6408 and debug_names::psymbol_tag. */
6412 switch (indexval
.dwarf_tag
)
6414 case DW_TAG_variable
:
6415 case DW_TAG_subprogram
:
6416 /* Some types are also in VAR_DOMAIN. */
6417 case DW_TAG_typedef
:
6418 case DW_TAG_structure_type
:
6425 switch (indexval
.dwarf_tag
)
6427 case DW_TAG_typedef
:
6428 case DW_TAG_structure_type
:
6435 switch (indexval
.dwarf_tag
)
6438 case DW_TAG_variable
:
6448 /* Match dw2_expand_symtabs_matching, symbol_kind and
6449 debug_names::psymbol_tag. */
6452 case VARIABLES_DOMAIN
:
6453 switch (indexval
.dwarf_tag
)
6455 case DW_TAG_variable
:
6461 case FUNCTIONS_DOMAIN
:
6462 switch (indexval
.dwarf_tag
)
6464 case DW_TAG_subprogram
:
6471 switch (indexval
.dwarf_tag
)
6473 case DW_TAG_typedef
:
6474 case DW_TAG_structure_type
:
6487 static struct compunit_symtab
*
6488 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, int block_index_int
,
6489 const char *name
, domain_enum domain
)
6491 const block_enum block_index
= static_cast<block_enum
> (block_index_int
);
6492 struct dwarf2_per_objfile
*dwarf2_per_objfile
6493 = get_dwarf2_per_objfile (objfile
);
6495 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6498 /* index is NULL if OBJF_READNOW. */
6501 const auto &map
= *mapp
;
6503 dw2_debug_names_iterator
iter (map
, true /* want_specific_block */,
6504 block_index
, domain
, name
);
6506 struct compunit_symtab
*stab_best
= NULL
;
6507 struct dwarf2_per_cu_data
*per_cu
;
6508 while ((per_cu
= iter
.next ()) != NULL
)
6510 struct symbol
*sym
, *with_opaque
= NULL
;
6511 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
);
6512 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6513 struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6515 sym
= block_find_symbol (block
, name
, domain
,
6516 block_find_non_opaque_type_preferred
,
6519 /* Some caution must be observed with overloaded functions and
6520 methods, since the index will not contain any overload
6521 information (but NAME might contain it). */
6524 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6526 if (with_opaque
!= NULL
6527 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6530 /* Keep looking through other CUs. */
6536 /* This dumps minimal information about .debug_names. It is called
6537 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6538 uses this to verify that .debug_names has been loaded. */
6541 dw2_debug_names_dump (struct objfile
*objfile
)
6543 struct dwarf2_per_objfile
*dwarf2_per_objfile
6544 = get_dwarf2_per_objfile (objfile
);
6546 gdb_assert (dwarf2_per_objfile
->using_index
);
6547 printf_filtered (".debug_names:");
6548 if (dwarf2_per_objfile
->debug_names_table
)
6549 printf_filtered (" exists\n");
6551 printf_filtered (" faked for \"readnow\"\n");
6552 printf_filtered ("\n");
6556 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6557 const char *func_name
)
6559 struct dwarf2_per_objfile
*dwarf2_per_objfile
6560 = get_dwarf2_per_objfile (objfile
);
6562 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6563 if (dwarf2_per_objfile
->debug_names_table
)
6565 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6567 /* Note: It doesn't matter what we pass for block_index here. */
6568 dw2_debug_names_iterator
iter (map
, false /* want_specific_block */,
6569 GLOBAL_BLOCK
, VAR_DOMAIN
, func_name
);
6571 struct dwarf2_per_cu_data
*per_cu
;
6572 while ((per_cu
= iter
.next ()) != NULL
)
6573 dw2_instantiate_symtab (per_cu
);
6578 dw2_debug_names_expand_symtabs_matching
6579 (struct objfile
*objfile
,
6580 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6581 const lookup_name_info
&lookup_name
,
6582 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6583 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6584 enum search_domain kind
)
6586 struct dwarf2_per_objfile
*dwarf2_per_objfile
6587 = get_dwarf2_per_objfile (objfile
);
6589 /* debug_names_table is NULL if OBJF_READNOW. */
6590 if (!dwarf2_per_objfile
->debug_names_table
)
6593 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6595 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6597 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6599 kind
, [&] (offset_type namei
)
6601 /* The name was matched, now expand corresponding CUs that were
6603 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6605 struct dwarf2_per_cu_data
*per_cu
;
6606 while ((per_cu
= iter
.next ()) != NULL
)
6607 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6612 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6615 dw2_find_last_source_symtab
,
6616 dw2_forget_cached_source_info
,
6617 dw2_map_symtabs_matching_filename
,
6618 dw2_debug_names_lookup_symbol
,
6620 dw2_debug_names_dump
,
6622 dw2_debug_names_expand_symtabs_for_function
,
6623 dw2_expand_all_symtabs
,
6624 dw2_expand_symtabs_with_fullname
,
6625 dw2_map_matching_symbols
,
6626 dw2_debug_names_expand_symtabs_matching
,
6627 dw2_find_pc_sect_compunit_symtab
,
6629 dw2_map_symbol_filenames
6632 /* See symfile.h. */
6635 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6637 struct dwarf2_per_objfile
*dwarf2_per_objfile
6638 = get_dwarf2_per_objfile (objfile
);
6640 /* If we're about to read full symbols, don't bother with the
6641 indices. In this case we also don't care if some other debug
6642 format is making psymtabs, because they are all about to be
6644 if ((objfile
->flags
& OBJF_READNOW
))
6648 dwarf2_per_objfile
->using_index
= 1;
6649 create_all_comp_units (dwarf2_per_objfile
);
6650 create_all_type_units (dwarf2_per_objfile
);
6651 dwarf2_per_objfile
->quick_file_names_table
=
6652 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
6654 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
6655 + dwarf2_per_objfile
->n_type_units
); ++i
)
6657 dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
6659 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6660 struct dwarf2_per_cu_quick_data
);
6663 /* Return 1 so that gdb sees the "quick" functions. However,
6664 these functions will be no-ops because we will have expanded
6666 *index_kind
= dw_index_kind::GDB_INDEX
;
6670 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6672 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6676 if (dwarf2_read_index (objfile
))
6678 *index_kind
= dw_index_kind::GDB_INDEX
;
6687 /* Build a partial symbol table. */
6690 dwarf2_build_psymtabs (struct objfile
*objfile
)
6692 struct dwarf2_per_objfile
*dwarf2_per_objfile
6693 = get_dwarf2_per_objfile (objfile
);
6695 if (objfile
->global_psymbols
.capacity () == 0
6696 && objfile
->static_psymbols
.capacity () == 0)
6697 init_psymbol_list (objfile
, 1024);
6701 /* This isn't really ideal: all the data we allocate on the
6702 objfile's obstack is still uselessly kept around. However,
6703 freeing it seems unsafe. */
6704 psymtab_discarder
psymtabs (objfile
);
6705 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6708 CATCH (except
, RETURN_MASK_ERROR
)
6710 exception_print (gdb_stderr
, except
);
6715 /* Return the total length of the CU described by HEADER. */
6718 get_cu_length (const struct comp_unit_head
*header
)
6720 return header
->initial_length_size
+ header
->length
;
6723 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6726 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6728 sect_offset bottom
= cu_header
->sect_off
;
6729 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6731 return sect_off
>= bottom
&& sect_off
< top
;
6734 /* Find the base address of the compilation unit for range lists and
6735 location lists. It will normally be specified by DW_AT_low_pc.
6736 In DWARF-3 draft 4, the base address could be overridden by
6737 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6738 compilation units with discontinuous ranges. */
6741 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6743 struct attribute
*attr
;
6746 cu
->base_address
= 0;
6748 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6751 cu
->base_address
= attr_value_as_address (attr
);
6756 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6759 cu
->base_address
= attr_value_as_address (attr
);
6765 /* Read in the comp unit header information from the debug_info at info_ptr.
6766 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6767 NOTE: This leaves members offset, first_die_offset to be filled in
6770 static const gdb_byte
*
6771 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6772 const gdb_byte
*info_ptr
,
6773 struct dwarf2_section_info
*section
,
6774 rcuh_kind section_kind
)
6777 unsigned int bytes_read
;
6778 const char *filename
= get_section_file_name (section
);
6779 bfd
*abfd
= get_section_bfd_owner (section
);
6781 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6782 cu_header
->initial_length_size
= bytes_read
;
6783 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6784 info_ptr
+= bytes_read
;
6785 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6787 if (cu_header
->version
< 5)
6788 switch (section_kind
)
6790 case rcuh_kind::COMPILE
:
6791 cu_header
->unit_type
= DW_UT_compile
;
6793 case rcuh_kind::TYPE
:
6794 cu_header
->unit_type
= DW_UT_type
;
6797 internal_error (__FILE__
, __LINE__
,
6798 _("read_comp_unit_head: invalid section_kind"));
6802 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6803 (read_1_byte (abfd
, info_ptr
));
6805 switch (cu_header
->unit_type
)
6808 if (section_kind
!= rcuh_kind::COMPILE
)
6809 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6810 "(is DW_UT_compile, should be DW_UT_type) [in module %s]"),
6814 section_kind
= rcuh_kind::TYPE
;
6817 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6818 "(is %d, should be %d or %d) [in module %s]"),
6819 cu_header
->unit_type
, DW_UT_compile
, DW_UT_type
, filename
);
6822 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6825 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6828 info_ptr
+= bytes_read
;
6829 if (cu_header
->version
< 5)
6831 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6834 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6835 if (signed_addr
< 0)
6836 internal_error (__FILE__
, __LINE__
,
6837 _("read_comp_unit_head: dwarf from non elf file"));
6838 cu_header
->signed_addr_p
= signed_addr
;
6840 if (section_kind
== rcuh_kind::TYPE
)
6842 LONGEST type_offset
;
6844 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6847 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6848 info_ptr
+= bytes_read
;
6849 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6850 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6851 error (_("Dwarf Error: Too big type_offset in compilation unit "
6852 "header (is %s) [in module %s]"), plongest (type_offset
),
6859 /* Helper function that returns the proper abbrev section for
6862 static struct dwarf2_section_info
*
6863 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6865 struct dwarf2_section_info
*abbrev
;
6866 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6868 if (this_cu
->is_dwz
)
6869 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6871 abbrev
= &dwarf2_per_objfile
->abbrev
;
6876 /* Subroutine of read_and_check_comp_unit_head and
6877 read_and_check_type_unit_head to simplify them.
6878 Perform various error checking on the header. */
6881 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6882 struct comp_unit_head
*header
,
6883 struct dwarf2_section_info
*section
,
6884 struct dwarf2_section_info
*abbrev_section
)
6886 const char *filename
= get_section_file_name (section
);
6888 if (header
->version
< 2 || header
->version
> 5)
6889 error (_("Dwarf Error: wrong version in compilation unit header "
6890 "(is %d, should be 2, 3, 4 or 5) [in module %s]"), header
->version
,
6893 if (to_underlying (header
->abbrev_sect_off
)
6894 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6895 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6896 "(offset %s + 6) [in module %s]"),
6897 sect_offset_str (header
->abbrev_sect_off
),
6898 sect_offset_str (header
->sect_off
),
6901 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6902 avoid potential 32-bit overflow. */
6903 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6905 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6906 "(offset %s + 0) [in module %s]"),
6907 header
->length
, sect_offset_str (header
->sect_off
),
6911 /* Read in a CU/TU header and perform some basic error checking.
6912 The contents of the header are stored in HEADER.
6913 The result is a pointer to the start of the first DIE. */
6915 static const gdb_byte
*
6916 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6917 struct comp_unit_head
*header
,
6918 struct dwarf2_section_info
*section
,
6919 struct dwarf2_section_info
*abbrev_section
,
6920 const gdb_byte
*info_ptr
,
6921 rcuh_kind section_kind
)
6923 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6925 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6927 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6929 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6931 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6937 /* Fetch the abbreviation table offset from a comp or type unit header. */
6940 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6941 struct dwarf2_section_info
*section
,
6942 sect_offset sect_off
)
6944 bfd
*abfd
= get_section_bfd_owner (section
);
6945 const gdb_byte
*info_ptr
;
6946 unsigned int initial_length_size
, offset_size
;
6949 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6950 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6951 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6952 offset_size
= initial_length_size
== 4 ? 4 : 8;
6953 info_ptr
+= initial_length_size
;
6955 version
= read_2_bytes (abfd
, info_ptr
);
6959 /* Skip unit type and address size. */
6963 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6966 /* Allocate a new partial symtab for file named NAME and mark this new
6967 partial symtab as being an include of PST. */
6970 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6971 struct objfile
*objfile
)
6973 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6975 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6977 /* It shares objfile->objfile_obstack. */
6978 subpst
->dirname
= pst
->dirname
;
6981 subpst
->textlow
= 0;
6982 subpst
->texthigh
= 0;
6984 subpst
->dependencies
6985 = XOBNEW (&objfile
->objfile_obstack
, struct partial_symtab
*);
6986 subpst
->dependencies
[0] = pst
;
6987 subpst
->number_of_dependencies
= 1;
6989 subpst
->globals_offset
= 0;
6990 subpst
->n_global_syms
= 0;
6991 subpst
->statics_offset
= 0;
6992 subpst
->n_static_syms
= 0;
6993 subpst
->compunit_symtab
= NULL
;
6994 subpst
->read_symtab
= pst
->read_symtab
;
6997 /* No private part is necessary for include psymtabs. This property
6998 can be used to differentiate between such include psymtabs and
6999 the regular ones. */
7000 subpst
->read_symtab_private
= NULL
;
7003 /* Read the Line Number Program data and extract the list of files
7004 included by the source file represented by PST. Build an include
7005 partial symtab for each of these included files. */
7008 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
7009 struct die_info
*die
,
7010 struct partial_symtab
*pst
)
7013 struct attribute
*attr
;
7015 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
7017 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
7019 return; /* No linetable, so no includes. */
7021 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
7022 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
, pst
->textlow
, 1);
7026 hash_signatured_type (const void *item
)
7028 const struct signatured_type
*sig_type
7029 = (const struct signatured_type
*) item
;
7031 /* This drops the top 32 bits of the signature, but is ok for a hash. */
7032 return sig_type
->signature
;
7036 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
7038 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
7039 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
7041 return lhs
->signature
== rhs
->signature
;
7044 /* Allocate a hash table for signatured types. */
7047 allocate_signatured_type_table (struct objfile
*objfile
)
7049 return htab_create_alloc_ex (41,
7050 hash_signatured_type
,
7053 &objfile
->objfile_obstack
,
7054 hashtab_obstack_allocate
,
7055 dummy_obstack_deallocate
);
7058 /* A helper function to add a signatured type CU to a table. */
7061 add_signatured_type_cu_to_table (void **slot
, void *datum
)
7063 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
7064 struct signatured_type
***datap
= (struct signatured_type
***) datum
;
7072 /* A helper for create_debug_types_hash_table. Read types from SECTION
7073 and fill them into TYPES_HTAB. It will process only type units,
7074 therefore DW_UT_type. */
7077 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7078 struct dwo_file
*dwo_file
,
7079 dwarf2_section_info
*section
, htab_t
&types_htab
,
7080 rcuh_kind section_kind
)
7082 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7083 struct dwarf2_section_info
*abbrev_section
;
7085 const gdb_byte
*info_ptr
, *end_ptr
;
7087 abbrev_section
= (dwo_file
!= NULL
7088 ? &dwo_file
->sections
.abbrev
7089 : &dwarf2_per_objfile
->abbrev
);
7091 if (dwarf_read_debug
)
7092 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
7093 get_section_name (section
),
7094 get_section_file_name (abbrev_section
));
7096 dwarf2_read_section (objfile
, section
);
7097 info_ptr
= section
->buffer
;
7099 if (info_ptr
== NULL
)
7102 /* We can't set abfd until now because the section may be empty or
7103 not present, in which case the bfd is unknown. */
7104 abfd
= get_section_bfd_owner (section
);
7106 /* We don't use init_cutu_and_read_dies_simple, or some such, here
7107 because we don't need to read any dies: the signature is in the
7110 end_ptr
= info_ptr
+ section
->size
;
7111 while (info_ptr
< end_ptr
)
7113 struct signatured_type
*sig_type
;
7114 struct dwo_unit
*dwo_tu
;
7116 const gdb_byte
*ptr
= info_ptr
;
7117 struct comp_unit_head header
;
7118 unsigned int length
;
7120 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
7122 /* Initialize it due to a false compiler warning. */
7123 header
.signature
= -1;
7124 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
7126 /* We need to read the type's signature in order to build the hash
7127 table, but we don't need anything else just yet. */
7129 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
7130 abbrev_section
, ptr
, section_kind
);
7132 length
= get_cu_length (&header
);
7134 /* Skip dummy type units. */
7135 if (ptr
>= info_ptr
+ length
7136 || peek_abbrev_code (abfd
, ptr
) == 0
7137 || header
.unit_type
!= DW_UT_type
)
7143 if (types_htab
== NULL
)
7146 types_htab
= allocate_dwo_unit_table (objfile
);
7148 types_htab
= allocate_signatured_type_table (objfile
);
7154 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7156 dwo_tu
->dwo_file
= dwo_file
;
7157 dwo_tu
->signature
= header
.signature
;
7158 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7159 dwo_tu
->section
= section
;
7160 dwo_tu
->sect_off
= sect_off
;
7161 dwo_tu
->length
= length
;
7165 /* N.B.: type_offset is not usable if this type uses a DWO file.
7166 The real type_offset is in the DWO file. */
7168 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7169 struct signatured_type
);
7170 sig_type
->signature
= header
.signature
;
7171 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
7172 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7173 sig_type
->per_cu
.is_debug_types
= 1;
7174 sig_type
->per_cu
.section
= section
;
7175 sig_type
->per_cu
.sect_off
= sect_off
;
7176 sig_type
->per_cu
.length
= length
;
7179 slot
= htab_find_slot (types_htab
,
7180 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
7182 gdb_assert (slot
!= NULL
);
7185 sect_offset dup_sect_off
;
7189 const struct dwo_unit
*dup_tu
7190 = (const struct dwo_unit
*) *slot
;
7192 dup_sect_off
= dup_tu
->sect_off
;
7196 const struct signatured_type
*dup_tu
7197 = (const struct signatured_type
*) *slot
;
7199 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
7202 complaint (&symfile_complaints
,
7203 _("debug type entry at offset %s is duplicate to"
7204 " the entry at offset %s, signature %s"),
7205 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
7206 hex_string (header
.signature
));
7208 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
7210 if (dwarf_read_debug
> 1)
7211 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
7212 sect_offset_str (sect_off
),
7213 hex_string (header
.signature
));
7219 /* Create the hash table of all entries in the .debug_types
7220 (or .debug_types.dwo) section(s).
7221 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
7222 otherwise it is NULL.
7224 The result is a pointer to the hash table or NULL if there are no types.
7226 Note: This function processes DWO files only, not DWP files. */
7229 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7230 struct dwo_file
*dwo_file
,
7231 VEC (dwarf2_section_info_def
) *types
,
7235 struct dwarf2_section_info
*section
;
7237 if (VEC_empty (dwarf2_section_info_def
, types
))
7241 VEC_iterate (dwarf2_section_info_def
, types
, ix
, section
);
7243 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, section
,
7244 types_htab
, rcuh_kind::TYPE
);
7247 /* Create the hash table of all entries in the .debug_types section,
7248 and initialize all_type_units.
7249 The result is zero if there is an error (e.g. missing .debug_types section),
7250 otherwise non-zero. */
7253 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7255 htab_t types_htab
= NULL
;
7256 struct signatured_type
**iter
;
7258 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
7259 &dwarf2_per_objfile
->info
, types_htab
,
7260 rcuh_kind::COMPILE
);
7261 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
7262 dwarf2_per_objfile
->types
, types_htab
);
7263 if (types_htab
== NULL
)
7265 dwarf2_per_objfile
->signatured_types
= NULL
;
7269 dwarf2_per_objfile
->signatured_types
= types_htab
;
7271 dwarf2_per_objfile
->n_type_units
7272 = dwarf2_per_objfile
->n_allocated_type_units
7273 = htab_elements (types_htab
);
7274 dwarf2_per_objfile
->all_type_units
=
7275 XNEWVEC (struct signatured_type
*, dwarf2_per_objfile
->n_type_units
);
7276 iter
= &dwarf2_per_objfile
->all_type_units
[0];
7277 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
, &iter
);
7278 gdb_assert (iter
- &dwarf2_per_objfile
->all_type_units
[0]
7279 == dwarf2_per_objfile
->n_type_units
);
7284 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
7285 If SLOT is non-NULL, it is the entry to use in the hash table.
7286 Otherwise we find one. */
7288 static struct signatured_type
*
7289 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
7292 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7293 int n_type_units
= dwarf2_per_objfile
->n_type_units
;
7294 struct signatured_type
*sig_type
;
7296 gdb_assert (n_type_units
<= dwarf2_per_objfile
->n_allocated_type_units
);
7298 if (n_type_units
> dwarf2_per_objfile
->n_allocated_type_units
)
7300 if (dwarf2_per_objfile
->n_allocated_type_units
== 0)
7301 dwarf2_per_objfile
->n_allocated_type_units
= 1;
7302 dwarf2_per_objfile
->n_allocated_type_units
*= 2;
7303 dwarf2_per_objfile
->all_type_units
7304 = XRESIZEVEC (struct signatured_type
*,
7305 dwarf2_per_objfile
->all_type_units
,
7306 dwarf2_per_objfile
->n_allocated_type_units
);
7307 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
7309 dwarf2_per_objfile
->n_type_units
= n_type_units
;
7311 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7312 struct signatured_type
);
7313 dwarf2_per_objfile
->all_type_units
[n_type_units
- 1] = sig_type
;
7314 sig_type
->signature
= sig
;
7315 sig_type
->per_cu
.is_debug_types
= 1;
7316 if (dwarf2_per_objfile
->using_index
)
7318 sig_type
->per_cu
.v
.quick
=
7319 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7320 struct dwarf2_per_cu_quick_data
);
7325 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7328 gdb_assert (*slot
== NULL
);
7330 /* The rest of sig_type must be filled in by the caller. */
7334 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7335 Fill in SIG_ENTRY with DWO_ENTRY. */
7338 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7339 struct signatured_type
*sig_entry
,
7340 struct dwo_unit
*dwo_entry
)
7342 /* Make sure we're not clobbering something we don't expect to. */
7343 gdb_assert (! sig_entry
->per_cu
.queued
);
7344 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7345 if (dwarf2_per_objfile
->using_index
)
7347 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7348 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7351 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7352 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7353 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7354 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7355 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7357 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7358 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7359 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7360 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7361 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7362 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7363 sig_entry
->dwo_unit
= dwo_entry
;
7366 /* Subroutine of lookup_signatured_type.
7367 If we haven't read the TU yet, create the signatured_type data structure
7368 for a TU to be read in directly from a DWO file, bypassing the stub.
7369 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7370 using .gdb_index, then when reading a CU we want to stay in the DWO file
7371 containing that CU. Otherwise we could end up reading several other DWO
7372 files (due to comdat folding) to process the transitive closure of all the
7373 mentioned TUs, and that can be slow. The current DWO file will have every
7374 type signature that it needs.
7375 We only do this for .gdb_index because in the psymtab case we already have
7376 to read all the DWOs to build the type unit groups. */
7378 static struct signatured_type
*
7379 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7381 struct dwarf2_per_objfile
*dwarf2_per_objfile
7382 = cu
->per_cu
->dwarf2_per_objfile
;
7383 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7384 struct dwo_file
*dwo_file
;
7385 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7386 struct signatured_type find_sig_entry
, *sig_entry
;
7389 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7391 /* If TU skeletons have been removed then we may not have read in any
7393 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7395 dwarf2_per_objfile
->signatured_types
7396 = allocate_signatured_type_table (objfile
);
7399 /* We only ever need to read in one copy of a signatured type.
7400 Use the global signatured_types array to do our own comdat-folding
7401 of types. If this is the first time we're reading this TU, and
7402 the TU has an entry in .gdb_index, replace the recorded data from
7403 .gdb_index with this TU. */
7405 find_sig_entry
.signature
= sig
;
7406 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7407 &find_sig_entry
, INSERT
);
7408 sig_entry
= (struct signatured_type
*) *slot
;
7410 /* We can get here with the TU already read, *or* in the process of being
7411 read. Don't reassign the global entry to point to this DWO if that's
7412 the case. Also note that if the TU is already being read, it may not
7413 have come from a DWO, the program may be a mix of Fission-compiled
7414 code and non-Fission-compiled code. */
7416 /* Have we already tried to read this TU?
7417 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7418 needn't exist in the global table yet). */
7419 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7422 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7423 dwo_unit of the TU itself. */
7424 dwo_file
= cu
->dwo_unit
->dwo_file
;
7426 /* Ok, this is the first time we're reading this TU. */
7427 if (dwo_file
->tus
== NULL
)
7429 find_dwo_entry
.signature
= sig
;
7430 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7431 if (dwo_entry
== NULL
)
7434 /* If the global table doesn't have an entry for this TU, add one. */
7435 if (sig_entry
== NULL
)
7436 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7438 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7439 sig_entry
->per_cu
.tu_read
= 1;
7443 /* Subroutine of lookup_signatured_type.
7444 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7445 then try the DWP file. If the TU stub (skeleton) has been removed then
7446 it won't be in .gdb_index. */
7448 static struct signatured_type
*
7449 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7451 struct dwarf2_per_objfile
*dwarf2_per_objfile
7452 = cu
->per_cu
->dwarf2_per_objfile
;
7453 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7454 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7455 struct dwo_unit
*dwo_entry
;
7456 struct signatured_type find_sig_entry
, *sig_entry
;
7459 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7460 gdb_assert (dwp_file
!= NULL
);
7462 /* If TU skeletons have been removed then we may not have read in any
7464 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7466 dwarf2_per_objfile
->signatured_types
7467 = allocate_signatured_type_table (objfile
);
7470 find_sig_entry
.signature
= sig
;
7471 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7472 &find_sig_entry
, INSERT
);
7473 sig_entry
= (struct signatured_type
*) *slot
;
7475 /* Have we already tried to read this TU?
7476 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7477 needn't exist in the global table yet). */
7478 if (sig_entry
!= NULL
)
7481 if (dwp_file
->tus
== NULL
)
7483 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7484 sig
, 1 /* is_debug_types */);
7485 if (dwo_entry
== NULL
)
7488 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7489 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7494 /* Lookup a signature based type for DW_FORM_ref_sig8.
7495 Returns NULL if signature SIG is not present in the table.
7496 It is up to the caller to complain about this. */
7498 static struct signatured_type
*
7499 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7501 struct dwarf2_per_objfile
*dwarf2_per_objfile
7502 = cu
->per_cu
->dwarf2_per_objfile
;
7505 && dwarf2_per_objfile
->using_index
)
7507 /* We're in a DWO/DWP file, and we're using .gdb_index.
7508 These cases require special processing. */
7509 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7510 return lookup_dwo_signatured_type (cu
, sig
);
7512 return lookup_dwp_signatured_type (cu
, sig
);
7516 struct signatured_type find_entry
, *entry
;
7518 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7520 find_entry
.signature
= sig
;
7521 entry
= ((struct signatured_type
*)
7522 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7527 /* Low level DIE reading support. */
7529 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7532 init_cu_die_reader (struct die_reader_specs
*reader
,
7533 struct dwarf2_cu
*cu
,
7534 struct dwarf2_section_info
*section
,
7535 struct dwo_file
*dwo_file
,
7536 struct abbrev_table
*abbrev_table
)
7538 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7539 reader
->abfd
= get_section_bfd_owner (section
);
7541 reader
->dwo_file
= dwo_file
;
7542 reader
->die_section
= section
;
7543 reader
->buffer
= section
->buffer
;
7544 reader
->buffer_end
= section
->buffer
+ section
->size
;
7545 reader
->comp_dir
= NULL
;
7546 reader
->abbrev_table
= abbrev_table
;
7549 /* Subroutine of init_cutu_and_read_dies to simplify it.
7550 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7551 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7554 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7555 from it to the DIE in the DWO. If NULL we are skipping the stub.
7556 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7557 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7558 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7559 STUB_COMP_DIR may be non-NULL.
7560 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7561 are filled in with the info of the DIE from the DWO file.
7562 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7563 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7564 kept around for at least as long as *RESULT_READER.
7566 The result is non-zero if a valid (non-dummy) DIE was found. */
7569 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7570 struct dwo_unit
*dwo_unit
,
7571 struct die_info
*stub_comp_unit_die
,
7572 const char *stub_comp_dir
,
7573 struct die_reader_specs
*result_reader
,
7574 const gdb_byte
**result_info_ptr
,
7575 struct die_info
**result_comp_unit_die
,
7576 int *result_has_children
,
7577 abbrev_table_up
*result_dwo_abbrev_table
)
7579 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7580 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7581 struct dwarf2_cu
*cu
= this_cu
->cu
;
7583 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7584 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7585 int i
,num_extra_attrs
;
7586 struct dwarf2_section_info
*dwo_abbrev_section
;
7587 struct attribute
*attr
;
7588 struct die_info
*comp_unit_die
;
7590 /* At most one of these may be provided. */
7591 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7593 /* These attributes aren't processed until later:
7594 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7595 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7596 referenced later. However, these attributes are found in the stub
7597 which we won't have later. In order to not impose this complication
7598 on the rest of the code, we read them here and copy them to the
7607 if (stub_comp_unit_die
!= NULL
)
7609 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7611 if (! this_cu
->is_debug_types
)
7612 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7613 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7614 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7615 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7616 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7618 /* There should be a DW_AT_addr_base attribute here (if needed).
7619 We need the value before we can process DW_FORM_GNU_addr_index. */
7621 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7623 cu
->addr_base
= DW_UNSND (attr
);
7625 /* There should be a DW_AT_ranges_base attribute here (if needed).
7626 We need the value before we can process DW_AT_ranges. */
7627 cu
->ranges_base
= 0;
7628 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7630 cu
->ranges_base
= DW_UNSND (attr
);
7632 else if (stub_comp_dir
!= NULL
)
7634 /* Reconstruct the comp_dir attribute to simplify the code below. */
7635 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7636 comp_dir
->name
= DW_AT_comp_dir
;
7637 comp_dir
->form
= DW_FORM_string
;
7638 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7639 DW_STRING (comp_dir
) = stub_comp_dir
;
7642 /* Set up for reading the DWO CU/TU. */
7643 cu
->dwo_unit
= dwo_unit
;
7644 dwarf2_section_info
*section
= dwo_unit
->section
;
7645 dwarf2_read_section (objfile
, section
);
7646 abfd
= get_section_bfd_owner (section
);
7647 begin_info_ptr
= info_ptr
= (section
->buffer
7648 + to_underlying (dwo_unit
->sect_off
));
7649 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7651 if (this_cu
->is_debug_types
)
7653 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7655 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7656 &cu
->header
, section
,
7658 info_ptr
, rcuh_kind::TYPE
);
7659 /* This is not an assert because it can be caused by bad debug info. */
7660 if (sig_type
->signature
!= cu
->header
.signature
)
7662 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7663 " TU at offset %s [in module %s]"),
7664 hex_string (sig_type
->signature
),
7665 hex_string (cu
->header
.signature
),
7666 sect_offset_str (dwo_unit
->sect_off
),
7667 bfd_get_filename (abfd
));
7669 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7670 /* For DWOs coming from DWP files, we don't know the CU length
7671 nor the type's offset in the TU until now. */
7672 dwo_unit
->length
= get_cu_length (&cu
->header
);
7673 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7675 /* Establish the type offset that can be used to lookup the type.
7676 For DWO files, we don't know it until now. */
7677 sig_type
->type_offset_in_section
7678 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7682 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7683 &cu
->header
, section
,
7685 info_ptr
, rcuh_kind::COMPILE
);
7686 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7687 /* For DWOs coming from DWP files, we don't know the CU length
7689 dwo_unit
->length
= get_cu_length (&cu
->header
);
7692 *result_dwo_abbrev_table
7693 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7694 cu
->header
.abbrev_sect_off
);
7695 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7696 result_dwo_abbrev_table
->get ());
7698 /* Read in the die, but leave space to copy over the attributes
7699 from the stub. This has the benefit of simplifying the rest of
7700 the code - all the work to maintain the illusion of a single
7701 DW_TAG_{compile,type}_unit DIE is done here. */
7702 num_extra_attrs
= ((stmt_list
!= NULL
)
7706 + (comp_dir
!= NULL
));
7707 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7708 result_has_children
, num_extra_attrs
);
7710 /* Copy over the attributes from the stub to the DIE we just read in. */
7711 comp_unit_die
= *result_comp_unit_die
;
7712 i
= comp_unit_die
->num_attrs
;
7713 if (stmt_list
!= NULL
)
7714 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7716 comp_unit_die
->attrs
[i
++] = *low_pc
;
7717 if (high_pc
!= NULL
)
7718 comp_unit_die
->attrs
[i
++] = *high_pc
;
7720 comp_unit_die
->attrs
[i
++] = *ranges
;
7721 if (comp_dir
!= NULL
)
7722 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7723 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7725 if (dwarf_die_debug
)
7727 fprintf_unfiltered (gdb_stdlog
,
7728 "Read die from %s@0x%x of %s:\n",
7729 get_section_name (section
),
7730 (unsigned) (begin_info_ptr
- section
->buffer
),
7731 bfd_get_filename (abfd
));
7732 dump_die (comp_unit_die
, dwarf_die_debug
);
7735 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7736 TUs by skipping the stub and going directly to the entry in the DWO file.
7737 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7738 to get it via circuitous means. Blech. */
7739 if (comp_dir
!= NULL
)
7740 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7742 /* Skip dummy compilation units. */
7743 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7744 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7747 *result_info_ptr
= info_ptr
;
7751 /* Subroutine of init_cutu_and_read_dies to simplify it.
7752 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7753 Returns NULL if the specified DWO unit cannot be found. */
7755 static struct dwo_unit
*
7756 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7757 struct die_info
*comp_unit_die
)
7759 struct dwarf2_cu
*cu
= this_cu
->cu
;
7761 struct dwo_unit
*dwo_unit
;
7762 const char *comp_dir
, *dwo_name
;
7764 gdb_assert (cu
!= NULL
);
7766 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7767 dwo_name
= dwarf2_string_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
7768 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7770 if (this_cu
->is_debug_types
)
7772 struct signatured_type
*sig_type
;
7774 /* Since this_cu is the first member of struct signatured_type,
7775 we can go from a pointer to one to a pointer to the other. */
7776 sig_type
= (struct signatured_type
*) this_cu
;
7777 signature
= sig_type
->signature
;
7778 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7782 struct attribute
*attr
;
7784 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7786 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7788 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7789 signature
= DW_UNSND (attr
);
7790 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7797 /* Subroutine of init_cutu_and_read_dies to simplify it.
7798 See it for a description of the parameters.
7799 Read a TU directly from a DWO file, bypassing the stub. */
7802 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7803 int use_existing_cu
, int keep
,
7804 die_reader_func_ftype
*die_reader_func
,
7807 std::unique_ptr
<dwarf2_cu
> new_cu
;
7808 struct signatured_type
*sig_type
;
7809 struct die_reader_specs reader
;
7810 const gdb_byte
*info_ptr
;
7811 struct die_info
*comp_unit_die
;
7813 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7815 /* Verify we can do the following downcast, and that we have the
7817 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7818 sig_type
= (struct signatured_type
*) this_cu
;
7819 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7821 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7823 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7824 /* There's no need to do the rereading_dwo_cu handling that
7825 init_cutu_and_read_dies does since we don't read the stub. */
7829 /* If !use_existing_cu, this_cu->cu must be NULL. */
7830 gdb_assert (this_cu
->cu
== NULL
);
7831 new_cu
.reset (new dwarf2_cu (this_cu
));
7834 /* A future optimization, if needed, would be to use an existing
7835 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7836 could share abbrev tables. */
7838 /* The abbreviation table used by READER, this must live at least as long as
7840 abbrev_table_up dwo_abbrev_table
;
7842 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7843 NULL
/* stub_comp_unit_die */,
7844 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7846 &comp_unit_die
, &has_children
,
7847 &dwo_abbrev_table
) == 0)
7853 /* All the "real" work is done here. */
7854 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7856 /* This duplicates the code in init_cutu_and_read_dies,
7857 but the alternative is making the latter more complex.
7858 This function is only for the special case of using DWO files directly:
7859 no point in overly complicating the general case just to handle this. */
7860 if (new_cu
!= NULL
&& keep
)
7862 /* Link this CU into read_in_chain. */
7863 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7864 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7865 /* The chain owns it now. */
7870 /* Initialize a CU (or TU) and read its DIEs.
7871 If the CU defers to a DWO file, read the DWO file as well.
7873 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7874 Otherwise the table specified in the comp unit header is read in and used.
7875 This is an optimization for when we already have the abbrev table.
7877 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7878 Otherwise, a new CU is allocated with xmalloc.
7880 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7881 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7883 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7884 linker) then DIE_READER_FUNC will not get called. */
7887 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7888 struct abbrev_table
*abbrev_table
,
7889 int use_existing_cu
, int keep
,
7890 die_reader_func_ftype
*die_reader_func
,
7893 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7895 struct dwarf2_section_info
*section
= this_cu
->section
;
7896 bfd
*abfd
= get_section_bfd_owner (section
);
7897 struct dwarf2_cu
*cu
;
7898 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7899 struct die_reader_specs reader
;
7900 struct die_info
*comp_unit_die
;
7902 struct attribute
*attr
;
7903 struct signatured_type
*sig_type
= NULL
;
7904 struct dwarf2_section_info
*abbrev_section
;
7905 /* Non-zero if CU currently points to a DWO file and we need to
7906 reread it. When this happens we need to reread the skeleton die
7907 before we can reread the DWO file (this only applies to CUs, not TUs). */
7908 int rereading_dwo_cu
= 0;
7910 if (dwarf_die_debug
)
7911 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7912 this_cu
->is_debug_types
? "type" : "comp",
7913 sect_offset_str (this_cu
->sect_off
));
7915 if (use_existing_cu
)
7918 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7919 file (instead of going through the stub), short-circuit all of this. */
7920 if (this_cu
->reading_dwo_directly
)
7922 /* Narrow down the scope of possibilities to have to understand. */
7923 gdb_assert (this_cu
->is_debug_types
);
7924 gdb_assert (abbrev_table
== NULL
);
7925 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7926 die_reader_func
, data
);
7930 /* This is cheap if the section is already read in. */
7931 dwarf2_read_section (objfile
, section
);
7933 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7935 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7937 std::unique_ptr
<dwarf2_cu
> new_cu
;
7938 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7941 /* If this CU is from a DWO file we need to start over, we need to
7942 refetch the attributes from the skeleton CU.
7943 This could be optimized by retrieving those attributes from when we
7944 were here the first time: the previous comp_unit_die was stored in
7945 comp_unit_obstack. But there's no data yet that we need this
7947 if (cu
->dwo_unit
!= NULL
)
7948 rereading_dwo_cu
= 1;
7952 /* If !use_existing_cu, this_cu->cu must be NULL. */
7953 gdb_assert (this_cu
->cu
== NULL
);
7954 new_cu
.reset (new dwarf2_cu (this_cu
));
7958 /* Get the header. */
7959 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7961 /* We already have the header, there's no need to read it in again. */
7962 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7966 if (this_cu
->is_debug_types
)
7968 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7969 &cu
->header
, section
,
7970 abbrev_section
, info_ptr
,
7973 /* Since per_cu is the first member of struct signatured_type,
7974 we can go from a pointer to one to a pointer to the other. */
7975 sig_type
= (struct signatured_type
*) this_cu
;
7976 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7977 gdb_assert (sig_type
->type_offset_in_tu
7978 == cu
->header
.type_cu_offset_in_tu
);
7979 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7981 /* LENGTH has not been set yet for type units if we're
7982 using .gdb_index. */
7983 this_cu
->length
= get_cu_length (&cu
->header
);
7985 /* Establish the type offset that can be used to lookup the type. */
7986 sig_type
->type_offset_in_section
=
7987 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7989 this_cu
->dwarf_version
= cu
->header
.version
;
7993 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7994 &cu
->header
, section
,
7997 rcuh_kind::COMPILE
);
7999 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
8000 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
8001 this_cu
->dwarf_version
= cu
->header
.version
;
8005 /* Skip dummy compilation units. */
8006 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8007 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8010 /* If we don't have them yet, read the abbrevs for this compilation unit.
8011 And if we need to read them now, make sure they're freed when we're
8012 done (own the table through ABBREV_TABLE_HOLDER). */
8013 abbrev_table_up abbrev_table_holder
;
8014 if (abbrev_table
!= NULL
)
8015 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
8019 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8020 cu
->header
.abbrev_sect_off
);
8021 abbrev_table
= abbrev_table_holder
.get ();
8024 /* Read the top level CU/TU die. */
8025 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
8026 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8028 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
8029 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
8030 table from the DWO file and pass the ownership over to us. It will be
8031 referenced from READER, so we must make sure to free it after we're done
8034 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
8035 DWO CU, that this test will fail (the attribute will not be present). */
8036 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_name
, cu
);
8037 abbrev_table_up dwo_abbrev_table
;
8040 struct dwo_unit
*dwo_unit
;
8041 struct die_info
*dwo_comp_unit_die
;
8045 complaint (&symfile_complaints
,
8046 _("compilation unit with DW_AT_GNU_dwo_name"
8047 " has children (offset %s) [in module %s]"),
8048 sect_offset_str (this_cu
->sect_off
),
8049 bfd_get_filename (abfd
));
8051 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
8052 if (dwo_unit
!= NULL
)
8054 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
8055 comp_unit_die
, NULL
,
8057 &dwo_comp_unit_die
, &has_children
,
8058 &dwo_abbrev_table
) == 0)
8063 comp_unit_die
= dwo_comp_unit_die
;
8067 /* Yikes, we couldn't find the rest of the DIE, we only have
8068 the stub. A complaint has already been logged. There's
8069 not much more we can do except pass on the stub DIE to
8070 die_reader_func. We don't want to throw an error on bad
8075 /* All of the above is setup for this call. Yikes. */
8076 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8078 /* Done, clean up. */
8079 if (new_cu
!= NULL
&& keep
)
8081 /* Link this CU into read_in_chain. */
8082 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
8083 dwarf2_per_objfile
->read_in_chain
= this_cu
;
8084 /* The chain owns it now. */
8089 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
8090 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
8091 to have already done the lookup to find the DWO file).
8093 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
8094 THIS_CU->is_debug_types, but nothing else.
8096 We fill in THIS_CU->length.
8098 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
8099 linker) then DIE_READER_FUNC will not get called.
8101 THIS_CU->cu is always freed when done.
8102 This is done in order to not leave THIS_CU->cu in a state where we have
8103 to care whether it refers to the "main" CU or the DWO CU. */
8106 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
8107 struct dwo_file
*dwo_file
,
8108 die_reader_func_ftype
*die_reader_func
,
8111 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
8112 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8113 struct dwarf2_section_info
*section
= this_cu
->section
;
8114 bfd
*abfd
= get_section_bfd_owner (section
);
8115 struct dwarf2_section_info
*abbrev_section
;
8116 const gdb_byte
*begin_info_ptr
, *info_ptr
;
8117 struct die_reader_specs reader
;
8118 struct die_info
*comp_unit_die
;
8121 if (dwarf_die_debug
)
8122 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
8123 this_cu
->is_debug_types
? "type" : "comp",
8124 sect_offset_str (this_cu
->sect_off
));
8126 gdb_assert (this_cu
->cu
== NULL
);
8128 abbrev_section
= (dwo_file
!= NULL
8129 ? &dwo_file
->sections
.abbrev
8130 : get_abbrev_section_for_cu (this_cu
));
8132 /* This is cheap if the section is already read in. */
8133 dwarf2_read_section (objfile
, section
);
8135 struct dwarf2_cu
cu (this_cu
);
8137 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
8138 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
8139 &cu
.header
, section
,
8140 abbrev_section
, info_ptr
,
8141 (this_cu
->is_debug_types
8143 : rcuh_kind::COMPILE
));
8145 this_cu
->length
= get_cu_length (&cu
.header
);
8147 /* Skip dummy compilation units. */
8148 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
8149 || peek_abbrev_code (abfd
, info_ptr
) == 0)
8152 abbrev_table_up abbrev_table
8153 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
8154 cu
.header
.abbrev_sect_off
);
8156 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
8157 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
8159 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
8162 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
8163 does not lookup the specified DWO file.
8164 This cannot be used to read DWO files.
8166 THIS_CU->cu is always freed when done.
8167 This is done in order to not leave THIS_CU->cu in a state where we have
8168 to care whether it refers to the "main" CU or the DWO CU.
8169 We can revisit this if the data shows there's a performance issue. */
8172 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
8173 die_reader_func_ftype
*die_reader_func
,
8176 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
8179 /* Type Unit Groups.
8181 Type Unit Groups are a way to collapse the set of all TUs (type units) into
8182 a more manageable set. The grouping is done by DW_AT_stmt_list entry
8183 so that all types coming from the same compilation (.o file) are grouped
8184 together. A future step could be to put the types in the same symtab as
8185 the CU the types ultimately came from. */
8188 hash_type_unit_group (const void *item
)
8190 const struct type_unit_group
*tu_group
8191 = (const struct type_unit_group
*) item
;
8193 return hash_stmt_list_entry (&tu_group
->hash
);
8197 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
8199 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
8200 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
8202 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
8205 /* Allocate a hash table for type unit groups. */
8208 allocate_type_unit_groups_table (struct objfile
*objfile
)
8210 return htab_create_alloc_ex (3,
8211 hash_type_unit_group
,
8214 &objfile
->objfile_obstack
,
8215 hashtab_obstack_allocate
,
8216 dummy_obstack_deallocate
);
8219 /* Type units that don't have DW_AT_stmt_list are grouped into their own
8220 partial symtabs. We combine several TUs per psymtab to not let the size
8221 of any one psymtab grow too big. */
8222 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
8223 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
8225 /* Helper routine for get_type_unit_group.
8226 Create the type_unit_group object used to hold one or more TUs. */
8228 static struct type_unit_group
*
8229 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
8231 struct dwarf2_per_objfile
*dwarf2_per_objfile
8232 = cu
->per_cu
->dwarf2_per_objfile
;
8233 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8234 struct dwarf2_per_cu_data
*per_cu
;
8235 struct type_unit_group
*tu_group
;
8237 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8238 struct type_unit_group
);
8239 per_cu
= &tu_group
->per_cu
;
8240 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8242 if (dwarf2_per_objfile
->using_index
)
8244 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
8245 struct dwarf2_per_cu_quick_data
);
8249 unsigned int line_offset
= to_underlying (line_offset_struct
);
8250 struct partial_symtab
*pst
;
8253 /* Give the symtab a useful name for debug purposes. */
8254 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
8255 name
= xstrprintf ("<type_units_%d>",
8256 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
8258 name
= xstrprintf ("<type_units_at_0x%x>", line_offset
);
8260 pst
= create_partial_symtab (per_cu
, name
);
8266 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
8267 tu_group
->hash
.line_sect_off
= line_offset_struct
;
8272 /* Look up the type_unit_group for type unit CU, and create it if necessary.
8273 STMT_LIST is a DW_AT_stmt_list attribute. */
8275 static struct type_unit_group
*
8276 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
8278 struct dwarf2_per_objfile
*dwarf2_per_objfile
8279 = cu
->per_cu
->dwarf2_per_objfile
;
8280 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8281 struct type_unit_group
*tu_group
;
8283 unsigned int line_offset
;
8284 struct type_unit_group type_unit_group_for_lookup
;
8286 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
8288 dwarf2_per_objfile
->type_unit_groups
=
8289 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
8292 /* Do we need to create a new group, or can we use an existing one? */
8296 line_offset
= DW_UNSND (stmt_list
);
8297 ++tu_stats
->nr_symtab_sharers
;
8301 /* Ugh, no stmt_list. Rare, but we have to handle it.
8302 We can do various things here like create one group per TU or
8303 spread them over multiple groups to split up the expansion work.
8304 To avoid worst case scenarios (too many groups or too large groups)
8305 we, umm, group them in bunches. */
8306 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
8307 | (tu_stats
->nr_stmt_less_type_units
8308 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
8309 ++tu_stats
->nr_stmt_less_type_units
;
8312 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
8313 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
8314 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8315 &type_unit_group_for_lookup
, INSERT
);
8318 tu_group
= (struct type_unit_group
*) *slot
;
8319 gdb_assert (tu_group
!= NULL
);
8323 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8324 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8326 ++tu_stats
->nr_symtabs
;
8332 /* Partial symbol tables. */
8334 /* Create a psymtab named NAME and assign it to PER_CU.
8336 The caller must fill in the following details:
8337 dirname, textlow, texthigh. */
8339 static struct partial_symtab
*
8340 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8342 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8343 struct partial_symtab
*pst
;
8345 pst
= start_psymtab_common (objfile
, name
, 0,
8346 objfile
->global_psymbols
,
8347 objfile
->static_psymbols
);
8349 pst
->psymtabs_addrmap_supported
= 1;
8351 /* This is the glue that links PST into GDB's symbol API. */
8352 pst
->read_symtab_private
= per_cu
;
8353 pst
->read_symtab
= dwarf2_read_symtab
;
8354 per_cu
->v
.psymtab
= pst
;
8359 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8362 struct process_psymtab_comp_unit_data
8364 /* True if we are reading a DW_TAG_partial_unit. */
8366 int want_partial_unit
;
8368 /* The "pretend" language that is used if the CU doesn't declare a
8371 enum language pretend_language
;
8374 /* die_reader_func for process_psymtab_comp_unit. */
8377 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8378 const gdb_byte
*info_ptr
,
8379 struct die_info
*comp_unit_die
,
8383 struct dwarf2_cu
*cu
= reader
->cu
;
8384 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8385 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8386 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8388 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8389 struct partial_symtab
*pst
;
8390 enum pc_bounds_kind cu_bounds_kind
;
8391 const char *filename
;
8392 struct process_psymtab_comp_unit_data
*info
8393 = (struct process_psymtab_comp_unit_data
*) data
;
8395 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8398 gdb_assert (! per_cu
->is_debug_types
);
8400 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8402 cu
->list_in_scope
= &file_symbols
;
8404 /* Allocate a new partial symbol table structure. */
8405 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8406 if (filename
== NULL
)
8409 pst
= create_partial_symtab (per_cu
, filename
);
8411 /* This must be done before calling dwarf2_build_include_psymtabs. */
8412 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8414 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8416 dwarf2_find_base_address (comp_unit_die
, cu
);
8418 /* Possibly set the default values of LOWPC and HIGHPC from
8420 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8421 &best_highpc
, cu
, pst
);
8422 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8423 /* Store the contiguous range if it is not empty; it can be empty for
8424 CUs with no code. */
8425 addrmap_set_empty (objfile
->psymtabs_addrmap
,
8426 gdbarch_adjust_dwarf2_addr (gdbarch
,
8427 best_lowpc
+ baseaddr
),
8428 gdbarch_adjust_dwarf2_addr (gdbarch
,
8429 best_highpc
+ baseaddr
) - 1,
8432 /* Check if comp unit has_children.
8433 If so, read the rest of the partial symbols from this comp unit.
8434 If not, there's no more debug_info for this comp unit. */
8437 struct partial_die_info
*first_die
;
8438 CORE_ADDR lowpc
, highpc
;
8440 lowpc
= ((CORE_ADDR
) -1);
8441 highpc
= ((CORE_ADDR
) 0);
8443 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8445 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8446 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8448 /* If we didn't find a lowpc, set it to highpc to avoid
8449 complaints from `maint check'. */
8450 if (lowpc
== ((CORE_ADDR
) -1))
8453 /* If the compilation unit didn't have an explicit address range,
8454 then use the information extracted from its child dies. */
8455 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8458 best_highpc
= highpc
;
8461 pst
->textlow
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
);
8462 pst
->texthigh
= gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
);
8464 end_psymtab_common (objfile
, pst
);
8466 if (!VEC_empty (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
))
8469 int len
= VEC_length (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8470 struct dwarf2_per_cu_data
*iter
;
8472 /* Fill in 'dependencies' here; we fill in 'users' in a
8474 pst
->number_of_dependencies
= len
;
8476 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8478 VEC_iterate (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
8481 pst
->dependencies
[i
] = iter
->v
.psymtab
;
8483 VEC_free (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
);
8486 /* Get the list of files included in the current compilation unit,
8487 and build a psymtab for each of them. */
8488 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8490 if (dwarf_read_debug
)
8492 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8494 fprintf_unfiltered (gdb_stdlog
,
8495 "Psymtab for %s unit @%s: %s - %s"
8496 ", %d global, %d static syms\n",
8497 per_cu
->is_debug_types
? "type" : "comp",
8498 sect_offset_str (per_cu
->sect_off
),
8499 paddress (gdbarch
, pst
->textlow
),
8500 paddress (gdbarch
, pst
->texthigh
),
8501 pst
->n_global_syms
, pst
->n_static_syms
);
8505 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8506 Process compilation unit THIS_CU for a psymtab. */
8509 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8510 int want_partial_unit
,
8511 enum language pretend_language
)
8513 /* If this compilation unit was already read in, free the
8514 cached copy in order to read it in again. This is
8515 necessary because we skipped some symbols when we first
8516 read in the compilation unit (see load_partial_dies).
8517 This problem could be avoided, but the benefit is unclear. */
8518 if (this_cu
->cu
!= NULL
)
8519 free_one_cached_comp_unit (this_cu
);
8521 if (this_cu
->is_debug_types
)
8522 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, build_type_psymtabs_reader
,
8526 process_psymtab_comp_unit_data info
;
8527 info
.want_partial_unit
= want_partial_unit
;
8528 info
.pretend_language
= pretend_language
;
8529 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0,
8530 process_psymtab_comp_unit_reader
, &info
);
8533 /* Age out any secondary CUs. */
8534 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8537 /* Reader function for build_type_psymtabs. */
8540 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8541 const gdb_byte
*info_ptr
,
8542 struct die_info
*type_unit_die
,
8546 struct dwarf2_per_objfile
*dwarf2_per_objfile
8547 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8549 struct dwarf2_cu
*cu
= reader
->cu
;
8550 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8551 struct signatured_type
*sig_type
;
8552 struct type_unit_group
*tu_group
;
8553 struct attribute
*attr
;
8554 struct partial_die_info
*first_die
;
8555 CORE_ADDR lowpc
, highpc
;
8556 struct partial_symtab
*pst
;
8558 gdb_assert (data
== NULL
);
8559 gdb_assert (per_cu
->is_debug_types
);
8560 sig_type
= (struct signatured_type
*) per_cu
;
8565 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8566 tu_group
= get_type_unit_group (cu
, attr
);
8568 VEC_safe_push (sig_type_ptr
, tu_group
->tus
, sig_type
);
8570 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8571 cu
->list_in_scope
= &file_symbols
;
8572 pst
= create_partial_symtab (per_cu
, "");
8575 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8577 lowpc
= (CORE_ADDR
) -1;
8578 highpc
= (CORE_ADDR
) 0;
8579 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8581 end_psymtab_common (objfile
, pst
);
8584 /* Struct used to sort TUs by their abbreviation table offset. */
8586 struct tu_abbrev_offset
8588 struct signatured_type
*sig_type
;
8589 sect_offset abbrev_offset
;
8592 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8595 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8596 const struct tu_abbrev_offset
&b
)
8598 return a
.abbrev_offset
< b
.abbrev_offset
;
8601 /* Efficiently read all the type units.
8602 This does the bulk of the work for build_type_psymtabs.
8604 The efficiency is because we sort TUs by the abbrev table they use and
8605 only read each abbrev table once. In one program there are 200K TUs
8606 sharing 8K abbrev tables.
8608 The main purpose of this function is to support building the
8609 dwarf2_per_objfile->type_unit_groups table.
8610 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8611 can collapse the search space by grouping them by stmt_list.
8612 The savings can be significant, in the same program from above the 200K TUs
8613 share 8K stmt_list tables.
8615 FUNC is expected to call get_type_unit_group, which will create the
8616 struct type_unit_group if necessary and add it to
8617 dwarf2_per_objfile->type_unit_groups. */
8620 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8622 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8623 abbrev_table_up abbrev_table
;
8624 sect_offset abbrev_offset
;
8627 /* It's up to the caller to not call us multiple times. */
8628 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8630 if (dwarf2_per_objfile
->n_type_units
== 0)
8633 /* TUs typically share abbrev tables, and there can be way more TUs than
8634 abbrev tables. Sort by abbrev table to reduce the number of times we
8635 read each abbrev table in.
8636 Alternatives are to punt or to maintain a cache of abbrev tables.
8637 This is simpler and efficient enough for now.
8639 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8640 symtab to use). Typically TUs with the same abbrev offset have the same
8641 stmt_list value too so in practice this should work well.
8643 The basic algorithm here is:
8645 sort TUs by abbrev table
8646 for each TU with same abbrev table:
8647 read abbrev table if first user
8648 read TU top level DIE
8649 [IWBN if DWO skeletons had DW_AT_stmt_list]
8652 if (dwarf_read_debug
)
8653 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8655 /* Sort in a separate table to maintain the order of all_type_units
8656 for .gdb_index: TU indices directly index all_type_units. */
8657 std::vector
<struct tu_abbrev_offset
> sorted_by_abbrev
8658 (dwarf2_per_objfile
->n_type_units
);
8659 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8661 struct signatured_type
*sig_type
= dwarf2_per_objfile
->all_type_units
[i
];
8663 sorted_by_abbrev
[i
].sig_type
= sig_type
;
8664 sorted_by_abbrev
[i
].abbrev_offset
=
8665 read_abbrev_offset (dwarf2_per_objfile
,
8666 sig_type
->per_cu
.section
,
8667 sig_type
->per_cu
.sect_off
);
8669 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8670 sort_tu_by_abbrev_offset
);
8672 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8674 for (i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
8676 const struct tu_abbrev_offset
*tu
= &sorted_by_abbrev
[i
];
8678 /* Switch to the next abbrev table if necessary. */
8679 if (abbrev_table
== NULL
8680 || tu
->abbrev_offset
!= abbrev_offset
)
8682 abbrev_offset
= tu
->abbrev_offset
;
8684 abbrev_table_read_table (dwarf2_per_objfile
,
8685 &dwarf2_per_objfile
->abbrev
,
8687 ++tu_stats
->nr_uniq_abbrev_tables
;
8690 init_cutu_and_read_dies (&tu
->sig_type
->per_cu
, abbrev_table
.get (),
8691 0, 0, build_type_psymtabs_reader
, NULL
);
8695 /* Print collected type unit statistics. */
8698 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8700 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8702 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8703 fprintf_unfiltered (gdb_stdlog
, " %d TUs\n",
8704 dwarf2_per_objfile
->n_type_units
);
8705 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8706 tu_stats
->nr_uniq_abbrev_tables
);
8707 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8708 tu_stats
->nr_symtabs
);
8709 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8710 tu_stats
->nr_symtab_sharers
);
8711 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8712 tu_stats
->nr_stmt_less_type_units
);
8713 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8714 tu_stats
->nr_all_type_units_reallocs
);
8717 /* Traversal function for build_type_psymtabs. */
8720 build_type_psymtab_dependencies (void **slot
, void *info
)
8722 struct dwarf2_per_objfile
*dwarf2_per_objfile
8723 = (struct dwarf2_per_objfile
*) info
;
8724 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8725 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8726 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8727 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8728 int len
= VEC_length (sig_type_ptr
, tu_group
->tus
);
8729 struct signatured_type
*iter
;
8732 gdb_assert (len
> 0);
8733 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8735 pst
->number_of_dependencies
= len
;
8737 XOBNEWVEC (&objfile
->objfile_obstack
, struct partial_symtab
*, len
);
8739 VEC_iterate (sig_type_ptr
, tu_group
->tus
, i
, iter
);
8742 gdb_assert (iter
->per_cu
.is_debug_types
);
8743 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8744 iter
->type_unit_group
= tu_group
;
8747 VEC_free (sig_type_ptr
, tu_group
->tus
);
8752 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8753 Build partial symbol tables for the .debug_types comp-units. */
8756 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8758 if (! create_all_type_units (dwarf2_per_objfile
))
8761 build_type_psymtabs_1 (dwarf2_per_objfile
);
8764 /* Traversal function for process_skeletonless_type_unit.
8765 Read a TU in a DWO file and build partial symbols for it. */
8768 process_skeletonless_type_unit (void **slot
, void *info
)
8770 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8771 struct dwarf2_per_objfile
*dwarf2_per_objfile
8772 = (struct dwarf2_per_objfile
*) info
;
8773 struct signatured_type find_entry
, *entry
;
8775 /* If this TU doesn't exist in the global table, add it and read it in. */
8777 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8779 dwarf2_per_objfile
->signatured_types
8780 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8783 find_entry
.signature
= dwo_unit
->signature
;
8784 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8786 /* If we've already seen this type there's nothing to do. What's happening
8787 is we're doing our own version of comdat-folding here. */
8791 /* This does the job that create_all_type_units would have done for
8793 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8794 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8797 /* This does the job that build_type_psymtabs_1 would have done. */
8798 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0,
8799 build_type_psymtabs_reader
, NULL
);
8804 /* Traversal function for process_skeletonless_type_units. */
8807 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8809 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8811 if (dwo_file
->tus
!= NULL
)
8813 htab_traverse_noresize (dwo_file
->tus
,
8814 process_skeletonless_type_unit
, info
);
8820 /* Scan all TUs of DWO files, verifying we've processed them.
8821 This is needed in case a TU was emitted without its skeleton.
8822 Note: This can't be done until we know what all the DWO files are. */
8825 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8827 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8828 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8829 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8831 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
,
8832 process_dwo_file_for_skeletonless_type_units
,
8833 dwarf2_per_objfile
);
8837 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8840 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8844 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8846 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8847 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8853 for (j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8855 /* Set the 'user' field only if it is not already set. */
8856 if (pst
->dependencies
[j
]->user
== NULL
)
8857 pst
->dependencies
[j
]->user
= pst
;
8862 /* Build the partial symbol table by doing a quick pass through the
8863 .debug_info and .debug_abbrev sections. */
8866 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8868 struct cleanup
*back_to
;
8870 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8872 if (dwarf_read_debug
)
8874 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8875 objfile_name (objfile
));
8878 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8880 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8882 /* Any cached compilation units will be linked by the per-objfile
8883 read_in_chain. Make sure to free them when we're done. */
8884 back_to
= make_cleanup (free_cached_comp_units
, dwarf2_per_objfile
);
8886 build_type_psymtabs (dwarf2_per_objfile
);
8888 create_all_comp_units (dwarf2_per_objfile
);
8890 /* Create a temporary address map on a temporary obstack. We later
8891 copy this to the final obstack. */
8892 auto_obstack temp_obstack
;
8894 scoped_restore save_psymtabs_addrmap
8895 = make_scoped_restore (&objfile
->psymtabs_addrmap
,
8896 addrmap_create_mutable (&temp_obstack
));
8898 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
8900 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cutu (dwarf2_per_objfile
, i
);
8902 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8905 /* This has to wait until we read the CUs, we need the list of DWOs. */
8906 process_skeletonless_type_units (dwarf2_per_objfile
);
8908 /* Now that all TUs have been processed we can fill in the dependencies. */
8909 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8911 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8912 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8915 if (dwarf_read_debug
)
8916 print_tu_stats (dwarf2_per_objfile
);
8918 set_partial_user (dwarf2_per_objfile
);
8920 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
8921 &objfile
->objfile_obstack
);
8922 /* At this point we want to keep the address map. */
8923 save_psymtabs_addrmap
.release ();
8925 do_cleanups (back_to
);
8927 if (dwarf_read_debug
)
8928 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8929 objfile_name (objfile
));
8932 /* die_reader_func for load_partial_comp_unit. */
8935 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8936 const gdb_byte
*info_ptr
,
8937 struct die_info
*comp_unit_die
,
8941 struct dwarf2_cu
*cu
= reader
->cu
;
8943 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8945 /* Check if comp unit has_children.
8946 If so, read the rest of the partial symbols from this comp unit.
8947 If not, there's no more debug_info for this comp unit. */
8949 load_partial_dies (reader
, info_ptr
, 0);
8952 /* Load the partial DIEs for a secondary CU into memory.
8953 This is also used when rereading a primary CU with load_all_dies. */
8956 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8958 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
8959 load_partial_comp_unit_reader
, NULL
);
8963 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8964 struct dwarf2_section_info
*section
,
8965 struct dwarf2_section_info
*abbrev_section
,
8966 unsigned int is_dwz
,
8969 struct dwarf2_per_cu_data
***all_comp_units
)
8971 const gdb_byte
*info_ptr
;
8972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8974 if (dwarf_read_debug
)
8975 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8976 get_section_name (section
),
8977 get_section_file_name (section
));
8979 dwarf2_read_section (objfile
, section
);
8981 info_ptr
= section
->buffer
;
8983 while (info_ptr
< section
->buffer
+ section
->size
)
8985 struct dwarf2_per_cu_data
*this_cu
;
8987 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8989 comp_unit_head cu_header
;
8990 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8991 abbrev_section
, info_ptr
,
8992 rcuh_kind::COMPILE
);
8994 /* Save the compilation unit for later lookup. */
8995 if (cu_header
.unit_type
!= DW_UT_type
)
8997 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8998 struct dwarf2_per_cu_data
);
8999 memset (this_cu
, 0, sizeof (*this_cu
));
9003 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
9004 struct signatured_type
);
9005 memset (sig_type
, 0, sizeof (*sig_type
));
9006 sig_type
->signature
= cu_header
.signature
;
9007 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
9008 this_cu
= &sig_type
->per_cu
;
9010 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
9011 this_cu
->sect_off
= sect_off
;
9012 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
9013 this_cu
->is_dwz
= is_dwz
;
9014 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
9015 this_cu
->section
= section
;
9017 if (*n_comp_units
== *n_allocated
)
9020 *all_comp_units
= XRESIZEVEC (struct dwarf2_per_cu_data
*,
9021 *all_comp_units
, *n_allocated
);
9023 (*all_comp_units
)[*n_comp_units
] = this_cu
;
9026 info_ptr
= info_ptr
+ this_cu
->length
;
9030 /* Create a list of all compilation units in OBJFILE.
9031 This is only done for -readnow and building partial symtabs. */
9034 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9038 struct dwarf2_per_cu_data
**all_comp_units
;
9039 struct dwz_file
*dwz
;
9040 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9044 all_comp_units
= XNEWVEC (struct dwarf2_per_cu_data
*, n_allocated
);
9046 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
9047 &dwarf2_per_objfile
->abbrev
, 0,
9048 &n_allocated
, &n_comp_units
, &all_comp_units
);
9050 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
9052 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
9053 1, &n_allocated
, &n_comp_units
,
9056 dwarf2_per_objfile
->all_comp_units
= XOBNEWVEC (&objfile
->objfile_obstack
,
9057 struct dwarf2_per_cu_data
*,
9059 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
9060 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
9061 xfree (all_comp_units
);
9062 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
9065 /* Process all loaded DIEs for compilation unit CU, starting at
9066 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
9067 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
9068 DW_AT_ranges). See the comments of add_partial_subprogram on how
9069 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
9072 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
9073 CORE_ADDR
*highpc
, int set_addrmap
,
9074 struct dwarf2_cu
*cu
)
9076 struct partial_die_info
*pdi
;
9078 /* Now, march along the PDI's, descending into ones which have
9079 interesting children but skipping the children of the other ones,
9080 until we reach the end of the compilation unit. */
9088 /* Anonymous namespaces or modules have no name but have interesting
9089 children, so we need to look at them. Ditto for anonymous
9092 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
9093 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
9094 || pdi
->tag
== DW_TAG_imported_unit
9095 || pdi
->tag
== DW_TAG_inlined_subroutine
)
9099 case DW_TAG_subprogram
:
9100 case DW_TAG_inlined_subroutine
:
9101 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9103 case DW_TAG_constant
:
9104 case DW_TAG_variable
:
9105 case DW_TAG_typedef
:
9106 case DW_TAG_union_type
:
9107 if (!pdi
->is_declaration
)
9109 add_partial_symbol (pdi
, cu
);
9112 case DW_TAG_class_type
:
9113 case DW_TAG_interface_type
:
9114 case DW_TAG_structure_type
:
9115 if (!pdi
->is_declaration
)
9117 add_partial_symbol (pdi
, cu
);
9119 if (cu
->language
== language_rust
&& pdi
->has_children
)
9120 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
9123 case DW_TAG_enumeration_type
:
9124 if (!pdi
->is_declaration
)
9125 add_partial_enumeration (pdi
, cu
);
9127 case DW_TAG_base_type
:
9128 case DW_TAG_subrange_type
:
9129 /* File scope base type definitions are added to the partial
9131 add_partial_symbol (pdi
, cu
);
9133 case DW_TAG_namespace
:
9134 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9137 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9139 case DW_TAG_imported_unit
:
9141 struct dwarf2_per_cu_data
*per_cu
;
9143 /* For now we don't handle imported units in type units. */
9144 if (cu
->per_cu
->is_debug_types
)
9146 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9147 " supported in type units [in module %s]"),
9148 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9151 per_cu
= dwarf2_find_containing_comp_unit
9152 (pdi
->d
.sect_off
, pdi
->is_dwz
,
9153 cu
->per_cu
->dwarf2_per_objfile
);
9155 /* Go read the partial unit, if needed. */
9156 if (per_cu
->v
.psymtab
== NULL
)
9157 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
9159 VEC_safe_push (dwarf2_per_cu_ptr
,
9160 cu
->per_cu
->imported_symtabs
, per_cu
);
9163 case DW_TAG_imported_declaration
:
9164 add_partial_symbol (pdi
, cu
);
9171 /* If the die has a sibling, skip to the sibling. */
9173 pdi
= pdi
->die_sibling
;
9177 /* Functions used to compute the fully scoped name of a partial DIE.
9179 Normally, this is simple. For C++, the parent DIE's fully scoped
9180 name is concatenated with "::" and the partial DIE's name.
9181 Enumerators are an exception; they use the scope of their parent
9182 enumeration type, i.e. the name of the enumeration type is not
9183 prepended to the enumerator.
9185 There are two complexities. One is DW_AT_specification; in this
9186 case "parent" means the parent of the target of the specification,
9187 instead of the direct parent of the DIE. The other is compilers
9188 which do not emit DW_TAG_namespace; in this case we try to guess
9189 the fully qualified name of structure types from their members'
9190 linkage names. This must be done using the DIE's children rather
9191 than the children of any DW_AT_specification target. We only need
9192 to do this for structures at the top level, i.e. if the target of
9193 any DW_AT_specification (if any; otherwise the DIE itself) does not
9196 /* Compute the scope prefix associated with PDI's parent, in
9197 compilation unit CU. The result will be allocated on CU's
9198 comp_unit_obstack, or a copy of the already allocated PDI->NAME
9199 field. NULL is returned if no prefix is necessary. */
9201 partial_die_parent_scope (struct partial_die_info
*pdi
,
9202 struct dwarf2_cu
*cu
)
9204 const char *grandparent_scope
;
9205 struct partial_die_info
*parent
, *real_pdi
;
9207 /* We need to look at our parent DIE; if we have a DW_AT_specification,
9208 then this means the parent of the specification DIE. */
9211 while (real_pdi
->has_specification
)
9212 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
9213 real_pdi
->spec_is_dwz
, cu
);
9215 parent
= real_pdi
->die_parent
;
9219 if (parent
->scope_set
)
9220 return parent
->scope
;
9224 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
9226 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9227 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9228 Work around this problem here. */
9229 if (cu
->language
== language_cplus
9230 && parent
->tag
== DW_TAG_namespace
9231 && strcmp (parent
->name
, "::") == 0
9232 && grandparent_scope
== NULL
)
9234 parent
->scope
= NULL
;
9235 parent
->scope_set
= 1;
9239 if (pdi
->tag
== DW_TAG_enumerator
)
9240 /* Enumerators should not get the name of the enumeration as a prefix. */
9241 parent
->scope
= grandparent_scope
;
9242 else if (parent
->tag
== DW_TAG_namespace
9243 || parent
->tag
== DW_TAG_module
9244 || parent
->tag
== DW_TAG_structure_type
9245 || parent
->tag
== DW_TAG_class_type
9246 || parent
->tag
== DW_TAG_interface_type
9247 || parent
->tag
== DW_TAG_union_type
9248 || parent
->tag
== DW_TAG_enumeration_type
)
9250 if (grandparent_scope
== NULL
)
9251 parent
->scope
= parent
->name
;
9253 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
9255 parent
->name
, 0, cu
);
9259 /* FIXME drow/2004-04-01: What should we be doing with
9260 function-local names? For partial symbols, we should probably be
9262 complaint (&symfile_complaints
,
9263 _("unhandled containing DIE tag %d for DIE at %s"),
9264 parent
->tag
, sect_offset_str (pdi
->sect_off
));
9265 parent
->scope
= grandparent_scope
;
9268 parent
->scope_set
= 1;
9269 return parent
->scope
;
9272 /* Return the fully scoped name associated with PDI, from compilation unit
9273 CU. The result will be allocated with malloc. */
9276 partial_die_full_name (struct partial_die_info
*pdi
,
9277 struct dwarf2_cu
*cu
)
9279 const char *parent_scope
;
9281 /* If this is a template instantiation, we can not work out the
9282 template arguments from partial DIEs. So, unfortunately, we have
9283 to go through the full DIEs. At least any work we do building
9284 types here will be reused if full symbols are loaded later. */
9285 if (pdi
->has_template_arguments
)
9289 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
9291 struct die_info
*die
;
9292 struct attribute attr
;
9293 struct dwarf2_cu
*ref_cu
= cu
;
9295 /* DW_FORM_ref_addr is using section offset. */
9296 attr
.name
= (enum dwarf_attribute
) 0;
9297 attr
.form
= DW_FORM_ref_addr
;
9298 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
9299 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
9301 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
9305 parent_scope
= partial_die_parent_scope (pdi
, cu
);
9306 if (parent_scope
== NULL
)
9309 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
9313 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
9315 struct dwarf2_per_objfile
*dwarf2_per_objfile
9316 = cu
->per_cu
->dwarf2_per_objfile
;
9317 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9318 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9320 const char *actual_name
= NULL
;
9322 char *built_actual_name
;
9324 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9326 built_actual_name
= partial_die_full_name (pdi
, cu
);
9327 if (built_actual_name
!= NULL
)
9328 actual_name
= built_actual_name
;
9330 if (actual_name
== NULL
)
9331 actual_name
= pdi
->name
;
9335 case DW_TAG_inlined_subroutine
:
9336 case DW_TAG_subprogram
:
9337 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
);
9338 if (pdi
->is_external
|| cu
->language
== language_ada
)
9340 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
9341 of the global scope. But in Ada, we want to be able to access
9342 nested procedures globally. So all Ada subprograms are stored
9343 in the global scope. */
9344 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9345 built_actual_name
!= NULL
,
9346 VAR_DOMAIN
, LOC_BLOCK
,
9347 &objfile
->global_psymbols
,
9348 addr
, cu
->language
, objfile
);
9352 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9353 built_actual_name
!= NULL
,
9354 VAR_DOMAIN
, LOC_BLOCK
,
9355 &objfile
->static_psymbols
,
9356 addr
, cu
->language
, objfile
);
9359 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9360 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9362 case DW_TAG_constant
:
9364 std::vector
<partial_symbol
*> *list
;
9366 if (pdi
->is_external
)
9367 list
= &objfile
->global_psymbols
;
9369 list
= &objfile
->static_psymbols
;
9370 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9371 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9372 list
, 0, cu
->language
, objfile
);
9375 case DW_TAG_variable
:
9377 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9381 && !dwarf2_per_objfile
->has_section_at_zero
)
9383 /* A global or static variable may also have been stripped
9384 out by the linker if unused, in which case its address
9385 will be nullified; do not add such variables into partial
9386 symbol table then. */
9388 else if (pdi
->is_external
)
9391 Don't enter into the minimal symbol tables as there is
9392 a minimal symbol table entry from the ELF symbols already.
9393 Enter into partial symbol table if it has a location
9394 descriptor or a type.
9395 If the location descriptor is missing, new_symbol will create
9396 a LOC_UNRESOLVED symbol, the address of the variable will then
9397 be determined from the minimal symbol table whenever the variable
9399 The address for the partial symbol table entry is not
9400 used by GDB, but it comes in handy for debugging partial symbol
9403 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9404 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9405 built_actual_name
!= NULL
,
9406 VAR_DOMAIN
, LOC_STATIC
,
9407 &objfile
->global_psymbols
,
9409 cu
->language
, objfile
);
9413 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9415 /* Static Variable. Skip symbols whose value we cannot know (those
9416 without location descriptors or constant values). */
9417 if (!has_loc
&& !pdi
->has_const_value
)
9419 xfree (built_actual_name
);
9423 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9424 built_actual_name
!= NULL
,
9425 VAR_DOMAIN
, LOC_STATIC
,
9426 &objfile
->static_psymbols
,
9427 has_loc
? addr
+ baseaddr
: (CORE_ADDR
) 0,
9428 cu
->language
, objfile
);
9431 case DW_TAG_typedef
:
9432 case DW_TAG_base_type
:
9433 case DW_TAG_subrange_type
:
9434 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9435 built_actual_name
!= NULL
,
9436 VAR_DOMAIN
, LOC_TYPEDEF
,
9437 &objfile
->static_psymbols
,
9438 0, cu
->language
, objfile
);
9440 case DW_TAG_imported_declaration
:
9441 case DW_TAG_namespace
:
9442 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9443 built_actual_name
!= NULL
,
9444 VAR_DOMAIN
, LOC_TYPEDEF
,
9445 &objfile
->global_psymbols
,
9446 0, cu
->language
, objfile
);
9449 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9450 built_actual_name
!= NULL
,
9451 MODULE_DOMAIN
, LOC_TYPEDEF
,
9452 &objfile
->global_psymbols
,
9453 0, cu
->language
, objfile
);
9455 case DW_TAG_class_type
:
9456 case DW_TAG_interface_type
:
9457 case DW_TAG_structure_type
:
9458 case DW_TAG_union_type
:
9459 case DW_TAG_enumeration_type
:
9460 /* Skip external references. The DWARF standard says in the section
9461 about "Structure, Union, and Class Type Entries": "An incomplete
9462 structure, union or class type is represented by a structure,
9463 union or class entry that does not have a byte size attribute
9464 and that has a DW_AT_declaration attribute." */
9465 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9467 xfree (built_actual_name
);
9471 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9472 static vs. global. */
9473 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9474 built_actual_name
!= NULL
,
9475 STRUCT_DOMAIN
, LOC_TYPEDEF
,
9476 cu
->language
== language_cplus
9477 ? &objfile
->global_psymbols
9478 : &objfile
->static_psymbols
,
9479 0, cu
->language
, objfile
);
9482 case DW_TAG_enumerator
:
9483 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9484 built_actual_name
!= NULL
,
9485 VAR_DOMAIN
, LOC_CONST
,
9486 cu
->language
== language_cplus
9487 ? &objfile
->global_psymbols
9488 : &objfile
->static_psymbols
,
9489 0, cu
->language
, objfile
);
9495 xfree (built_actual_name
);
9498 /* Read a partial die corresponding to a namespace; also, add a symbol
9499 corresponding to that namespace to the symbol table. NAMESPACE is
9500 the name of the enclosing namespace. */
9503 add_partial_namespace (struct partial_die_info
*pdi
,
9504 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9505 int set_addrmap
, struct dwarf2_cu
*cu
)
9507 /* Add a symbol for the namespace. */
9509 add_partial_symbol (pdi
, cu
);
9511 /* Now scan partial symbols in that namespace. */
9513 if (pdi
->has_children
)
9514 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9517 /* Read a partial die corresponding to a Fortran module. */
9520 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9521 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9523 /* Add a symbol for the namespace. */
9525 add_partial_symbol (pdi
, cu
);
9527 /* Now scan partial symbols in that module. */
9529 if (pdi
->has_children
)
9530 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9533 /* Read a partial die corresponding to a subprogram or an inlined
9534 subprogram and create a partial symbol for that subprogram.
9535 When the CU language allows it, this routine also defines a partial
9536 symbol for each nested subprogram that this subprogram contains.
9537 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9538 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9540 PDI may also be a lexical block, in which case we simply search
9541 recursively for subprograms defined inside that lexical block.
9542 Again, this is only performed when the CU language allows this
9543 type of definitions. */
9546 add_partial_subprogram (struct partial_die_info
*pdi
,
9547 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9548 int set_addrmap
, struct dwarf2_cu
*cu
)
9550 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9552 if (pdi
->has_pc_info
)
9554 if (pdi
->lowpc
< *lowpc
)
9555 *lowpc
= pdi
->lowpc
;
9556 if (pdi
->highpc
> *highpc
)
9557 *highpc
= pdi
->highpc
;
9560 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9561 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9566 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9567 SECT_OFF_TEXT (objfile
));
9568 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9569 pdi
->lowpc
+ baseaddr
);
9570 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
9571 pdi
->highpc
+ baseaddr
);
9572 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
9573 cu
->per_cu
->v
.psymtab
);
9577 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9579 if (!pdi
->is_declaration
)
9580 /* Ignore subprogram DIEs that do not have a name, they are
9581 illegal. Do not emit a complaint at this point, we will
9582 do so when we convert this psymtab into a symtab. */
9584 add_partial_symbol (pdi
, cu
);
9588 if (! pdi
->has_children
)
9591 if (cu
->language
== language_ada
)
9593 pdi
= pdi
->die_child
;
9597 if (pdi
->tag
== DW_TAG_subprogram
9598 || pdi
->tag
== DW_TAG_inlined_subroutine
9599 || pdi
->tag
== DW_TAG_lexical_block
)
9600 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9601 pdi
= pdi
->die_sibling
;
9606 /* Read a partial die corresponding to an enumeration type. */
9609 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9610 struct dwarf2_cu
*cu
)
9612 struct partial_die_info
*pdi
;
9614 if (enum_pdi
->name
!= NULL
)
9615 add_partial_symbol (enum_pdi
, cu
);
9617 pdi
= enum_pdi
->die_child
;
9620 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9621 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
9623 add_partial_symbol (pdi
, cu
);
9624 pdi
= pdi
->die_sibling
;
9628 /* Return the initial uleb128 in the die at INFO_PTR. */
9631 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9633 unsigned int bytes_read
;
9635 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9638 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9639 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9641 Return the corresponding abbrev, or NULL if the number is zero (indicating
9642 an empty DIE). In either case *BYTES_READ will be set to the length of
9643 the initial number. */
9645 static struct abbrev_info
*
9646 peek_die_abbrev (const die_reader_specs
&reader
,
9647 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9649 dwarf2_cu
*cu
= reader
.cu
;
9650 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9651 unsigned int abbrev_number
9652 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9654 if (abbrev_number
== 0)
9657 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9660 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9661 " at offset %s [in module %s]"),
9662 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9663 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9669 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9670 Returns a pointer to the end of a series of DIEs, terminated by an empty
9671 DIE. Any children of the skipped DIEs will also be skipped. */
9673 static const gdb_byte
*
9674 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9678 unsigned int bytes_read
;
9679 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9682 return info_ptr
+ bytes_read
;
9684 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9688 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9689 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9690 abbrev corresponding to that skipped uleb128 should be passed in
9691 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9694 static const gdb_byte
*
9695 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9696 struct abbrev_info
*abbrev
)
9698 unsigned int bytes_read
;
9699 struct attribute attr
;
9700 bfd
*abfd
= reader
->abfd
;
9701 struct dwarf2_cu
*cu
= reader
->cu
;
9702 const gdb_byte
*buffer
= reader
->buffer
;
9703 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9704 unsigned int form
, i
;
9706 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9708 /* The only abbrev we care about is DW_AT_sibling. */
9709 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9711 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9712 if (attr
.form
== DW_FORM_ref_addr
)
9713 complaint (&symfile_complaints
,
9714 _("ignoring absolute DW_AT_sibling"));
9717 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9718 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9720 if (sibling_ptr
< info_ptr
)
9721 complaint (&symfile_complaints
,
9722 _("DW_AT_sibling points backwards"));
9723 else if (sibling_ptr
> reader
->buffer_end
)
9724 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9730 /* If it isn't DW_AT_sibling, skip this attribute. */
9731 form
= abbrev
->attrs
[i
].form
;
9735 case DW_FORM_ref_addr
:
9736 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9737 and later it is offset sized. */
9738 if (cu
->header
.version
== 2)
9739 info_ptr
+= cu
->header
.addr_size
;
9741 info_ptr
+= cu
->header
.offset_size
;
9743 case DW_FORM_GNU_ref_alt
:
9744 info_ptr
+= cu
->header
.offset_size
;
9747 info_ptr
+= cu
->header
.addr_size
;
9754 case DW_FORM_flag_present
:
9755 case DW_FORM_implicit_const
:
9767 case DW_FORM_ref_sig8
:
9770 case DW_FORM_data16
:
9773 case DW_FORM_string
:
9774 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9775 info_ptr
+= bytes_read
;
9777 case DW_FORM_sec_offset
:
9779 case DW_FORM_GNU_strp_alt
:
9780 info_ptr
+= cu
->header
.offset_size
;
9782 case DW_FORM_exprloc
:
9784 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9785 info_ptr
+= bytes_read
;
9787 case DW_FORM_block1
:
9788 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9790 case DW_FORM_block2
:
9791 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9793 case DW_FORM_block4
:
9794 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9798 case DW_FORM_ref_udata
:
9799 case DW_FORM_GNU_addr_index
:
9800 case DW_FORM_GNU_str_index
:
9801 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9803 case DW_FORM_indirect
:
9804 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9805 info_ptr
+= bytes_read
;
9806 /* We need to continue parsing from here, so just go back to
9808 goto skip_attribute
;
9811 error (_("Dwarf Error: Cannot handle %s "
9812 "in DWARF reader [in module %s]"),
9813 dwarf_form_name (form
),
9814 bfd_get_filename (abfd
));
9818 if (abbrev
->has_children
)
9819 return skip_children (reader
, info_ptr
);
9824 /* Locate ORIG_PDI's sibling.
9825 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9827 static const gdb_byte
*
9828 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9829 struct partial_die_info
*orig_pdi
,
9830 const gdb_byte
*info_ptr
)
9832 /* Do we know the sibling already? */
9834 if (orig_pdi
->sibling
)
9835 return orig_pdi
->sibling
;
9837 /* Are there any children to deal with? */
9839 if (!orig_pdi
->has_children
)
9842 /* Skip the children the long way. */
9844 return skip_children (reader
, info_ptr
);
9847 /* Expand this partial symbol table into a full symbol table. SELF is
9851 dwarf2_read_symtab (struct partial_symtab
*self
,
9852 struct objfile
*objfile
)
9854 struct dwarf2_per_objfile
*dwarf2_per_objfile
9855 = get_dwarf2_per_objfile (objfile
);
9859 warning (_("bug: psymtab for %s is already read in."),
9866 printf_filtered (_("Reading in symbols for %s..."),
9868 gdb_flush (gdb_stdout
);
9871 /* If this psymtab is constructed from a debug-only objfile, the
9872 has_section_at_zero flag will not necessarily be correct. We
9873 can get the correct value for this flag by looking at the data
9874 associated with the (presumably stripped) associated objfile. */
9875 if (objfile
->separate_debug_objfile_backlink
)
9877 struct dwarf2_per_objfile
*dpo_backlink
9878 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9880 dwarf2_per_objfile
->has_section_at_zero
9881 = dpo_backlink
->has_section_at_zero
;
9884 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9886 psymtab_to_symtab_1 (self
);
9888 /* Finish up the debug error message. */
9890 printf_filtered (_("done.\n"));
9893 process_cu_includes (dwarf2_per_objfile
);
9896 /* Reading in full CUs. */
9898 /* Add PER_CU to the queue. */
9901 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9902 enum language pretend_language
)
9904 struct dwarf2_queue_item
*item
;
9907 item
= XNEW (struct dwarf2_queue_item
);
9908 item
->per_cu
= per_cu
;
9909 item
->pretend_language
= pretend_language
;
9912 if (dwarf2_queue
== NULL
)
9913 dwarf2_queue
= item
;
9915 dwarf2_queue_tail
->next
= item
;
9917 dwarf2_queue_tail
= item
;
9920 /* If PER_CU is not yet queued, add it to the queue.
9921 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9923 The result is non-zero if PER_CU was queued, otherwise the result is zero
9924 meaning either PER_CU is already queued or it is already loaded.
9926 N.B. There is an invariant here that if a CU is queued then it is loaded.
9927 The caller is required to load PER_CU if we return non-zero. */
9930 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9931 struct dwarf2_per_cu_data
*per_cu
,
9932 enum language pretend_language
)
9934 /* We may arrive here during partial symbol reading, if we need full
9935 DIEs to process an unusual case (e.g. template arguments). Do
9936 not queue PER_CU, just tell our caller to load its DIEs. */
9937 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9939 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9944 /* Mark the dependence relation so that we don't flush PER_CU
9946 if (dependent_cu
!= NULL
)
9947 dwarf2_add_dependence (dependent_cu
, per_cu
);
9949 /* If it's already on the queue, we have nothing to do. */
9953 /* If the compilation unit is already loaded, just mark it as
9955 if (per_cu
->cu
!= NULL
)
9957 per_cu
->cu
->last_used
= 0;
9961 /* Add it to the queue. */
9962 queue_comp_unit (per_cu
, pretend_language
);
9967 /* Process the queue. */
9970 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9972 struct dwarf2_queue_item
*item
, *next_item
;
9974 if (dwarf_read_debug
)
9976 fprintf_unfiltered (gdb_stdlog
,
9977 "Expanding one or more symtabs of objfile %s ...\n",
9978 objfile_name (dwarf2_per_objfile
->objfile
));
9981 /* The queue starts out with one item, but following a DIE reference
9982 may load a new CU, adding it to the end of the queue. */
9983 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9985 if ((dwarf2_per_objfile
->using_index
9986 ? !item
->per_cu
->v
.quick
->compunit_symtab
9987 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9988 /* Skip dummy CUs. */
9989 && item
->per_cu
->cu
!= NULL
)
9991 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9992 unsigned int debug_print_threshold
;
9995 if (per_cu
->is_debug_types
)
9997 struct signatured_type
*sig_type
=
9998 (struct signatured_type
*) per_cu
;
10000 sprintf (buf
, "TU %s at offset %s",
10001 hex_string (sig_type
->signature
),
10002 sect_offset_str (per_cu
->sect_off
));
10003 /* There can be 100s of TUs.
10004 Only print them in verbose mode. */
10005 debug_print_threshold
= 2;
10009 sprintf (buf
, "CU at offset %s",
10010 sect_offset_str (per_cu
->sect_off
));
10011 debug_print_threshold
= 1;
10014 if (dwarf_read_debug
>= debug_print_threshold
)
10015 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
10017 if (per_cu
->is_debug_types
)
10018 process_full_type_unit (per_cu
, item
->pretend_language
);
10020 process_full_comp_unit (per_cu
, item
->pretend_language
);
10022 if (dwarf_read_debug
>= debug_print_threshold
)
10023 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
10026 item
->per_cu
->queued
= 0;
10027 next_item
= item
->next
;
10031 dwarf2_queue_tail
= NULL
;
10033 if (dwarf_read_debug
)
10035 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
10036 objfile_name (dwarf2_per_objfile
->objfile
));
10040 /* Read in full symbols for PST, and anything it depends on. */
10043 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
10045 struct dwarf2_per_cu_data
*per_cu
;
10051 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
10052 if (!pst
->dependencies
[i
]->readin
10053 && pst
->dependencies
[i
]->user
== NULL
)
10055 /* Inform about additional files that need to be read in. */
10058 /* FIXME: i18n: Need to make this a single string. */
10059 fputs_filtered (" ", gdb_stdout
);
10061 fputs_filtered ("and ", gdb_stdout
);
10063 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
10064 wrap_here (""); /* Flush output. */
10065 gdb_flush (gdb_stdout
);
10067 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
10070 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
10072 if (per_cu
== NULL
)
10074 /* It's an include file, no symbols to read for it.
10075 Everything is in the parent symtab. */
10080 dw2_do_instantiate_symtab (per_cu
);
10083 /* Trivial hash function for die_info: the hash value of a DIE
10084 is its offset in .debug_info for this objfile. */
10087 die_hash (const void *item
)
10089 const struct die_info
*die
= (const struct die_info
*) item
;
10091 return to_underlying (die
->sect_off
);
10094 /* Trivial comparison function for die_info structures: two DIEs
10095 are equal if they have the same offset. */
10098 die_eq (const void *item_lhs
, const void *item_rhs
)
10100 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
10101 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
10103 return die_lhs
->sect_off
== die_rhs
->sect_off
;
10106 /* die_reader_func for load_full_comp_unit.
10107 This is identical to read_signatured_type_reader,
10108 but is kept separate for now. */
10111 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
10112 const gdb_byte
*info_ptr
,
10113 struct die_info
*comp_unit_die
,
10117 struct dwarf2_cu
*cu
= reader
->cu
;
10118 enum language
*language_ptr
= (enum language
*) data
;
10120 gdb_assert (cu
->die_hash
== NULL
);
10122 htab_create_alloc_ex (cu
->header
.length
/ 12,
10126 &cu
->comp_unit_obstack
,
10127 hashtab_obstack_allocate
,
10128 dummy_obstack_deallocate
);
10131 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
10132 &info_ptr
, comp_unit_die
);
10133 cu
->dies
= comp_unit_die
;
10134 /* comp_unit_die is not stored in die_hash, no need. */
10136 /* We try not to read any attributes in this function, because not
10137 all CUs needed for references have been loaded yet, and symbol
10138 table processing isn't initialized. But we have to set the CU language,
10139 or we won't be able to build types correctly.
10140 Similarly, if we do not read the producer, we can not apply
10141 producer-specific interpretation. */
10142 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
10145 /* Load the DIEs associated with PER_CU into memory. */
10148 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
10149 enum language pretend_language
)
10151 gdb_assert (! this_cu
->is_debug_types
);
10153 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1,
10154 load_full_comp_unit_reader
, &pretend_language
);
10157 /* Add a DIE to the delayed physname list. */
10160 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
10161 const char *name
, struct die_info
*die
,
10162 struct dwarf2_cu
*cu
)
10164 struct delayed_method_info mi
;
10166 mi
.fnfield_index
= fnfield_index
;
10170 cu
->method_list
.push_back (mi
);
10173 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
10174 "const" / "volatile". If so, decrements LEN by the length of the
10175 modifier and return true. Otherwise return false. */
10179 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
10181 size_t mod_len
= sizeof (mod
) - 1;
10182 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
10190 /* Compute the physnames of any methods on the CU's method list.
10192 The computation of method physnames is delayed in order to avoid the
10193 (bad) condition that one of the method's formal parameters is of an as yet
10194 incomplete type. */
10197 compute_delayed_physnames (struct dwarf2_cu
*cu
)
10199 /* Only C++ delays computing physnames. */
10200 if (cu
->method_list
.empty ())
10202 gdb_assert (cu
->language
== language_cplus
);
10204 for (struct delayed_method_info
&mi
: cu
->method_list
)
10206 const char *physname
;
10207 struct fn_fieldlist
*fn_flp
10208 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
10209 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
10210 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
10211 = physname
? physname
: "";
10213 /* Since there's no tag to indicate whether a method is a
10214 const/volatile overload, extract that information out of the
10216 if (physname
!= NULL
)
10218 size_t len
= strlen (physname
);
10222 if (physname
[len
] == ')') /* shortcut */
10224 else if (check_modifier (physname
, len
, " const"))
10225 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
10226 else if (check_modifier (physname
, len
, " volatile"))
10227 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
10234 /* The list is no longer needed. */
10235 cu
->method_list
.clear ();
10238 /* Go objects should be embedded in a DW_TAG_module DIE,
10239 and it's not clear if/how imported objects will appear.
10240 To keep Go support simple until that's worked out,
10241 go back through what we've read and create something usable.
10242 We could do this while processing each DIE, and feels kinda cleaner,
10243 but that way is more invasive.
10244 This is to, for example, allow the user to type "p var" or "b main"
10245 without having to specify the package name, and allow lookups
10246 of module.object to work in contexts that use the expression
10250 fixup_go_packaging (struct dwarf2_cu
*cu
)
10252 char *package_name
= NULL
;
10253 struct pending
*list
;
10256 for (list
= global_symbols
; list
!= NULL
; list
= list
->next
)
10258 for (i
= 0; i
< list
->nsyms
; ++i
)
10260 struct symbol
*sym
= list
->symbol
[i
];
10262 if (SYMBOL_LANGUAGE (sym
) == language_go
10263 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
10265 char *this_package_name
= go_symbol_package_name (sym
);
10267 if (this_package_name
== NULL
)
10269 if (package_name
== NULL
)
10270 package_name
= this_package_name
;
10273 struct objfile
*objfile
10274 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10275 if (strcmp (package_name
, this_package_name
) != 0)
10276 complaint (&symfile_complaints
,
10277 _("Symtab %s has objects from two different Go packages: %s and %s"),
10278 (symbol_symtab (sym
) != NULL
10279 ? symtab_to_filename_for_display
10280 (symbol_symtab (sym
))
10281 : objfile_name (objfile
)),
10282 this_package_name
, package_name
);
10283 xfree (this_package_name
);
10289 if (package_name
!= NULL
)
10291 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10292 const char *saved_package_name
10293 = (const char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
10295 strlen (package_name
));
10296 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
10297 saved_package_name
);
10298 struct symbol
*sym
;
10300 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
10302 sym
= allocate_symbol (objfile
);
10303 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
10304 SYMBOL_SET_NAMES (sym
, saved_package_name
,
10305 strlen (saved_package_name
), 0, objfile
);
10306 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
10307 e.g., "main" finds the "main" module and not C's main(). */
10308 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10309 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
10310 SYMBOL_TYPE (sym
) = type
;
10312 add_symbol_to_list (sym
, &global_symbols
);
10314 xfree (package_name
);
10318 /* Allocate a fully-qualified name consisting of the two parts on the
10321 static const char *
10322 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
10324 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
10327 /* A helper that allocates a struct discriminant_info to attach to a
10330 static struct discriminant_info
*
10331 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
10334 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10335 gdb_assert (discriminant_index
== -1
10336 || (discriminant_index
>= 0
10337 && discriminant_index
< TYPE_NFIELDS (type
)));
10338 gdb_assert (default_index
== -1
10339 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
10341 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
10343 struct discriminant_info
*disc
10344 = ((struct discriminant_info
*)
10346 offsetof (struct discriminant_info
, discriminants
)
10347 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
10348 disc
->default_index
= default_index
;
10349 disc
->discriminant_index
= discriminant_index
;
10351 struct dynamic_prop prop
;
10352 prop
.kind
= PROP_UNDEFINED
;
10353 prop
.data
.baton
= disc
;
10355 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
10360 /* Some versions of rustc emitted enums in an unusual way.
10362 Ordinary enums were emitted as unions. The first element of each
10363 structure in the union was named "RUST$ENUM$DISR". This element
10364 held the discriminant.
10366 These versions of Rust also implemented the "non-zero"
10367 optimization. When the enum had two values, and one is empty and
10368 the other holds a pointer that cannot be zero, the pointer is used
10369 as the discriminant, with a zero value meaning the empty variant.
10370 Here, the union's first member is of the form
10371 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10372 where the fieldnos are the indices of the fields that should be
10373 traversed in order to find the field (which may be several fields deep)
10374 and the variantname is the name of the variant of the case when the
10377 This function recognizes whether TYPE is of one of these forms,
10378 and, if so, smashes it to be a variant type. */
10381 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10383 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10385 /* We don't need to deal with empty enums. */
10386 if (TYPE_NFIELDS (type
) == 0)
10389 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10390 if (TYPE_NFIELDS (type
) == 1
10391 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10393 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10395 /* Decode the field name to find the offset of the
10397 ULONGEST bit_offset
= 0;
10398 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10399 while (name
[0] >= '0' && name
[0] <= '9')
10402 unsigned long index
= strtoul (name
, &tail
, 10);
10405 || index
>= TYPE_NFIELDS (field_type
)
10406 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10407 != FIELD_LOC_KIND_BITPOS
))
10409 complaint (&symfile_complaints
,
10410 _("Could not parse Rust enum encoding string \"%s\""
10412 TYPE_FIELD_NAME (type
, 0),
10413 objfile_name (objfile
));
10418 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10419 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10422 /* Make a union to hold the variants. */
10423 struct type
*union_type
= alloc_type (objfile
);
10424 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10425 TYPE_NFIELDS (union_type
) = 3;
10426 TYPE_FIELDS (union_type
)
10427 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10428 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10430 /* Put the discriminant must at index 0. */
10431 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10432 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10433 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10434 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10436 /* The order of fields doesn't really matter, so put the real
10437 field at index 1 and the data-less field at index 2. */
10438 struct discriminant_info
*disc
10439 = alloc_discriminant_info (union_type
, 0, 1);
10440 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10441 TYPE_FIELD_NAME (union_type
, 1)
10442 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10443 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10444 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10445 TYPE_FIELD_NAME (union_type
, 1));
10447 const char *dataless_name
10448 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10450 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10452 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10453 /* NAME points into the original discriminant name, which
10454 already has the correct lifetime. */
10455 TYPE_FIELD_NAME (union_type
, 2) = name
;
10456 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10457 disc
->discriminants
[2] = 0;
10459 /* Smash this type to be a structure type. We have to do this
10460 because the type has already been recorded. */
10461 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10462 TYPE_NFIELDS (type
) = 1;
10464 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10466 /* Install the variant part. */
10467 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10468 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10469 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10471 else if (TYPE_NFIELDS (type
) == 1)
10473 /* We assume that a union with a single field is a univariant
10475 /* Smash this type to be a structure type. We have to do this
10476 because the type has already been recorded. */
10477 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10479 /* Make a union to hold the variants. */
10480 struct type
*union_type
= alloc_type (objfile
);
10481 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10482 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10483 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10484 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10486 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10487 const char *variant_name
10488 = rust_last_path_segment (TYPE_NAME (field_type
));
10489 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10490 TYPE_NAME (field_type
)
10491 = rust_fully_qualify (&objfile
->objfile_obstack
,
10492 TYPE_NAME (type
), variant_name
);
10494 /* Install the union in the outer struct type. */
10495 TYPE_NFIELDS (type
) = 1;
10497 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10498 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10499 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10500 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10502 alloc_discriminant_info (union_type
, -1, 0);
10506 struct type
*disr_type
= nullptr;
10507 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10509 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10511 if (TYPE_NFIELDS (disr_type
) == 0)
10513 /* Could be data-less variant, so keep going. */
10515 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10516 "RUST$ENUM$DISR") != 0)
10518 /* Not a Rust enum. */
10528 /* If we got here without a discriminant, then it's probably
10530 if (disr_type
== nullptr)
10533 /* Smash this type to be a structure type. We have to do this
10534 because the type has already been recorded. */
10535 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10537 /* Make a union to hold the variants. */
10538 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10539 struct type
*union_type
= alloc_type (objfile
);
10540 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10541 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10542 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10543 TYPE_FIELDS (union_type
)
10544 = (struct field
*) TYPE_ZALLOC (union_type
,
10545 (TYPE_NFIELDS (union_type
)
10546 * sizeof (struct field
)));
10548 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10549 TYPE_NFIELDS (type
) * sizeof (struct field
));
10551 /* Install the discriminant at index 0 in the union. */
10552 TYPE_FIELD (union_type
, 0) = *disr_field
;
10553 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10554 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10556 /* Install the union in the outer struct type. */
10557 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10558 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10559 TYPE_NFIELDS (type
) = 1;
10561 /* Set the size and offset of the union type. */
10562 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10564 /* We need a way to find the correct discriminant given a
10565 variant name. For convenience we build a map here. */
10566 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10567 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10568 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10570 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10573 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10574 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10578 int n_fields
= TYPE_NFIELDS (union_type
);
10579 struct discriminant_info
*disc
10580 = alloc_discriminant_info (union_type
, 0, -1);
10581 /* Skip the discriminant here. */
10582 for (int i
= 1; i
< n_fields
; ++i
)
10584 /* Find the final word in the name of this variant's type.
10585 That name can be used to look up the correct
10587 const char *variant_name
10588 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10591 auto iter
= discriminant_map
.find (variant_name
);
10592 if (iter
!= discriminant_map
.end ())
10593 disc
->discriminants
[i
] = iter
->second
;
10595 /* Remove the discriminant field. */
10596 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10597 --TYPE_NFIELDS (sub_type
);
10598 ++TYPE_FIELDS (sub_type
);
10599 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10600 TYPE_NAME (sub_type
)
10601 = rust_fully_qualify (&objfile
->objfile_obstack
,
10602 TYPE_NAME (type
), variant_name
);
10607 /* Rewrite some Rust unions to be structures with variants parts. */
10610 rust_union_quirks (struct dwarf2_cu
*cu
)
10612 gdb_assert (cu
->language
== language_rust
);
10613 for (struct type
*type
: cu
->rust_unions
)
10614 quirk_rust_enum (type
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10617 /* Return the symtab for PER_CU. This works properly regardless of
10618 whether we're using the index or psymtabs. */
10620 static struct compunit_symtab
*
10621 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10623 return (per_cu
->dwarf2_per_objfile
->using_index
10624 ? per_cu
->v
.quick
->compunit_symtab
10625 : per_cu
->v
.psymtab
->compunit_symtab
);
10628 /* A helper function for computing the list of all symbol tables
10629 included by PER_CU. */
10632 recursively_compute_inclusions (VEC (compunit_symtab_ptr
) **result
,
10633 htab_t all_children
, htab_t all_type_symtabs
,
10634 struct dwarf2_per_cu_data
*per_cu
,
10635 struct compunit_symtab
*immediate_parent
)
10639 struct compunit_symtab
*cust
;
10640 struct dwarf2_per_cu_data
*iter
;
10642 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10645 /* This inclusion and its children have been processed. */
10650 /* Only add a CU if it has a symbol table. */
10651 cust
= get_compunit_symtab (per_cu
);
10654 /* If this is a type unit only add its symbol table if we haven't
10655 seen it yet (type unit per_cu's can share symtabs). */
10656 if (per_cu
->is_debug_types
)
10658 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10662 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10663 if (cust
->user
== NULL
)
10664 cust
->user
= immediate_parent
;
10669 VEC_safe_push (compunit_symtab_ptr
, *result
, cust
);
10670 if (cust
->user
== NULL
)
10671 cust
->user
= immediate_parent
;
10676 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, ix
, iter
);
10679 recursively_compute_inclusions (result
, all_children
,
10680 all_type_symtabs
, iter
, cust
);
10684 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10688 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10690 gdb_assert (! per_cu
->is_debug_types
);
10692 if (!VEC_empty (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
))
10695 struct dwarf2_per_cu_data
*per_cu_iter
;
10696 struct compunit_symtab
*compunit_symtab_iter
;
10697 VEC (compunit_symtab_ptr
) *result_symtabs
= NULL
;
10698 htab_t all_children
, all_type_symtabs
;
10699 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10701 /* If we don't have a symtab, we can just skip this case. */
10705 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10706 NULL
, xcalloc
, xfree
);
10707 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10708 NULL
, xcalloc
, xfree
);
10711 VEC_iterate (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
,
10715 recursively_compute_inclusions (&result_symtabs
, all_children
,
10716 all_type_symtabs
, per_cu_iter
,
10720 /* Now we have a transitive closure of all the included symtabs. */
10721 len
= VEC_length (compunit_symtab_ptr
, result_symtabs
);
10723 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10724 struct compunit_symtab
*, len
+ 1);
10726 VEC_iterate (compunit_symtab_ptr
, result_symtabs
, ix
,
10727 compunit_symtab_iter
);
10729 cust
->includes
[ix
] = compunit_symtab_iter
;
10730 cust
->includes
[len
] = NULL
;
10732 VEC_free (compunit_symtab_ptr
, result_symtabs
);
10733 htab_delete (all_children
);
10734 htab_delete (all_type_symtabs
);
10738 /* Compute the 'includes' field for the symtabs of all the CUs we just
10742 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10745 struct dwarf2_per_cu_data
*iter
;
10748 VEC_iterate (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
,
10752 if (! iter
->is_debug_types
)
10753 compute_compunit_symtab_includes (iter
);
10756 VEC_free (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
);
10759 /* Generate full symbol information for PER_CU, whose DIEs have
10760 already been loaded into memory. */
10763 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10764 enum language pretend_language
)
10766 struct dwarf2_cu
*cu
= per_cu
->cu
;
10767 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10768 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10769 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10770 CORE_ADDR lowpc
, highpc
;
10771 struct compunit_symtab
*cust
;
10772 CORE_ADDR baseaddr
;
10773 struct block
*static_block
;
10776 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10779 scoped_free_pendings free_pending
;
10781 /* Clear the list here in case something was left over. */
10782 cu
->method_list
.clear ();
10784 cu
->list_in_scope
= &file_symbols
;
10786 cu
->language
= pretend_language
;
10787 cu
->language_defn
= language_def (cu
->language
);
10789 /* Do line number decoding in read_file_scope () */
10790 process_die (cu
->dies
, cu
);
10792 /* For now fudge the Go package. */
10793 if (cu
->language
== language_go
)
10794 fixup_go_packaging (cu
);
10796 /* Now that we have processed all the DIEs in the CU, all the types
10797 should be complete, and it should now be safe to compute all of the
10799 compute_delayed_physnames (cu
);
10801 if (cu
->language
== language_rust
)
10802 rust_union_quirks (cu
);
10804 /* Some compilers don't define a DW_AT_high_pc attribute for the
10805 compilation unit. If the DW_AT_high_pc is missing, synthesize
10806 it, by scanning the DIE's below the compilation unit. */
10807 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10809 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10810 static_block
= end_symtab_get_static_block (addr
, 0, 1);
10812 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10813 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10814 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10815 addrmap to help ensure it has an accurate map of pc values belonging to
10817 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10819 cust
= end_symtab_from_static_block (static_block
,
10820 SECT_OFF_TEXT (objfile
), 0);
10824 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10826 /* Set symtab language to language from DW_AT_language. If the
10827 compilation is from a C file generated by language preprocessors, do
10828 not set the language if it was already deduced by start_subfile. */
10829 if (!(cu
->language
== language_c
10830 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10831 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10833 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10834 produce DW_AT_location with location lists but it can be possibly
10835 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10836 there were bugs in prologue debug info, fixed later in GCC-4.5
10837 by "unwind info for epilogues" patch (which is not directly related).
10839 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10840 needed, it would be wrong due to missing DW_AT_producer there.
10842 Still one can confuse GDB by using non-standard GCC compilation
10843 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10845 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10846 cust
->locations_valid
= 1;
10848 if (gcc_4_minor
>= 5)
10849 cust
->epilogue_unwind_valid
= 1;
10851 cust
->call_site_htab
= cu
->call_site_htab
;
10854 if (dwarf2_per_objfile
->using_index
)
10855 per_cu
->v
.quick
->compunit_symtab
= cust
;
10858 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10859 pst
->compunit_symtab
= cust
;
10863 /* Push it for inclusion processing later. */
10864 VEC_safe_push (dwarf2_per_cu_ptr
, dwarf2_per_objfile
->just_read_cus
, per_cu
);
10867 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10868 already been loaded into memory. */
10871 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10872 enum language pretend_language
)
10874 struct dwarf2_cu
*cu
= per_cu
->cu
;
10875 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10876 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10877 struct compunit_symtab
*cust
;
10878 struct signatured_type
*sig_type
;
10880 gdb_assert (per_cu
->is_debug_types
);
10881 sig_type
= (struct signatured_type
*) per_cu
;
10884 scoped_free_pendings free_pending
;
10886 /* Clear the list here in case something was left over. */
10887 cu
->method_list
.clear ();
10889 cu
->list_in_scope
= &file_symbols
;
10891 cu
->language
= pretend_language
;
10892 cu
->language_defn
= language_def (cu
->language
);
10894 /* The symbol tables are set up in read_type_unit_scope. */
10895 process_die (cu
->dies
, cu
);
10897 /* For now fudge the Go package. */
10898 if (cu
->language
== language_go
)
10899 fixup_go_packaging (cu
);
10901 /* Now that we have processed all the DIEs in the CU, all the types
10902 should be complete, and it should now be safe to compute all of the
10904 compute_delayed_physnames (cu
);
10906 if (cu
->language
== language_rust
)
10907 rust_union_quirks (cu
);
10909 /* TUs share symbol tables.
10910 If this is the first TU to use this symtab, complete the construction
10911 of it with end_expandable_symtab. Otherwise, complete the addition of
10912 this TU's symbols to the existing symtab. */
10913 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10915 cust
= end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10916 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10920 /* Set symtab language to language from DW_AT_language. If the
10921 compilation is from a C file generated by language preprocessors,
10922 do not set the language if it was already deduced by
10924 if (!(cu
->language
== language_c
10925 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10926 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10931 augment_type_symtab ();
10932 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10935 if (dwarf2_per_objfile
->using_index
)
10936 per_cu
->v
.quick
->compunit_symtab
= cust
;
10939 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10940 pst
->compunit_symtab
= cust
;
10945 /* Process an imported unit DIE. */
10948 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10950 struct attribute
*attr
;
10952 /* For now we don't handle imported units in type units. */
10953 if (cu
->per_cu
->is_debug_types
)
10955 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10956 " supported in type units [in module %s]"),
10957 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10960 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10963 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10964 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10965 dwarf2_per_cu_data
*per_cu
10966 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10967 cu
->per_cu
->dwarf2_per_objfile
);
10969 /* If necessary, add it to the queue and load its DIEs. */
10970 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10971 load_full_comp_unit (per_cu
, cu
->language
);
10973 VEC_safe_push (dwarf2_per_cu_ptr
, cu
->per_cu
->imported_symtabs
,
10978 /* RAII object that represents a process_die scope: i.e.,
10979 starts/finishes processing a DIE. */
10980 class process_die_scope
10983 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10984 : m_die (die
), m_cu (cu
)
10986 /* We should only be processing DIEs not already in process. */
10987 gdb_assert (!m_die
->in_process
);
10988 m_die
->in_process
= true;
10991 ~process_die_scope ()
10993 m_die
->in_process
= false;
10995 /* If we're done processing the DIE for the CU that owns the line
10996 header, we don't need the line header anymore. */
10997 if (m_cu
->line_header_die_owner
== m_die
)
10999 delete m_cu
->line_header
;
11000 m_cu
->line_header
= NULL
;
11001 m_cu
->line_header_die_owner
= NULL
;
11010 /* Process a die and its children. */
11013 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11015 process_die_scope
scope (die
, cu
);
11019 case DW_TAG_padding
:
11021 case DW_TAG_compile_unit
:
11022 case DW_TAG_partial_unit
:
11023 read_file_scope (die
, cu
);
11025 case DW_TAG_type_unit
:
11026 read_type_unit_scope (die
, cu
);
11028 case DW_TAG_subprogram
:
11029 case DW_TAG_inlined_subroutine
:
11030 read_func_scope (die
, cu
);
11032 case DW_TAG_lexical_block
:
11033 case DW_TAG_try_block
:
11034 case DW_TAG_catch_block
:
11035 read_lexical_block_scope (die
, cu
);
11037 case DW_TAG_call_site
:
11038 case DW_TAG_GNU_call_site
:
11039 read_call_site_scope (die
, cu
);
11041 case DW_TAG_class_type
:
11042 case DW_TAG_interface_type
:
11043 case DW_TAG_structure_type
:
11044 case DW_TAG_union_type
:
11045 process_structure_scope (die
, cu
);
11047 case DW_TAG_enumeration_type
:
11048 process_enumeration_scope (die
, cu
);
11051 /* These dies have a type, but processing them does not create
11052 a symbol or recurse to process the children. Therefore we can
11053 read them on-demand through read_type_die. */
11054 case DW_TAG_subroutine_type
:
11055 case DW_TAG_set_type
:
11056 case DW_TAG_array_type
:
11057 case DW_TAG_pointer_type
:
11058 case DW_TAG_ptr_to_member_type
:
11059 case DW_TAG_reference_type
:
11060 case DW_TAG_rvalue_reference_type
:
11061 case DW_TAG_string_type
:
11064 case DW_TAG_base_type
:
11065 case DW_TAG_subrange_type
:
11066 case DW_TAG_typedef
:
11067 /* Add a typedef symbol for the type definition, if it has a
11069 new_symbol (die
, read_type_die (die
, cu
), cu
);
11071 case DW_TAG_common_block
:
11072 read_common_block (die
, cu
);
11074 case DW_TAG_common_inclusion
:
11076 case DW_TAG_namespace
:
11077 cu
->processing_has_namespace_info
= 1;
11078 read_namespace (die
, cu
);
11080 case DW_TAG_module
:
11081 cu
->processing_has_namespace_info
= 1;
11082 read_module (die
, cu
);
11084 case DW_TAG_imported_declaration
:
11085 cu
->processing_has_namespace_info
= 1;
11086 if (read_namespace_alias (die
, cu
))
11088 /* The declaration is not a global namespace alias: fall through. */
11089 case DW_TAG_imported_module
:
11090 cu
->processing_has_namespace_info
= 1;
11091 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
11092 || cu
->language
!= language_fortran
))
11093 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
11094 dwarf_tag_name (die
->tag
));
11095 read_import_statement (die
, cu
);
11098 case DW_TAG_imported_unit
:
11099 process_imported_unit_die (die
, cu
);
11102 case DW_TAG_variable
:
11103 read_variable (die
, cu
);
11107 new_symbol (die
, NULL
, cu
);
11112 /* DWARF name computation. */
11114 /* A helper function for dwarf2_compute_name which determines whether DIE
11115 needs to have the name of the scope prepended to the name listed in the
11119 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
11121 struct attribute
*attr
;
11125 case DW_TAG_namespace
:
11126 case DW_TAG_typedef
:
11127 case DW_TAG_class_type
:
11128 case DW_TAG_interface_type
:
11129 case DW_TAG_structure_type
:
11130 case DW_TAG_union_type
:
11131 case DW_TAG_enumeration_type
:
11132 case DW_TAG_enumerator
:
11133 case DW_TAG_subprogram
:
11134 case DW_TAG_inlined_subroutine
:
11135 case DW_TAG_member
:
11136 case DW_TAG_imported_declaration
:
11139 case DW_TAG_variable
:
11140 case DW_TAG_constant
:
11141 /* We only need to prefix "globally" visible variables. These include
11142 any variable marked with DW_AT_external or any variable that
11143 lives in a namespace. [Variables in anonymous namespaces
11144 require prefixing, but they are not DW_AT_external.] */
11146 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
11148 struct dwarf2_cu
*spec_cu
= cu
;
11150 return die_needs_namespace (die_specification (die
, &spec_cu
),
11154 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
11155 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
11156 && die
->parent
->tag
!= DW_TAG_module
)
11158 /* A variable in a lexical block of some kind does not need a
11159 namespace, even though in C++ such variables may be external
11160 and have a mangled name. */
11161 if (die
->parent
->tag
== DW_TAG_lexical_block
11162 || die
->parent
->tag
== DW_TAG_try_block
11163 || die
->parent
->tag
== DW_TAG_catch_block
11164 || die
->parent
->tag
== DW_TAG_subprogram
)
11173 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
11174 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
11175 defined for the given DIE. */
11177 static struct attribute
*
11178 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
11180 struct attribute
*attr
;
11182 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
11184 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
11189 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
11190 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
11191 defined for the given DIE. */
11193 static const char *
11194 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11196 const char *linkage_name
;
11198 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
11199 if (linkage_name
== NULL
)
11200 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
11202 return linkage_name
;
11205 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
11206 compute the physname for the object, which include a method's:
11207 - formal parameters (C++),
11208 - receiver type (Go),
11210 The term "physname" is a bit confusing.
11211 For C++, for example, it is the demangled name.
11212 For Go, for example, it's the mangled name.
11214 For Ada, return the DIE's linkage name rather than the fully qualified
11215 name. PHYSNAME is ignored..
11217 The result is allocated on the objfile_obstack and canonicalized. */
11219 static const char *
11220 dwarf2_compute_name (const char *name
,
11221 struct die_info
*die
, struct dwarf2_cu
*cu
,
11224 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11227 name
= dwarf2_name (die
, cu
);
11229 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
11230 but otherwise compute it by typename_concat inside GDB.
11231 FIXME: Actually this is not really true, or at least not always true.
11232 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
11233 Fortran names because there is no mangling standard. So new_symbol
11234 will set the demangled name to the result of dwarf2_full_name, and it is
11235 the demangled name that GDB uses if it exists. */
11236 if (cu
->language
== language_ada
11237 || (cu
->language
== language_fortran
&& physname
))
11239 /* For Ada unit, we prefer the linkage name over the name, as
11240 the former contains the exported name, which the user expects
11241 to be able to reference. Ideally, we want the user to be able
11242 to reference this entity using either natural or linkage name,
11243 but we haven't started looking at this enhancement yet. */
11244 const char *linkage_name
= dw2_linkage_name (die
, cu
);
11246 if (linkage_name
!= NULL
)
11247 return linkage_name
;
11250 /* These are the only languages we know how to qualify names in. */
11252 && (cu
->language
== language_cplus
11253 || cu
->language
== language_fortran
|| cu
->language
== language_d
11254 || cu
->language
== language_rust
))
11256 if (die_needs_namespace (die
, cu
))
11258 const char *prefix
;
11259 const char *canonical_name
= NULL
;
11263 prefix
= determine_prefix (die
, cu
);
11264 if (*prefix
!= '\0')
11266 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
11269 buf
.puts (prefixed_name
);
11270 xfree (prefixed_name
);
11275 /* Template parameters may be specified in the DIE's DW_AT_name, or
11276 as children with DW_TAG_template_type_param or
11277 DW_TAG_value_type_param. If the latter, add them to the name
11278 here. If the name already has template parameters, then
11279 skip this step; some versions of GCC emit both, and
11280 it is more efficient to use the pre-computed name.
11282 Something to keep in mind about this process: it is very
11283 unlikely, or in some cases downright impossible, to produce
11284 something that will match the mangled name of a function.
11285 If the definition of the function has the same debug info,
11286 we should be able to match up with it anyway. But fallbacks
11287 using the minimal symbol, for instance to find a method
11288 implemented in a stripped copy of libstdc++, will not work.
11289 If we do not have debug info for the definition, we will have to
11290 match them up some other way.
11292 When we do name matching there is a related problem with function
11293 templates; two instantiated function templates are allowed to
11294 differ only by their return types, which we do not add here. */
11296 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
11298 struct attribute
*attr
;
11299 struct die_info
*child
;
11302 die
->building_fullname
= 1;
11304 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
11308 const gdb_byte
*bytes
;
11309 struct dwarf2_locexpr_baton
*baton
;
11312 if (child
->tag
!= DW_TAG_template_type_param
11313 && child
->tag
!= DW_TAG_template_value_param
)
11324 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
11327 complaint (&symfile_complaints
,
11328 _("template parameter missing DW_AT_type"));
11329 buf
.puts ("UNKNOWN_TYPE");
11332 type
= die_type (child
, cu
);
11334 if (child
->tag
== DW_TAG_template_type_param
)
11336 c_print_type (type
, "", &buf
, -1, 0, &type_print_raw_options
);
11340 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
11343 complaint (&symfile_complaints
,
11344 _("template parameter missing "
11345 "DW_AT_const_value"));
11346 buf
.puts ("UNKNOWN_VALUE");
11350 dwarf2_const_value_attr (attr
, type
, name
,
11351 &cu
->comp_unit_obstack
, cu
,
11352 &value
, &bytes
, &baton
);
11354 if (TYPE_NOSIGN (type
))
11355 /* GDB prints characters as NUMBER 'CHAR'. If that's
11356 changed, this can use value_print instead. */
11357 c_printchar (value
, type
, &buf
);
11360 struct value_print_options opts
;
11363 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
11367 else if (bytes
!= NULL
)
11369 v
= allocate_value (type
);
11370 memcpy (value_contents_writeable (v
), bytes
,
11371 TYPE_LENGTH (type
));
11374 v
= value_from_longest (type
, value
);
11376 /* Specify decimal so that we do not depend on
11378 get_formatted_print_options (&opts
, 'd');
11380 value_print (v
, &buf
, &opts
);
11386 die
->building_fullname
= 0;
11390 /* Close the argument list, with a space if necessary
11391 (nested templates). */
11392 if (!buf
.empty () && buf
.string ().back () == '>')
11399 /* For C++ methods, append formal parameter type
11400 information, if PHYSNAME. */
11402 if (physname
&& die
->tag
== DW_TAG_subprogram
11403 && cu
->language
== language_cplus
)
11405 struct type
*type
= read_type_die (die
, cu
);
11407 c_type_print_args (type
, &buf
, 1, cu
->language
,
11408 &type_print_raw_options
);
11410 if (cu
->language
== language_cplus
)
11412 /* Assume that an artificial first parameter is
11413 "this", but do not crash if it is not. RealView
11414 marks unnamed (and thus unused) parameters as
11415 artificial; there is no way to differentiate
11417 if (TYPE_NFIELDS (type
) > 0
11418 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11419 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11420 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11422 buf
.puts (" const");
11426 const std::string
&intermediate_name
= buf
.string ();
11428 if (cu
->language
== language_cplus
)
11430 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11431 &objfile
->per_bfd
->storage_obstack
);
11433 /* If we only computed INTERMEDIATE_NAME, or if
11434 INTERMEDIATE_NAME is already canonical, then we need to
11435 copy it to the appropriate obstack. */
11436 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11437 name
= ((const char *)
11438 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11439 intermediate_name
.c_str (),
11440 intermediate_name
.length ()));
11442 name
= canonical_name
;
11449 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11450 If scope qualifiers are appropriate they will be added. The result
11451 will be allocated on the storage_obstack, or NULL if the DIE does
11452 not have a name. NAME may either be from a previous call to
11453 dwarf2_name or NULL.
11455 The output string will be canonicalized (if C++). */
11457 static const char *
11458 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11460 return dwarf2_compute_name (name
, die
, cu
, 0);
11463 /* Construct a physname for the given DIE in CU. NAME may either be
11464 from a previous call to dwarf2_name or NULL. The result will be
11465 allocated on the objfile_objstack or NULL if the DIE does not have a
11468 The output string will be canonicalized (if C++). */
11470 static const char *
11471 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11473 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11474 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11477 /* In this case dwarf2_compute_name is just a shortcut not building anything
11479 if (!die_needs_namespace (die
, cu
))
11480 return dwarf2_compute_name (name
, die
, cu
, 1);
11482 mangled
= dw2_linkage_name (die
, cu
);
11484 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11485 See https://github.com/rust-lang/rust/issues/32925. */
11486 if (cu
->language
== language_rust
&& mangled
!= NULL
11487 && strchr (mangled
, '{') != NULL
)
11490 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11492 gdb::unique_xmalloc_ptr
<char> demangled
;
11493 if (mangled
!= NULL
)
11496 if (cu
->language
== language_go
)
11498 /* This is a lie, but we already lie to the caller new_symbol.
11499 new_symbol assumes we return the mangled name.
11500 This just undoes that lie until things are cleaned up. */
11504 /* Use DMGL_RET_DROP for C++ template functions to suppress
11505 their return type. It is easier for GDB users to search
11506 for such functions as `name(params)' than `long name(params)'.
11507 In such case the minimal symbol names do not match the full
11508 symbol names but for template functions there is never a need
11509 to look up their definition from their declaration so
11510 the only disadvantage remains the minimal symbol variant
11511 `long name(params)' does not have the proper inferior type. */
11512 demangled
.reset (gdb_demangle (mangled
,
11513 (DMGL_PARAMS
| DMGL_ANSI
11514 | DMGL_RET_DROP
)));
11517 canon
= demangled
.get ();
11525 if (canon
== NULL
|| check_physname
)
11527 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11529 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11531 /* It may not mean a bug in GDB. The compiler could also
11532 compute DW_AT_linkage_name incorrectly. But in such case
11533 GDB would need to be bug-to-bug compatible. */
11535 complaint (&symfile_complaints
,
11536 _("Computed physname <%s> does not match demangled <%s> "
11537 "(from linkage <%s>) - DIE at %s [in module %s]"),
11538 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11539 objfile_name (objfile
));
11541 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11542 is available here - over computed PHYSNAME. It is safer
11543 against both buggy GDB and buggy compilers. */
11557 retval
= ((const char *)
11558 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
11559 retval
, strlen (retval
)));
11564 /* Inspect DIE in CU for a namespace alias. If one exists, record
11565 a new symbol for it.
11567 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11570 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11572 struct attribute
*attr
;
11574 /* If the die does not have a name, this is not a namespace
11576 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11580 struct die_info
*d
= die
;
11581 struct dwarf2_cu
*imported_cu
= cu
;
11583 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11584 keep inspecting DIEs until we hit the underlying import. */
11585 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11586 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11588 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11592 d
= follow_die_ref (d
, attr
, &imported_cu
);
11593 if (d
->tag
!= DW_TAG_imported_declaration
)
11597 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11599 complaint (&symfile_complaints
,
11600 _("DIE at %s has too many recursively imported "
11601 "declarations"), sect_offset_str (d
->sect_off
));
11608 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11610 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11611 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11613 /* This declaration is a global namespace alias. Add
11614 a symbol for it whose type is the aliased namespace. */
11615 new_symbol (die
, type
, cu
);
11624 /* Return the using directives repository (global or local?) to use in the
11625 current context for LANGUAGE.
11627 For Ada, imported declarations can materialize renamings, which *may* be
11628 global. However it is impossible (for now?) in DWARF to distinguish
11629 "external" imported declarations and "static" ones. As all imported
11630 declarations seem to be static in all other languages, make them all CU-wide
11631 global only in Ada. */
11633 static struct using_direct
**
11634 using_directives (enum language language
)
11636 if (language
== language_ada
&& context_stack_depth
== 0)
11637 return &global_using_directives
;
11639 return &local_using_directives
;
11642 /* Read the import statement specified by the given die and record it. */
11645 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11647 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11648 struct attribute
*import_attr
;
11649 struct die_info
*imported_die
, *child_die
;
11650 struct dwarf2_cu
*imported_cu
;
11651 const char *imported_name
;
11652 const char *imported_name_prefix
;
11653 const char *canonical_name
;
11654 const char *import_alias
;
11655 const char *imported_declaration
= NULL
;
11656 const char *import_prefix
;
11657 std::vector
<const char *> excludes
;
11659 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11660 if (import_attr
== NULL
)
11662 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11663 dwarf_tag_name (die
->tag
));
11668 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11669 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11670 if (imported_name
== NULL
)
11672 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11674 The import in the following code:
11688 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11689 <52> DW_AT_decl_file : 1
11690 <53> DW_AT_decl_line : 6
11691 <54> DW_AT_import : <0x75>
11692 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11693 <59> DW_AT_name : B
11694 <5b> DW_AT_decl_file : 1
11695 <5c> DW_AT_decl_line : 2
11696 <5d> DW_AT_type : <0x6e>
11698 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11699 <76> DW_AT_byte_size : 4
11700 <77> DW_AT_encoding : 5 (signed)
11702 imports the wrong die ( 0x75 instead of 0x58 ).
11703 This case will be ignored until the gcc bug is fixed. */
11707 /* Figure out the local name after import. */
11708 import_alias
= dwarf2_name (die
, cu
);
11710 /* Figure out where the statement is being imported to. */
11711 import_prefix
= determine_prefix (die
, cu
);
11713 /* Figure out what the scope of the imported die is and prepend it
11714 to the name of the imported die. */
11715 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11717 if (imported_die
->tag
!= DW_TAG_namespace
11718 && imported_die
->tag
!= DW_TAG_module
)
11720 imported_declaration
= imported_name
;
11721 canonical_name
= imported_name_prefix
;
11723 else if (strlen (imported_name_prefix
) > 0)
11724 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11725 imported_name_prefix
,
11726 (cu
->language
== language_d
? "." : "::"),
11727 imported_name
, (char *) NULL
);
11729 canonical_name
= imported_name
;
11731 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11732 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11733 child_die
= sibling_die (child_die
))
11735 /* DWARF-4: A Fortran use statement with a “rename list” may be
11736 represented by an imported module entry with an import attribute
11737 referring to the module and owned entries corresponding to those
11738 entities that are renamed as part of being imported. */
11740 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11742 complaint (&symfile_complaints
,
11743 _("child DW_TAG_imported_declaration expected "
11744 "- DIE at %s [in module %s]"),
11745 sect_offset_str (child_die
->sect_off
),
11746 objfile_name (objfile
));
11750 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11751 if (import_attr
== NULL
)
11753 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
11754 dwarf_tag_name (child_die
->tag
));
11759 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11761 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11762 if (imported_name
== NULL
)
11764 complaint (&symfile_complaints
,
11765 _("child DW_TAG_imported_declaration has unknown "
11766 "imported name - DIE at %s [in module %s]"),
11767 sect_offset_str (child_die
->sect_off
),
11768 objfile_name (objfile
));
11772 excludes
.push_back (imported_name
);
11774 process_die (child_die
, cu
);
11777 add_using_directive (using_directives (cu
->language
),
11781 imported_declaration
,
11784 &objfile
->objfile_obstack
);
11787 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11788 types, but gives them a size of zero. Starting with version 14,
11789 ICC is compatible with GCC. */
11792 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11794 if (!cu
->checked_producer
)
11795 check_producer (cu
);
11797 return cu
->producer_is_icc_lt_14
;
11800 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11801 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11802 this, it was first present in GCC release 4.3.0. */
11805 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11807 if (!cu
->checked_producer
)
11808 check_producer (cu
);
11810 return cu
->producer_is_gcc_lt_4_3
;
11813 static file_and_directory
11814 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11816 file_and_directory res
;
11818 /* Find the filename. Do not use dwarf2_name here, since the filename
11819 is not a source language identifier. */
11820 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11821 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11823 if (res
.comp_dir
== NULL
11824 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11825 && IS_ABSOLUTE_PATH (res
.name
))
11827 res
.comp_dir_storage
= ldirname (res
.name
);
11828 if (!res
.comp_dir_storage
.empty ())
11829 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11831 if (res
.comp_dir
!= NULL
)
11833 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11834 directory, get rid of it. */
11835 const char *cp
= strchr (res
.comp_dir
, ':');
11837 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11838 res
.comp_dir
= cp
+ 1;
11841 if (res
.name
== NULL
)
11842 res
.name
= "<unknown>";
11847 /* Handle DW_AT_stmt_list for a compilation unit.
11848 DIE is the DW_TAG_compile_unit die for CU.
11849 COMP_DIR is the compilation directory. LOWPC is passed to
11850 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11853 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11854 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11856 struct dwarf2_per_objfile
*dwarf2_per_objfile
11857 = cu
->per_cu
->dwarf2_per_objfile
;
11858 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11859 struct attribute
*attr
;
11860 struct line_header line_header_local
;
11861 hashval_t line_header_local_hash
;
11863 int decode_mapping
;
11865 gdb_assert (! cu
->per_cu
->is_debug_types
);
11867 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11871 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11873 /* The line header hash table is only created if needed (it exists to
11874 prevent redundant reading of the line table for partial_units).
11875 If we're given a partial_unit, we'll need it. If we're given a
11876 compile_unit, then use the line header hash table if it's already
11877 created, but don't create one just yet. */
11879 if (dwarf2_per_objfile
->line_header_hash
== NULL
11880 && die
->tag
== DW_TAG_partial_unit
)
11882 dwarf2_per_objfile
->line_header_hash
11883 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11884 line_header_eq_voidp
,
11885 free_line_header_voidp
,
11886 &objfile
->objfile_obstack
,
11887 hashtab_obstack_allocate
,
11888 dummy_obstack_deallocate
);
11891 line_header_local
.sect_off
= line_offset
;
11892 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11893 line_header_local_hash
= line_header_hash (&line_header_local
);
11894 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11896 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11897 &line_header_local
,
11898 line_header_local_hash
, NO_INSERT
);
11900 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11901 is not present in *SLOT (since if there is something in *SLOT then
11902 it will be for a partial_unit). */
11903 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11905 gdb_assert (*slot
!= NULL
);
11906 cu
->line_header
= (struct line_header
*) *slot
;
11911 /* dwarf_decode_line_header does not yet provide sufficient information.
11912 We always have to call also dwarf_decode_lines for it. */
11913 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11917 cu
->line_header
= lh
.release ();
11918 cu
->line_header_die_owner
= die
;
11920 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11924 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11925 &line_header_local
,
11926 line_header_local_hash
, INSERT
);
11927 gdb_assert (slot
!= NULL
);
11929 if (slot
!= NULL
&& *slot
== NULL
)
11931 /* This newly decoded line number information unit will be owned
11932 by line_header_hash hash table. */
11933 *slot
= cu
->line_header
;
11934 cu
->line_header_die_owner
= NULL
;
11938 /* We cannot free any current entry in (*slot) as that struct line_header
11939 may be already used by multiple CUs. Create only temporary decoded
11940 line_header for this CU - it may happen at most once for each line
11941 number information unit. And if we're not using line_header_hash
11942 then this is what we want as well. */
11943 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11945 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11946 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11951 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11954 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11956 struct dwarf2_per_objfile
*dwarf2_per_objfile
11957 = cu
->per_cu
->dwarf2_per_objfile
;
11958 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11959 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11960 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11961 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11962 struct attribute
*attr
;
11963 struct die_info
*child_die
;
11964 CORE_ADDR baseaddr
;
11966 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11968 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11970 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11971 from finish_block. */
11972 if (lowpc
== ((CORE_ADDR
) -1))
11974 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11976 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11978 prepare_one_comp_unit (cu
, die
, cu
->language
);
11980 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11981 standardised yet. As a workaround for the language detection we fall
11982 back to the DW_AT_producer string. */
11983 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11984 cu
->language
= language_opencl
;
11986 /* Similar hack for Go. */
11987 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11988 set_cu_language (DW_LANG_Go
, cu
);
11990 dwarf2_start_symtab (cu
, fnd
.name
, fnd
.comp_dir
, lowpc
);
11992 /* Decode line number information if present. We do this before
11993 processing child DIEs, so that the line header table is available
11994 for DW_AT_decl_file. */
11995 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11997 /* Process all dies in compilation unit. */
11998 if (die
->child
!= NULL
)
12000 child_die
= die
->child
;
12001 while (child_die
&& child_die
->tag
)
12003 process_die (child_die
, cu
);
12004 child_die
= sibling_die (child_die
);
12008 /* Decode macro information, if present. Dwarf 2 macro information
12009 refers to information in the line number info statement program
12010 header, so we can only read it if we've read the header
12012 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
12014 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
12015 if (attr
&& cu
->line_header
)
12017 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
12018 complaint (&symfile_complaints
,
12019 _("CU refers to both DW_AT_macros and DW_AT_macro_info"));
12021 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
12025 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
12026 if (attr
&& cu
->line_header
)
12028 unsigned int macro_offset
= DW_UNSND (attr
);
12030 dwarf_decode_macros (cu
, macro_offset
, 0);
12035 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
12036 Create the set of symtabs used by this TU, or if this TU is sharing
12037 symtabs with another TU and the symtabs have already been created
12038 then restore those symtabs in the line header.
12039 We don't need the pc/line-number mapping for type units. */
12042 setup_type_unit_groups (struct die_info
*die
, struct dwarf2_cu
*cu
)
12044 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
12045 struct type_unit_group
*tu_group
;
12047 struct attribute
*attr
;
12049 struct signatured_type
*sig_type
;
12051 gdb_assert (per_cu
->is_debug_types
);
12052 sig_type
= (struct signatured_type
*) per_cu
;
12054 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
12056 /* If we're using .gdb_index (includes -readnow) then
12057 per_cu->type_unit_group may not have been set up yet. */
12058 if (sig_type
->type_unit_group
== NULL
)
12059 sig_type
->type_unit_group
= get_type_unit_group (cu
, attr
);
12060 tu_group
= sig_type
->type_unit_group
;
12062 /* If we've already processed this stmt_list there's no real need to
12063 do it again, we could fake it and just recreate the part we need
12064 (file name,index -> symtab mapping). If data shows this optimization
12065 is useful we can do it then. */
12066 first_time
= tu_group
->compunit_symtab
== NULL
;
12068 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
12073 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
12074 lh
= dwarf_decode_line_header (line_offset
, cu
);
12079 dwarf2_start_symtab (cu
, "", NULL
, 0);
12082 gdb_assert (tu_group
->symtabs
== NULL
);
12083 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12088 cu
->line_header
= lh
.release ();
12089 cu
->line_header_die_owner
= die
;
12093 struct compunit_symtab
*cust
= dwarf2_start_symtab (cu
, "", NULL
, 0);
12095 /* Note: We don't assign tu_group->compunit_symtab yet because we're
12096 still initializing it, and our caller (a few levels up)
12097 process_full_type_unit still needs to know if this is the first
12100 tu_group
->num_symtabs
= cu
->line_header
->file_names
.size ();
12101 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
12102 cu
->line_header
->file_names
.size ());
12104 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12106 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12108 dwarf2_start_subfile (fe
.name
, fe
.include_dir (cu
->line_header
));
12110 if (current_subfile
->symtab
== NULL
)
12112 /* NOTE: start_subfile will recognize when it's been
12113 passed a file it has already seen. So we can't
12114 assume there's a simple mapping from
12115 cu->line_header->file_names to subfiles, plus
12116 cu->line_header->file_names may contain dups. */
12117 current_subfile
->symtab
12118 = allocate_symtab (cust
, current_subfile
->name
);
12121 fe
.symtab
= current_subfile
->symtab
;
12122 tu_group
->symtabs
[i
] = fe
.symtab
;
12127 restart_symtab (tu_group
->compunit_symtab
, "", 0);
12129 for (i
= 0; i
< cu
->line_header
->file_names
.size (); ++i
)
12131 file_entry
&fe
= cu
->line_header
->file_names
[i
];
12133 fe
.symtab
= tu_group
->symtabs
[i
];
12137 /* The main symtab is allocated last. Type units don't have DW_AT_name
12138 so they don't have a "real" (so to speak) symtab anyway.
12139 There is later code that will assign the main symtab to all symbols
12140 that don't have one. We need to handle the case of a symbol with a
12141 missing symtab (DW_AT_decl_file) anyway. */
12144 /* Process DW_TAG_type_unit.
12145 For TUs we want to skip the first top level sibling if it's not the
12146 actual type being defined by this TU. In this case the first top
12147 level sibling is there to provide context only. */
12150 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12152 struct die_info
*child_die
;
12154 prepare_one_comp_unit (cu
, die
, language_minimal
);
12156 /* Initialize (or reinitialize) the machinery for building symtabs.
12157 We do this before processing child DIEs, so that the line header table
12158 is available for DW_AT_decl_file. */
12159 setup_type_unit_groups (die
, cu
);
12161 if (die
->child
!= NULL
)
12163 child_die
= die
->child
;
12164 while (child_die
&& child_die
->tag
)
12166 process_die (child_die
, cu
);
12167 child_die
= sibling_die (child_die
);
12174 http://gcc.gnu.org/wiki/DebugFission
12175 http://gcc.gnu.org/wiki/DebugFissionDWP
12177 To simplify handling of both DWO files ("object" files with the DWARF info)
12178 and DWP files (a file with the DWOs packaged up into one file), we treat
12179 DWP files as having a collection of virtual DWO files. */
12182 hash_dwo_file (const void *item
)
12184 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
12187 hash
= htab_hash_string (dwo_file
->dwo_name
);
12188 if (dwo_file
->comp_dir
!= NULL
)
12189 hash
+= htab_hash_string (dwo_file
->comp_dir
);
12194 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
12196 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
12197 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
12199 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
12201 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
12202 return lhs
->comp_dir
== rhs
->comp_dir
;
12203 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
12206 /* Allocate a hash table for DWO files. */
12209 allocate_dwo_file_hash_table (struct objfile
*objfile
)
12211 return htab_create_alloc_ex (41,
12215 &objfile
->objfile_obstack
,
12216 hashtab_obstack_allocate
,
12217 dummy_obstack_deallocate
);
12220 /* Lookup DWO file DWO_NAME. */
12223 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12224 const char *dwo_name
,
12225 const char *comp_dir
)
12227 struct dwo_file find_entry
;
12230 if (dwarf2_per_objfile
->dwo_files
== NULL
)
12231 dwarf2_per_objfile
->dwo_files
12232 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
12234 memset (&find_entry
, 0, sizeof (find_entry
));
12235 find_entry
.dwo_name
= dwo_name
;
12236 find_entry
.comp_dir
= comp_dir
;
12237 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
, &find_entry
, INSERT
);
12243 hash_dwo_unit (const void *item
)
12245 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12247 /* This drops the top 32 bits of the id, but is ok for a hash. */
12248 return dwo_unit
->signature
;
12252 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
12254 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
12255 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
12257 /* The signature is assumed to be unique within the DWO file.
12258 So while object file CU dwo_id's always have the value zero,
12259 that's OK, assuming each object file DWO file has only one CU,
12260 and that's the rule for now. */
12261 return lhs
->signature
== rhs
->signature
;
12264 /* Allocate a hash table for DWO CUs,TUs.
12265 There is one of these tables for each of CUs,TUs for each DWO file. */
12268 allocate_dwo_unit_table (struct objfile
*objfile
)
12270 /* Start out with a pretty small number.
12271 Generally DWO files contain only one CU and maybe some TUs. */
12272 return htab_create_alloc_ex (3,
12276 &objfile
->objfile_obstack
,
12277 hashtab_obstack_allocate
,
12278 dummy_obstack_deallocate
);
12281 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
12283 struct create_dwo_cu_data
12285 struct dwo_file
*dwo_file
;
12286 struct dwo_unit dwo_unit
;
12289 /* die_reader_func for create_dwo_cu. */
12292 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
12293 const gdb_byte
*info_ptr
,
12294 struct die_info
*comp_unit_die
,
12298 struct dwarf2_cu
*cu
= reader
->cu
;
12299 sect_offset sect_off
= cu
->per_cu
->sect_off
;
12300 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
12301 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
12302 struct dwo_file
*dwo_file
= data
->dwo_file
;
12303 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
12304 struct attribute
*attr
;
12306 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
12309 complaint (&symfile_complaints
,
12310 _("Dwarf Error: debug entry at offset %s is missing"
12311 " its dwo_id [in module %s]"),
12312 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
12316 dwo_unit
->dwo_file
= dwo_file
;
12317 dwo_unit
->signature
= DW_UNSND (attr
);
12318 dwo_unit
->section
= section
;
12319 dwo_unit
->sect_off
= sect_off
;
12320 dwo_unit
->length
= cu
->per_cu
->length
;
12322 if (dwarf_read_debug
)
12323 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
12324 sect_offset_str (sect_off
),
12325 hex_string (dwo_unit
->signature
));
12328 /* Create the dwo_units for the CUs in a DWO_FILE.
12329 Note: This function processes DWO files only, not DWP files. */
12332 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12333 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
12336 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12337 const gdb_byte
*info_ptr
, *end_ptr
;
12339 dwarf2_read_section (objfile
, §ion
);
12340 info_ptr
= section
.buffer
;
12342 if (info_ptr
== NULL
)
12345 if (dwarf_read_debug
)
12347 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12348 get_section_name (§ion
),
12349 get_section_file_name (§ion
));
12352 end_ptr
= info_ptr
+ section
.size
;
12353 while (info_ptr
< end_ptr
)
12355 struct dwarf2_per_cu_data per_cu
;
12356 struct create_dwo_cu_data create_dwo_cu_data
;
12357 struct dwo_unit
*dwo_unit
;
12359 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12361 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12362 sizeof (create_dwo_cu_data
.dwo_unit
));
12363 memset (&per_cu
, 0, sizeof (per_cu
));
12364 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12365 per_cu
.is_debug_types
= 0;
12366 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12367 per_cu
.section
= §ion
;
12368 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12370 init_cutu_and_read_dies_no_follow (
12371 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12372 info_ptr
+= per_cu
.length
;
12374 // If the unit could not be parsed, skip it.
12375 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12378 if (cus_htab
== NULL
)
12379 cus_htab
= allocate_dwo_unit_table (objfile
);
12381 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12382 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12383 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12384 gdb_assert (slot
!= NULL
);
12387 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12388 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12390 complaint (&symfile_complaints
,
12391 _("debug cu entry at offset %s is duplicate to"
12392 " the entry at offset %s, signature %s"),
12393 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12394 hex_string (dwo_unit
->signature
));
12396 *slot
= (void *)dwo_unit
;
12400 /* DWP file .debug_{cu,tu}_index section format:
12401 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12405 Both index sections have the same format, and serve to map a 64-bit
12406 signature to a set of section numbers. Each section begins with a header,
12407 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12408 indexes, and a pool of 32-bit section numbers. The index sections will be
12409 aligned at 8-byte boundaries in the file.
12411 The index section header consists of:
12413 V, 32 bit version number
12415 N, 32 bit number of compilation units or type units in the index
12416 M, 32 bit number of slots in the hash table
12418 Numbers are recorded using the byte order of the application binary.
12420 The hash table begins at offset 16 in the section, and consists of an array
12421 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12422 order of the application binary). Unused slots in the hash table are 0.
12423 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12425 The parallel table begins immediately after the hash table
12426 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12427 array of 32-bit indexes (using the byte order of the application binary),
12428 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12429 table contains a 32-bit index into the pool of section numbers. For unused
12430 hash table slots, the corresponding entry in the parallel table will be 0.
12432 The pool of section numbers begins immediately following the hash table
12433 (at offset 16 + 12 * M from the beginning of the section). The pool of
12434 section numbers consists of an array of 32-bit words (using the byte order
12435 of the application binary). Each item in the array is indexed starting
12436 from 0. The hash table entry provides the index of the first section
12437 number in the set. Additional section numbers in the set follow, and the
12438 set is terminated by a 0 entry (section number 0 is not used in ELF).
12440 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12441 section must be the first entry in the set, and the .debug_abbrev.dwo must
12442 be the second entry. Other members of the set may follow in any order.
12448 DWP Version 2 combines all the .debug_info, etc. sections into one,
12449 and the entries in the index tables are now offsets into these sections.
12450 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12453 Index Section Contents:
12455 Hash Table of Signatures dwp_hash_table.hash_table
12456 Parallel Table of Indices dwp_hash_table.unit_table
12457 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12458 Table of Section Sizes dwp_hash_table.v2.sizes
12460 The index section header consists of:
12462 V, 32 bit version number
12463 L, 32 bit number of columns in the table of section offsets
12464 N, 32 bit number of compilation units or type units in the index
12465 M, 32 bit number of slots in the hash table
12467 Numbers are recorded using the byte order of the application binary.
12469 The hash table has the same format as version 1.
12470 The parallel table of indices has the same format as version 1,
12471 except that the entries are origin-1 indices into the table of sections
12472 offsets and the table of section sizes.
12474 The table of offsets begins immediately following the parallel table
12475 (at offset 16 + 12 * M from the beginning of the section). The table is
12476 a two-dimensional array of 32-bit words (using the byte order of the
12477 application binary), with L columns and N+1 rows, in row-major order.
12478 Each row in the array is indexed starting from 0. The first row provides
12479 a key to the remaining rows: each column in this row provides an identifier
12480 for a debug section, and the offsets in the same column of subsequent rows
12481 refer to that section. The section identifiers are:
12483 DW_SECT_INFO 1 .debug_info.dwo
12484 DW_SECT_TYPES 2 .debug_types.dwo
12485 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12486 DW_SECT_LINE 4 .debug_line.dwo
12487 DW_SECT_LOC 5 .debug_loc.dwo
12488 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12489 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12490 DW_SECT_MACRO 8 .debug_macro.dwo
12492 The offsets provided by the CU and TU index sections are the base offsets
12493 for the contributions made by each CU or TU to the corresponding section
12494 in the package file. Each CU and TU header contains an abbrev_offset
12495 field, used to find the abbreviations table for that CU or TU within the
12496 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12497 be interpreted as relative to the base offset given in the index section.
12498 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12499 should be interpreted as relative to the base offset for .debug_line.dwo,
12500 and offsets into other debug sections obtained from DWARF attributes should
12501 also be interpreted as relative to the corresponding base offset.
12503 The table of sizes begins immediately following the table of offsets.
12504 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12505 with L columns and N rows, in row-major order. Each row in the array is
12506 indexed starting from 1 (row 0 is shared by the two tables).
12510 Hash table lookup is handled the same in version 1 and 2:
12512 We assume that N and M will not exceed 2^32 - 1.
12513 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12515 Given a 64-bit compilation unit signature or a type signature S, an entry
12516 in the hash table is located as follows:
12518 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12519 the low-order k bits all set to 1.
12521 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12523 3) If the hash table entry at index H matches the signature, use that
12524 entry. If the hash table entry at index H is unused (all zeroes),
12525 terminate the search: the signature is not present in the table.
12527 4) Let H = (H + H') modulo M. Repeat at Step 3.
12529 Because M > N and H' and M are relatively prime, the search is guaranteed
12530 to stop at an unused slot or find the match. */
12532 /* Create a hash table to map DWO IDs to their CU/TU entry in
12533 .debug_{info,types}.dwo in DWP_FILE.
12534 Returns NULL if there isn't one.
12535 Note: This function processes DWP files only, not DWO files. */
12537 static struct dwp_hash_table
*
12538 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12539 struct dwp_file
*dwp_file
, int is_debug_types
)
12541 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12542 bfd
*dbfd
= dwp_file
->dbfd
;
12543 const gdb_byte
*index_ptr
, *index_end
;
12544 struct dwarf2_section_info
*index
;
12545 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12546 struct dwp_hash_table
*htab
;
12548 if (is_debug_types
)
12549 index
= &dwp_file
->sections
.tu_index
;
12551 index
= &dwp_file
->sections
.cu_index
;
12553 if (dwarf2_section_empty_p (index
))
12555 dwarf2_read_section (objfile
, index
);
12557 index_ptr
= index
->buffer
;
12558 index_end
= index_ptr
+ index
->size
;
12560 version
= read_4_bytes (dbfd
, index_ptr
);
12563 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12567 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12569 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12572 if (version
!= 1 && version
!= 2)
12574 error (_("Dwarf Error: unsupported DWP file version (%s)"
12575 " [in module %s]"),
12576 pulongest (version
), dwp_file
->name
);
12578 if (nr_slots
!= (nr_slots
& -nr_slots
))
12580 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12581 " is not power of 2 [in module %s]"),
12582 pulongest (nr_slots
), dwp_file
->name
);
12585 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12586 htab
->version
= version
;
12587 htab
->nr_columns
= nr_columns
;
12588 htab
->nr_units
= nr_units
;
12589 htab
->nr_slots
= nr_slots
;
12590 htab
->hash_table
= index_ptr
;
12591 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12593 /* Exit early if the table is empty. */
12594 if (nr_slots
== 0 || nr_units
== 0
12595 || (version
== 2 && nr_columns
== 0))
12597 /* All must be zero. */
12598 if (nr_slots
!= 0 || nr_units
!= 0
12599 || (version
== 2 && nr_columns
!= 0))
12601 complaint (&symfile_complaints
,
12602 _("Empty DWP but nr_slots,nr_units,nr_columns not"
12603 " all zero [in modules %s]"),
12611 htab
->section_pool
.v1
.indices
=
12612 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12613 /* It's harder to decide whether the section is too small in v1.
12614 V1 is deprecated anyway so we punt. */
12618 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12619 int *ids
= htab
->section_pool
.v2
.section_ids
;
12620 /* Reverse map for error checking. */
12621 int ids_seen
[DW_SECT_MAX
+ 1];
12624 if (nr_columns
< 2)
12626 error (_("Dwarf Error: bad DWP hash table, too few columns"
12627 " in section table [in module %s]"),
12630 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12632 error (_("Dwarf Error: bad DWP hash table, too many columns"
12633 " in section table [in module %s]"),
12636 memset (ids
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12637 memset (ids_seen
, 255, (DW_SECT_MAX
+ 1) * sizeof (int32_t));
12638 for (i
= 0; i
< nr_columns
; ++i
)
12640 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12642 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12644 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12645 " in section table [in module %s]"),
12646 id
, dwp_file
->name
);
12648 if (ids_seen
[id
] != -1)
12650 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12651 " id %d in section table [in module %s]"),
12652 id
, dwp_file
->name
);
12657 /* Must have exactly one info or types section. */
12658 if (((ids_seen
[DW_SECT_INFO
] != -1)
12659 + (ids_seen
[DW_SECT_TYPES
] != -1))
12662 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12663 " DWO info/types section [in module %s]"),
12666 /* Must have an abbrev section. */
12667 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12669 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12670 " section [in module %s]"),
12673 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12674 htab
->section_pool
.v2
.sizes
=
12675 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12676 * nr_units
* nr_columns
);
12677 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12678 * nr_units
* nr_columns
))
12681 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12682 " [in module %s]"),
12690 /* Update SECTIONS with the data from SECTP.
12692 This function is like the other "locate" section routines that are
12693 passed to bfd_map_over_sections, but in this context the sections to
12694 read comes from the DWP V1 hash table, not the full ELF section table.
12696 The result is non-zero for success, or zero if an error was found. */
12699 locate_v1_virtual_dwo_sections (asection
*sectp
,
12700 struct virtual_v1_dwo_sections
*sections
)
12702 const struct dwop_section_names
*names
= &dwop_section_names
;
12704 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12706 /* There can be only one. */
12707 if (sections
->abbrev
.s
.section
!= NULL
)
12709 sections
->abbrev
.s
.section
= sectp
;
12710 sections
->abbrev
.size
= bfd_get_section_size (sectp
);
12712 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12713 || section_is_p (sectp
->name
, &names
->types_dwo
))
12715 /* There can be only one. */
12716 if (sections
->info_or_types
.s
.section
!= NULL
)
12718 sections
->info_or_types
.s
.section
= sectp
;
12719 sections
->info_or_types
.size
= bfd_get_section_size (sectp
);
12721 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12723 /* There can be only one. */
12724 if (sections
->line
.s
.section
!= NULL
)
12726 sections
->line
.s
.section
= sectp
;
12727 sections
->line
.size
= bfd_get_section_size (sectp
);
12729 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12731 /* There can be only one. */
12732 if (sections
->loc
.s
.section
!= NULL
)
12734 sections
->loc
.s
.section
= sectp
;
12735 sections
->loc
.size
= bfd_get_section_size (sectp
);
12737 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12739 /* There can be only one. */
12740 if (sections
->macinfo
.s
.section
!= NULL
)
12742 sections
->macinfo
.s
.section
= sectp
;
12743 sections
->macinfo
.size
= bfd_get_section_size (sectp
);
12745 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12747 /* There can be only one. */
12748 if (sections
->macro
.s
.section
!= NULL
)
12750 sections
->macro
.s
.section
= sectp
;
12751 sections
->macro
.size
= bfd_get_section_size (sectp
);
12753 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12755 /* There can be only one. */
12756 if (sections
->str_offsets
.s
.section
!= NULL
)
12758 sections
->str_offsets
.s
.section
= sectp
;
12759 sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
12763 /* No other kind of section is valid. */
12770 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12771 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12772 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12773 This is for DWP version 1 files. */
12775 static struct dwo_unit
*
12776 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12777 struct dwp_file
*dwp_file
,
12778 uint32_t unit_index
,
12779 const char *comp_dir
,
12780 ULONGEST signature
, int is_debug_types
)
12782 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12783 const struct dwp_hash_table
*dwp_htab
=
12784 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12785 bfd
*dbfd
= dwp_file
->dbfd
;
12786 const char *kind
= is_debug_types
? "TU" : "CU";
12787 struct dwo_file
*dwo_file
;
12788 struct dwo_unit
*dwo_unit
;
12789 struct virtual_v1_dwo_sections sections
;
12790 void **dwo_file_slot
;
12793 gdb_assert (dwp_file
->version
== 1);
12795 if (dwarf_read_debug
)
12797 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12799 pulongest (unit_index
), hex_string (signature
),
12803 /* Fetch the sections of this DWO unit.
12804 Put a limit on the number of sections we look for so that bad data
12805 doesn't cause us to loop forever. */
12807 #define MAX_NR_V1_DWO_SECTIONS \
12808 (1 /* .debug_info or .debug_types */ \
12809 + 1 /* .debug_abbrev */ \
12810 + 1 /* .debug_line */ \
12811 + 1 /* .debug_loc */ \
12812 + 1 /* .debug_str_offsets */ \
12813 + 1 /* .debug_macro or .debug_macinfo */ \
12814 + 1 /* trailing zero */)
12816 memset (§ions
, 0, sizeof (sections
));
12818 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12821 uint32_t section_nr
=
12822 read_4_bytes (dbfd
,
12823 dwp_htab
->section_pool
.v1
.indices
12824 + (unit_index
+ i
) * sizeof (uint32_t));
12826 if (section_nr
== 0)
12828 if (section_nr
>= dwp_file
->num_sections
)
12830 error (_("Dwarf Error: bad DWP hash table, section number too large"
12831 " [in module %s]"),
12835 sectp
= dwp_file
->elf_sections
[section_nr
];
12836 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12838 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12839 " [in module %s]"),
12845 || dwarf2_section_empty_p (§ions
.info_or_types
)
12846 || dwarf2_section_empty_p (§ions
.abbrev
))
12848 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12849 " [in module %s]"),
12852 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12854 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12855 " [in module %s]"),
12859 /* It's easier for the rest of the code if we fake a struct dwo_file and
12860 have dwo_unit "live" in that. At least for now.
12862 The DWP file can be made up of a random collection of CUs and TUs.
12863 However, for each CU + set of TUs that came from the same original DWO
12864 file, we can combine them back into a virtual DWO file to save space
12865 (fewer struct dwo_file objects to allocate). Remember that for really
12866 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12868 std::string virtual_dwo_name
=
12869 string_printf ("virtual-dwo/%d-%d-%d-%d",
12870 get_section_id (§ions
.abbrev
),
12871 get_section_id (§ions
.line
),
12872 get_section_id (§ions
.loc
),
12873 get_section_id (§ions
.str_offsets
));
12874 /* Can we use an existing virtual DWO file? */
12875 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12876 virtual_dwo_name
.c_str (),
12878 /* Create one if necessary. */
12879 if (*dwo_file_slot
== NULL
)
12881 if (dwarf_read_debug
)
12883 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12884 virtual_dwo_name
.c_str ());
12886 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
12888 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
12889 virtual_dwo_name
.c_str (),
12890 virtual_dwo_name
.size ());
12891 dwo_file
->comp_dir
= comp_dir
;
12892 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12893 dwo_file
->sections
.line
= sections
.line
;
12894 dwo_file
->sections
.loc
= sections
.loc
;
12895 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12896 dwo_file
->sections
.macro
= sections
.macro
;
12897 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12898 /* The "str" section is global to the entire DWP file. */
12899 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12900 /* The info or types section is assigned below to dwo_unit,
12901 there's no need to record it in dwo_file.
12902 Also, we can't simply record type sections in dwo_file because
12903 we record a pointer into the vector in dwo_unit. As we collect more
12904 types we'll grow the vector and eventually have to reallocate space
12905 for it, invalidating all copies of pointers into the previous
12907 *dwo_file_slot
= dwo_file
;
12911 if (dwarf_read_debug
)
12913 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12914 virtual_dwo_name
.c_str ());
12916 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12919 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12920 dwo_unit
->dwo_file
= dwo_file
;
12921 dwo_unit
->signature
= signature
;
12922 dwo_unit
->section
=
12923 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12924 *dwo_unit
->section
= sections
.info_or_types
;
12925 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12930 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12931 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12932 piece within that section used by a TU/CU, return a virtual section
12933 of just that piece. */
12935 static struct dwarf2_section_info
12936 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12937 struct dwarf2_section_info
*section
,
12938 bfd_size_type offset
, bfd_size_type size
)
12940 struct dwarf2_section_info result
;
12943 gdb_assert (section
!= NULL
);
12944 gdb_assert (!section
->is_virtual
);
12946 memset (&result
, 0, sizeof (result
));
12947 result
.s
.containing_section
= section
;
12948 result
.is_virtual
= 1;
12953 sectp
= get_section_bfd_section (section
);
12955 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12956 bounds of the real section. This is a pretty-rare event, so just
12957 flag an error (easier) instead of a warning and trying to cope. */
12959 || offset
+ size
> bfd_get_section_size (sectp
))
12961 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12962 " in section %s [in module %s]"),
12963 sectp
? bfd_section_name (abfd
, sectp
) : "<unknown>",
12964 objfile_name (dwarf2_per_objfile
->objfile
));
12967 result
.virtual_offset
= offset
;
12968 result
.size
= size
;
12972 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12973 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12974 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12975 This is for DWP version 2 files. */
12977 static struct dwo_unit
*
12978 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12979 struct dwp_file
*dwp_file
,
12980 uint32_t unit_index
,
12981 const char *comp_dir
,
12982 ULONGEST signature
, int is_debug_types
)
12984 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12985 const struct dwp_hash_table
*dwp_htab
=
12986 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12987 bfd
*dbfd
= dwp_file
->dbfd
;
12988 const char *kind
= is_debug_types
? "TU" : "CU";
12989 struct dwo_file
*dwo_file
;
12990 struct dwo_unit
*dwo_unit
;
12991 struct virtual_v2_dwo_sections sections
;
12992 void **dwo_file_slot
;
12995 gdb_assert (dwp_file
->version
== 2);
12997 if (dwarf_read_debug
)
12999 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
13001 pulongest (unit_index
), hex_string (signature
),
13005 /* Fetch the section offsets of this DWO unit. */
13007 memset (§ions
, 0, sizeof (sections
));
13009 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
13011 uint32_t offset
= read_4_bytes (dbfd
,
13012 dwp_htab
->section_pool
.v2
.offsets
13013 + (((unit_index
- 1) * dwp_htab
->nr_columns
13015 * sizeof (uint32_t)));
13016 uint32_t size
= read_4_bytes (dbfd
,
13017 dwp_htab
->section_pool
.v2
.sizes
13018 + (((unit_index
- 1) * dwp_htab
->nr_columns
13020 * sizeof (uint32_t)));
13022 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
13025 case DW_SECT_TYPES
:
13026 sections
.info_or_types_offset
= offset
;
13027 sections
.info_or_types_size
= size
;
13029 case DW_SECT_ABBREV
:
13030 sections
.abbrev_offset
= offset
;
13031 sections
.abbrev_size
= size
;
13034 sections
.line_offset
= offset
;
13035 sections
.line_size
= size
;
13038 sections
.loc_offset
= offset
;
13039 sections
.loc_size
= size
;
13041 case DW_SECT_STR_OFFSETS
:
13042 sections
.str_offsets_offset
= offset
;
13043 sections
.str_offsets_size
= size
;
13045 case DW_SECT_MACINFO
:
13046 sections
.macinfo_offset
= offset
;
13047 sections
.macinfo_size
= size
;
13049 case DW_SECT_MACRO
:
13050 sections
.macro_offset
= offset
;
13051 sections
.macro_size
= size
;
13056 /* It's easier for the rest of the code if we fake a struct dwo_file and
13057 have dwo_unit "live" in that. At least for now.
13059 The DWP file can be made up of a random collection of CUs and TUs.
13060 However, for each CU + set of TUs that came from the same original DWO
13061 file, we can combine them back into a virtual DWO file to save space
13062 (fewer struct dwo_file objects to allocate). Remember that for really
13063 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
13065 std::string virtual_dwo_name
=
13066 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
13067 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
13068 (long) (sections
.line_size
? sections
.line_offset
: 0),
13069 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
13070 (long) (sections
.str_offsets_size
13071 ? sections
.str_offsets_offset
: 0));
13072 /* Can we use an existing virtual DWO file? */
13073 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13074 virtual_dwo_name
.c_str (),
13076 /* Create one if necessary. */
13077 if (*dwo_file_slot
== NULL
)
13079 if (dwarf_read_debug
)
13081 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
13082 virtual_dwo_name
.c_str ());
13084 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13086 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
13087 virtual_dwo_name
.c_str (),
13088 virtual_dwo_name
.size ());
13089 dwo_file
->comp_dir
= comp_dir
;
13090 dwo_file
->sections
.abbrev
=
13091 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
13092 sections
.abbrev_offset
, sections
.abbrev_size
);
13093 dwo_file
->sections
.line
=
13094 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
13095 sections
.line_offset
, sections
.line_size
);
13096 dwo_file
->sections
.loc
=
13097 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
13098 sections
.loc_offset
, sections
.loc_size
);
13099 dwo_file
->sections
.macinfo
=
13100 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
13101 sections
.macinfo_offset
, sections
.macinfo_size
);
13102 dwo_file
->sections
.macro
=
13103 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
13104 sections
.macro_offset
, sections
.macro_size
);
13105 dwo_file
->sections
.str_offsets
=
13106 create_dwp_v2_section (dwarf2_per_objfile
,
13107 &dwp_file
->sections
.str_offsets
,
13108 sections
.str_offsets_offset
,
13109 sections
.str_offsets_size
);
13110 /* The "str" section is global to the entire DWP file. */
13111 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
13112 /* The info or types section is assigned below to dwo_unit,
13113 there's no need to record it in dwo_file.
13114 Also, we can't simply record type sections in dwo_file because
13115 we record a pointer into the vector in dwo_unit. As we collect more
13116 types we'll grow the vector and eventually have to reallocate space
13117 for it, invalidating all copies of pointers into the previous
13119 *dwo_file_slot
= dwo_file
;
13123 if (dwarf_read_debug
)
13125 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
13126 virtual_dwo_name
.c_str ());
13128 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13131 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
13132 dwo_unit
->dwo_file
= dwo_file
;
13133 dwo_unit
->signature
= signature
;
13134 dwo_unit
->section
=
13135 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
13136 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
13138 ? &dwp_file
->sections
.types
13139 : &dwp_file
->sections
.info
,
13140 sections
.info_or_types_offset
,
13141 sections
.info_or_types_size
);
13142 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
13147 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
13148 Returns NULL if the signature isn't found. */
13150 static struct dwo_unit
*
13151 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13152 struct dwp_file
*dwp_file
, const char *comp_dir
,
13153 ULONGEST signature
, int is_debug_types
)
13155 const struct dwp_hash_table
*dwp_htab
=
13156 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13157 bfd
*dbfd
= dwp_file
->dbfd
;
13158 uint32_t mask
= dwp_htab
->nr_slots
- 1;
13159 uint32_t hash
= signature
& mask
;
13160 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
13163 struct dwo_unit find_dwo_cu
;
13165 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
13166 find_dwo_cu
.signature
= signature
;
13167 slot
= htab_find_slot (is_debug_types
13168 ? dwp_file
->loaded_tus
13169 : dwp_file
->loaded_cus
,
13170 &find_dwo_cu
, INSERT
);
13173 return (struct dwo_unit
*) *slot
;
13175 /* Use a for loop so that we don't loop forever on bad debug info. */
13176 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
13178 ULONGEST signature_in_table
;
13180 signature_in_table
=
13181 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
13182 if (signature_in_table
== signature
)
13184 uint32_t unit_index
=
13185 read_4_bytes (dbfd
,
13186 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
13188 if (dwp_file
->version
== 1)
13190 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
13191 dwp_file
, unit_index
,
13192 comp_dir
, signature
,
13197 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
13198 dwp_file
, unit_index
,
13199 comp_dir
, signature
,
13202 return (struct dwo_unit
*) *slot
;
13204 if (signature_in_table
== 0)
13206 hash
= (hash
+ hash2
) & mask
;
13209 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
13210 " [in module %s]"),
13214 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
13215 Open the file specified by FILE_NAME and hand it off to BFD for
13216 preliminary analysis. Return a newly initialized bfd *, which
13217 includes a canonicalized copy of FILE_NAME.
13218 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
13219 SEARCH_CWD is true if the current directory is to be searched.
13220 It will be searched before debug-file-directory.
13221 If successful, the file is added to the bfd include table of the
13222 objfile's bfd (see gdb_bfd_record_inclusion).
13223 If unable to find/open the file, return NULL.
13224 NOTE: This function is derived from symfile_bfd_open. */
13226 static gdb_bfd_ref_ptr
13227 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13228 const char *file_name
, int is_dwp
, int search_cwd
)
13231 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
13232 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
13233 to debug_file_directory. */
13234 const char *search_path
;
13235 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
13237 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
13240 if (*debug_file_directory
!= '\0')
13242 search_path_holder
.reset (concat (".", dirname_separator_string
,
13243 debug_file_directory
,
13245 search_path
= search_path_holder
.get ();
13251 search_path
= debug_file_directory
;
13253 openp_flags flags
= OPF_RETURN_REALPATH
;
13255 flags
|= OPF_SEARCH_IN_PATH
;
13257 gdb::unique_xmalloc_ptr
<char> absolute_name
;
13258 desc
= openp (search_path
, flags
, file_name
,
13259 O_RDONLY
| O_BINARY
, &absolute_name
);
13263 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
13265 if (sym_bfd
== NULL
)
13267 bfd_set_cacheable (sym_bfd
.get (), 1);
13269 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
13272 /* Success. Record the bfd as having been included by the objfile's bfd.
13273 This is important because things like demangled_names_hash lives in the
13274 objfile's per_bfd space and may have references to things like symbol
13275 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
13276 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
13281 /* Try to open DWO file FILE_NAME.
13282 COMP_DIR is the DW_AT_comp_dir attribute.
13283 The result is the bfd handle of the file.
13284 If there is a problem finding or opening the file, return NULL.
13285 Upon success, the canonicalized path of the file is stored in the bfd,
13286 same as symfile_bfd_open. */
13288 static gdb_bfd_ref_ptr
13289 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13290 const char *file_name
, const char *comp_dir
)
13292 if (IS_ABSOLUTE_PATH (file_name
))
13293 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13294 0 /*is_dwp*/, 0 /*search_cwd*/);
13296 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
13298 if (comp_dir
!= NULL
)
13300 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
13301 file_name
, (char *) NULL
);
13303 /* NOTE: If comp_dir is a relative path, this will also try the
13304 search path, which seems useful. */
13305 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
13308 1 /*search_cwd*/));
13309 xfree (path_to_try
);
13314 /* That didn't work, try debug-file-directory, which, despite its name,
13315 is a list of paths. */
13317 if (*debug_file_directory
== '\0')
13320 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13321 0 /*is_dwp*/, 1 /*search_cwd*/);
13324 /* This function is mapped across the sections and remembers the offset and
13325 size of each of the DWO debugging sections we are interested in. */
13328 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
13330 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
13331 const struct dwop_section_names
*names
= &dwop_section_names
;
13333 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13335 dwo_sections
->abbrev
.s
.section
= sectp
;
13336 dwo_sections
->abbrev
.size
= bfd_get_section_size (sectp
);
13338 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13340 dwo_sections
->info
.s
.section
= sectp
;
13341 dwo_sections
->info
.size
= bfd_get_section_size (sectp
);
13343 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13345 dwo_sections
->line
.s
.section
= sectp
;
13346 dwo_sections
->line
.size
= bfd_get_section_size (sectp
);
13348 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13350 dwo_sections
->loc
.s
.section
= sectp
;
13351 dwo_sections
->loc
.size
= bfd_get_section_size (sectp
);
13353 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13355 dwo_sections
->macinfo
.s
.section
= sectp
;
13356 dwo_sections
->macinfo
.size
= bfd_get_section_size (sectp
);
13358 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13360 dwo_sections
->macro
.s
.section
= sectp
;
13361 dwo_sections
->macro
.size
= bfd_get_section_size (sectp
);
13363 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13365 dwo_sections
->str
.s
.section
= sectp
;
13366 dwo_sections
->str
.size
= bfd_get_section_size (sectp
);
13368 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13370 dwo_sections
->str_offsets
.s
.section
= sectp
;
13371 dwo_sections
->str_offsets
.size
= bfd_get_section_size (sectp
);
13373 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13375 struct dwarf2_section_info type_section
;
13377 memset (&type_section
, 0, sizeof (type_section
));
13378 type_section
.s
.section
= sectp
;
13379 type_section
.size
= bfd_get_section_size (sectp
);
13380 VEC_safe_push (dwarf2_section_info_def
, dwo_sections
->types
,
13385 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13386 by PER_CU. This is for the non-DWP case.
13387 The result is NULL if DWO_NAME can't be found. */
13389 static struct dwo_file
*
13390 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13391 const char *dwo_name
, const char *comp_dir
)
13393 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13394 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13395 struct dwo_file
*dwo_file
;
13396 struct cleanup
*cleanups
;
13398 gdb_bfd_ref_ptr
dbfd (open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
));
13401 if (dwarf_read_debug
)
13402 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13405 dwo_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_file
);
13406 dwo_file
->dwo_name
= dwo_name
;
13407 dwo_file
->comp_dir
= comp_dir
;
13408 dwo_file
->dbfd
= dbfd
.release ();
13410 free_dwo_file_cleanup_data
*cleanup_data
= XNEW (free_dwo_file_cleanup_data
);
13411 cleanup_data
->dwo_file
= dwo_file
;
13412 cleanup_data
->dwarf2_per_objfile
= dwarf2_per_objfile
;
13414 cleanups
= make_cleanup (free_dwo_file_cleanup
, cleanup_data
);
13416 bfd_map_over_sections (dwo_file
->dbfd
, dwarf2_locate_dwo_sections
,
13417 &dwo_file
->sections
);
13419 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13422 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
,
13423 dwo_file
->sections
.types
, dwo_file
->tus
);
13425 discard_cleanups (cleanups
);
13427 if (dwarf_read_debug
)
13428 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13433 /* This function is mapped across the sections and remembers the offset and
13434 size of each of the DWP debugging sections common to version 1 and 2 that
13435 we are interested in. */
13438 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13439 void *dwp_file_ptr
)
13441 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13442 const struct dwop_section_names
*names
= &dwop_section_names
;
13443 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13445 /* Record the ELF section number for later lookup: this is what the
13446 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13447 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13448 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13450 /* Look for specific sections that we need. */
13451 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13453 dwp_file
->sections
.str
.s
.section
= sectp
;
13454 dwp_file
->sections
.str
.size
= bfd_get_section_size (sectp
);
13456 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13458 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13459 dwp_file
->sections
.cu_index
.size
= bfd_get_section_size (sectp
);
13461 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13463 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13464 dwp_file
->sections
.tu_index
.size
= bfd_get_section_size (sectp
);
13468 /* This function is mapped across the sections and remembers the offset and
13469 size of each of the DWP version 2 debugging sections that we are interested
13470 in. This is split into a separate function because we don't know if we
13471 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13474 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13476 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13477 const struct dwop_section_names
*names
= &dwop_section_names
;
13478 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13480 /* Record the ELF section number for later lookup: this is what the
13481 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13482 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13483 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13485 /* Look for specific sections that we need. */
13486 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13488 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13489 dwp_file
->sections
.abbrev
.size
= bfd_get_section_size (sectp
);
13491 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13493 dwp_file
->sections
.info
.s
.section
= sectp
;
13494 dwp_file
->sections
.info
.size
= bfd_get_section_size (sectp
);
13496 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13498 dwp_file
->sections
.line
.s
.section
= sectp
;
13499 dwp_file
->sections
.line
.size
= bfd_get_section_size (sectp
);
13501 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13503 dwp_file
->sections
.loc
.s
.section
= sectp
;
13504 dwp_file
->sections
.loc
.size
= bfd_get_section_size (sectp
);
13506 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13508 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13509 dwp_file
->sections
.macinfo
.size
= bfd_get_section_size (sectp
);
13511 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13513 dwp_file
->sections
.macro
.s
.section
= sectp
;
13514 dwp_file
->sections
.macro
.size
= bfd_get_section_size (sectp
);
13516 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13518 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13519 dwp_file
->sections
.str_offsets
.size
= bfd_get_section_size (sectp
);
13521 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13523 dwp_file
->sections
.types
.s
.section
= sectp
;
13524 dwp_file
->sections
.types
.size
= bfd_get_section_size (sectp
);
13528 /* Hash function for dwp_file loaded CUs/TUs. */
13531 hash_dwp_loaded_cutus (const void *item
)
13533 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13535 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13536 return dwo_unit
->signature
;
13539 /* Equality function for dwp_file loaded CUs/TUs. */
13542 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13544 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13545 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13547 return dua
->signature
== dub
->signature
;
13550 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13553 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13555 return htab_create_alloc_ex (3,
13556 hash_dwp_loaded_cutus
,
13557 eq_dwp_loaded_cutus
,
13559 &objfile
->objfile_obstack
,
13560 hashtab_obstack_allocate
,
13561 dummy_obstack_deallocate
);
13564 /* Try to open DWP file FILE_NAME.
13565 The result is the bfd handle of the file.
13566 If there is a problem finding or opening the file, return NULL.
13567 Upon success, the canonicalized path of the file is stored in the bfd,
13568 same as symfile_bfd_open. */
13570 static gdb_bfd_ref_ptr
13571 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13572 const char *file_name
)
13574 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13576 1 /*search_cwd*/));
13580 /* Work around upstream bug 15652.
13581 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13582 [Whether that's a "bug" is debatable, but it is getting in our way.]
13583 We have no real idea where the dwp file is, because gdb's realpath-ing
13584 of the executable's path may have discarded the needed info.
13585 [IWBN if the dwp file name was recorded in the executable, akin to
13586 .gnu_debuglink, but that doesn't exist yet.]
13587 Strip the directory from FILE_NAME and search again. */
13588 if (*debug_file_directory
!= '\0')
13590 /* Don't implicitly search the current directory here.
13591 If the user wants to search "." to handle this case,
13592 it must be added to debug-file-directory. */
13593 return try_open_dwop_file (dwarf2_per_objfile
,
13594 lbasename (file_name
), 1 /*is_dwp*/,
13601 /* Initialize the use of the DWP file for the current objfile.
13602 By convention the name of the DWP file is ${objfile}.dwp.
13603 The result is NULL if it can't be found. */
13605 static struct dwp_file
*
13606 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13608 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13609 struct dwp_file
*dwp_file
;
13611 /* Try to find first .dwp for the binary file before any symbolic links
13614 /* If the objfile is a debug file, find the name of the real binary
13615 file and get the name of dwp file from there. */
13616 std::string dwp_name
;
13617 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13619 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13620 const char *backlink_basename
= lbasename (backlink
->original_name
);
13622 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13625 dwp_name
= objfile
->original_name
;
13627 dwp_name
+= ".dwp";
13629 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13631 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13633 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13634 dwp_name
= objfile_name (objfile
);
13635 dwp_name
+= ".dwp";
13636 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13641 if (dwarf_read_debug
)
13642 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13645 dwp_file
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_file
);
13646 dwp_file
->name
= bfd_get_filename (dbfd
.get ());
13647 dwp_file
->dbfd
= dbfd
.release ();
13649 /* +1: section 0 is unused */
13650 dwp_file
->num_sections
= bfd_count_sections (dwp_file
->dbfd
) + 1;
13651 dwp_file
->elf_sections
=
13652 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13653 dwp_file
->num_sections
, asection
*);
13655 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_common_dwp_sections
,
13658 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 0);
13660 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
, 1);
13662 /* The DWP file version is stored in the hash table. Oh well. */
13663 if (dwp_file
->cus
&& dwp_file
->tus
13664 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13666 /* Technically speaking, we should try to limp along, but this is
13667 pretty bizarre. We use pulongest here because that's the established
13668 portability solution (e.g, we cannot use %u for uint32_t). */
13669 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13670 " TU version %s [in DWP file %s]"),
13671 pulongest (dwp_file
->cus
->version
),
13672 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13676 dwp_file
->version
= dwp_file
->cus
->version
;
13677 else if (dwp_file
->tus
)
13678 dwp_file
->version
= dwp_file
->tus
->version
;
13680 dwp_file
->version
= 2;
13682 if (dwp_file
->version
== 2)
13683 bfd_map_over_sections (dwp_file
->dbfd
, dwarf2_locate_v2_dwp_sections
,
13686 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13687 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13689 if (dwarf_read_debug
)
13691 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13692 fprintf_unfiltered (gdb_stdlog
,
13693 " %s CUs, %s TUs\n",
13694 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13695 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13701 /* Wrapper around open_and_init_dwp_file, only open it once. */
13703 static struct dwp_file
*
13704 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13706 if (! dwarf2_per_objfile
->dwp_checked
)
13708 dwarf2_per_objfile
->dwp_file
13709 = open_and_init_dwp_file (dwarf2_per_objfile
);
13710 dwarf2_per_objfile
->dwp_checked
= 1;
13712 return dwarf2_per_objfile
->dwp_file
;
13715 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13716 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13717 or in the DWP file for the objfile, referenced by THIS_UNIT.
13718 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13719 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13721 This is called, for example, when wanting to read a variable with a
13722 complex location. Therefore we don't want to do file i/o for every call.
13723 Therefore we don't want to look for a DWO file on every call.
13724 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13725 then we check if we've already seen DWO_NAME, and only THEN do we check
13728 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13729 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13731 static struct dwo_unit
*
13732 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13733 const char *dwo_name
, const char *comp_dir
,
13734 ULONGEST signature
, int is_debug_types
)
13736 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13737 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13738 const char *kind
= is_debug_types
? "TU" : "CU";
13739 void **dwo_file_slot
;
13740 struct dwo_file
*dwo_file
;
13741 struct dwp_file
*dwp_file
;
13743 /* First see if there's a DWP file.
13744 If we have a DWP file but didn't find the DWO inside it, don't
13745 look for the original DWO file. It makes gdb behave differently
13746 depending on whether one is debugging in the build tree. */
13748 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13749 if (dwp_file
!= NULL
)
13751 const struct dwp_hash_table
*dwp_htab
=
13752 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13754 if (dwp_htab
!= NULL
)
13756 struct dwo_unit
*dwo_cutu
=
13757 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13758 signature
, is_debug_types
);
13760 if (dwo_cutu
!= NULL
)
13762 if (dwarf_read_debug
)
13764 fprintf_unfiltered (gdb_stdlog
,
13765 "Virtual DWO %s %s found: @%s\n",
13766 kind
, hex_string (signature
),
13767 host_address_to_string (dwo_cutu
));
13775 /* No DWP file, look for the DWO file. */
13777 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13778 dwo_name
, comp_dir
);
13779 if (*dwo_file_slot
== NULL
)
13781 /* Read in the file and build a table of the CUs/TUs it contains. */
13782 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13784 /* NOTE: This will be NULL if unable to open the file. */
13785 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13787 if (dwo_file
!= NULL
)
13789 struct dwo_unit
*dwo_cutu
= NULL
;
13791 if (is_debug_types
&& dwo_file
->tus
)
13793 struct dwo_unit find_dwo_cutu
;
13795 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13796 find_dwo_cutu
.signature
= signature
;
13798 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13800 else if (!is_debug_types
&& dwo_file
->cus
)
13802 struct dwo_unit find_dwo_cutu
;
13804 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13805 find_dwo_cutu
.signature
= signature
;
13806 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13810 if (dwo_cutu
!= NULL
)
13812 if (dwarf_read_debug
)
13814 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13815 kind
, dwo_name
, hex_string (signature
),
13816 host_address_to_string (dwo_cutu
));
13823 /* We didn't find it. This could mean a dwo_id mismatch, or
13824 someone deleted the DWO/DWP file, or the search path isn't set up
13825 correctly to find the file. */
13827 if (dwarf_read_debug
)
13829 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13830 kind
, dwo_name
, hex_string (signature
));
13833 /* This is a warning and not a complaint because it can be caused by
13834 pilot error (e.g., user accidentally deleting the DWO). */
13836 /* Print the name of the DWP file if we looked there, helps the user
13837 better diagnose the problem. */
13838 std::string dwp_text
;
13840 if (dwp_file
!= NULL
)
13841 dwp_text
= string_printf (" [in DWP file %s]",
13842 lbasename (dwp_file
->name
));
13844 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13845 " [in module %s]"),
13846 kind
, dwo_name
, hex_string (signature
),
13848 this_unit
->is_debug_types
? "TU" : "CU",
13849 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13854 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13855 See lookup_dwo_cutu_unit for details. */
13857 static struct dwo_unit
*
13858 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13859 const char *dwo_name
, const char *comp_dir
,
13860 ULONGEST signature
)
13862 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13865 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13866 See lookup_dwo_cutu_unit for details. */
13868 static struct dwo_unit
*
13869 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13870 const char *dwo_name
, const char *comp_dir
)
13872 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13875 /* Traversal function for queue_and_load_all_dwo_tus. */
13878 queue_and_load_dwo_tu (void **slot
, void *info
)
13880 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13881 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13882 ULONGEST signature
= dwo_unit
->signature
;
13883 struct signatured_type
*sig_type
=
13884 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13886 if (sig_type
!= NULL
)
13888 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13890 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13891 a real dependency of PER_CU on SIG_TYPE. That is detected later
13892 while processing PER_CU. */
13893 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13894 load_full_type_unit (sig_cu
);
13895 VEC_safe_push (dwarf2_per_cu_ptr
, per_cu
->imported_symtabs
, sig_cu
);
13901 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13902 The DWO may have the only definition of the type, though it may not be
13903 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13904 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13907 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13909 struct dwo_unit
*dwo_unit
;
13910 struct dwo_file
*dwo_file
;
13912 gdb_assert (!per_cu
->is_debug_types
);
13913 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13914 gdb_assert (per_cu
->cu
!= NULL
);
13916 dwo_unit
= per_cu
->cu
->dwo_unit
;
13917 gdb_assert (dwo_unit
!= NULL
);
13919 dwo_file
= dwo_unit
->dwo_file
;
13920 if (dwo_file
->tus
!= NULL
)
13921 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13924 /* Free all resources associated with DWO_FILE.
13925 Close the DWO file and munmap the sections.
13926 All memory should be on the objfile obstack. */
13929 free_dwo_file (struct dwo_file
*dwo_file
, struct objfile
*objfile
)
13932 /* Note: dbfd is NULL for virtual DWO files. */
13933 gdb_bfd_unref (dwo_file
->dbfd
);
13935 VEC_free (dwarf2_section_info_def
, dwo_file
->sections
.types
);
13938 /* Wrapper for free_dwo_file for use in cleanups. */
13941 free_dwo_file_cleanup (void *arg
)
13943 struct free_dwo_file_cleanup_data
*data
13944 = (struct free_dwo_file_cleanup_data
*) arg
;
13945 struct objfile
*objfile
= data
->dwarf2_per_objfile
->objfile
;
13947 free_dwo_file (data
->dwo_file
, objfile
);
13952 /* Traversal function for free_dwo_files. */
13955 free_dwo_file_from_slot (void **slot
, void *info
)
13957 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
13958 struct objfile
*objfile
= (struct objfile
*) info
;
13960 free_dwo_file (dwo_file
, objfile
);
13965 /* Free all resources associated with DWO_FILES. */
13968 free_dwo_files (htab_t dwo_files
, struct objfile
*objfile
)
13970 htab_traverse_noresize (dwo_files
, free_dwo_file_from_slot
, objfile
);
13973 /* Read in various DIEs. */
13975 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13976 Inherit only the children of the DW_AT_abstract_origin DIE not being
13977 already referenced by DW_AT_abstract_origin from the children of the
13981 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13983 struct die_info
*child_die
;
13984 sect_offset
*offsetp
;
13985 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13986 struct die_info
*origin_die
;
13987 /* Iterator of the ORIGIN_DIE children. */
13988 struct die_info
*origin_child_die
;
13989 struct attribute
*attr
;
13990 struct dwarf2_cu
*origin_cu
;
13991 struct pending
**origin_previous_list_in_scope
;
13993 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13997 /* Note that following die references may follow to a die in a
14001 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
14003 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
14005 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
14006 origin_cu
->list_in_scope
= cu
->list_in_scope
;
14008 if (die
->tag
!= origin_die
->tag
14009 && !(die
->tag
== DW_TAG_inlined_subroutine
14010 && origin_die
->tag
== DW_TAG_subprogram
))
14011 complaint (&symfile_complaints
,
14012 _("DIE %s and its abstract origin %s have different tags"),
14013 sect_offset_str (die
->sect_off
),
14014 sect_offset_str (origin_die
->sect_off
));
14016 std::vector
<sect_offset
> offsets
;
14018 for (child_die
= die
->child
;
14019 child_die
&& child_die
->tag
;
14020 child_die
= sibling_die (child_die
))
14022 struct die_info
*child_origin_die
;
14023 struct dwarf2_cu
*child_origin_cu
;
14025 /* We are trying to process concrete instance entries:
14026 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
14027 it's not relevant to our analysis here. i.e. detecting DIEs that are
14028 present in the abstract instance but not referenced in the concrete
14030 if (child_die
->tag
== DW_TAG_call_site
14031 || child_die
->tag
== DW_TAG_GNU_call_site
)
14034 /* For each CHILD_DIE, find the corresponding child of
14035 ORIGIN_DIE. If there is more than one layer of
14036 DW_AT_abstract_origin, follow them all; there shouldn't be,
14037 but GCC versions at least through 4.4 generate this (GCC PR
14039 child_origin_die
= child_die
;
14040 child_origin_cu
= cu
;
14043 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
14047 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
14051 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
14052 counterpart may exist. */
14053 if (child_origin_die
!= child_die
)
14055 if (child_die
->tag
!= child_origin_die
->tag
14056 && !(child_die
->tag
== DW_TAG_inlined_subroutine
14057 && child_origin_die
->tag
== DW_TAG_subprogram
))
14058 complaint (&symfile_complaints
,
14059 _("Child DIE %s and its abstract origin %s have "
14061 sect_offset_str (child_die
->sect_off
),
14062 sect_offset_str (child_origin_die
->sect_off
));
14063 if (child_origin_die
->parent
!= origin_die
)
14064 complaint (&symfile_complaints
,
14065 _("Child DIE %s and its abstract origin %s have "
14066 "different parents"),
14067 sect_offset_str (child_die
->sect_off
),
14068 sect_offset_str (child_origin_die
->sect_off
));
14070 offsets
.push_back (child_origin_die
->sect_off
);
14073 std::sort (offsets
.begin (), offsets
.end ());
14074 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
14075 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
14076 if (offsetp
[-1] == *offsetp
)
14077 complaint (&symfile_complaints
,
14078 _("Multiple children of DIE %s refer "
14079 "to DIE %s as their abstract origin"),
14080 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
14082 offsetp
= offsets
.data ();
14083 origin_child_die
= origin_die
->child
;
14084 while (origin_child_die
&& origin_child_die
->tag
)
14086 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
14087 while (offsetp
< offsets_end
14088 && *offsetp
< origin_child_die
->sect_off
)
14090 if (offsetp
>= offsets_end
14091 || *offsetp
> origin_child_die
->sect_off
)
14093 /* Found that ORIGIN_CHILD_DIE is really not referenced.
14094 Check whether we're already processing ORIGIN_CHILD_DIE.
14095 This can happen with mutually referenced abstract_origins.
14097 if (!origin_child_die
->in_process
)
14098 process_die (origin_child_die
, origin_cu
);
14100 origin_child_die
= sibling_die (origin_child_die
);
14102 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
14106 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14108 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14109 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14110 struct context_stack
*newobj
;
14113 struct die_info
*child_die
;
14114 struct attribute
*attr
, *call_line
, *call_file
;
14116 CORE_ADDR baseaddr
;
14117 struct block
*block
;
14118 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
14119 std::vector
<struct symbol
*> template_args
;
14120 struct template_symbol
*templ_func
= NULL
;
14124 /* If we do not have call site information, we can't show the
14125 caller of this inlined function. That's too confusing, so
14126 only use the scope for local variables. */
14127 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
14128 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
14129 if (call_line
== NULL
|| call_file
== NULL
)
14131 read_lexical_block_scope (die
, cu
);
14136 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14138 name
= dwarf2_name (die
, cu
);
14140 /* Ignore functions with missing or empty names. These are actually
14141 illegal according to the DWARF standard. */
14144 complaint (&symfile_complaints
,
14145 _("missing name for subprogram DIE at %s"),
14146 sect_offset_str (die
->sect_off
));
14150 /* Ignore functions with missing or invalid low and high pc attributes. */
14151 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
14152 <= PC_BOUNDS_INVALID
)
14154 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
14155 if (!attr
|| !DW_UNSND (attr
))
14156 complaint (&symfile_complaints
,
14157 _("cannot get low and high bounds "
14158 "for subprogram DIE at %s"),
14159 sect_offset_str (die
->sect_off
));
14163 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14164 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14166 /* If we have any template arguments, then we must allocate a
14167 different sort of symbol. */
14168 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
14170 if (child_die
->tag
== DW_TAG_template_type_param
14171 || child_die
->tag
== DW_TAG_template_value_param
)
14173 templ_func
= allocate_template_symbol (objfile
);
14174 templ_func
->subclass
= SYMBOL_TEMPLATE
;
14179 newobj
= push_context (0, lowpc
);
14180 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
14181 (struct symbol
*) templ_func
);
14183 /* If there is a location expression for DW_AT_frame_base, record
14185 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
14187 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
14189 /* If there is a location for the static link, record it. */
14190 newobj
->static_link
= NULL
;
14191 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
14194 newobj
->static_link
14195 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
14196 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
);
14199 cu
->list_in_scope
= &local_symbols
;
14201 if (die
->child
!= NULL
)
14203 child_die
= die
->child
;
14204 while (child_die
&& child_die
->tag
)
14206 if (child_die
->tag
== DW_TAG_template_type_param
14207 || child_die
->tag
== DW_TAG_template_value_param
)
14209 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
14212 template_args
.push_back (arg
);
14215 process_die (child_die
, cu
);
14216 child_die
= sibling_die (child_die
);
14220 inherit_abstract_dies (die
, cu
);
14222 /* If we have a DW_AT_specification, we might need to import using
14223 directives from the context of the specification DIE. See the
14224 comment in determine_prefix. */
14225 if (cu
->language
== language_cplus
14226 && dwarf2_attr (die
, DW_AT_specification
, cu
))
14228 struct dwarf2_cu
*spec_cu
= cu
;
14229 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
14233 child_die
= spec_die
->child
;
14234 while (child_die
&& child_die
->tag
)
14236 if (child_die
->tag
== DW_TAG_imported_module
)
14237 process_die (child_die
, spec_cu
);
14238 child_die
= sibling_die (child_die
);
14241 /* In some cases, GCC generates specification DIEs that
14242 themselves contain DW_AT_specification attributes. */
14243 spec_die
= die_specification (spec_die
, &spec_cu
);
14247 newobj
= pop_context ();
14248 /* Make a block for the local symbols within. */
14249 block
= finish_block (newobj
->name
, &local_symbols
, newobj
->old_blocks
,
14250 newobj
->static_link
, lowpc
, highpc
);
14252 /* For C++, set the block's scope. */
14253 if ((cu
->language
== language_cplus
14254 || cu
->language
== language_fortran
14255 || cu
->language
== language_d
14256 || cu
->language
== language_rust
)
14257 && cu
->processing_has_namespace_info
)
14258 block_set_scope (block
, determine_prefix (die
, cu
),
14259 &objfile
->objfile_obstack
);
14261 /* If we have address ranges, record them. */
14262 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14264 gdbarch_make_symbol_special (gdbarch
, newobj
->name
, objfile
);
14266 /* Attach template arguments to function. */
14267 if (!template_args
.empty ())
14269 gdb_assert (templ_func
!= NULL
);
14271 templ_func
->n_template_arguments
= template_args
.size ();
14272 templ_func
->template_arguments
14273 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
14274 templ_func
->n_template_arguments
);
14275 memcpy (templ_func
->template_arguments
,
14276 template_args
.data (),
14277 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
14280 /* In C++, we can have functions nested inside functions (e.g., when
14281 a function declares a class that has methods). This means that
14282 when we finish processing a function scope, we may need to go
14283 back to building a containing block's symbol lists. */
14284 local_symbols
= newobj
->locals
;
14285 local_using_directives
= newobj
->local_using_directives
;
14287 /* If we've finished processing a top-level function, subsequent
14288 symbols go in the file symbol list. */
14289 if (outermost_context_p ())
14290 cu
->list_in_scope
= &file_symbols
;
14293 /* Process all the DIES contained within a lexical block scope. Start
14294 a new scope, process the dies, and then close the scope. */
14297 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14299 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14300 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14301 struct context_stack
*newobj
;
14302 CORE_ADDR lowpc
, highpc
;
14303 struct die_info
*child_die
;
14304 CORE_ADDR baseaddr
;
14306 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14308 /* Ignore blocks with missing or invalid low and high pc attributes. */
14309 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
14310 as multiple lexical blocks? Handling children in a sane way would
14311 be nasty. Might be easier to properly extend generic blocks to
14312 describe ranges. */
14313 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
14315 case PC_BOUNDS_NOT_PRESENT
:
14316 /* DW_TAG_lexical_block has no attributes, process its children as if
14317 there was no wrapping by that DW_TAG_lexical_block.
14318 GCC does no longer produces such DWARF since GCC r224161. */
14319 for (child_die
= die
->child
;
14320 child_die
!= NULL
&& child_die
->tag
;
14321 child_die
= sibling_die (child_die
))
14322 process_die (child_die
, cu
);
14324 case PC_BOUNDS_INVALID
:
14327 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14328 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
14330 push_context (0, lowpc
);
14331 if (die
->child
!= NULL
)
14333 child_die
= die
->child
;
14334 while (child_die
&& child_die
->tag
)
14336 process_die (child_die
, cu
);
14337 child_die
= sibling_die (child_die
);
14340 inherit_abstract_dies (die
, cu
);
14341 newobj
= pop_context ();
14343 if (local_symbols
!= NULL
|| local_using_directives
!= NULL
)
14345 struct block
*block
14346 = finish_block (0, &local_symbols
, newobj
->old_blocks
, NULL
,
14347 newobj
->start_addr
, highpc
);
14349 /* Note that recording ranges after traversing children, as we
14350 do here, means that recording a parent's ranges entails
14351 walking across all its children's ranges as they appear in
14352 the address map, which is quadratic behavior.
14354 It would be nicer to record the parent's ranges before
14355 traversing its children, simply overriding whatever you find
14356 there. But since we don't even decide whether to create a
14357 block until after we've traversed its children, that's hard
14359 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14361 local_symbols
= newobj
->locals
;
14362 local_using_directives
= newobj
->local_using_directives
;
14365 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
14368 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14370 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14371 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14372 CORE_ADDR pc
, baseaddr
;
14373 struct attribute
*attr
;
14374 struct call_site
*call_site
, call_site_local
;
14377 struct die_info
*child_die
;
14379 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14381 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
14384 /* This was a pre-DWARF-5 GNU extension alias
14385 for DW_AT_call_return_pc. */
14386 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14390 complaint (&symfile_complaints
,
14391 _("missing DW_AT_call_return_pc for DW_TAG_call_site "
14392 "DIE %s [in module %s]"),
14393 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14396 pc
= attr_value_as_address (attr
) + baseaddr
;
14397 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14399 if (cu
->call_site_htab
== NULL
)
14400 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14401 NULL
, &objfile
->objfile_obstack
,
14402 hashtab_obstack_allocate
, NULL
);
14403 call_site_local
.pc
= pc
;
14404 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14407 complaint (&symfile_complaints
,
14408 _("Duplicate PC %s for DW_TAG_call_site "
14409 "DIE %s [in module %s]"),
14410 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14411 objfile_name (objfile
));
14415 /* Count parameters at the caller. */
14418 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14419 child_die
= sibling_die (child_die
))
14421 if (child_die
->tag
!= DW_TAG_call_site_parameter
14422 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14424 complaint (&symfile_complaints
,
14425 _("Tag %d is not DW_TAG_call_site_parameter in "
14426 "DW_TAG_call_site child DIE %s [in module %s]"),
14427 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14428 objfile_name (objfile
));
14436 = ((struct call_site
*)
14437 obstack_alloc (&objfile
->objfile_obstack
,
14438 sizeof (*call_site
)
14439 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14441 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14442 call_site
->pc
= pc
;
14444 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14445 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14447 struct die_info
*func_die
;
14449 /* Skip also over DW_TAG_inlined_subroutine. */
14450 for (func_die
= die
->parent
;
14451 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14452 && func_die
->tag
!= DW_TAG_subroutine_type
;
14453 func_die
= func_die
->parent
);
14455 /* DW_AT_call_all_calls is a superset
14456 of DW_AT_call_all_tail_calls. */
14458 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14459 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14460 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14461 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14463 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14464 not complete. But keep CALL_SITE for look ups via call_site_htab,
14465 both the initial caller containing the real return address PC and
14466 the final callee containing the current PC of a chain of tail
14467 calls do not need to have the tail call list complete. But any
14468 function candidate for a virtual tail call frame searched via
14469 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14470 determined unambiguously. */
14474 struct type
*func_type
= NULL
;
14477 func_type
= get_die_type (func_die
, cu
);
14478 if (func_type
!= NULL
)
14480 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14482 /* Enlist this call site to the function. */
14483 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14484 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14487 complaint (&symfile_complaints
,
14488 _("Cannot find function owning DW_TAG_call_site "
14489 "DIE %s [in module %s]"),
14490 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14494 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14496 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14498 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14501 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14502 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14504 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14505 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14506 /* Keep NULL DWARF_BLOCK. */;
14507 else if (attr_form_is_block (attr
))
14509 struct dwarf2_locexpr_baton
*dlbaton
;
14511 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14512 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14513 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14514 dlbaton
->per_cu
= cu
->per_cu
;
14516 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14518 else if (attr_form_is_ref (attr
))
14520 struct dwarf2_cu
*target_cu
= cu
;
14521 struct die_info
*target_die
;
14523 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14524 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14525 if (die_is_declaration (target_die
, target_cu
))
14527 const char *target_physname
;
14529 /* Prefer the mangled name; otherwise compute the demangled one. */
14530 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14531 if (target_physname
== NULL
)
14532 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14533 if (target_physname
== NULL
)
14534 complaint (&symfile_complaints
,
14535 _("DW_AT_call_target target DIE has invalid "
14536 "physname, for referencing DIE %s [in module %s]"),
14537 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14539 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14545 /* DW_AT_entry_pc should be preferred. */
14546 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14547 <= PC_BOUNDS_INVALID
)
14548 complaint (&symfile_complaints
,
14549 _("DW_AT_call_target target DIE has invalid "
14550 "low pc, for referencing DIE %s [in module %s]"),
14551 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14554 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14555 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14560 complaint (&symfile_complaints
,
14561 _("DW_TAG_call_site DW_AT_call_target is neither "
14562 "block nor reference, for DIE %s [in module %s]"),
14563 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14565 call_site
->per_cu
= cu
->per_cu
;
14567 for (child_die
= die
->child
;
14568 child_die
&& child_die
->tag
;
14569 child_die
= sibling_die (child_die
))
14571 struct call_site_parameter
*parameter
;
14572 struct attribute
*loc
, *origin
;
14574 if (child_die
->tag
!= DW_TAG_call_site_parameter
14575 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14577 /* Already printed the complaint above. */
14581 gdb_assert (call_site
->parameter_count
< nparams
);
14582 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14584 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14585 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14586 register is contained in DW_AT_call_value. */
14588 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14589 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14590 if (origin
== NULL
)
14592 /* This was a pre-DWARF-5 GNU extension alias
14593 for DW_AT_call_parameter. */
14594 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14596 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14598 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14600 sect_offset sect_off
14601 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14602 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14604 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14605 binding can be done only inside one CU. Such referenced DIE
14606 therefore cannot be even moved to DW_TAG_partial_unit. */
14607 complaint (&symfile_complaints
,
14608 _("DW_AT_call_parameter offset is not in CU for "
14609 "DW_TAG_call_site child DIE %s [in module %s]"),
14610 sect_offset_str (child_die
->sect_off
),
14611 objfile_name (objfile
));
14614 parameter
->u
.param_cu_off
14615 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14617 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14619 complaint (&symfile_complaints
,
14620 _("No DW_FORM_block* DW_AT_location for "
14621 "DW_TAG_call_site child DIE %s [in module %s]"),
14622 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14627 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14628 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14629 if (parameter
->u
.dwarf_reg
!= -1)
14630 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14631 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14632 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14633 ¶meter
->u
.fb_offset
))
14634 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14637 complaint (&symfile_complaints
,
14638 _("Only single DW_OP_reg or DW_OP_fbreg is supported "
14639 "for DW_FORM_block* DW_AT_location is supported for "
14640 "DW_TAG_call_site child DIE %s "
14642 sect_offset_str (child_die
->sect_off
),
14643 objfile_name (objfile
));
14648 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14650 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14651 if (!attr_form_is_block (attr
))
14653 complaint (&symfile_complaints
,
14654 _("No DW_FORM_block* DW_AT_call_value for "
14655 "DW_TAG_call_site child DIE %s [in module %s]"),
14656 sect_offset_str (child_die
->sect_off
),
14657 objfile_name (objfile
));
14660 parameter
->value
= DW_BLOCK (attr
)->data
;
14661 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14663 /* Parameters are not pre-cleared by memset above. */
14664 parameter
->data_value
= NULL
;
14665 parameter
->data_value_size
= 0;
14666 call_site
->parameter_count
++;
14668 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14670 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14673 if (!attr_form_is_block (attr
))
14674 complaint (&symfile_complaints
,
14675 _("No DW_FORM_block* DW_AT_call_data_value for "
14676 "DW_TAG_call_site child DIE %s [in module %s]"),
14677 sect_offset_str (child_die
->sect_off
),
14678 objfile_name (objfile
));
14681 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14682 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14688 /* Helper function for read_variable. If DIE represents a virtual
14689 table, then return the type of the concrete object that is
14690 associated with the virtual table. Otherwise, return NULL. */
14692 static struct type
*
14693 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14695 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14699 /* Find the type DIE. */
14700 struct die_info
*type_die
= NULL
;
14701 struct dwarf2_cu
*type_cu
= cu
;
14703 if (attr_form_is_ref (attr
))
14704 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14705 if (type_die
== NULL
)
14708 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14710 return die_containing_type (type_die
, type_cu
);
14713 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14716 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14718 struct rust_vtable_symbol
*storage
= NULL
;
14720 if (cu
->language
== language_rust
)
14722 struct type
*containing_type
= rust_containing_type (die
, cu
);
14724 if (containing_type
!= NULL
)
14726 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14728 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14729 struct rust_vtable_symbol
);
14730 initialize_objfile_symbol (storage
);
14731 storage
->concrete_type
= containing_type
;
14732 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14736 new_symbol (die
, NULL
, cu
, storage
);
14739 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14740 reading .debug_rnglists.
14741 Callback's type should be:
14742 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14743 Return true if the attributes are present and valid, otherwise,
14746 template <typename Callback
>
14748 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14749 Callback
&&callback
)
14751 struct dwarf2_per_objfile
*dwarf2_per_objfile
14752 = cu
->per_cu
->dwarf2_per_objfile
;
14753 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14754 bfd
*obfd
= objfile
->obfd
;
14755 /* Base address selection entry. */
14758 const gdb_byte
*buffer
;
14759 CORE_ADDR baseaddr
;
14760 bool overflow
= false;
14762 found_base
= cu
->base_known
;
14763 base
= cu
->base_address
;
14765 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14766 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14768 complaint (&symfile_complaints
,
14769 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14773 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14775 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14779 /* Initialize it due to a false compiler warning. */
14780 CORE_ADDR range_beginning
= 0, range_end
= 0;
14781 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14782 + dwarf2_per_objfile
->rnglists
.size
);
14783 unsigned int bytes_read
;
14785 if (buffer
== buf_end
)
14790 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14793 case DW_RLE_end_of_list
:
14795 case DW_RLE_base_address
:
14796 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14801 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14803 buffer
+= bytes_read
;
14805 case DW_RLE_start_length
:
14806 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14811 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14812 buffer
+= bytes_read
;
14813 range_end
= (range_beginning
14814 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14815 buffer
+= bytes_read
;
14816 if (buffer
> buf_end
)
14822 case DW_RLE_offset_pair
:
14823 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14824 buffer
+= bytes_read
;
14825 if (buffer
> buf_end
)
14830 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14831 buffer
+= bytes_read
;
14832 if (buffer
> buf_end
)
14838 case DW_RLE_start_end
:
14839 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14844 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14845 buffer
+= bytes_read
;
14846 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14847 buffer
+= bytes_read
;
14850 complaint (&symfile_complaints
,
14851 _("Invalid .debug_rnglists data (no base address)"));
14854 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14856 if (rlet
== DW_RLE_base_address
)
14861 /* We have no valid base address for the ranges
14863 complaint (&symfile_complaints
,
14864 _("Invalid .debug_rnglists data (no base address)"));
14868 if (range_beginning
> range_end
)
14870 /* Inverted range entries are invalid. */
14871 complaint (&symfile_complaints
,
14872 _("Invalid .debug_rnglists data (inverted range)"));
14876 /* Empty range entries have no effect. */
14877 if (range_beginning
== range_end
)
14880 range_beginning
+= base
;
14883 /* A not-uncommon case of bad debug info.
14884 Don't pollute the addrmap with bad data. */
14885 if (range_beginning
+ baseaddr
== 0
14886 && !dwarf2_per_objfile
->has_section_at_zero
)
14888 complaint (&symfile_complaints
,
14889 _(".debug_rnglists entry has start address of zero"
14890 " [in module %s]"), objfile_name (objfile
));
14894 callback (range_beginning
, range_end
);
14899 complaint (&symfile_complaints
,
14900 _("Offset %d is not terminated "
14901 "for DW_AT_ranges attribute"),
14909 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14910 Callback's type should be:
14911 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14912 Return 1 if the attributes are present and valid, otherwise, return 0. */
14914 template <typename Callback
>
14916 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14917 Callback
&&callback
)
14919 struct dwarf2_per_objfile
*dwarf2_per_objfile
14920 = cu
->per_cu
->dwarf2_per_objfile
;
14921 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14922 struct comp_unit_head
*cu_header
= &cu
->header
;
14923 bfd
*obfd
= objfile
->obfd
;
14924 unsigned int addr_size
= cu_header
->addr_size
;
14925 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14926 /* Base address selection entry. */
14929 unsigned int dummy
;
14930 const gdb_byte
*buffer
;
14931 CORE_ADDR baseaddr
;
14933 if (cu_header
->version
>= 5)
14934 return dwarf2_rnglists_process (offset
, cu
, callback
);
14936 found_base
= cu
->base_known
;
14937 base
= cu
->base_address
;
14939 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14940 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14942 complaint (&symfile_complaints
,
14943 _("Offset %d out of bounds for DW_AT_ranges attribute"),
14947 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14949 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14953 CORE_ADDR range_beginning
, range_end
;
14955 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14956 buffer
+= addr_size
;
14957 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14958 buffer
+= addr_size
;
14959 offset
+= 2 * addr_size
;
14961 /* An end of list marker is a pair of zero addresses. */
14962 if (range_beginning
== 0 && range_end
== 0)
14963 /* Found the end of list entry. */
14966 /* Each base address selection entry is a pair of 2 values.
14967 The first is the largest possible address, the second is
14968 the base address. Check for a base address here. */
14969 if ((range_beginning
& mask
) == mask
)
14971 /* If we found the largest possible address, then we already
14972 have the base address in range_end. */
14980 /* We have no valid base address for the ranges
14982 complaint (&symfile_complaints
,
14983 _("Invalid .debug_ranges data (no base address)"));
14987 if (range_beginning
> range_end
)
14989 /* Inverted range entries are invalid. */
14990 complaint (&symfile_complaints
,
14991 _("Invalid .debug_ranges data (inverted range)"));
14995 /* Empty range entries have no effect. */
14996 if (range_beginning
== range_end
)
14999 range_beginning
+= base
;
15002 /* A not-uncommon case of bad debug info.
15003 Don't pollute the addrmap with bad data. */
15004 if (range_beginning
+ baseaddr
== 0
15005 && !dwarf2_per_objfile
->has_section_at_zero
)
15007 complaint (&symfile_complaints
,
15008 _(".debug_ranges entry has start address of zero"
15009 " [in module %s]"), objfile_name (objfile
));
15013 callback (range_beginning
, range_end
);
15019 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
15020 Return 1 if the attributes are present and valid, otherwise, return 0.
15021 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
15024 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
15025 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
15026 struct partial_symtab
*ranges_pst
)
15028 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15029 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15030 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
15031 SECT_OFF_TEXT (objfile
));
15034 CORE_ADDR high
= 0;
15037 retval
= dwarf2_ranges_process (offset
, cu
,
15038 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
15040 if (ranges_pst
!= NULL
)
15045 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15046 range_beginning
+ baseaddr
);
15047 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
,
15048 range_end
+ baseaddr
);
15049 addrmap_set_empty (objfile
->psymtabs_addrmap
, lowpc
, highpc
- 1,
15053 /* FIXME: This is recording everything as a low-high
15054 segment of consecutive addresses. We should have a
15055 data structure for discontiguous block ranges
15059 low
= range_beginning
;
15065 if (range_beginning
< low
)
15066 low
= range_beginning
;
15067 if (range_end
> high
)
15075 /* If the first entry is an end-of-list marker, the range
15076 describes an empty scope, i.e. no instructions. */
15082 *high_return
= high
;
15086 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
15087 definition for the return value. *LOWPC and *HIGHPC are set iff
15088 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
15090 static enum pc_bounds_kind
15091 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
15092 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
15093 struct partial_symtab
*pst
)
15095 struct dwarf2_per_objfile
*dwarf2_per_objfile
15096 = cu
->per_cu
->dwarf2_per_objfile
;
15097 struct attribute
*attr
;
15098 struct attribute
*attr_high
;
15100 CORE_ADDR high
= 0;
15101 enum pc_bounds_kind ret
;
15103 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15106 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15109 low
= attr_value_as_address (attr
);
15110 high
= attr_value_as_address (attr_high
);
15111 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15115 /* Found high w/o low attribute. */
15116 return PC_BOUNDS_INVALID
;
15118 /* Found consecutive range of addresses. */
15119 ret
= PC_BOUNDS_HIGH_LOW
;
15123 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15126 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15127 We take advantage of the fact that DW_AT_ranges does not appear
15128 in DW_TAG_compile_unit of DWO files. */
15129 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15130 unsigned int ranges_offset
= (DW_UNSND (attr
)
15131 + (need_ranges_base
15135 /* Value of the DW_AT_ranges attribute is the offset in the
15136 .debug_ranges section. */
15137 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
15138 return PC_BOUNDS_INVALID
;
15139 /* Found discontinuous range of addresses. */
15140 ret
= PC_BOUNDS_RANGES
;
15143 return PC_BOUNDS_NOT_PRESENT
;
15146 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
15148 return PC_BOUNDS_INVALID
;
15150 /* When using the GNU linker, .gnu.linkonce. sections are used to
15151 eliminate duplicate copies of functions and vtables and such.
15152 The linker will arbitrarily choose one and discard the others.
15153 The AT_*_pc values for such functions refer to local labels in
15154 these sections. If the section from that file was discarded, the
15155 labels are not in the output, so the relocs get a value of 0.
15156 If this is a discarded function, mark the pc bounds as invalid,
15157 so that GDB will ignore it. */
15158 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
15159 return PC_BOUNDS_INVALID
;
15167 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
15168 its low and high PC addresses. Do nothing if these addresses could not
15169 be determined. Otherwise, set LOWPC to the low address if it is smaller,
15170 and HIGHPC to the high address if greater than HIGHPC. */
15173 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
15174 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15175 struct dwarf2_cu
*cu
)
15177 CORE_ADDR low
, high
;
15178 struct die_info
*child
= die
->child
;
15180 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
15182 *lowpc
= std::min (*lowpc
, low
);
15183 *highpc
= std::max (*highpc
, high
);
15186 /* If the language does not allow nested subprograms (either inside
15187 subprograms or lexical blocks), we're done. */
15188 if (cu
->language
!= language_ada
)
15191 /* Check all the children of the given DIE. If it contains nested
15192 subprograms, then check their pc bounds. Likewise, we need to
15193 check lexical blocks as well, as they may also contain subprogram
15195 while (child
&& child
->tag
)
15197 if (child
->tag
== DW_TAG_subprogram
15198 || child
->tag
== DW_TAG_lexical_block
)
15199 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
15200 child
= sibling_die (child
);
15204 /* Get the low and high pc's represented by the scope DIE, and store
15205 them in *LOWPC and *HIGHPC. If the correct values can't be
15206 determined, set *LOWPC to -1 and *HIGHPC to 0. */
15209 get_scope_pc_bounds (struct die_info
*die
,
15210 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
15211 struct dwarf2_cu
*cu
)
15213 CORE_ADDR best_low
= (CORE_ADDR
) -1;
15214 CORE_ADDR best_high
= (CORE_ADDR
) 0;
15215 CORE_ADDR current_low
, current_high
;
15217 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
15218 >= PC_BOUNDS_RANGES
)
15220 best_low
= current_low
;
15221 best_high
= current_high
;
15225 struct die_info
*child
= die
->child
;
15227 while (child
&& child
->tag
)
15229 switch (child
->tag
) {
15230 case DW_TAG_subprogram
:
15231 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
15233 case DW_TAG_namespace
:
15234 case DW_TAG_module
:
15235 /* FIXME: carlton/2004-01-16: Should we do this for
15236 DW_TAG_class_type/DW_TAG_structure_type, too? I think
15237 that current GCC's always emit the DIEs corresponding
15238 to definitions of methods of classes as children of a
15239 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
15240 the DIEs giving the declarations, which could be
15241 anywhere). But I don't see any reason why the
15242 standards says that they have to be there. */
15243 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
15245 if (current_low
!= ((CORE_ADDR
) -1))
15247 best_low
= std::min (best_low
, current_low
);
15248 best_high
= std::max (best_high
, current_high
);
15256 child
= sibling_die (child
);
15261 *highpc
= best_high
;
15264 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
15268 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
15269 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
15271 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15272 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15273 struct attribute
*attr
;
15274 struct attribute
*attr_high
;
15276 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
15279 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
15282 CORE_ADDR low
= attr_value_as_address (attr
);
15283 CORE_ADDR high
= attr_value_as_address (attr_high
);
15285 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
15288 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
15289 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
15290 record_block_range (block
, low
, high
- 1);
15294 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
15297 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
15298 We take advantage of the fact that DW_AT_ranges does not appear
15299 in DW_TAG_compile_unit of DWO files. */
15300 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
15302 /* The value of the DW_AT_ranges attribute is the offset of the
15303 address range list in the .debug_ranges section. */
15304 unsigned long offset
= (DW_UNSND (attr
)
15305 + (need_ranges_base
? cu
->ranges_base
: 0));
15306 const gdb_byte
*buffer
;
15308 /* For some target architectures, but not others, the
15309 read_address function sign-extends the addresses it returns.
15310 To recognize base address selection entries, we need a
15312 unsigned int addr_size
= cu
->header
.addr_size
;
15313 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
15315 /* The base address, to which the next pair is relative. Note
15316 that this 'base' is a DWARF concept: most entries in a range
15317 list are relative, to reduce the number of relocs against the
15318 debugging information. This is separate from this function's
15319 'baseaddr' argument, which GDB uses to relocate debugging
15320 information from a shared library based on the address at
15321 which the library was loaded. */
15322 CORE_ADDR base
= cu
->base_address
;
15323 int base_known
= cu
->base_known
;
15325 dwarf2_ranges_process (offset
, cu
,
15326 [&] (CORE_ADDR start
, CORE_ADDR end
)
15330 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
15331 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
15332 record_block_range (block
, start
, end
- 1);
15337 /* Check whether the producer field indicates either of GCC < 4.6, or the
15338 Intel C/C++ compiler, and cache the result in CU. */
15341 check_producer (struct dwarf2_cu
*cu
)
15345 if (cu
->producer
== NULL
)
15347 /* For unknown compilers expect their behavior is DWARF version
15350 GCC started to support .debug_types sections by -gdwarf-4 since
15351 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
15352 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
15353 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
15354 interpreted incorrectly by GDB now - GCC PR debug/48229. */
15356 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
15358 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
15359 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
15361 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
15362 cu
->producer_is_icc_lt_14
= major
< 14;
15365 /* For other non-GCC compilers, expect their behavior is DWARF version
15369 cu
->checked_producer
= 1;
15372 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
15373 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
15374 during 4.6.0 experimental. */
15377 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
15379 if (!cu
->checked_producer
)
15380 check_producer (cu
);
15382 return cu
->producer_is_gxx_lt_4_6
;
15385 /* Return the default accessibility type if it is not overriden by
15386 DW_AT_accessibility. */
15388 static enum dwarf_access_attribute
15389 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15391 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15393 /* The default DWARF 2 accessibility for members is public, the default
15394 accessibility for inheritance is private. */
15396 if (die
->tag
!= DW_TAG_inheritance
)
15397 return DW_ACCESS_public
;
15399 return DW_ACCESS_private
;
15403 /* DWARF 3+ defines the default accessibility a different way. The same
15404 rules apply now for DW_TAG_inheritance as for the members and it only
15405 depends on the container kind. */
15407 if (die
->parent
->tag
== DW_TAG_class_type
)
15408 return DW_ACCESS_private
;
15410 return DW_ACCESS_public
;
15414 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15415 offset. If the attribute was not found return 0, otherwise return
15416 1. If it was found but could not properly be handled, set *OFFSET
15420 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15423 struct attribute
*attr
;
15425 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15430 /* Note that we do not check for a section offset first here.
15431 This is because DW_AT_data_member_location is new in DWARF 4,
15432 so if we see it, we can assume that a constant form is really
15433 a constant and not a section offset. */
15434 if (attr_form_is_constant (attr
))
15435 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15436 else if (attr_form_is_section_offset (attr
))
15437 dwarf2_complex_location_expr_complaint ();
15438 else if (attr_form_is_block (attr
))
15439 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15441 dwarf2_complex_location_expr_complaint ();
15449 /* Add an aggregate field to the field list. */
15452 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15453 struct dwarf2_cu
*cu
)
15455 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15456 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15457 struct nextfield
*new_field
;
15458 struct attribute
*attr
;
15460 const char *fieldname
= "";
15462 if (die
->tag
== DW_TAG_inheritance
)
15464 fip
->baseclasses
.emplace_back ();
15465 new_field
= &fip
->baseclasses
.back ();
15469 fip
->fields
.emplace_back ();
15470 new_field
= &fip
->fields
.back ();
15475 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15477 new_field
->accessibility
= DW_UNSND (attr
);
15479 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15480 if (new_field
->accessibility
!= DW_ACCESS_public
)
15481 fip
->non_public_fields
= 1;
15483 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15485 new_field
->virtuality
= DW_UNSND (attr
);
15487 new_field
->virtuality
= DW_VIRTUALITY_none
;
15489 fp
= &new_field
->field
;
15491 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15495 /* Data member other than a C++ static data member. */
15497 /* Get type of field. */
15498 fp
->type
= die_type (die
, cu
);
15500 SET_FIELD_BITPOS (*fp
, 0);
15502 /* Get bit size of field (zero if none). */
15503 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15506 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15510 FIELD_BITSIZE (*fp
) = 0;
15513 /* Get bit offset of field. */
15514 if (handle_data_member_location (die
, cu
, &offset
))
15515 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15516 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15519 if (gdbarch_bits_big_endian (gdbarch
))
15521 /* For big endian bits, the DW_AT_bit_offset gives the
15522 additional bit offset from the MSB of the containing
15523 anonymous object to the MSB of the field. We don't
15524 have to do anything special since we don't need to
15525 know the size of the anonymous object. */
15526 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15530 /* For little endian bits, compute the bit offset to the
15531 MSB of the anonymous object, subtract off the number of
15532 bits from the MSB of the field to the MSB of the
15533 object, and then subtract off the number of bits of
15534 the field itself. The result is the bit offset of
15535 the LSB of the field. */
15536 int anonymous_size
;
15537 int bit_offset
= DW_UNSND (attr
);
15539 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15542 /* The size of the anonymous object containing
15543 the bit field is explicit, so use the
15544 indicated size (in bytes). */
15545 anonymous_size
= DW_UNSND (attr
);
15549 /* The size of the anonymous object containing
15550 the bit field must be inferred from the type
15551 attribute of the data member containing the
15553 anonymous_size
= TYPE_LENGTH (fp
->type
);
15555 SET_FIELD_BITPOS (*fp
,
15556 (FIELD_BITPOS (*fp
)
15557 + anonymous_size
* bits_per_byte
15558 - bit_offset
- FIELD_BITSIZE (*fp
)));
15561 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15563 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15564 + dwarf2_get_attr_constant_value (attr
, 0)));
15566 /* Get name of field. */
15567 fieldname
= dwarf2_name (die
, cu
);
15568 if (fieldname
== NULL
)
15571 /* The name is already allocated along with this objfile, so we don't
15572 need to duplicate it for the type. */
15573 fp
->name
= fieldname
;
15575 /* Change accessibility for artificial fields (e.g. virtual table
15576 pointer or virtual base class pointer) to private. */
15577 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15579 FIELD_ARTIFICIAL (*fp
) = 1;
15580 new_field
->accessibility
= DW_ACCESS_private
;
15581 fip
->non_public_fields
= 1;
15584 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15586 /* C++ static member. */
15588 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15589 is a declaration, but all versions of G++ as of this writing
15590 (so through at least 3.2.1) incorrectly generate
15591 DW_TAG_variable tags. */
15593 const char *physname
;
15595 /* Get name of field. */
15596 fieldname
= dwarf2_name (die
, cu
);
15597 if (fieldname
== NULL
)
15600 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15602 /* Only create a symbol if this is an external value.
15603 new_symbol checks this and puts the value in the global symbol
15604 table, which we want. If it is not external, new_symbol
15605 will try to put the value in cu->list_in_scope which is wrong. */
15606 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15608 /* A static const member, not much different than an enum as far as
15609 we're concerned, except that we can support more types. */
15610 new_symbol (die
, NULL
, cu
);
15613 /* Get physical name. */
15614 physname
= dwarf2_physname (fieldname
, die
, cu
);
15616 /* The name is already allocated along with this objfile, so we don't
15617 need to duplicate it for the type. */
15618 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15619 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15620 FIELD_NAME (*fp
) = fieldname
;
15622 else if (die
->tag
== DW_TAG_inheritance
)
15626 /* C++ base class field. */
15627 if (handle_data_member_location (die
, cu
, &offset
))
15628 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15629 FIELD_BITSIZE (*fp
) = 0;
15630 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15631 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
15633 else if (die
->tag
== DW_TAG_variant_part
)
15635 /* process_structure_scope will treat this DIE as a union. */
15636 process_structure_scope (die
, cu
);
15638 /* The variant part is relative to the start of the enclosing
15640 SET_FIELD_BITPOS (*fp
, 0);
15641 fp
->type
= get_die_type (die
, cu
);
15642 fp
->artificial
= 1;
15643 fp
->name
= "<<variant>>";
15646 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15649 /* Can the type given by DIE define another type? */
15652 type_can_define_types (const struct die_info
*die
)
15656 case DW_TAG_typedef
:
15657 case DW_TAG_class_type
:
15658 case DW_TAG_structure_type
:
15659 case DW_TAG_union_type
:
15660 case DW_TAG_enumeration_type
:
15668 /* Add a type definition defined in the scope of the FIP's class. */
15671 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15672 struct dwarf2_cu
*cu
)
15674 struct decl_field fp
;
15675 memset (&fp
, 0, sizeof (fp
));
15677 gdb_assert (type_can_define_types (die
));
15679 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15680 fp
.name
= dwarf2_name (die
, cu
);
15681 fp
.type
= read_type_die (die
, cu
);
15683 /* Save accessibility. */
15684 enum dwarf_access_attribute accessibility
;
15685 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15687 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15689 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15690 switch (accessibility
)
15692 case DW_ACCESS_public
:
15693 /* The assumed value if neither private nor protected. */
15695 case DW_ACCESS_private
:
15698 case DW_ACCESS_protected
:
15699 fp
.is_protected
= 1;
15702 complaint (&symfile_complaints
,
15703 _("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15706 if (die
->tag
== DW_TAG_typedef
)
15707 fip
->typedef_field_list
.push_back (fp
);
15709 fip
->nested_types_list
.push_back (fp
);
15712 /* Create the vector of fields, and attach it to the type. */
15715 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15716 struct dwarf2_cu
*cu
)
15718 int nfields
= fip
->nfields
;
15720 /* Record the field count, allocate space for the array of fields,
15721 and create blank accessibility bitfields if necessary. */
15722 TYPE_NFIELDS (type
) = nfields
;
15723 TYPE_FIELDS (type
) = (struct field
*)
15724 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15726 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15728 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15730 TYPE_FIELD_PRIVATE_BITS (type
) =
15731 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15732 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15734 TYPE_FIELD_PROTECTED_BITS (type
) =
15735 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15736 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15738 TYPE_FIELD_IGNORE_BITS (type
) =
15739 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15740 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15743 /* If the type has baseclasses, allocate and clear a bit vector for
15744 TYPE_FIELD_VIRTUAL_BITS. */
15745 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15747 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15748 unsigned char *pointer
;
15750 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15751 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15752 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15753 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15754 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15757 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15759 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15761 for (int index
= 0; index
< nfields
; ++index
)
15763 struct nextfield
&field
= fip
->fields
[index
];
15765 if (field
.variant
.is_discriminant
)
15766 di
->discriminant_index
= index
;
15767 else if (field
.variant
.default_branch
)
15768 di
->default_index
= index
;
15770 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15774 /* Copy the saved-up fields into the field vector. */
15775 for (int i
= 0; i
< nfields
; ++i
)
15777 struct nextfield
&field
15778 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15779 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15781 TYPE_FIELD (type
, i
) = field
.field
;
15782 switch (field
.accessibility
)
15784 case DW_ACCESS_private
:
15785 if (cu
->language
!= language_ada
)
15786 SET_TYPE_FIELD_PRIVATE (type
, i
);
15789 case DW_ACCESS_protected
:
15790 if (cu
->language
!= language_ada
)
15791 SET_TYPE_FIELD_PROTECTED (type
, i
);
15794 case DW_ACCESS_public
:
15798 /* Unknown accessibility. Complain and treat it as public. */
15800 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
15801 field
.accessibility
);
15805 if (i
< fip
->baseclasses
.size ())
15807 switch (field
.virtuality
)
15809 case DW_VIRTUALITY_virtual
:
15810 case DW_VIRTUALITY_pure_virtual
:
15811 if (cu
->language
== language_ada
)
15812 error (_("unexpected virtuality in component of Ada type"));
15813 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15820 /* Return true if this member function is a constructor, false
15824 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15826 const char *fieldname
;
15827 const char *type_name
;
15830 if (die
->parent
== NULL
)
15833 if (die
->parent
->tag
!= DW_TAG_structure_type
15834 && die
->parent
->tag
!= DW_TAG_union_type
15835 && die
->parent
->tag
!= DW_TAG_class_type
)
15838 fieldname
= dwarf2_name (die
, cu
);
15839 type_name
= dwarf2_name (die
->parent
, cu
);
15840 if (fieldname
== NULL
|| type_name
== NULL
)
15843 len
= strlen (fieldname
);
15844 return (strncmp (fieldname
, type_name
, len
) == 0
15845 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15848 /* Add a member function to the proper fieldlist. */
15851 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15852 struct type
*type
, struct dwarf2_cu
*cu
)
15854 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15855 struct attribute
*attr
;
15857 struct fnfieldlist
*flp
= nullptr;
15858 struct fn_field
*fnp
;
15859 const char *fieldname
;
15860 struct type
*this_type
;
15861 enum dwarf_access_attribute accessibility
;
15863 if (cu
->language
== language_ada
)
15864 error (_("unexpected member function in Ada type"));
15866 /* Get name of member function. */
15867 fieldname
= dwarf2_name (die
, cu
);
15868 if (fieldname
== NULL
)
15871 /* Look up member function name in fieldlist. */
15872 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15874 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15876 flp
= &fip
->fnfieldlists
[i
];
15881 /* Create a new fnfieldlist if necessary. */
15882 if (flp
== nullptr)
15884 fip
->fnfieldlists
.emplace_back ();
15885 flp
= &fip
->fnfieldlists
.back ();
15886 flp
->name
= fieldname
;
15887 i
= fip
->fnfieldlists
.size () - 1;
15890 /* Create a new member function field and add it to the vector of
15892 flp
->fnfields
.emplace_back ();
15893 fnp
= &flp
->fnfields
.back ();
15895 /* Delay processing of the physname until later. */
15896 if (cu
->language
== language_cplus
)
15897 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15901 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15902 fnp
->physname
= physname
? physname
: "";
15905 fnp
->type
= alloc_type (objfile
);
15906 this_type
= read_type_die (die
, cu
);
15907 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15909 int nparams
= TYPE_NFIELDS (this_type
);
15911 /* TYPE is the domain of this method, and THIS_TYPE is the type
15912 of the method itself (TYPE_CODE_METHOD). */
15913 smash_to_method_type (fnp
->type
, type
,
15914 TYPE_TARGET_TYPE (this_type
),
15915 TYPE_FIELDS (this_type
),
15916 TYPE_NFIELDS (this_type
),
15917 TYPE_VARARGS (this_type
));
15919 /* Handle static member functions.
15920 Dwarf2 has no clean way to discern C++ static and non-static
15921 member functions. G++ helps GDB by marking the first
15922 parameter for non-static member functions (which is the this
15923 pointer) as artificial. We obtain this information from
15924 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15925 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15926 fnp
->voffset
= VOFFSET_STATIC
;
15929 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
15930 dwarf2_full_name (fieldname
, die
, cu
));
15932 /* Get fcontext from DW_AT_containing_type if present. */
15933 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15934 fnp
->fcontext
= die_containing_type (die
, cu
);
15936 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15937 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15939 /* Get accessibility. */
15940 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15942 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15944 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15945 switch (accessibility
)
15947 case DW_ACCESS_private
:
15948 fnp
->is_private
= 1;
15950 case DW_ACCESS_protected
:
15951 fnp
->is_protected
= 1;
15955 /* Check for artificial methods. */
15956 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15957 if (attr
&& DW_UNSND (attr
) != 0)
15958 fnp
->is_artificial
= 1;
15960 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15962 /* Get index in virtual function table if it is a virtual member
15963 function. For older versions of GCC, this is an offset in the
15964 appropriate virtual table, as specified by DW_AT_containing_type.
15965 For everyone else, it is an expression to be evaluated relative
15966 to the object address. */
15968 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15971 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15973 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15975 /* Old-style GCC. */
15976 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15978 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15979 || (DW_BLOCK (attr
)->size
> 1
15980 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15981 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15983 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15984 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15985 dwarf2_complex_location_expr_complaint ();
15987 fnp
->voffset
/= cu
->header
.addr_size
;
15991 dwarf2_complex_location_expr_complaint ();
15993 if (!fnp
->fcontext
)
15995 /* If there is no `this' field and no DW_AT_containing_type,
15996 we cannot actually find a base class context for the
15998 if (TYPE_NFIELDS (this_type
) == 0
15999 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
16001 complaint (&symfile_complaints
,
16002 _("cannot determine context for virtual member "
16003 "function \"%s\" (offset %s)"),
16004 fieldname
, sect_offset_str (die
->sect_off
));
16009 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
16013 else if (attr_form_is_section_offset (attr
))
16015 dwarf2_complex_location_expr_complaint ();
16019 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
16025 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
16026 if (attr
&& DW_UNSND (attr
))
16028 /* GCC does this, as of 2008-08-25; PR debug/37237. */
16029 complaint (&symfile_complaints
,
16030 _("Member function \"%s\" (offset %s) is virtual "
16031 "but the vtable offset is not specified"),
16032 fieldname
, sect_offset_str (die
->sect_off
));
16033 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16034 TYPE_CPLUS_DYNAMIC (type
) = 1;
16039 /* Create the vector of member function fields, and attach it to the type. */
16042 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
16043 struct dwarf2_cu
*cu
)
16045 if (cu
->language
== language_ada
)
16046 error (_("unexpected member functions in Ada type"));
16048 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16049 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
16051 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
16053 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
16055 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
16056 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
16058 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
16059 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
16060 fn_flp
->fn_fields
= (struct fn_field
*)
16061 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
16063 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
16064 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
16067 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
16070 /* Returns non-zero if NAME is the name of a vtable member in CU's
16071 language, zero otherwise. */
16073 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
16075 static const char vptr
[] = "_vptr";
16077 /* Look for the C++ form of the vtable. */
16078 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
16084 /* GCC outputs unnamed structures that are really pointers to member
16085 functions, with the ABI-specified layout. If TYPE describes
16086 such a structure, smash it into a member function type.
16088 GCC shouldn't do this; it should just output pointer to member DIEs.
16089 This is GCC PR debug/28767. */
16092 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
16094 struct type
*pfn_type
, *self_type
, *new_type
;
16096 /* Check for a structure with no name and two children. */
16097 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
16100 /* Check for __pfn and __delta members. */
16101 if (TYPE_FIELD_NAME (type
, 0) == NULL
16102 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
16103 || TYPE_FIELD_NAME (type
, 1) == NULL
16104 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
16107 /* Find the type of the method. */
16108 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
16109 if (pfn_type
== NULL
16110 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
16111 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
16114 /* Look for the "this" argument. */
16115 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
16116 if (TYPE_NFIELDS (pfn_type
) == 0
16117 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
16118 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
16121 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
16122 new_type
= alloc_type (objfile
);
16123 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
16124 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
16125 TYPE_VARARGS (pfn_type
));
16126 smash_to_methodptr_type (type
, new_type
);
16130 /* Called when we find the DIE that starts a structure or union scope
16131 (definition) to create a type for the structure or union. Fill in
16132 the type's name and general properties; the members will not be
16133 processed until process_structure_scope. A symbol table entry for
16134 the type will also not be done until process_structure_scope (assuming
16135 the type has a name).
16137 NOTE: we need to call these functions regardless of whether or not the
16138 DIE has a DW_AT_name attribute, since it might be an anonymous
16139 structure or union. This gets the type entered into our set of
16140 user defined types. */
16142 static struct type
*
16143 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16145 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16147 struct attribute
*attr
;
16150 /* If the definition of this type lives in .debug_types, read that type.
16151 Don't follow DW_AT_specification though, that will take us back up
16152 the chain and we want to go down. */
16153 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16156 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16158 /* The type's CU may not be the same as CU.
16159 Ensure TYPE is recorded with CU in die_type_hash. */
16160 return set_die_type (die
, type
, cu
);
16163 type
= alloc_type (objfile
);
16164 INIT_CPLUS_SPECIFIC (type
);
16166 name
= dwarf2_name (die
, cu
);
16169 if (cu
->language
== language_cplus
16170 || cu
->language
== language_d
16171 || cu
->language
== language_rust
)
16173 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
16175 /* dwarf2_full_name might have already finished building the DIE's
16176 type. If so, there is no need to continue. */
16177 if (get_die_type (die
, cu
) != NULL
)
16178 return get_die_type (die
, cu
);
16180 TYPE_TAG_NAME (type
) = full_name
;
16181 if (die
->tag
== DW_TAG_structure_type
16182 || die
->tag
== DW_TAG_class_type
)
16183 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16187 /* The name is already allocated along with this objfile, so
16188 we don't need to duplicate it for the type. */
16189 TYPE_TAG_NAME (type
) = name
;
16190 if (die
->tag
== DW_TAG_class_type
)
16191 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
16195 if (die
->tag
== DW_TAG_structure_type
)
16197 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16199 else if (die
->tag
== DW_TAG_union_type
)
16201 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16203 else if (die
->tag
== DW_TAG_variant_part
)
16205 TYPE_CODE (type
) = TYPE_CODE_UNION
;
16206 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
16210 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16213 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16214 TYPE_DECLARED_CLASS (type
) = 1;
16216 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16219 if (attr_form_is_constant (attr
))
16220 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16223 /* For the moment, dynamic type sizes are not supported
16224 by GDB's struct type. The actual size is determined
16225 on-demand when resolving the type of a given object,
16226 so set the type's length to zero for now. Otherwise,
16227 we record an expression as the length, and that expression
16228 could lead to a very large value, which could eventually
16229 lead to us trying to allocate that much memory when creating
16230 a value of that type. */
16231 TYPE_LENGTH (type
) = 0;
16236 TYPE_LENGTH (type
) = 0;
16239 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16241 /* ICC<14 does not output the required DW_AT_declaration on
16242 incomplete types, but gives them a size of zero. */
16243 TYPE_STUB (type
) = 1;
16246 TYPE_STUB_SUPPORTED (type
) = 1;
16248 if (die_is_declaration (die
, cu
))
16249 TYPE_STUB (type
) = 1;
16250 else if (attr
== NULL
&& die
->child
== NULL
16251 && producer_is_realview (cu
->producer
))
16252 /* RealView does not output the required DW_AT_declaration
16253 on incomplete types. */
16254 TYPE_STUB (type
) = 1;
16256 /* We need to add the type field to the die immediately so we don't
16257 infinitely recurse when dealing with pointers to the structure
16258 type within the structure itself. */
16259 set_die_type (die
, type
, cu
);
16261 /* set_die_type should be already done. */
16262 set_descriptive_type (type
, die
, cu
);
16267 /* A helper for process_structure_scope that handles a single member
16271 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16272 struct field_info
*fi
,
16273 std::vector
<struct symbol
*> *template_args
,
16274 struct dwarf2_cu
*cu
)
16276 if (child_die
->tag
== DW_TAG_member
16277 || child_die
->tag
== DW_TAG_variable
16278 || child_die
->tag
== DW_TAG_variant_part
)
16280 /* NOTE: carlton/2002-11-05: A C++ static data member
16281 should be a DW_TAG_member that is a declaration, but
16282 all versions of G++ as of this writing (so through at
16283 least 3.2.1) incorrectly generate DW_TAG_variable
16284 tags for them instead. */
16285 dwarf2_add_field (fi
, child_die
, cu
);
16287 else if (child_die
->tag
== DW_TAG_subprogram
)
16289 /* Rust doesn't have member functions in the C++ sense.
16290 However, it does emit ordinary functions as children
16291 of a struct DIE. */
16292 if (cu
->language
== language_rust
)
16293 read_func_scope (child_die
, cu
);
16296 /* C++ member function. */
16297 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16300 else if (child_die
->tag
== DW_TAG_inheritance
)
16302 /* C++ base class field. */
16303 dwarf2_add_field (fi
, child_die
, cu
);
16305 else if (type_can_define_types (child_die
))
16306 dwarf2_add_type_defn (fi
, child_die
, cu
);
16307 else if (child_die
->tag
== DW_TAG_template_type_param
16308 || child_die
->tag
== DW_TAG_template_value_param
)
16310 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16313 template_args
->push_back (arg
);
16315 else if (child_die
->tag
== DW_TAG_variant
)
16317 /* In a variant we want to get the discriminant and also add a
16318 field for our sole member child. */
16319 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16321 for (struct die_info
*variant_child
= child_die
->child
;
16322 variant_child
!= NULL
;
16323 variant_child
= sibling_die (variant_child
))
16325 if (variant_child
->tag
== DW_TAG_member
)
16327 handle_struct_member_die (variant_child
, type
, fi
,
16328 template_args
, cu
);
16329 /* Only handle the one. */
16334 /* We don't handle this but we might as well report it if we see
16336 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16337 complaint (&symfile_complaints
,
16338 _("DW_AT_discr_list is not supported yet"
16339 " - DIE at %s [in module %s]"),
16340 sect_offset_str (child_die
->sect_off
),
16341 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16343 /* The first field was just added, so we can stash the
16344 discriminant there. */
16345 gdb_assert (!fi
->fields
.empty ());
16347 fi
->fields
.back ().variant
.default_branch
= true;
16349 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16353 /* Finish creating a structure or union type, including filling in
16354 its members and creating a symbol for it. */
16357 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16359 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16360 struct die_info
*child_die
;
16363 type
= get_die_type (die
, cu
);
16365 type
= read_structure_type (die
, cu
);
16367 /* When reading a DW_TAG_variant_part, we need to notice when we
16368 read the discriminant member, so we can record it later in the
16369 discriminant_info. */
16370 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16371 sect_offset discr_offset
;
16373 if (is_variant_part
)
16375 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16378 /* Maybe it's a univariant form, an extension we support.
16379 In this case arrange not to check the offset. */
16380 is_variant_part
= false;
16382 else if (attr_form_is_ref (discr
))
16384 struct dwarf2_cu
*target_cu
= cu
;
16385 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16387 discr_offset
= target_die
->sect_off
;
16391 complaint (&symfile_complaints
,
16392 _("DW_AT_discr does not have DIE reference form"
16393 " - DIE at %s [in module %s]"),
16394 sect_offset_str (die
->sect_off
),
16395 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16396 is_variant_part
= false;
16400 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16402 struct field_info fi
;
16403 std::vector
<struct symbol
*> template_args
;
16405 child_die
= die
->child
;
16407 while (child_die
&& child_die
->tag
)
16409 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16411 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16412 fi
.fields
.back ().variant
.is_discriminant
= true;
16414 child_die
= sibling_die (child_die
);
16417 /* Attach template arguments to type. */
16418 if (!template_args
.empty ())
16420 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16421 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16422 TYPE_TEMPLATE_ARGUMENTS (type
)
16423 = XOBNEWVEC (&objfile
->objfile_obstack
,
16425 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16426 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16427 template_args
.data (),
16428 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16429 * sizeof (struct symbol
*)));
16432 /* Attach fields and member functions to the type. */
16434 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16435 if (!fi
.fnfieldlists
.empty ())
16437 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16439 /* Get the type which refers to the base class (possibly this
16440 class itself) which contains the vtable pointer for the current
16441 class from the DW_AT_containing_type attribute. This use of
16442 DW_AT_containing_type is a GNU extension. */
16444 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16446 struct type
*t
= die_containing_type (die
, cu
);
16448 set_type_vptr_basetype (type
, t
);
16453 /* Our own class provides vtbl ptr. */
16454 for (i
= TYPE_NFIELDS (t
) - 1;
16455 i
>= TYPE_N_BASECLASSES (t
);
16458 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16460 if (is_vtable_name (fieldname
, cu
))
16462 set_type_vptr_fieldno (type
, i
);
16467 /* Complain if virtual function table field not found. */
16468 if (i
< TYPE_N_BASECLASSES (t
))
16469 complaint (&symfile_complaints
,
16470 _("virtual function table pointer "
16471 "not found when defining class '%s'"),
16472 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
16477 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16480 else if (cu
->producer
16481 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16483 /* The IBM XLC compiler does not provide direct indication
16484 of the containing type, but the vtable pointer is
16485 always named __vfp. */
16489 for (i
= TYPE_NFIELDS (type
) - 1;
16490 i
>= TYPE_N_BASECLASSES (type
);
16493 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16495 set_type_vptr_fieldno (type
, i
);
16496 set_type_vptr_basetype (type
, type
);
16503 /* Copy fi.typedef_field_list linked list elements content into the
16504 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16505 if (!fi
.typedef_field_list
.empty ())
16507 int count
= fi
.typedef_field_list
.size ();
16509 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16510 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16511 = ((struct decl_field
*)
16513 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16514 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16516 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16517 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16520 /* Copy fi.nested_types_list linked list elements content into the
16521 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16522 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16524 int count
= fi
.nested_types_list
.size ();
16526 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16527 TYPE_NESTED_TYPES_ARRAY (type
)
16528 = ((struct decl_field
*)
16529 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16530 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16532 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16533 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16537 quirk_gcc_member_function_pointer (type
, objfile
);
16538 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16539 cu
->rust_unions
.push_back (type
);
16541 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16542 snapshots) has been known to create a die giving a declaration
16543 for a class that has, as a child, a die giving a definition for a
16544 nested class. So we have to process our children even if the
16545 current die is a declaration. Normally, of course, a declaration
16546 won't have any children at all. */
16548 child_die
= die
->child
;
16550 while (child_die
!= NULL
&& child_die
->tag
)
16552 if (child_die
->tag
== DW_TAG_member
16553 || child_die
->tag
== DW_TAG_variable
16554 || child_die
->tag
== DW_TAG_inheritance
16555 || child_die
->tag
== DW_TAG_template_value_param
16556 || child_die
->tag
== DW_TAG_template_type_param
)
16561 process_die (child_die
, cu
);
16563 child_die
= sibling_die (child_die
);
16566 /* Do not consider external references. According to the DWARF standard,
16567 these DIEs are identified by the fact that they have no byte_size
16568 attribute, and a declaration attribute. */
16569 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16570 || !die_is_declaration (die
, cu
))
16571 new_symbol (die
, type
, cu
);
16574 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16575 update TYPE using some information only available in DIE's children. */
16578 update_enumeration_type_from_children (struct die_info
*die
,
16580 struct dwarf2_cu
*cu
)
16582 struct die_info
*child_die
;
16583 int unsigned_enum
= 1;
16587 auto_obstack obstack
;
16589 for (child_die
= die
->child
;
16590 child_die
!= NULL
&& child_die
->tag
;
16591 child_die
= sibling_die (child_die
))
16593 struct attribute
*attr
;
16595 const gdb_byte
*bytes
;
16596 struct dwarf2_locexpr_baton
*baton
;
16599 if (child_die
->tag
!= DW_TAG_enumerator
)
16602 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16606 name
= dwarf2_name (child_die
, cu
);
16608 name
= "<anonymous enumerator>";
16610 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16611 &value
, &bytes
, &baton
);
16617 else if ((mask
& value
) != 0)
16622 /* If we already know that the enum type is neither unsigned, nor
16623 a flag type, no need to look at the rest of the enumerates. */
16624 if (!unsigned_enum
&& !flag_enum
)
16629 TYPE_UNSIGNED (type
) = 1;
16631 TYPE_FLAG_ENUM (type
) = 1;
16634 /* Given a DW_AT_enumeration_type die, set its type. We do not
16635 complete the type's fields yet, or create any symbols. */
16637 static struct type
*
16638 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16640 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16642 struct attribute
*attr
;
16645 /* If the definition of this type lives in .debug_types, read that type.
16646 Don't follow DW_AT_specification though, that will take us back up
16647 the chain and we want to go down. */
16648 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16651 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16653 /* The type's CU may not be the same as CU.
16654 Ensure TYPE is recorded with CU in die_type_hash. */
16655 return set_die_type (die
, type
, cu
);
16658 type
= alloc_type (objfile
);
16660 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16661 name
= dwarf2_full_name (NULL
, die
, cu
);
16663 TYPE_TAG_NAME (type
) = name
;
16665 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16668 struct type
*underlying_type
= die_type (die
, cu
);
16670 TYPE_TARGET_TYPE (type
) = underlying_type
;
16673 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16676 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16680 TYPE_LENGTH (type
) = 0;
16683 /* The enumeration DIE can be incomplete. In Ada, any type can be
16684 declared as private in the package spec, and then defined only
16685 inside the package body. Such types are known as Taft Amendment
16686 Types. When another package uses such a type, an incomplete DIE
16687 may be generated by the compiler. */
16688 if (die_is_declaration (die
, cu
))
16689 TYPE_STUB (type
) = 1;
16691 /* Finish the creation of this type by using the enum's children.
16692 We must call this even when the underlying type has been provided
16693 so that we can determine if we're looking at a "flag" enum. */
16694 update_enumeration_type_from_children (die
, type
, cu
);
16696 /* If this type has an underlying type that is not a stub, then we
16697 may use its attributes. We always use the "unsigned" attribute
16698 in this situation, because ordinarily we guess whether the type
16699 is unsigned -- but the guess can be wrong and the underlying type
16700 can tell us the reality. However, we defer to a local size
16701 attribute if one exists, because this lets the compiler override
16702 the underlying type if needed. */
16703 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16705 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16706 if (TYPE_LENGTH (type
) == 0)
16707 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16710 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16712 return set_die_type (die
, type
, cu
);
16715 /* Given a pointer to a die which begins an enumeration, process all
16716 the dies that define the members of the enumeration, and create the
16717 symbol for the enumeration type.
16719 NOTE: We reverse the order of the element list. */
16722 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16724 struct type
*this_type
;
16726 this_type
= get_die_type (die
, cu
);
16727 if (this_type
== NULL
)
16728 this_type
= read_enumeration_type (die
, cu
);
16730 if (die
->child
!= NULL
)
16732 struct die_info
*child_die
;
16733 struct symbol
*sym
;
16734 struct field
*fields
= NULL
;
16735 int num_fields
= 0;
16738 child_die
= die
->child
;
16739 while (child_die
&& child_die
->tag
)
16741 if (child_die
->tag
!= DW_TAG_enumerator
)
16743 process_die (child_die
, cu
);
16747 name
= dwarf2_name (child_die
, cu
);
16750 sym
= new_symbol (child_die
, this_type
, cu
);
16752 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16754 fields
= (struct field
*)
16756 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16757 * sizeof (struct field
));
16760 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16761 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16762 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16763 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16769 child_die
= sibling_die (child_die
);
16774 TYPE_NFIELDS (this_type
) = num_fields
;
16775 TYPE_FIELDS (this_type
) = (struct field
*)
16776 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16777 memcpy (TYPE_FIELDS (this_type
), fields
,
16778 sizeof (struct field
) * num_fields
);
16783 /* If we are reading an enum from a .debug_types unit, and the enum
16784 is a declaration, and the enum is not the signatured type in the
16785 unit, then we do not want to add a symbol for it. Adding a
16786 symbol would in some cases obscure the true definition of the
16787 enum, giving users an incomplete type when the definition is
16788 actually available. Note that we do not want to do this for all
16789 enums which are just declarations, because C++0x allows forward
16790 enum declarations. */
16791 if (cu
->per_cu
->is_debug_types
16792 && die_is_declaration (die
, cu
))
16794 struct signatured_type
*sig_type
;
16796 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16797 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16798 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16802 new_symbol (die
, this_type
, cu
);
16805 /* Extract all information from a DW_TAG_array_type DIE and put it in
16806 the DIE's type field. For now, this only handles one dimensional
16809 static struct type
*
16810 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16812 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16813 struct die_info
*child_die
;
16815 struct type
*element_type
, *range_type
, *index_type
;
16816 struct attribute
*attr
;
16818 struct dynamic_prop
*byte_stride_prop
= NULL
;
16819 unsigned int bit_stride
= 0;
16821 element_type
= die_type (die
, cu
);
16823 /* The die_type call above may have already set the type for this DIE. */
16824 type
= get_die_type (die
, cu
);
16828 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16834 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16835 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
);
16838 complaint (&symfile_complaints
,
16839 _("unable to read array DW_AT_byte_stride "
16840 " - DIE at %s [in module %s]"),
16841 sect_offset_str (die
->sect_off
),
16842 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16843 /* Ignore this attribute. We will likely not be able to print
16844 arrays of this type correctly, but there is little we can do
16845 to help if we cannot read the attribute's value. */
16846 byte_stride_prop
= NULL
;
16850 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16852 bit_stride
= DW_UNSND (attr
);
16854 /* Irix 6.2 native cc creates array types without children for
16855 arrays with unspecified length. */
16856 if (die
->child
== NULL
)
16858 index_type
= objfile_type (objfile
)->builtin_int
;
16859 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16860 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16861 byte_stride_prop
, bit_stride
);
16862 return set_die_type (die
, type
, cu
);
16865 std::vector
<struct type
*> range_types
;
16866 child_die
= die
->child
;
16867 while (child_die
&& child_die
->tag
)
16869 if (child_die
->tag
== DW_TAG_subrange_type
)
16871 struct type
*child_type
= read_type_die (child_die
, cu
);
16873 if (child_type
!= NULL
)
16875 /* The range type was succesfully read. Save it for the
16876 array type creation. */
16877 range_types
.push_back (child_type
);
16880 child_die
= sibling_die (child_die
);
16883 /* Dwarf2 dimensions are output from left to right, create the
16884 necessary array types in backwards order. */
16886 type
= element_type
;
16888 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16892 while (i
< range_types
.size ())
16893 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16894 byte_stride_prop
, bit_stride
);
16898 size_t ndim
= range_types
.size ();
16900 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16901 byte_stride_prop
, bit_stride
);
16904 /* Understand Dwarf2 support for vector types (like they occur on
16905 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16906 array type. This is not part of the Dwarf2/3 standard yet, but a
16907 custom vendor extension. The main difference between a regular
16908 array and the vector variant is that vectors are passed by value
16910 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16912 make_vector_type (type
);
16914 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16915 implementation may choose to implement triple vectors using this
16917 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16920 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16921 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16923 complaint (&symfile_complaints
,
16924 _("DW_AT_byte_size for array type smaller "
16925 "than the total size of elements"));
16928 name
= dwarf2_name (die
, cu
);
16930 TYPE_NAME (type
) = name
;
16932 /* Install the type in the die. */
16933 set_die_type (die
, type
, cu
);
16935 /* set_die_type should be already done. */
16936 set_descriptive_type (type
, die
, cu
);
16941 static enum dwarf_array_dim_ordering
16942 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16944 struct attribute
*attr
;
16946 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16949 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16951 /* GNU F77 is a special case, as at 08/2004 array type info is the
16952 opposite order to the dwarf2 specification, but data is still
16953 laid out as per normal fortran.
16955 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16956 version checking. */
16958 if (cu
->language
== language_fortran
16959 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16961 return DW_ORD_row_major
;
16964 switch (cu
->language_defn
->la_array_ordering
)
16966 case array_column_major
:
16967 return DW_ORD_col_major
;
16968 case array_row_major
:
16970 return DW_ORD_row_major
;
16974 /* Extract all information from a DW_TAG_set_type DIE and put it in
16975 the DIE's type field. */
16977 static struct type
*
16978 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16980 struct type
*domain_type
, *set_type
;
16981 struct attribute
*attr
;
16983 domain_type
= die_type (die
, cu
);
16985 /* The die_type call above may have already set the type for this DIE. */
16986 set_type
= get_die_type (die
, cu
);
16990 set_type
= create_set_type (NULL
, domain_type
);
16992 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16994 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16996 return set_die_type (die
, set_type
, cu
);
16999 /* A helper for read_common_block that creates a locexpr baton.
17000 SYM is the symbol which we are marking as computed.
17001 COMMON_DIE is the DIE for the common block.
17002 COMMON_LOC is the location expression attribute for the common
17004 MEMBER_LOC is the location expression attribute for the particular
17005 member of the common block that we are processing.
17006 CU is the CU from which the above come. */
17009 mark_common_block_symbol_computed (struct symbol
*sym
,
17010 struct die_info
*common_die
,
17011 struct attribute
*common_loc
,
17012 struct attribute
*member_loc
,
17013 struct dwarf2_cu
*cu
)
17015 struct dwarf2_per_objfile
*dwarf2_per_objfile
17016 = cu
->per_cu
->dwarf2_per_objfile
;
17017 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17018 struct dwarf2_locexpr_baton
*baton
;
17020 unsigned int cu_off
;
17021 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
17022 LONGEST offset
= 0;
17024 gdb_assert (common_loc
&& member_loc
);
17025 gdb_assert (attr_form_is_block (common_loc
));
17026 gdb_assert (attr_form_is_block (member_loc
)
17027 || attr_form_is_constant (member_loc
));
17029 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
17030 baton
->per_cu
= cu
->per_cu
;
17031 gdb_assert (baton
->per_cu
);
17033 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
17035 if (attr_form_is_constant (member_loc
))
17037 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
17038 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
17041 baton
->size
+= DW_BLOCK (member_loc
)->size
;
17043 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
17046 *ptr
++ = DW_OP_call4
;
17047 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
17048 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
17051 if (attr_form_is_constant (member_loc
))
17053 *ptr
++ = DW_OP_addr
;
17054 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
17055 ptr
+= cu
->header
.addr_size
;
17059 /* We have to copy the data here, because DW_OP_call4 will only
17060 use a DW_AT_location attribute. */
17061 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
17062 ptr
+= DW_BLOCK (member_loc
)->size
;
17065 *ptr
++ = DW_OP_plus
;
17066 gdb_assert (ptr
- baton
->data
== baton
->size
);
17068 SYMBOL_LOCATION_BATON (sym
) = baton
;
17069 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
17072 /* Create appropriate locally-scoped variables for all the
17073 DW_TAG_common_block entries. Also create a struct common_block
17074 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
17075 is used to sepate the common blocks name namespace from regular
17079 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
17081 struct attribute
*attr
;
17083 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
17086 /* Support the .debug_loc offsets. */
17087 if (attr_form_is_block (attr
))
17091 else if (attr_form_is_section_offset (attr
))
17093 dwarf2_complex_location_expr_complaint ();
17098 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17099 "common block member");
17104 if (die
->child
!= NULL
)
17106 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17107 struct die_info
*child_die
;
17108 size_t n_entries
= 0, size
;
17109 struct common_block
*common_block
;
17110 struct symbol
*sym
;
17112 for (child_die
= die
->child
;
17113 child_die
&& child_die
->tag
;
17114 child_die
= sibling_die (child_die
))
17117 size
= (sizeof (struct common_block
)
17118 + (n_entries
- 1) * sizeof (struct symbol
*));
17120 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
17122 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
17123 common_block
->n_entries
= 0;
17125 for (child_die
= die
->child
;
17126 child_die
&& child_die
->tag
;
17127 child_die
= sibling_die (child_die
))
17129 /* Create the symbol in the DW_TAG_common_block block in the current
17131 sym
= new_symbol (child_die
, NULL
, cu
);
17134 struct attribute
*member_loc
;
17136 common_block
->contents
[common_block
->n_entries
++] = sym
;
17138 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
17142 /* GDB has handled this for a long time, but it is
17143 not specified by DWARF. It seems to have been
17144 emitted by gfortran at least as recently as:
17145 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
17146 complaint (&symfile_complaints
,
17147 _("Variable in common block has "
17148 "DW_AT_data_member_location "
17149 "- DIE at %s [in module %s]"),
17150 sect_offset_str (child_die
->sect_off
),
17151 objfile_name (objfile
));
17153 if (attr_form_is_section_offset (member_loc
))
17154 dwarf2_complex_location_expr_complaint ();
17155 else if (attr_form_is_constant (member_loc
)
17156 || attr_form_is_block (member_loc
))
17159 mark_common_block_symbol_computed (sym
, die
, attr
,
17163 dwarf2_complex_location_expr_complaint ();
17168 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17169 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17173 /* Create a type for a C++ namespace. */
17175 static struct type
*
17176 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17178 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17179 const char *previous_prefix
, *name
;
17183 /* For extensions, reuse the type of the original namespace. */
17184 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17186 struct die_info
*ext_die
;
17187 struct dwarf2_cu
*ext_cu
= cu
;
17189 ext_die
= dwarf2_extension (die
, &ext_cu
);
17190 type
= read_type_die (ext_die
, ext_cu
);
17192 /* EXT_CU may not be the same as CU.
17193 Ensure TYPE is recorded with CU in die_type_hash. */
17194 return set_die_type (die
, type
, cu
);
17197 name
= namespace_name (die
, &is_anonymous
, cu
);
17199 /* Now build the name of the current namespace. */
17201 previous_prefix
= determine_prefix (die
, cu
);
17202 if (previous_prefix
[0] != '\0')
17203 name
= typename_concat (&objfile
->objfile_obstack
,
17204 previous_prefix
, name
, 0, cu
);
17206 /* Create the type. */
17207 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17208 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17210 return set_die_type (die
, type
, cu
);
17213 /* Read a namespace scope. */
17216 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17218 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17221 /* Add a symbol associated to this if we haven't seen the namespace
17222 before. Also, add a using directive if it's an anonymous
17225 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17229 type
= read_type_die (die
, cu
);
17230 new_symbol (die
, type
, cu
);
17232 namespace_name (die
, &is_anonymous
, cu
);
17235 const char *previous_prefix
= determine_prefix (die
, cu
);
17237 std::vector
<const char *> excludes
;
17238 add_using_directive (using_directives (cu
->language
),
17239 previous_prefix
, TYPE_NAME (type
), NULL
,
17240 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17244 if (die
->child
!= NULL
)
17246 struct die_info
*child_die
= die
->child
;
17248 while (child_die
&& child_die
->tag
)
17250 process_die (child_die
, cu
);
17251 child_die
= sibling_die (child_die
);
17256 /* Read a Fortran module as type. This DIE can be only a declaration used for
17257 imported module. Still we need that type as local Fortran "use ... only"
17258 declaration imports depend on the created type in determine_prefix. */
17260 static struct type
*
17261 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17263 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17264 const char *module_name
;
17267 module_name
= dwarf2_name (die
, cu
);
17269 complaint (&symfile_complaints
,
17270 _("DW_TAG_module has no name, offset %s"),
17271 sect_offset_str (die
->sect_off
));
17272 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17274 /* determine_prefix uses TYPE_TAG_NAME. */
17275 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
17277 return set_die_type (die
, type
, cu
);
17280 /* Read a Fortran module. */
17283 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17285 struct die_info
*child_die
= die
->child
;
17288 type
= read_type_die (die
, cu
);
17289 new_symbol (die
, type
, cu
);
17291 while (child_die
&& child_die
->tag
)
17293 process_die (child_die
, cu
);
17294 child_die
= sibling_die (child_die
);
17298 /* Return the name of the namespace represented by DIE. Set
17299 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17302 static const char *
17303 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17305 struct die_info
*current_die
;
17306 const char *name
= NULL
;
17308 /* Loop through the extensions until we find a name. */
17310 for (current_die
= die
;
17311 current_die
!= NULL
;
17312 current_die
= dwarf2_extension (die
, &cu
))
17314 /* We don't use dwarf2_name here so that we can detect the absence
17315 of a name -> anonymous namespace. */
17316 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17322 /* Is it an anonymous namespace? */
17324 *is_anonymous
= (name
== NULL
);
17326 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17331 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17332 the user defined type vector. */
17334 static struct type
*
17335 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17337 struct gdbarch
*gdbarch
17338 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17339 struct comp_unit_head
*cu_header
= &cu
->header
;
17341 struct attribute
*attr_byte_size
;
17342 struct attribute
*attr_address_class
;
17343 int byte_size
, addr_class
;
17344 struct type
*target_type
;
17346 target_type
= die_type (die
, cu
);
17348 /* The die_type call above may have already set the type for this DIE. */
17349 type
= get_die_type (die
, cu
);
17353 type
= lookup_pointer_type (target_type
);
17355 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17356 if (attr_byte_size
)
17357 byte_size
= DW_UNSND (attr_byte_size
);
17359 byte_size
= cu_header
->addr_size
;
17361 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17362 if (attr_address_class
)
17363 addr_class
= DW_UNSND (attr_address_class
);
17365 addr_class
= DW_ADDR_none
;
17367 /* If the pointer size or address class is different than the
17368 default, create a type variant marked as such and set the
17369 length accordingly. */
17370 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
17372 if (gdbarch_address_class_type_flags_p (gdbarch
))
17376 type_flags
= gdbarch_address_class_type_flags
17377 (gdbarch
, byte_size
, addr_class
);
17378 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17380 type
= make_type_with_address_space (type
, type_flags
);
17382 else if (TYPE_LENGTH (type
) != byte_size
)
17384 complaint (&symfile_complaints
,
17385 _("invalid pointer size %d"), byte_size
);
17389 /* Should we also complain about unhandled address classes? */
17393 TYPE_LENGTH (type
) = byte_size
;
17394 return set_die_type (die
, type
, cu
);
17397 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17398 the user defined type vector. */
17400 static struct type
*
17401 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17404 struct type
*to_type
;
17405 struct type
*domain
;
17407 to_type
= die_type (die
, cu
);
17408 domain
= die_containing_type (die
, cu
);
17410 /* The calls above may have already set the type for this DIE. */
17411 type
= get_die_type (die
, cu
);
17415 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17416 type
= lookup_methodptr_type (to_type
);
17417 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17419 struct type
*new_type
17420 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17422 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17423 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17424 TYPE_VARARGS (to_type
));
17425 type
= lookup_methodptr_type (new_type
);
17428 type
= lookup_memberptr_type (to_type
, domain
);
17430 return set_die_type (die
, type
, cu
);
17433 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17434 the user defined type vector. */
17436 static struct type
*
17437 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17438 enum type_code refcode
)
17440 struct comp_unit_head
*cu_header
= &cu
->header
;
17441 struct type
*type
, *target_type
;
17442 struct attribute
*attr
;
17444 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17446 target_type
= die_type (die
, cu
);
17448 /* The die_type call above may have already set the type for this DIE. */
17449 type
= get_die_type (die
, cu
);
17453 type
= lookup_reference_type (target_type
, refcode
);
17454 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17457 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17461 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17463 return set_die_type (die
, type
, cu
);
17466 /* Add the given cv-qualifiers to the element type of the array. GCC
17467 outputs DWARF type qualifiers that apply to an array, not the
17468 element type. But GDB relies on the array element type to carry
17469 the cv-qualifiers. This mimics section 6.7.3 of the C99
17472 static struct type
*
17473 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17474 struct type
*base_type
, int cnst
, int voltl
)
17476 struct type
*el_type
, *inner_array
;
17478 base_type
= copy_type (base_type
);
17479 inner_array
= base_type
;
17481 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17483 TYPE_TARGET_TYPE (inner_array
) =
17484 copy_type (TYPE_TARGET_TYPE (inner_array
));
17485 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17488 el_type
= TYPE_TARGET_TYPE (inner_array
);
17489 cnst
|= TYPE_CONST (el_type
);
17490 voltl
|= TYPE_VOLATILE (el_type
);
17491 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17493 return set_die_type (die
, base_type
, cu
);
17496 static struct type
*
17497 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17499 struct type
*base_type
, *cv_type
;
17501 base_type
= die_type (die
, cu
);
17503 /* The die_type call above may have already set the type for this DIE. */
17504 cv_type
= get_die_type (die
, cu
);
17508 /* In case the const qualifier is applied to an array type, the element type
17509 is so qualified, not the array type (section 6.7.3 of C99). */
17510 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17511 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17513 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17514 return set_die_type (die
, cv_type
, cu
);
17517 static struct type
*
17518 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17520 struct type
*base_type
, *cv_type
;
17522 base_type
= die_type (die
, cu
);
17524 /* The die_type call above may have already set the type for this DIE. */
17525 cv_type
= get_die_type (die
, cu
);
17529 /* In case the volatile qualifier is applied to an array type, the
17530 element type is so qualified, not the array type (section 6.7.3
17532 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17533 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17535 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17536 return set_die_type (die
, cv_type
, cu
);
17539 /* Handle DW_TAG_restrict_type. */
17541 static struct type
*
17542 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17544 struct type
*base_type
, *cv_type
;
17546 base_type
= die_type (die
, cu
);
17548 /* The die_type call above may have already set the type for this DIE. */
17549 cv_type
= get_die_type (die
, cu
);
17553 cv_type
= make_restrict_type (base_type
);
17554 return set_die_type (die
, cv_type
, cu
);
17557 /* Handle DW_TAG_atomic_type. */
17559 static struct type
*
17560 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17562 struct type
*base_type
, *cv_type
;
17564 base_type
= die_type (die
, cu
);
17566 /* The die_type call above may have already set the type for this DIE. */
17567 cv_type
= get_die_type (die
, cu
);
17571 cv_type
= make_atomic_type (base_type
);
17572 return set_die_type (die
, cv_type
, cu
);
17575 /* Extract all information from a DW_TAG_string_type DIE and add to
17576 the user defined type vector. It isn't really a user defined type,
17577 but it behaves like one, with other DIE's using an AT_user_def_type
17578 attribute to reference it. */
17580 static struct type
*
17581 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17583 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17584 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17585 struct type
*type
, *range_type
, *index_type
, *char_type
;
17586 struct attribute
*attr
;
17587 unsigned int length
;
17589 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17592 length
= DW_UNSND (attr
);
17596 /* Check for the DW_AT_byte_size attribute. */
17597 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17600 length
= DW_UNSND (attr
);
17608 index_type
= objfile_type (objfile
)->builtin_int
;
17609 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17610 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17611 type
= create_string_type (NULL
, char_type
, range_type
);
17613 return set_die_type (die
, type
, cu
);
17616 /* Assuming that DIE corresponds to a function, returns nonzero
17617 if the function is prototyped. */
17620 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17622 struct attribute
*attr
;
17624 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17625 if (attr
&& (DW_UNSND (attr
) != 0))
17628 /* The DWARF standard implies that the DW_AT_prototyped attribute
17629 is only meaninful for C, but the concept also extends to other
17630 languages that allow unprototyped functions (Eg: Objective C).
17631 For all other languages, assume that functions are always
17633 if (cu
->language
!= language_c
17634 && cu
->language
!= language_objc
17635 && cu
->language
!= language_opencl
)
17638 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17639 prototyped and unprototyped functions; default to prototyped,
17640 since that is more common in modern code (and RealView warns
17641 about unprototyped functions). */
17642 if (producer_is_realview (cu
->producer
))
17648 /* Handle DIES due to C code like:
17652 int (*funcp)(int a, long l);
17656 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17658 static struct type
*
17659 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17661 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17662 struct type
*type
; /* Type that this function returns. */
17663 struct type
*ftype
; /* Function that returns above type. */
17664 struct attribute
*attr
;
17666 type
= die_type (die
, cu
);
17668 /* The die_type call above may have already set the type for this DIE. */
17669 ftype
= get_die_type (die
, cu
);
17673 ftype
= lookup_function_type (type
);
17675 if (prototyped_function_p (die
, cu
))
17676 TYPE_PROTOTYPED (ftype
) = 1;
17678 /* Store the calling convention in the type if it's available in
17679 the subroutine die. Otherwise set the calling convention to
17680 the default value DW_CC_normal. */
17681 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17683 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17684 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17685 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17687 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17689 /* Record whether the function returns normally to its caller or not
17690 if the DWARF producer set that information. */
17691 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17692 if (attr
&& (DW_UNSND (attr
) != 0))
17693 TYPE_NO_RETURN (ftype
) = 1;
17695 /* We need to add the subroutine type to the die immediately so
17696 we don't infinitely recurse when dealing with parameters
17697 declared as the same subroutine type. */
17698 set_die_type (die
, ftype
, cu
);
17700 if (die
->child
!= NULL
)
17702 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17703 struct die_info
*child_die
;
17704 int nparams
, iparams
;
17706 /* Count the number of parameters.
17707 FIXME: GDB currently ignores vararg functions, but knows about
17708 vararg member functions. */
17710 child_die
= die
->child
;
17711 while (child_die
&& child_die
->tag
)
17713 if (child_die
->tag
== DW_TAG_formal_parameter
)
17715 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17716 TYPE_VARARGS (ftype
) = 1;
17717 child_die
= sibling_die (child_die
);
17720 /* Allocate storage for parameters and fill them in. */
17721 TYPE_NFIELDS (ftype
) = nparams
;
17722 TYPE_FIELDS (ftype
) = (struct field
*)
17723 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17725 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17726 even if we error out during the parameters reading below. */
17727 for (iparams
= 0; iparams
< nparams
; iparams
++)
17728 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17731 child_die
= die
->child
;
17732 while (child_die
&& child_die
->tag
)
17734 if (child_die
->tag
== DW_TAG_formal_parameter
)
17736 struct type
*arg_type
;
17738 /* DWARF version 2 has no clean way to discern C++
17739 static and non-static member functions. G++ helps
17740 GDB by marking the first parameter for non-static
17741 member functions (which is the this pointer) as
17742 artificial. We pass this information to
17743 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17745 DWARF version 3 added DW_AT_object_pointer, which GCC
17746 4.5 does not yet generate. */
17747 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17749 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17751 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17752 arg_type
= die_type (child_die
, cu
);
17754 /* RealView does not mark THIS as const, which the testsuite
17755 expects. GCC marks THIS as const in method definitions,
17756 but not in the class specifications (GCC PR 43053). */
17757 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17758 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17761 struct dwarf2_cu
*arg_cu
= cu
;
17762 const char *name
= dwarf2_name (child_die
, cu
);
17764 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17767 /* If the compiler emits this, use it. */
17768 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17771 else if (name
&& strcmp (name
, "this") == 0)
17772 /* Function definitions will have the argument names. */
17774 else if (name
== NULL
&& iparams
== 0)
17775 /* Declarations may not have the names, so like
17776 elsewhere in GDB, assume an artificial first
17777 argument is "this". */
17781 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17785 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17788 child_die
= sibling_die (child_die
);
17795 static struct type
*
17796 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17798 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17799 const char *name
= NULL
;
17800 struct type
*this_type
, *target_type
;
17802 name
= dwarf2_full_name (NULL
, die
, cu
);
17803 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17804 TYPE_TARGET_STUB (this_type
) = 1;
17805 set_die_type (die
, this_type
, cu
);
17806 target_type
= die_type (die
, cu
);
17807 if (target_type
!= this_type
)
17808 TYPE_TARGET_TYPE (this_type
) = target_type
;
17811 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17812 spec and cause infinite loops in GDB. */
17813 complaint (&symfile_complaints
,
17814 _("Self-referential DW_TAG_typedef "
17815 "- DIE at %s [in module %s]"),
17816 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17817 TYPE_TARGET_TYPE (this_type
) = NULL
;
17822 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17823 (which may be different from NAME) to the architecture back-end to allow
17824 it to guess the correct format if necessary. */
17826 static struct type
*
17827 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17828 const char *name_hint
)
17830 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17831 const struct floatformat
**format
;
17834 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17836 type
= init_float_type (objfile
, bits
, name
, format
);
17838 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17843 /* Find a representation of a given base type and install
17844 it in the TYPE field of the die. */
17846 static struct type
*
17847 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17849 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17851 struct attribute
*attr
;
17852 int encoding
= 0, bits
= 0;
17855 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17858 encoding
= DW_UNSND (attr
);
17860 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17863 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17865 name
= dwarf2_name (die
, cu
);
17868 complaint (&symfile_complaints
,
17869 _("DW_AT_name missing from DW_TAG_base_type"));
17874 case DW_ATE_address
:
17875 /* Turn DW_ATE_address into a void * pointer. */
17876 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17877 type
= init_pointer_type (objfile
, bits
, name
, type
);
17879 case DW_ATE_boolean
:
17880 type
= init_boolean_type (objfile
, bits
, 1, name
);
17882 case DW_ATE_complex_float
:
17883 type
= dwarf2_init_float_type (objfile
, bits
/ 2, NULL
, name
);
17884 type
= init_complex_type (objfile
, name
, type
);
17886 case DW_ATE_decimal_float
:
17887 type
= init_decfloat_type (objfile
, bits
, name
);
17890 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17892 case DW_ATE_signed
:
17893 type
= init_integer_type (objfile
, bits
, 0, name
);
17895 case DW_ATE_unsigned
:
17896 if (cu
->language
== language_fortran
17898 && startswith (name
, "character("))
17899 type
= init_character_type (objfile
, bits
, 1, name
);
17901 type
= init_integer_type (objfile
, bits
, 1, name
);
17903 case DW_ATE_signed_char
:
17904 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17905 || cu
->language
== language_pascal
17906 || cu
->language
== language_fortran
)
17907 type
= init_character_type (objfile
, bits
, 0, name
);
17909 type
= init_integer_type (objfile
, bits
, 0, name
);
17911 case DW_ATE_unsigned_char
:
17912 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17913 || cu
->language
== language_pascal
17914 || cu
->language
== language_fortran
17915 || cu
->language
== language_rust
)
17916 type
= init_character_type (objfile
, bits
, 1, name
);
17918 type
= init_integer_type (objfile
, bits
, 1, name
);
17922 gdbarch
*arch
= get_objfile_arch (objfile
);
17925 type
= builtin_type (arch
)->builtin_char16
;
17926 else if (bits
== 32)
17927 type
= builtin_type (arch
)->builtin_char32
;
17930 complaint (&symfile_complaints
,
17931 _("unsupported DW_ATE_UTF bit size: '%d'"),
17933 type
= init_integer_type (objfile
, bits
, 1, name
);
17935 return set_die_type (die
, type
, cu
);
17940 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
17941 dwarf_type_encoding_name (encoding
));
17942 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17946 if (name
&& strcmp (name
, "char") == 0)
17947 TYPE_NOSIGN (type
) = 1;
17949 return set_die_type (die
, type
, cu
);
17952 /* Parse dwarf attribute if it's a block, reference or constant and put the
17953 resulting value of the attribute into struct bound_prop.
17954 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17957 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17958 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
)
17960 struct dwarf2_property_baton
*baton
;
17961 struct obstack
*obstack
17962 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17964 if (attr
== NULL
|| prop
== NULL
)
17967 if (attr_form_is_block (attr
))
17969 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17970 baton
->referenced_type
= NULL
;
17971 baton
->locexpr
.per_cu
= cu
->per_cu
;
17972 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17973 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17974 prop
->data
.baton
= baton
;
17975 prop
->kind
= PROP_LOCEXPR
;
17976 gdb_assert (prop
->data
.baton
!= NULL
);
17978 else if (attr_form_is_ref (attr
))
17980 struct dwarf2_cu
*target_cu
= cu
;
17981 struct die_info
*target_die
;
17982 struct attribute
*target_attr
;
17984 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17985 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17986 if (target_attr
== NULL
)
17987 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17989 if (target_attr
== NULL
)
17992 switch (target_attr
->name
)
17994 case DW_AT_location
:
17995 if (attr_form_is_section_offset (target_attr
))
17997 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17998 baton
->referenced_type
= die_type (target_die
, target_cu
);
17999 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18000 prop
->data
.baton
= baton
;
18001 prop
->kind
= PROP_LOCLIST
;
18002 gdb_assert (prop
->data
.baton
!= NULL
);
18004 else if (attr_form_is_block (target_attr
))
18006 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18007 baton
->referenced_type
= die_type (target_die
, target_cu
);
18008 baton
->locexpr
.per_cu
= cu
->per_cu
;
18009 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
18010 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
18011 prop
->data
.baton
= baton
;
18012 prop
->kind
= PROP_LOCEXPR
;
18013 gdb_assert (prop
->data
.baton
!= NULL
);
18017 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18018 "dynamic property");
18022 case DW_AT_data_member_location
:
18026 if (!handle_data_member_location (target_die
, target_cu
,
18030 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18031 baton
->referenced_type
= read_type_die (target_die
->parent
,
18033 baton
->offset_info
.offset
= offset
;
18034 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18035 prop
->data
.baton
= baton
;
18036 prop
->kind
= PROP_ADDR_OFFSET
;
18041 else if (attr_form_is_constant (attr
))
18043 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18044 prop
->kind
= PROP_CONST
;
18048 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18049 dwarf2_name (die
, cu
));
18056 /* Read the given DW_AT_subrange DIE. */
18058 static struct type
*
18059 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18061 struct type
*base_type
, *orig_base_type
;
18062 struct type
*range_type
;
18063 struct attribute
*attr
;
18064 struct dynamic_prop low
, high
;
18065 int low_default_is_valid
;
18066 int high_bound_is_count
= 0;
18068 LONGEST negative_mask
;
18070 orig_base_type
= die_type (die
, cu
);
18071 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18072 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18073 creating the range type, but we use the result of check_typedef
18074 when examining properties of the type. */
18075 base_type
= check_typedef (orig_base_type
);
18077 /* The die_type call above may have already set the type for this DIE. */
18078 range_type
= get_die_type (die
, cu
);
18082 low
.kind
= PROP_CONST
;
18083 high
.kind
= PROP_CONST
;
18084 high
.data
.const_val
= 0;
18086 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18087 omitting DW_AT_lower_bound. */
18088 switch (cu
->language
)
18091 case language_cplus
:
18092 low
.data
.const_val
= 0;
18093 low_default_is_valid
= 1;
18095 case language_fortran
:
18096 low
.data
.const_val
= 1;
18097 low_default_is_valid
= 1;
18100 case language_objc
:
18101 case language_rust
:
18102 low
.data
.const_val
= 0;
18103 low_default_is_valid
= (cu
->header
.version
>= 4);
18107 case language_pascal
:
18108 low
.data
.const_val
= 1;
18109 low_default_is_valid
= (cu
->header
.version
>= 4);
18112 low
.data
.const_val
= 0;
18113 low_default_is_valid
= 0;
18117 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18119 attr_to_dynamic_prop (attr
, die
, cu
, &low
);
18120 else if (!low_default_is_valid
)
18121 complaint (&symfile_complaints
, _("Missing DW_AT_lower_bound "
18122 "- DIE at %s [in module %s]"),
18123 sect_offset_str (die
->sect_off
),
18124 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18126 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18127 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18129 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
18130 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
))
18132 /* If bounds are constant do the final calculation here. */
18133 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18134 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18136 high_bound_is_count
= 1;
18140 /* Dwarf-2 specifications explicitly allows to create subrange types
18141 without specifying a base type.
18142 In that case, the base type must be set to the type of
18143 the lower bound, upper bound or count, in that order, if any of these
18144 three attributes references an object that has a type.
18145 If no base type is found, the Dwarf-2 specifications say that
18146 a signed integer type of size equal to the size of an address should
18148 For the following C code: `extern char gdb_int [];'
18149 GCC produces an empty range DIE.
18150 FIXME: muller/2010-05-28: Possible references to object for low bound,
18151 high bound or count are not yet handled by this code. */
18152 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
18154 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18155 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18156 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
18157 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
18159 /* Test "int", "long int", and "long long int" objfile types,
18160 and select the first one having a size above or equal to the
18161 architecture address size. */
18162 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18163 base_type
= int_type
;
18166 int_type
= objfile_type (objfile
)->builtin_long
;
18167 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18168 base_type
= int_type
;
18171 int_type
= objfile_type (objfile
)->builtin_long_long
;
18172 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
18173 base_type
= int_type
;
18178 /* Normally, the DWARF producers are expected to use a signed
18179 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18180 But this is unfortunately not always the case, as witnessed
18181 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18182 is used instead. To work around that ambiguity, we treat
18183 the bounds as signed, and thus sign-extend their values, when
18184 the base type is signed. */
18186 -((LONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18187 if (low
.kind
== PROP_CONST
18188 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18189 low
.data
.const_val
|= negative_mask
;
18190 if (high
.kind
== PROP_CONST
18191 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18192 high
.data
.const_val
|= negative_mask
;
18194 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
);
18196 if (high_bound_is_count
)
18197 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18199 /* Ada expects an empty array on no boundary attributes. */
18200 if (attr
== NULL
&& cu
->language
!= language_ada
)
18201 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18203 name
= dwarf2_name (die
, cu
);
18205 TYPE_NAME (range_type
) = name
;
18207 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18209 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18211 set_die_type (die
, range_type
, cu
);
18213 /* set_die_type should be already done. */
18214 set_descriptive_type (range_type
, die
, cu
);
18219 static struct type
*
18220 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18224 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18226 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18228 /* In Ada, an unspecified type is typically used when the description
18229 of the type is defered to a different unit. When encountering
18230 such a type, we treat it as a stub, and try to resolve it later on,
18232 if (cu
->language
== language_ada
)
18233 TYPE_STUB (type
) = 1;
18235 return set_die_type (die
, type
, cu
);
18238 /* Read a single die and all its descendents. Set the die's sibling
18239 field to NULL; set other fields in the die correctly, and set all
18240 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18241 location of the info_ptr after reading all of those dies. PARENT
18242 is the parent of the die in question. */
18244 static struct die_info
*
18245 read_die_and_children (const struct die_reader_specs
*reader
,
18246 const gdb_byte
*info_ptr
,
18247 const gdb_byte
**new_info_ptr
,
18248 struct die_info
*parent
)
18250 struct die_info
*die
;
18251 const gdb_byte
*cur_ptr
;
18254 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18257 *new_info_ptr
= cur_ptr
;
18260 store_in_ref_table (die
, reader
->cu
);
18263 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18267 *new_info_ptr
= cur_ptr
;
18270 die
->sibling
= NULL
;
18271 die
->parent
= parent
;
18275 /* Read a die, all of its descendents, and all of its siblings; set
18276 all of the fields of all of the dies correctly. Arguments are as
18277 in read_die_and_children. */
18279 static struct die_info
*
18280 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18281 const gdb_byte
*info_ptr
,
18282 const gdb_byte
**new_info_ptr
,
18283 struct die_info
*parent
)
18285 struct die_info
*first_die
, *last_sibling
;
18286 const gdb_byte
*cur_ptr
;
18288 cur_ptr
= info_ptr
;
18289 first_die
= last_sibling
= NULL
;
18293 struct die_info
*die
18294 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18298 *new_info_ptr
= cur_ptr
;
18305 last_sibling
->sibling
= die
;
18307 last_sibling
= die
;
18311 /* Read a die, all of its descendents, and all of its siblings; set
18312 all of the fields of all of the dies correctly. Arguments are as
18313 in read_die_and_children.
18314 This the main entry point for reading a DIE and all its children. */
18316 static struct die_info
*
18317 read_die_and_siblings (const struct die_reader_specs
*reader
,
18318 const gdb_byte
*info_ptr
,
18319 const gdb_byte
**new_info_ptr
,
18320 struct die_info
*parent
)
18322 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18323 new_info_ptr
, parent
);
18325 if (dwarf_die_debug
)
18327 fprintf_unfiltered (gdb_stdlog
,
18328 "Read die from %s@0x%x of %s:\n",
18329 get_section_name (reader
->die_section
),
18330 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18331 bfd_get_filename (reader
->abfd
));
18332 dump_die (die
, dwarf_die_debug
);
18338 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18340 The caller is responsible for filling in the extra attributes
18341 and updating (*DIEP)->num_attrs.
18342 Set DIEP to point to a newly allocated die with its information,
18343 except for its child, sibling, and parent fields.
18344 Set HAS_CHILDREN to tell whether the die has children or not. */
18346 static const gdb_byte
*
18347 read_full_die_1 (const struct die_reader_specs
*reader
,
18348 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18349 int *has_children
, int num_extra_attrs
)
18351 unsigned int abbrev_number
, bytes_read
, i
;
18352 struct abbrev_info
*abbrev
;
18353 struct die_info
*die
;
18354 struct dwarf2_cu
*cu
= reader
->cu
;
18355 bfd
*abfd
= reader
->abfd
;
18357 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18358 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18359 info_ptr
+= bytes_read
;
18360 if (!abbrev_number
)
18367 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18369 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18371 bfd_get_filename (abfd
));
18373 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18374 die
->sect_off
= sect_off
;
18375 die
->tag
= abbrev
->tag
;
18376 die
->abbrev
= abbrev_number
;
18378 /* Make the result usable.
18379 The caller needs to update num_attrs after adding the extra
18381 die
->num_attrs
= abbrev
->num_attrs
;
18383 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18384 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18388 *has_children
= abbrev
->has_children
;
18392 /* Read a die and all its attributes.
18393 Set DIEP to point to a newly allocated die with its information,
18394 except for its child, sibling, and parent fields.
18395 Set HAS_CHILDREN to tell whether the die has children or not. */
18397 static const gdb_byte
*
18398 read_full_die (const struct die_reader_specs
*reader
,
18399 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18402 const gdb_byte
*result
;
18404 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18406 if (dwarf_die_debug
)
18408 fprintf_unfiltered (gdb_stdlog
,
18409 "Read die from %s@0x%x of %s:\n",
18410 get_section_name (reader
->die_section
),
18411 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18412 bfd_get_filename (reader
->abfd
));
18413 dump_die (*diep
, dwarf_die_debug
);
18419 /* Abbreviation tables.
18421 In DWARF version 2, the description of the debugging information is
18422 stored in a separate .debug_abbrev section. Before we read any
18423 dies from a section we read in all abbreviations and install them
18424 in a hash table. */
18426 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18428 struct abbrev_info
*
18429 abbrev_table::alloc_abbrev ()
18431 struct abbrev_info
*abbrev
;
18433 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18434 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18439 /* Add an abbreviation to the table. */
18442 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18443 struct abbrev_info
*abbrev
)
18445 unsigned int hash_number
;
18447 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18448 abbrev
->next
= m_abbrevs
[hash_number
];
18449 m_abbrevs
[hash_number
] = abbrev
;
18452 /* Look up an abbrev in the table.
18453 Returns NULL if the abbrev is not found. */
18455 struct abbrev_info
*
18456 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18458 unsigned int hash_number
;
18459 struct abbrev_info
*abbrev
;
18461 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18462 abbrev
= m_abbrevs
[hash_number
];
18466 if (abbrev
->number
== abbrev_number
)
18468 abbrev
= abbrev
->next
;
18473 /* Read in an abbrev table. */
18475 static abbrev_table_up
18476 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18477 struct dwarf2_section_info
*section
,
18478 sect_offset sect_off
)
18480 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18481 bfd
*abfd
= get_section_bfd_owner (section
);
18482 const gdb_byte
*abbrev_ptr
;
18483 struct abbrev_info
*cur_abbrev
;
18484 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18485 unsigned int abbrev_form
;
18486 struct attr_abbrev
*cur_attrs
;
18487 unsigned int allocated_attrs
;
18489 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18491 dwarf2_read_section (objfile
, section
);
18492 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18493 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18494 abbrev_ptr
+= bytes_read
;
18496 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18497 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18499 /* Loop until we reach an abbrev number of 0. */
18500 while (abbrev_number
)
18502 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18504 /* read in abbrev header */
18505 cur_abbrev
->number
= abbrev_number
;
18507 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18508 abbrev_ptr
+= bytes_read
;
18509 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18512 /* now read in declarations */
18515 LONGEST implicit_const
;
18517 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18518 abbrev_ptr
+= bytes_read
;
18519 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18520 abbrev_ptr
+= bytes_read
;
18521 if (abbrev_form
== DW_FORM_implicit_const
)
18523 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18525 abbrev_ptr
+= bytes_read
;
18529 /* Initialize it due to a false compiler warning. */
18530 implicit_const
= -1;
18533 if (abbrev_name
== 0)
18536 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18538 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18540 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18543 cur_attrs
[cur_abbrev
->num_attrs
].name
18544 = (enum dwarf_attribute
) abbrev_name
;
18545 cur_attrs
[cur_abbrev
->num_attrs
].form
18546 = (enum dwarf_form
) abbrev_form
;
18547 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18548 ++cur_abbrev
->num_attrs
;
18551 cur_abbrev
->attrs
=
18552 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18553 cur_abbrev
->num_attrs
);
18554 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18555 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18557 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18559 /* Get next abbreviation.
18560 Under Irix6 the abbreviations for a compilation unit are not
18561 always properly terminated with an abbrev number of 0.
18562 Exit loop if we encounter an abbreviation which we have
18563 already read (which means we are about to read the abbreviations
18564 for the next compile unit) or if the end of the abbreviation
18565 table is reached. */
18566 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18568 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18569 abbrev_ptr
+= bytes_read
;
18570 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18575 return abbrev_table
;
18578 /* Returns nonzero if TAG represents a type that we might generate a partial
18582 is_type_tag_for_partial (int tag
)
18587 /* Some types that would be reasonable to generate partial symbols for,
18588 that we don't at present. */
18589 case DW_TAG_array_type
:
18590 case DW_TAG_file_type
:
18591 case DW_TAG_ptr_to_member_type
:
18592 case DW_TAG_set_type
:
18593 case DW_TAG_string_type
:
18594 case DW_TAG_subroutine_type
:
18596 case DW_TAG_base_type
:
18597 case DW_TAG_class_type
:
18598 case DW_TAG_interface_type
:
18599 case DW_TAG_enumeration_type
:
18600 case DW_TAG_structure_type
:
18601 case DW_TAG_subrange_type
:
18602 case DW_TAG_typedef
:
18603 case DW_TAG_union_type
:
18610 /* Load all DIEs that are interesting for partial symbols into memory. */
18612 static struct partial_die_info
*
18613 load_partial_dies (const struct die_reader_specs
*reader
,
18614 const gdb_byte
*info_ptr
, int building_psymtab
)
18616 struct dwarf2_cu
*cu
= reader
->cu
;
18617 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18618 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18619 unsigned int bytes_read
;
18620 unsigned int load_all
= 0;
18621 int nesting_level
= 1;
18626 gdb_assert (cu
->per_cu
!= NULL
);
18627 if (cu
->per_cu
->load_all_dies
)
18631 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18635 &cu
->comp_unit_obstack
,
18636 hashtab_obstack_allocate
,
18637 dummy_obstack_deallocate
);
18641 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18643 /* A NULL abbrev means the end of a series of children. */
18644 if (abbrev
== NULL
)
18646 if (--nesting_level
== 0)
18649 info_ptr
+= bytes_read
;
18650 last_die
= parent_die
;
18651 parent_die
= parent_die
->die_parent
;
18655 /* Check for template arguments. We never save these; if
18656 they're seen, we just mark the parent, and go on our way. */
18657 if (parent_die
!= NULL
18658 && cu
->language
== language_cplus
18659 && (abbrev
->tag
== DW_TAG_template_type_param
18660 || abbrev
->tag
== DW_TAG_template_value_param
))
18662 parent_die
->has_template_arguments
= 1;
18666 /* We don't need a partial DIE for the template argument. */
18667 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18672 /* We only recurse into c++ subprograms looking for template arguments.
18673 Skip their other children. */
18675 && cu
->language
== language_cplus
18676 && parent_die
!= NULL
18677 && parent_die
->tag
== DW_TAG_subprogram
)
18679 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18683 /* Check whether this DIE is interesting enough to save. Normally
18684 we would not be interested in members here, but there may be
18685 later variables referencing them via DW_AT_specification (for
18686 static members). */
18688 && !is_type_tag_for_partial (abbrev
->tag
)
18689 && abbrev
->tag
!= DW_TAG_constant
18690 && abbrev
->tag
!= DW_TAG_enumerator
18691 && abbrev
->tag
!= DW_TAG_subprogram
18692 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18693 && abbrev
->tag
!= DW_TAG_lexical_block
18694 && abbrev
->tag
!= DW_TAG_variable
18695 && abbrev
->tag
!= DW_TAG_namespace
18696 && abbrev
->tag
!= DW_TAG_module
18697 && abbrev
->tag
!= DW_TAG_member
18698 && abbrev
->tag
!= DW_TAG_imported_unit
18699 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18701 /* Otherwise we skip to the next sibling, if any. */
18702 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18706 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18709 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18711 /* This two-pass algorithm for processing partial symbols has a
18712 high cost in cache pressure. Thus, handle some simple cases
18713 here which cover the majority of C partial symbols. DIEs
18714 which neither have specification tags in them, nor could have
18715 specification tags elsewhere pointing at them, can simply be
18716 processed and discarded.
18718 This segment is also optional; scan_partial_symbols and
18719 add_partial_symbol will handle these DIEs if we chain
18720 them in normally. When compilers which do not emit large
18721 quantities of duplicate debug information are more common,
18722 this code can probably be removed. */
18724 /* Any complete simple types at the top level (pretty much all
18725 of them, for a language without namespaces), can be processed
18727 if (parent_die
== NULL
18728 && pdi
.has_specification
== 0
18729 && pdi
.is_declaration
== 0
18730 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18731 || pdi
.tag
== DW_TAG_base_type
18732 || pdi
.tag
== DW_TAG_subrange_type
))
18734 if (building_psymtab
&& pdi
.name
!= NULL
)
18735 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18736 VAR_DOMAIN
, LOC_TYPEDEF
,
18737 &objfile
->static_psymbols
,
18738 0, cu
->language
, objfile
);
18739 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18743 /* The exception for DW_TAG_typedef with has_children above is
18744 a workaround of GCC PR debug/47510. In the case of this complaint
18745 type_name_no_tag_or_error will error on such types later.
18747 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18748 it could not find the child DIEs referenced later, this is checked
18749 above. In correct DWARF DW_TAG_typedef should have no children. */
18751 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18752 complaint (&symfile_complaints
,
18753 _("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18754 "- DIE at %s [in module %s]"),
18755 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18757 /* If we're at the second level, and we're an enumerator, and
18758 our parent has no specification (meaning possibly lives in a
18759 namespace elsewhere), then we can add the partial symbol now
18760 instead of queueing it. */
18761 if (pdi
.tag
== DW_TAG_enumerator
18762 && parent_die
!= NULL
18763 && parent_die
->die_parent
== NULL
18764 && parent_die
->tag
== DW_TAG_enumeration_type
18765 && parent_die
->has_specification
== 0)
18767 if (pdi
.name
== NULL
)
18768 complaint (&symfile_complaints
,
18769 _("malformed enumerator DIE ignored"));
18770 else if (building_psymtab
)
18771 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), 0,
18772 VAR_DOMAIN
, LOC_CONST
,
18773 cu
->language
== language_cplus
18774 ? &objfile
->global_psymbols
18775 : &objfile
->static_psymbols
,
18776 0, cu
->language
, objfile
);
18778 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18782 struct partial_die_info
*part_die
18783 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18785 /* We'll save this DIE so link it in. */
18786 part_die
->die_parent
= parent_die
;
18787 part_die
->die_sibling
= NULL
;
18788 part_die
->die_child
= NULL
;
18790 if (last_die
&& last_die
== parent_die
)
18791 last_die
->die_child
= part_die
;
18793 last_die
->die_sibling
= part_die
;
18795 last_die
= part_die
;
18797 if (first_die
== NULL
)
18798 first_die
= part_die
;
18800 /* Maybe add the DIE to the hash table. Not all DIEs that we
18801 find interesting need to be in the hash table, because we
18802 also have the parent/sibling/child chains; only those that we
18803 might refer to by offset later during partial symbol reading.
18805 For now this means things that might have be the target of a
18806 DW_AT_specification, DW_AT_abstract_origin, or
18807 DW_AT_extension. DW_AT_extension will refer only to
18808 namespaces; DW_AT_abstract_origin refers to functions (and
18809 many things under the function DIE, but we do not recurse
18810 into function DIEs during partial symbol reading) and
18811 possibly variables as well; DW_AT_specification refers to
18812 declarations. Declarations ought to have the DW_AT_declaration
18813 flag. It happens that GCC forgets to put it in sometimes, but
18814 only for functions, not for types.
18816 Adding more things than necessary to the hash table is harmless
18817 except for the performance cost. Adding too few will result in
18818 wasted time in find_partial_die, when we reread the compilation
18819 unit with load_all_dies set. */
18822 || abbrev
->tag
== DW_TAG_constant
18823 || abbrev
->tag
== DW_TAG_subprogram
18824 || abbrev
->tag
== DW_TAG_variable
18825 || abbrev
->tag
== DW_TAG_namespace
18826 || part_die
->is_declaration
)
18830 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18831 to_underlying (part_die
->sect_off
),
18836 /* For some DIEs we want to follow their children (if any). For C
18837 we have no reason to follow the children of structures; for other
18838 languages we have to, so that we can get at method physnames
18839 to infer fully qualified class names, for DW_AT_specification,
18840 and for C++ template arguments. For C++, we also look one level
18841 inside functions to find template arguments (if the name of the
18842 function does not already contain the template arguments).
18844 For Ada, we need to scan the children of subprograms and lexical
18845 blocks as well because Ada allows the definition of nested
18846 entities that could be interesting for the debugger, such as
18847 nested subprograms for instance. */
18848 if (last_die
->has_children
18850 || last_die
->tag
== DW_TAG_namespace
18851 || last_die
->tag
== DW_TAG_module
18852 || last_die
->tag
== DW_TAG_enumeration_type
18853 || (cu
->language
== language_cplus
18854 && last_die
->tag
== DW_TAG_subprogram
18855 && (last_die
->name
== NULL
18856 || strchr (last_die
->name
, '<') == NULL
))
18857 || (cu
->language
!= language_c
18858 && (last_die
->tag
== DW_TAG_class_type
18859 || last_die
->tag
== DW_TAG_interface_type
18860 || last_die
->tag
== DW_TAG_structure_type
18861 || last_die
->tag
== DW_TAG_union_type
))
18862 || (cu
->language
== language_ada
18863 && (last_die
->tag
== DW_TAG_subprogram
18864 || last_die
->tag
== DW_TAG_lexical_block
))))
18867 parent_die
= last_die
;
18871 /* Otherwise we skip to the next sibling, if any. */
18872 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18874 /* Back to the top, do it again. */
18878 partial_die_info::partial_die_info (sect_offset sect_off_
,
18879 struct abbrev_info
*abbrev
)
18880 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18884 /* Read a minimal amount of information into the minimal die structure.
18885 INFO_PTR should point just after the initial uleb128 of a DIE. */
18888 partial_die_info::read (const struct die_reader_specs
*reader
,
18889 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18891 struct dwarf2_cu
*cu
= reader
->cu
;
18892 struct dwarf2_per_objfile
*dwarf2_per_objfile
18893 = cu
->per_cu
->dwarf2_per_objfile
;
18895 int has_low_pc_attr
= 0;
18896 int has_high_pc_attr
= 0;
18897 int high_pc_relative
= 0;
18899 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18901 struct attribute attr
;
18903 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18905 /* Store the data if it is of an attribute we want to keep in a
18906 partial symbol table. */
18912 case DW_TAG_compile_unit
:
18913 case DW_TAG_partial_unit
:
18914 case DW_TAG_type_unit
:
18915 /* Compilation units have a DW_AT_name that is a filename, not
18916 a source language identifier. */
18917 case DW_TAG_enumeration_type
:
18918 case DW_TAG_enumerator
:
18919 /* These tags always have simple identifiers already; no need
18920 to canonicalize them. */
18921 name
= DW_STRING (&attr
);
18925 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18928 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18929 &objfile
->per_bfd
->storage_obstack
);
18934 case DW_AT_linkage_name
:
18935 case DW_AT_MIPS_linkage_name
:
18936 /* Note that both forms of linkage name might appear. We
18937 assume they will be the same, and we only store the last
18939 if (cu
->language
== language_ada
)
18940 name
= DW_STRING (&attr
);
18941 linkage_name
= DW_STRING (&attr
);
18944 has_low_pc_attr
= 1;
18945 lowpc
= attr_value_as_address (&attr
);
18947 case DW_AT_high_pc
:
18948 has_high_pc_attr
= 1;
18949 highpc
= attr_value_as_address (&attr
);
18950 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18951 high_pc_relative
= 1;
18953 case DW_AT_location
:
18954 /* Support the .debug_loc offsets. */
18955 if (attr_form_is_block (&attr
))
18957 d
.locdesc
= DW_BLOCK (&attr
);
18959 else if (attr_form_is_section_offset (&attr
))
18961 dwarf2_complex_location_expr_complaint ();
18965 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18966 "partial symbol information");
18969 case DW_AT_external
:
18970 is_external
= DW_UNSND (&attr
);
18972 case DW_AT_declaration
:
18973 is_declaration
= DW_UNSND (&attr
);
18978 case DW_AT_abstract_origin
:
18979 case DW_AT_specification
:
18980 case DW_AT_extension
:
18981 has_specification
= 1;
18982 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18983 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18984 || cu
->per_cu
->is_dwz
);
18986 case DW_AT_sibling
:
18987 /* Ignore absolute siblings, they might point outside of
18988 the current compile unit. */
18989 if (attr
.form
== DW_FORM_ref_addr
)
18990 complaint (&symfile_complaints
,
18991 _("ignoring absolute DW_AT_sibling"));
18994 const gdb_byte
*buffer
= reader
->buffer
;
18995 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18996 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18998 if (sibling_ptr
< info_ptr
)
18999 complaint (&symfile_complaints
,
19000 _("DW_AT_sibling points backwards"));
19001 else if (sibling_ptr
> reader
->buffer_end
)
19002 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19004 sibling
= sibling_ptr
;
19007 case DW_AT_byte_size
:
19010 case DW_AT_const_value
:
19011 has_const_value
= 1;
19013 case DW_AT_calling_convention
:
19014 /* DWARF doesn't provide a way to identify a program's source-level
19015 entry point. DW_AT_calling_convention attributes are only meant
19016 to describe functions' calling conventions.
19018 However, because it's a necessary piece of information in
19019 Fortran, and before DWARF 4 DW_CC_program was the only
19020 piece of debugging information whose definition refers to
19021 a 'main program' at all, several compilers marked Fortran
19022 main programs with DW_CC_program --- even when those
19023 functions use the standard calling conventions.
19025 Although DWARF now specifies a way to provide this
19026 information, we support this practice for backward
19028 if (DW_UNSND (&attr
) == DW_CC_program
19029 && cu
->language
== language_fortran
)
19030 main_subprogram
= 1;
19033 if (DW_UNSND (&attr
) == DW_INL_inlined
19034 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19035 may_be_inlined
= 1;
19039 if (tag
== DW_TAG_imported_unit
)
19041 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19042 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19043 || cu
->per_cu
->is_dwz
);
19047 case DW_AT_main_subprogram
:
19048 main_subprogram
= DW_UNSND (&attr
);
19056 if (high_pc_relative
)
19059 if (has_low_pc_attr
&& has_high_pc_attr
)
19061 /* When using the GNU linker, .gnu.linkonce. sections are used to
19062 eliminate duplicate copies of functions and vtables and such.
19063 The linker will arbitrarily choose one and discard the others.
19064 The AT_*_pc values for such functions refer to local labels in
19065 these sections. If the section from that file was discarded, the
19066 labels are not in the output, so the relocs get a value of 0.
19067 If this is a discarded function, mark the pc bounds as invalid,
19068 so that GDB will ignore it. */
19069 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19071 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19072 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19074 complaint (&symfile_complaints
,
19075 _("DW_AT_low_pc %s is zero "
19076 "for DIE at %s [in module %s]"),
19077 paddress (gdbarch
, lowpc
),
19078 sect_offset_str (sect_off
),
19079 objfile_name (objfile
));
19081 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19082 else if (lowpc
>= highpc
)
19084 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19085 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19087 complaint (&symfile_complaints
,
19088 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19089 "for DIE at %s [in module %s]"),
19090 paddress (gdbarch
, lowpc
),
19091 paddress (gdbarch
, highpc
),
19092 sect_offset_str (sect_off
),
19093 objfile_name (objfile
));
19102 /* Find a cached partial DIE at OFFSET in CU. */
19104 struct partial_die_info
*
19105 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19107 struct partial_die_info
*lookup_die
= NULL
;
19108 struct partial_die_info
part_die (sect_off
);
19110 lookup_die
= ((struct partial_die_info
*)
19111 htab_find_with_hash (partial_dies
, &part_die
,
19112 to_underlying (sect_off
)));
19117 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19118 except in the case of .debug_types DIEs which do not reference
19119 outside their CU (they do however referencing other types via
19120 DW_FORM_ref_sig8). */
19122 static struct partial_die_info
*
19123 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19125 struct dwarf2_per_objfile
*dwarf2_per_objfile
19126 = cu
->per_cu
->dwarf2_per_objfile
;
19127 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19128 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19129 struct partial_die_info
*pd
= NULL
;
19131 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19132 && offset_in_cu_p (&cu
->header
, sect_off
))
19134 pd
= cu
->find_partial_die (sect_off
);
19137 /* We missed recording what we needed.
19138 Load all dies and try again. */
19139 per_cu
= cu
->per_cu
;
19143 /* TUs don't reference other CUs/TUs (except via type signatures). */
19144 if (cu
->per_cu
->is_debug_types
)
19146 error (_("Dwarf Error: Type Unit at offset %s contains"
19147 " external reference to offset %s [in module %s].\n"),
19148 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19149 bfd_get_filename (objfile
->obfd
));
19151 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19152 dwarf2_per_objfile
);
19154 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19155 load_partial_comp_unit (per_cu
);
19157 per_cu
->cu
->last_used
= 0;
19158 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19161 /* If we didn't find it, and not all dies have been loaded,
19162 load them all and try again. */
19164 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19166 per_cu
->load_all_dies
= 1;
19168 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19169 THIS_CU->cu may already be in use. So we can't just free it and
19170 replace its DIEs with the ones we read in. Instead, we leave those
19171 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19172 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19174 load_partial_comp_unit (per_cu
);
19176 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19180 internal_error (__FILE__
, __LINE__
,
19181 _("could not find partial DIE %s "
19182 "in cache [from module %s]\n"),
19183 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19187 /* See if we can figure out if the class lives in a namespace. We do
19188 this by looking for a member function; its demangled name will
19189 contain namespace info, if there is any. */
19192 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19193 struct dwarf2_cu
*cu
)
19195 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19196 what template types look like, because the demangler
19197 frequently doesn't give the same name as the debug info. We
19198 could fix this by only using the demangled name to get the
19199 prefix (but see comment in read_structure_type). */
19201 struct partial_die_info
*real_pdi
;
19202 struct partial_die_info
*child_pdi
;
19204 /* If this DIE (this DIE's specification, if any) has a parent, then
19205 we should not do this. We'll prepend the parent's fully qualified
19206 name when we create the partial symbol. */
19208 real_pdi
= struct_pdi
;
19209 while (real_pdi
->has_specification
)
19210 real_pdi
= find_partial_die (real_pdi
->spec_offset
,
19211 real_pdi
->spec_is_dwz
, cu
);
19213 if (real_pdi
->die_parent
!= NULL
)
19216 for (child_pdi
= struct_pdi
->die_child
;
19218 child_pdi
= child_pdi
->die_sibling
)
19220 if (child_pdi
->tag
== DW_TAG_subprogram
19221 && child_pdi
->linkage_name
!= NULL
)
19223 char *actual_class_name
19224 = language_class_name_from_physname (cu
->language_defn
,
19225 child_pdi
->linkage_name
);
19226 if (actual_class_name
!= NULL
)
19228 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19231 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19233 strlen (actual_class_name
)));
19234 xfree (actual_class_name
);
19242 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19244 /* Once we've fixed up a die, there's no point in doing so again.
19245 This also avoids a memory leak if we were to call
19246 guess_partial_die_structure_name multiple times. */
19250 /* If we found a reference attribute and the DIE has no name, try
19251 to find a name in the referred to DIE. */
19253 if (name
== NULL
&& has_specification
)
19255 struct partial_die_info
*spec_die
;
19257 spec_die
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19259 spec_die
->fixup (cu
);
19261 if (spec_die
->name
)
19263 name
= spec_die
->name
;
19265 /* Copy DW_AT_external attribute if it is set. */
19266 if (spec_die
->is_external
)
19267 is_external
= spec_die
->is_external
;
19271 /* Set default names for some unnamed DIEs. */
19273 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19274 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19276 /* If there is no parent die to provide a namespace, and there are
19277 children, see if we can determine the namespace from their linkage
19279 if (cu
->language
== language_cplus
19280 && !VEC_empty (dwarf2_section_info_def
,
19281 cu
->per_cu
->dwarf2_per_objfile
->types
)
19282 && die_parent
== NULL
19284 && (tag
== DW_TAG_class_type
19285 || tag
== DW_TAG_structure_type
19286 || tag
== DW_TAG_union_type
))
19287 guess_partial_die_structure_name (this, cu
);
19289 /* GCC might emit a nameless struct or union that has a linkage
19290 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19292 && (tag
== DW_TAG_class_type
19293 || tag
== DW_TAG_interface_type
19294 || tag
== DW_TAG_structure_type
19295 || tag
== DW_TAG_union_type
)
19296 && linkage_name
!= NULL
)
19300 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19305 /* Strip any leading namespaces/classes, keep only the base name.
19306 DW_AT_name for named DIEs does not contain the prefixes. */
19307 base
= strrchr (demangled
, ':');
19308 if (base
&& base
> demangled
&& base
[-1] == ':')
19313 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19316 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
19317 base
, strlen (base
)));
19325 /* Read an attribute value described by an attribute form. */
19327 static const gdb_byte
*
19328 read_attribute_value (const struct die_reader_specs
*reader
,
19329 struct attribute
*attr
, unsigned form
,
19330 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19332 struct dwarf2_cu
*cu
= reader
->cu
;
19333 struct dwarf2_per_objfile
*dwarf2_per_objfile
19334 = cu
->per_cu
->dwarf2_per_objfile
;
19335 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19336 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19337 bfd
*abfd
= reader
->abfd
;
19338 struct comp_unit_head
*cu_header
= &cu
->header
;
19339 unsigned int bytes_read
;
19340 struct dwarf_block
*blk
;
19342 attr
->form
= (enum dwarf_form
) form
;
19345 case DW_FORM_ref_addr
:
19346 if (cu
->header
.version
== 2)
19347 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19349 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19350 &cu
->header
, &bytes_read
);
19351 info_ptr
+= bytes_read
;
19353 case DW_FORM_GNU_ref_alt
:
19354 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19355 info_ptr
+= bytes_read
;
19358 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19359 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19360 info_ptr
+= bytes_read
;
19362 case DW_FORM_block2
:
19363 blk
= dwarf_alloc_block (cu
);
19364 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19366 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19367 info_ptr
+= blk
->size
;
19368 DW_BLOCK (attr
) = blk
;
19370 case DW_FORM_block4
:
19371 blk
= dwarf_alloc_block (cu
);
19372 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19374 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19375 info_ptr
+= blk
->size
;
19376 DW_BLOCK (attr
) = blk
;
19378 case DW_FORM_data2
:
19379 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19382 case DW_FORM_data4
:
19383 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19386 case DW_FORM_data8
:
19387 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19390 case DW_FORM_data16
:
19391 blk
= dwarf_alloc_block (cu
);
19393 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19395 DW_BLOCK (attr
) = blk
;
19397 case DW_FORM_sec_offset
:
19398 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19399 info_ptr
+= bytes_read
;
19401 case DW_FORM_string
:
19402 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19403 DW_STRING_IS_CANONICAL (attr
) = 0;
19404 info_ptr
+= bytes_read
;
19407 if (!cu
->per_cu
->is_dwz
)
19409 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19410 abfd
, info_ptr
, cu_header
,
19412 DW_STRING_IS_CANONICAL (attr
) = 0;
19413 info_ptr
+= bytes_read
;
19417 case DW_FORM_line_strp
:
19418 if (!cu
->per_cu
->is_dwz
)
19420 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19422 cu_header
, &bytes_read
);
19423 DW_STRING_IS_CANONICAL (attr
) = 0;
19424 info_ptr
+= bytes_read
;
19428 case DW_FORM_GNU_strp_alt
:
19430 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19431 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19434 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19436 DW_STRING_IS_CANONICAL (attr
) = 0;
19437 info_ptr
+= bytes_read
;
19440 case DW_FORM_exprloc
:
19441 case DW_FORM_block
:
19442 blk
= dwarf_alloc_block (cu
);
19443 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19444 info_ptr
+= bytes_read
;
19445 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19446 info_ptr
+= blk
->size
;
19447 DW_BLOCK (attr
) = blk
;
19449 case DW_FORM_block1
:
19450 blk
= dwarf_alloc_block (cu
);
19451 blk
->size
= read_1_byte (abfd
, info_ptr
);
19453 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19454 info_ptr
+= blk
->size
;
19455 DW_BLOCK (attr
) = blk
;
19457 case DW_FORM_data1
:
19458 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19462 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19465 case DW_FORM_flag_present
:
19466 DW_UNSND (attr
) = 1;
19468 case DW_FORM_sdata
:
19469 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19470 info_ptr
+= bytes_read
;
19472 case DW_FORM_udata
:
19473 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19474 info_ptr
+= bytes_read
;
19477 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19478 + read_1_byte (abfd
, info_ptr
));
19482 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19483 + read_2_bytes (abfd
, info_ptr
));
19487 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19488 + read_4_bytes (abfd
, info_ptr
));
19492 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19493 + read_8_bytes (abfd
, info_ptr
));
19496 case DW_FORM_ref_sig8
:
19497 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19500 case DW_FORM_ref_udata
:
19501 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19502 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19503 info_ptr
+= bytes_read
;
19505 case DW_FORM_indirect
:
19506 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19507 info_ptr
+= bytes_read
;
19508 if (form
== DW_FORM_implicit_const
)
19510 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19511 info_ptr
+= bytes_read
;
19513 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19516 case DW_FORM_implicit_const
:
19517 DW_SND (attr
) = implicit_const
;
19519 case DW_FORM_GNU_addr_index
:
19520 if (reader
->dwo_file
== NULL
)
19522 /* For now flag a hard error.
19523 Later we can turn this into a complaint. */
19524 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19525 dwarf_form_name (form
),
19526 bfd_get_filename (abfd
));
19528 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19529 info_ptr
+= bytes_read
;
19531 case DW_FORM_GNU_str_index
:
19532 if (reader
->dwo_file
== NULL
)
19534 /* For now flag a hard error.
19535 Later we can turn this into a complaint if warranted. */
19536 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19537 dwarf_form_name (form
),
19538 bfd_get_filename (abfd
));
19541 ULONGEST str_index
=
19542 read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19544 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19545 DW_STRING_IS_CANONICAL (attr
) = 0;
19546 info_ptr
+= bytes_read
;
19550 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19551 dwarf_form_name (form
),
19552 bfd_get_filename (abfd
));
19556 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19557 attr
->form
= DW_FORM_GNU_ref_alt
;
19559 /* We have seen instances where the compiler tried to emit a byte
19560 size attribute of -1 which ended up being encoded as an unsigned
19561 0xffffffff. Although 0xffffffff is technically a valid size value,
19562 an object of this size seems pretty unlikely so we can relatively
19563 safely treat these cases as if the size attribute was invalid and
19564 treat them as zero by default. */
19565 if (attr
->name
== DW_AT_byte_size
19566 && form
== DW_FORM_data4
19567 && DW_UNSND (attr
) >= 0xffffffff)
19570 (&symfile_complaints
,
19571 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19572 hex_string (DW_UNSND (attr
)));
19573 DW_UNSND (attr
) = 0;
19579 /* Read an attribute described by an abbreviated attribute. */
19581 static const gdb_byte
*
19582 read_attribute (const struct die_reader_specs
*reader
,
19583 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19584 const gdb_byte
*info_ptr
)
19586 attr
->name
= abbrev
->name
;
19587 return read_attribute_value (reader
, attr
, abbrev
->form
,
19588 abbrev
->implicit_const
, info_ptr
);
19591 /* Read dwarf information from a buffer. */
19593 static unsigned int
19594 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19596 return bfd_get_8 (abfd
, buf
);
19600 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19602 return bfd_get_signed_8 (abfd
, buf
);
19605 static unsigned int
19606 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19608 return bfd_get_16 (abfd
, buf
);
19612 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19614 return bfd_get_signed_16 (abfd
, buf
);
19617 static unsigned int
19618 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19620 return bfd_get_32 (abfd
, buf
);
19624 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19626 return bfd_get_signed_32 (abfd
, buf
);
19630 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19632 return bfd_get_64 (abfd
, buf
);
19636 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19637 unsigned int *bytes_read
)
19639 struct comp_unit_head
*cu_header
= &cu
->header
;
19640 CORE_ADDR retval
= 0;
19642 if (cu_header
->signed_addr_p
)
19644 switch (cu_header
->addr_size
)
19647 retval
= bfd_get_signed_16 (abfd
, buf
);
19650 retval
= bfd_get_signed_32 (abfd
, buf
);
19653 retval
= bfd_get_signed_64 (abfd
, buf
);
19656 internal_error (__FILE__
, __LINE__
,
19657 _("read_address: bad switch, signed [in module %s]"),
19658 bfd_get_filename (abfd
));
19663 switch (cu_header
->addr_size
)
19666 retval
= bfd_get_16 (abfd
, buf
);
19669 retval
= bfd_get_32 (abfd
, buf
);
19672 retval
= bfd_get_64 (abfd
, buf
);
19675 internal_error (__FILE__
, __LINE__
,
19676 _("read_address: bad switch, "
19677 "unsigned [in module %s]"),
19678 bfd_get_filename (abfd
));
19682 *bytes_read
= cu_header
->addr_size
;
19686 /* Read the initial length from a section. The (draft) DWARF 3
19687 specification allows the initial length to take up either 4 bytes
19688 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19689 bytes describe the length and all offsets will be 8 bytes in length
19692 An older, non-standard 64-bit format is also handled by this
19693 function. The older format in question stores the initial length
19694 as an 8-byte quantity without an escape value. Lengths greater
19695 than 2^32 aren't very common which means that the initial 4 bytes
19696 is almost always zero. Since a length value of zero doesn't make
19697 sense for the 32-bit format, this initial zero can be considered to
19698 be an escape value which indicates the presence of the older 64-bit
19699 format. As written, the code can't detect (old format) lengths
19700 greater than 4GB. If it becomes necessary to handle lengths
19701 somewhat larger than 4GB, we could allow other small values (such
19702 as the non-sensical values of 1, 2, and 3) to also be used as
19703 escape values indicating the presence of the old format.
19705 The value returned via bytes_read should be used to increment the
19706 relevant pointer after calling read_initial_length().
19708 [ Note: read_initial_length() and read_offset() are based on the
19709 document entitled "DWARF Debugging Information Format", revision
19710 3, draft 8, dated November 19, 2001. This document was obtained
19713 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19715 This document is only a draft and is subject to change. (So beware.)
19717 Details regarding the older, non-standard 64-bit format were
19718 determined empirically by examining 64-bit ELF files produced by
19719 the SGI toolchain on an IRIX 6.5 machine.
19721 - Kevin, July 16, 2002
19725 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19727 LONGEST length
= bfd_get_32 (abfd
, buf
);
19729 if (length
== 0xffffffff)
19731 length
= bfd_get_64 (abfd
, buf
+ 4);
19734 else if (length
== 0)
19736 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19737 length
= bfd_get_64 (abfd
, buf
);
19748 /* Cover function for read_initial_length.
19749 Returns the length of the object at BUF, and stores the size of the
19750 initial length in *BYTES_READ and stores the size that offsets will be in
19752 If the initial length size is not equivalent to that specified in
19753 CU_HEADER then issue a complaint.
19754 This is useful when reading non-comp-unit headers. */
19757 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19758 const struct comp_unit_head
*cu_header
,
19759 unsigned int *bytes_read
,
19760 unsigned int *offset_size
)
19762 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19764 gdb_assert (cu_header
->initial_length_size
== 4
19765 || cu_header
->initial_length_size
== 8
19766 || cu_header
->initial_length_size
== 12);
19768 if (cu_header
->initial_length_size
!= *bytes_read
)
19769 complaint (&symfile_complaints
,
19770 _("intermixed 32-bit and 64-bit DWARF sections"));
19772 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19776 /* Read an offset from the data stream. The size of the offset is
19777 given by cu_header->offset_size. */
19780 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19781 const struct comp_unit_head
*cu_header
,
19782 unsigned int *bytes_read
)
19784 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19786 *bytes_read
= cu_header
->offset_size
;
19790 /* Read an offset from the data stream. */
19793 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19795 LONGEST retval
= 0;
19797 switch (offset_size
)
19800 retval
= bfd_get_32 (abfd
, buf
);
19803 retval
= bfd_get_64 (abfd
, buf
);
19806 internal_error (__FILE__
, __LINE__
,
19807 _("read_offset_1: bad switch [in module %s]"),
19808 bfd_get_filename (abfd
));
19814 static const gdb_byte
*
19815 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19817 /* If the size of a host char is 8 bits, we can return a pointer
19818 to the buffer, otherwise we have to copy the data to a buffer
19819 allocated on the temporary obstack. */
19820 gdb_assert (HOST_CHAR_BIT
== 8);
19824 static const char *
19825 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19826 unsigned int *bytes_read_ptr
)
19828 /* If the size of a host char is 8 bits, we can return a pointer
19829 to the string, otherwise we have to copy the string to a buffer
19830 allocated on the temporary obstack. */
19831 gdb_assert (HOST_CHAR_BIT
== 8);
19834 *bytes_read_ptr
= 1;
19837 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19838 return (const char *) buf
;
19841 /* Return pointer to string at section SECT offset STR_OFFSET with error
19842 reporting strings FORM_NAME and SECT_NAME. */
19844 static const char *
19845 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19846 bfd
*abfd
, LONGEST str_offset
,
19847 struct dwarf2_section_info
*sect
,
19848 const char *form_name
,
19849 const char *sect_name
)
19851 dwarf2_read_section (objfile
, sect
);
19852 if (sect
->buffer
== NULL
)
19853 error (_("%s used without %s section [in module %s]"),
19854 form_name
, sect_name
, bfd_get_filename (abfd
));
19855 if (str_offset
>= sect
->size
)
19856 error (_("%s pointing outside of %s section [in module %s]"),
19857 form_name
, sect_name
, bfd_get_filename (abfd
));
19858 gdb_assert (HOST_CHAR_BIT
== 8);
19859 if (sect
->buffer
[str_offset
] == '\0')
19861 return (const char *) (sect
->buffer
+ str_offset
);
19864 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19866 static const char *
19867 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19868 bfd
*abfd
, LONGEST str_offset
)
19870 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19872 &dwarf2_per_objfile
->str
,
19873 "DW_FORM_strp", ".debug_str");
19876 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19878 static const char *
19879 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19880 bfd
*abfd
, LONGEST str_offset
)
19882 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19884 &dwarf2_per_objfile
->line_str
,
19885 "DW_FORM_line_strp",
19886 ".debug_line_str");
19889 /* Read a string at offset STR_OFFSET in the .debug_str section from
19890 the .dwz file DWZ. Throw an error if the offset is too large. If
19891 the string consists of a single NUL byte, return NULL; otherwise
19892 return a pointer to the string. */
19894 static const char *
19895 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19896 LONGEST str_offset
)
19898 dwarf2_read_section (objfile
, &dwz
->str
);
19900 if (dwz
->str
.buffer
== NULL
)
19901 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19902 "section [in module %s]"),
19903 bfd_get_filename (dwz
->dwz_bfd
));
19904 if (str_offset
>= dwz
->str
.size
)
19905 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19906 ".debug_str section [in module %s]"),
19907 bfd_get_filename (dwz
->dwz_bfd
));
19908 gdb_assert (HOST_CHAR_BIT
== 8);
19909 if (dwz
->str
.buffer
[str_offset
] == '\0')
19911 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19914 /* Return pointer to string at .debug_str offset as read from BUF.
19915 BUF is assumed to be in a compilation unit described by CU_HEADER.
19916 Return *BYTES_READ_PTR count of bytes read from BUF. */
19918 static const char *
19919 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19920 const gdb_byte
*buf
,
19921 const struct comp_unit_head
*cu_header
,
19922 unsigned int *bytes_read_ptr
)
19924 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19926 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19929 /* Return pointer to string at .debug_line_str offset as read from BUF.
19930 BUF is assumed to be in a compilation unit described by CU_HEADER.
19931 Return *BYTES_READ_PTR count of bytes read from BUF. */
19933 static const char *
19934 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19935 bfd
*abfd
, const gdb_byte
*buf
,
19936 const struct comp_unit_head
*cu_header
,
19937 unsigned int *bytes_read_ptr
)
19939 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19941 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19946 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19947 unsigned int *bytes_read_ptr
)
19950 unsigned int num_read
;
19952 unsigned char byte
;
19959 byte
= bfd_get_8 (abfd
, buf
);
19962 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19963 if ((byte
& 128) == 0)
19969 *bytes_read_ptr
= num_read
;
19974 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19975 unsigned int *bytes_read_ptr
)
19978 int shift
, num_read
;
19979 unsigned char byte
;
19986 byte
= bfd_get_8 (abfd
, buf
);
19989 result
|= ((LONGEST
) (byte
& 127) << shift
);
19991 if ((byte
& 128) == 0)
19996 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19997 result
|= -(((LONGEST
) 1) << shift
);
19998 *bytes_read_ptr
= num_read
;
20002 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20003 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20004 ADDR_SIZE is the size of addresses from the CU header. */
20007 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20008 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20010 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20011 bfd
*abfd
= objfile
->obfd
;
20012 const gdb_byte
*info_ptr
;
20014 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20015 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20016 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20017 objfile_name (objfile
));
20018 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20019 error (_("DW_FORM_addr_index pointing outside of "
20020 ".debug_addr section [in module %s]"),
20021 objfile_name (objfile
));
20022 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20023 + addr_base
+ addr_index
* addr_size
);
20024 if (addr_size
== 4)
20025 return bfd_get_32 (abfd
, info_ptr
);
20027 return bfd_get_64 (abfd
, info_ptr
);
20030 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20033 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20035 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20036 cu
->addr_base
, cu
->header
.addr_size
);
20039 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20042 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20043 unsigned int *bytes_read
)
20045 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20046 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20048 return read_addr_index (cu
, addr_index
);
20051 /* Data structure to pass results from dwarf2_read_addr_index_reader
20052 back to dwarf2_read_addr_index. */
20054 struct dwarf2_read_addr_index_data
20056 ULONGEST addr_base
;
20060 /* die_reader_func for dwarf2_read_addr_index. */
20063 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20064 const gdb_byte
*info_ptr
,
20065 struct die_info
*comp_unit_die
,
20069 struct dwarf2_cu
*cu
= reader
->cu
;
20070 struct dwarf2_read_addr_index_data
*aidata
=
20071 (struct dwarf2_read_addr_index_data
*) data
;
20073 aidata
->addr_base
= cu
->addr_base
;
20074 aidata
->addr_size
= cu
->header
.addr_size
;
20077 /* Given an index in .debug_addr, fetch the value.
20078 NOTE: This can be called during dwarf expression evaluation,
20079 long after the debug information has been read, and thus per_cu->cu
20080 may no longer exist. */
20083 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20084 unsigned int addr_index
)
20086 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20087 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20088 struct dwarf2_cu
*cu
= per_cu
->cu
;
20089 ULONGEST addr_base
;
20092 /* We need addr_base and addr_size.
20093 If we don't have PER_CU->cu, we have to get it.
20094 Nasty, but the alternative is storing the needed info in PER_CU,
20095 which at this point doesn't seem justified: it's not clear how frequently
20096 it would get used and it would increase the size of every PER_CU.
20097 Entry points like dwarf2_per_cu_addr_size do a similar thing
20098 so we're not in uncharted territory here.
20099 Alas we need to be a bit more complicated as addr_base is contained
20102 We don't need to read the entire CU(/TU).
20103 We just need the header and top level die.
20105 IWBN to use the aging mechanism to let us lazily later discard the CU.
20106 For now we skip this optimization. */
20110 addr_base
= cu
->addr_base
;
20111 addr_size
= cu
->header
.addr_size
;
20115 struct dwarf2_read_addr_index_data aidata
;
20117 /* Note: We can't use init_cutu_and_read_dies_simple here,
20118 we need addr_base. */
20119 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0,
20120 dwarf2_read_addr_index_reader
, &aidata
);
20121 addr_base
= aidata
.addr_base
;
20122 addr_size
= aidata
.addr_size
;
20125 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20129 /* Given a DW_FORM_GNU_str_index, fetch the string.
20130 This is only used by the Fission support. */
20132 static const char *
20133 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20135 struct dwarf2_cu
*cu
= reader
->cu
;
20136 struct dwarf2_per_objfile
*dwarf2_per_objfile
20137 = cu
->per_cu
->dwarf2_per_objfile
;
20138 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20139 const char *objf_name
= objfile_name (objfile
);
20140 bfd
*abfd
= objfile
->obfd
;
20141 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20142 struct dwarf2_section_info
*str_offsets_section
=
20143 &reader
->dwo_file
->sections
.str_offsets
;
20144 const gdb_byte
*info_ptr
;
20145 ULONGEST str_offset
;
20146 static const char form_name
[] = "DW_FORM_GNU_str_index";
20148 dwarf2_read_section (objfile
, str_section
);
20149 dwarf2_read_section (objfile
, str_offsets_section
);
20150 if (str_section
->buffer
== NULL
)
20151 error (_("%s used without .debug_str.dwo section"
20152 " in CU at offset %s [in module %s]"),
20153 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20154 if (str_offsets_section
->buffer
== NULL
)
20155 error (_("%s used without .debug_str_offsets.dwo section"
20156 " in CU at offset %s [in module %s]"),
20157 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20158 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20159 error (_("%s pointing outside of .debug_str_offsets.dwo"
20160 " section in CU at offset %s [in module %s]"),
20161 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20162 info_ptr
= (str_offsets_section
->buffer
20163 + str_index
* cu
->header
.offset_size
);
20164 if (cu
->header
.offset_size
== 4)
20165 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20167 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20168 if (str_offset
>= str_section
->size
)
20169 error (_("Offset from %s pointing outside of"
20170 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20171 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20172 return (const char *) (str_section
->buffer
+ str_offset
);
20175 /* Return the length of an LEB128 number in BUF. */
20178 leb128_size (const gdb_byte
*buf
)
20180 const gdb_byte
*begin
= buf
;
20186 if ((byte
& 128) == 0)
20187 return buf
- begin
;
20192 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20201 cu
->language
= language_c
;
20204 case DW_LANG_C_plus_plus
:
20205 case DW_LANG_C_plus_plus_11
:
20206 case DW_LANG_C_plus_plus_14
:
20207 cu
->language
= language_cplus
;
20210 cu
->language
= language_d
;
20212 case DW_LANG_Fortran77
:
20213 case DW_LANG_Fortran90
:
20214 case DW_LANG_Fortran95
:
20215 case DW_LANG_Fortran03
:
20216 case DW_LANG_Fortran08
:
20217 cu
->language
= language_fortran
;
20220 cu
->language
= language_go
;
20222 case DW_LANG_Mips_Assembler
:
20223 cu
->language
= language_asm
;
20225 case DW_LANG_Ada83
:
20226 case DW_LANG_Ada95
:
20227 cu
->language
= language_ada
;
20229 case DW_LANG_Modula2
:
20230 cu
->language
= language_m2
;
20232 case DW_LANG_Pascal83
:
20233 cu
->language
= language_pascal
;
20236 cu
->language
= language_objc
;
20239 case DW_LANG_Rust_old
:
20240 cu
->language
= language_rust
;
20242 case DW_LANG_Cobol74
:
20243 case DW_LANG_Cobol85
:
20245 cu
->language
= language_minimal
;
20248 cu
->language_defn
= language_def (cu
->language
);
20251 /* Return the named attribute or NULL if not there. */
20253 static struct attribute
*
20254 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20259 struct attribute
*spec
= NULL
;
20261 for (i
= 0; i
< die
->num_attrs
; ++i
)
20263 if (die
->attrs
[i
].name
== name
)
20264 return &die
->attrs
[i
];
20265 if (die
->attrs
[i
].name
== DW_AT_specification
20266 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20267 spec
= &die
->attrs
[i
];
20273 die
= follow_die_ref (die
, spec
, &cu
);
20279 /* Return the named attribute or NULL if not there,
20280 but do not follow DW_AT_specification, etc.
20281 This is for use in contexts where we're reading .debug_types dies.
20282 Following DW_AT_specification, DW_AT_abstract_origin will take us
20283 back up the chain, and we want to go down. */
20285 static struct attribute
*
20286 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20290 for (i
= 0; i
< die
->num_attrs
; ++i
)
20291 if (die
->attrs
[i
].name
== name
)
20292 return &die
->attrs
[i
];
20297 /* Return the string associated with a string-typed attribute, or NULL if it
20298 is either not found or is of an incorrect type. */
20300 static const char *
20301 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20303 struct attribute
*attr
;
20304 const char *str
= NULL
;
20306 attr
= dwarf2_attr (die
, name
, cu
);
20310 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20311 || attr
->form
== DW_FORM_string
20312 || attr
->form
== DW_FORM_GNU_str_index
20313 || attr
->form
== DW_FORM_GNU_strp_alt
)
20314 str
= DW_STRING (attr
);
20316 complaint (&symfile_complaints
,
20317 _("string type expected for attribute %s for "
20318 "DIE at %s in module %s"),
20319 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20320 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20326 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20327 and holds a non-zero value. This function should only be used for
20328 DW_FORM_flag or DW_FORM_flag_present attributes. */
20331 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20333 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20335 return (attr
&& DW_UNSND (attr
));
20339 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20341 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20342 which value is non-zero. However, we have to be careful with
20343 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20344 (via dwarf2_flag_true_p) follows this attribute. So we may
20345 end up accidently finding a declaration attribute that belongs
20346 to a different DIE referenced by the specification attribute,
20347 even though the given DIE does not have a declaration attribute. */
20348 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20349 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20352 /* Return the die giving the specification for DIE, if there is
20353 one. *SPEC_CU is the CU containing DIE on input, and the CU
20354 containing the return value on output. If there is no
20355 specification, but there is an abstract origin, that is
20358 static struct die_info
*
20359 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20361 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20364 if (spec_attr
== NULL
)
20365 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20367 if (spec_attr
== NULL
)
20370 return follow_die_ref (die
, spec_attr
, spec_cu
);
20373 /* Stub for free_line_header to match void * callback types. */
20376 free_line_header_voidp (void *arg
)
20378 struct line_header
*lh
= (struct line_header
*) arg
;
20384 line_header::add_include_dir (const char *include_dir
)
20386 if (dwarf_line_debug
>= 2)
20387 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20388 include_dirs
.size () + 1, include_dir
);
20390 include_dirs
.push_back (include_dir
);
20394 line_header::add_file_name (const char *name
,
20396 unsigned int mod_time
,
20397 unsigned int length
)
20399 if (dwarf_line_debug
>= 2)
20400 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20401 (unsigned) file_names
.size () + 1, name
);
20403 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20406 /* A convenience function to find the proper .debug_line section for a CU. */
20408 static struct dwarf2_section_info
*
20409 get_debug_line_section (struct dwarf2_cu
*cu
)
20411 struct dwarf2_section_info
*section
;
20412 struct dwarf2_per_objfile
*dwarf2_per_objfile
20413 = cu
->per_cu
->dwarf2_per_objfile
;
20415 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20417 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20418 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20419 else if (cu
->per_cu
->is_dwz
)
20421 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20423 section
= &dwz
->line
;
20426 section
= &dwarf2_per_objfile
->line
;
20431 /* Read directory or file name entry format, starting with byte of
20432 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20433 entries count and the entries themselves in the described entry
20437 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20438 bfd
*abfd
, const gdb_byte
**bufp
,
20439 struct line_header
*lh
,
20440 const struct comp_unit_head
*cu_header
,
20441 void (*callback
) (struct line_header
*lh
,
20444 unsigned int mod_time
,
20445 unsigned int length
))
20447 gdb_byte format_count
, formati
;
20448 ULONGEST data_count
, datai
;
20449 const gdb_byte
*buf
= *bufp
;
20450 const gdb_byte
*format_header_data
;
20451 unsigned int bytes_read
;
20453 format_count
= read_1_byte (abfd
, buf
);
20455 format_header_data
= buf
;
20456 for (formati
= 0; formati
< format_count
; formati
++)
20458 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20460 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20464 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20466 for (datai
= 0; datai
< data_count
; datai
++)
20468 const gdb_byte
*format
= format_header_data
;
20469 struct file_entry fe
;
20471 for (formati
= 0; formati
< format_count
; formati
++)
20473 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20474 format
+= bytes_read
;
20476 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20477 format
+= bytes_read
;
20479 gdb::optional
<const char *> string
;
20480 gdb::optional
<unsigned int> uint
;
20484 case DW_FORM_string
:
20485 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20489 case DW_FORM_line_strp
:
20490 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20497 case DW_FORM_data1
:
20498 uint
.emplace (read_1_byte (abfd
, buf
));
20502 case DW_FORM_data2
:
20503 uint
.emplace (read_2_bytes (abfd
, buf
));
20507 case DW_FORM_data4
:
20508 uint
.emplace (read_4_bytes (abfd
, buf
));
20512 case DW_FORM_data8
:
20513 uint
.emplace (read_8_bytes (abfd
, buf
));
20517 case DW_FORM_udata
:
20518 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20522 case DW_FORM_block
:
20523 /* It is valid only for DW_LNCT_timestamp which is ignored by
20528 switch (content_type
)
20531 if (string
.has_value ())
20534 case DW_LNCT_directory_index
:
20535 if (uint
.has_value ())
20536 fe
.d_index
= (dir_index
) *uint
;
20538 case DW_LNCT_timestamp
:
20539 if (uint
.has_value ())
20540 fe
.mod_time
= *uint
;
20543 if (uint
.has_value ())
20549 complaint (&symfile_complaints
,
20550 _("Unknown format content type %s"),
20551 pulongest (content_type
));
20555 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20561 /* Read the statement program header starting at OFFSET in
20562 .debug_line, or .debug_line.dwo. Return a pointer
20563 to a struct line_header, allocated using xmalloc.
20564 Returns NULL if there is a problem reading the header, e.g., if it
20565 has a version we don't understand.
20567 NOTE: the strings in the include directory and file name tables of
20568 the returned object point into the dwarf line section buffer,
20569 and must not be freed. */
20571 static line_header_up
20572 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20574 const gdb_byte
*line_ptr
;
20575 unsigned int bytes_read
, offset_size
;
20577 const char *cur_dir
, *cur_file
;
20578 struct dwarf2_section_info
*section
;
20580 struct dwarf2_per_objfile
*dwarf2_per_objfile
20581 = cu
->per_cu
->dwarf2_per_objfile
;
20583 section
= get_debug_line_section (cu
);
20584 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20585 if (section
->buffer
== NULL
)
20587 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20588 complaint (&symfile_complaints
, _("missing .debug_line.dwo section"));
20590 complaint (&symfile_complaints
, _("missing .debug_line section"));
20594 /* We can't do this until we know the section is non-empty.
20595 Only then do we know we have such a section. */
20596 abfd
= get_section_bfd_owner (section
);
20598 /* Make sure that at least there's room for the total_length field.
20599 That could be 12 bytes long, but we're just going to fudge that. */
20600 if (to_underlying (sect_off
) + 4 >= section
->size
)
20602 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20606 line_header_up
lh (new line_header ());
20608 lh
->sect_off
= sect_off
;
20609 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20611 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20613 /* Read in the header. */
20615 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20616 &bytes_read
, &offset_size
);
20617 line_ptr
+= bytes_read
;
20618 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20620 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20623 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20624 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20626 if (lh
->version
> 5)
20628 /* This is a version we don't understand. The format could have
20629 changed in ways we don't handle properly so just punt. */
20630 complaint (&symfile_complaints
,
20631 _("unsupported version in .debug_line section"));
20634 if (lh
->version
>= 5)
20636 gdb_byte segment_selector_size
;
20638 /* Skip address size. */
20639 read_1_byte (abfd
, line_ptr
);
20642 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20644 if (segment_selector_size
!= 0)
20646 complaint (&symfile_complaints
,
20647 _("unsupported segment selector size %u "
20648 "in .debug_line section"),
20649 segment_selector_size
);
20653 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20654 line_ptr
+= offset_size
;
20655 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20657 if (lh
->version
>= 4)
20659 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20663 lh
->maximum_ops_per_instruction
= 1;
20665 if (lh
->maximum_ops_per_instruction
== 0)
20667 lh
->maximum_ops_per_instruction
= 1;
20668 complaint (&symfile_complaints
,
20669 _("invalid maximum_ops_per_instruction "
20670 "in `.debug_line' section"));
20673 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20675 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20677 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20679 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20681 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20683 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20684 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20686 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20690 if (lh
->version
>= 5)
20692 /* Read directory table. */
20693 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20695 [] (struct line_header
*lh
, const char *name
,
20696 dir_index d_index
, unsigned int mod_time
,
20697 unsigned int length
)
20699 lh
->add_include_dir (name
);
20702 /* Read file name table. */
20703 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20705 [] (struct line_header
*lh
, const char *name
,
20706 dir_index d_index
, unsigned int mod_time
,
20707 unsigned int length
)
20709 lh
->add_file_name (name
, d_index
, mod_time
, length
);
20714 /* Read directory table. */
20715 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20717 line_ptr
+= bytes_read
;
20718 lh
->add_include_dir (cur_dir
);
20720 line_ptr
+= bytes_read
;
20722 /* Read file name table. */
20723 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20725 unsigned int mod_time
, length
;
20728 line_ptr
+= bytes_read
;
20729 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20730 line_ptr
+= bytes_read
;
20731 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20732 line_ptr
+= bytes_read
;
20733 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20734 line_ptr
+= bytes_read
;
20736 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20738 line_ptr
+= bytes_read
;
20740 lh
->statement_program_start
= line_ptr
;
20742 if (line_ptr
> (section
->buffer
+ section
->size
))
20743 complaint (&symfile_complaints
,
20744 _("line number info header doesn't "
20745 "fit in `.debug_line' section"));
20750 /* Subroutine of dwarf_decode_lines to simplify it.
20751 Return the file name of the psymtab for included file FILE_INDEX
20752 in line header LH of PST.
20753 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20754 If space for the result is malloc'd, *NAME_HOLDER will be set.
20755 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20757 static const char *
20758 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20759 const struct partial_symtab
*pst
,
20760 const char *comp_dir
,
20761 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20763 const file_entry
&fe
= lh
->file_names
[file_index
];
20764 const char *include_name
= fe
.name
;
20765 const char *include_name_to_compare
= include_name
;
20766 const char *pst_filename
;
20769 const char *dir_name
= fe
.include_dir (lh
);
20771 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20772 if (!IS_ABSOLUTE_PATH (include_name
)
20773 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20775 /* Avoid creating a duplicate psymtab for PST.
20776 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20777 Before we do the comparison, however, we need to account
20778 for DIR_NAME and COMP_DIR.
20779 First prepend dir_name (if non-NULL). If we still don't
20780 have an absolute path prepend comp_dir (if non-NULL).
20781 However, the directory we record in the include-file's
20782 psymtab does not contain COMP_DIR (to match the
20783 corresponding symtab(s)).
20788 bash$ gcc -g ./hello.c
20789 include_name = "hello.c"
20791 DW_AT_comp_dir = comp_dir = "/tmp"
20792 DW_AT_name = "./hello.c"
20796 if (dir_name
!= NULL
)
20798 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20799 include_name
, (char *) NULL
));
20800 include_name
= name_holder
->get ();
20801 include_name_to_compare
= include_name
;
20803 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20805 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20806 include_name
, (char *) NULL
));
20807 include_name_to_compare
= hold_compare
.get ();
20811 pst_filename
= pst
->filename
;
20812 gdb::unique_xmalloc_ptr
<char> copied_name
;
20813 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20815 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20816 pst_filename
, (char *) NULL
));
20817 pst_filename
= copied_name
.get ();
20820 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20824 return include_name
;
20827 /* State machine to track the state of the line number program. */
20829 class lnp_state_machine
20832 /* Initialize a machine state for the start of a line number
20834 lnp_state_machine (gdbarch
*arch
, line_header
*lh
, bool record_lines_p
);
20836 file_entry
*current_file ()
20838 /* lh->file_names is 0-based, but the file name numbers in the
20839 statement program are 1-based. */
20840 return m_line_header
->file_name_at (m_file
);
20843 /* Record the line in the state machine. END_SEQUENCE is true if
20844 we're processing the end of a sequence. */
20845 void record_line (bool end_sequence
);
20847 /* Check address and if invalid nop-out the rest of the lines in this
20849 void check_line_address (struct dwarf2_cu
*cu
,
20850 const gdb_byte
*line_ptr
,
20851 CORE_ADDR lowpc
, CORE_ADDR address
);
20853 void handle_set_discriminator (unsigned int discriminator
)
20855 m_discriminator
= discriminator
;
20856 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20859 /* Handle DW_LNE_set_address. */
20860 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20863 address
+= baseaddr
;
20864 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20867 /* Handle DW_LNS_advance_pc. */
20868 void handle_advance_pc (CORE_ADDR adjust
);
20870 /* Handle a special opcode. */
20871 void handle_special_opcode (unsigned char op_code
);
20873 /* Handle DW_LNS_advance_line. */
20874 void handle_advance_line (int line_delta
)
20876 advance_line (line_delta
);
20879 /* Handle DW_LNS_set_file. */
20880 void handle_set_file (file_name_index file
);
20882 /* Handle DW_LNS_negate_stmt. */
20883 void handle_negate_stmt ()
20885 m_is_stmt
= !m_is_stmt
;
20888 /* Handle DW_LNS_const_add_pc. */
20889 void handle_const_add_pc ();
20891 /* Handle DW_LNS_fixed_advance_pc. */
20892 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20894 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20898 /* Handle DW_LNS_copy. */
20899 void handle_copy ()
20901 record_line (false);
20902 m_discriminator
= 0;
20905 /* Handle DW_LNE_end_sequence. */
20906 void handle_end_sequence ()
20908 m_record_line_callback
= ::record_line
;
20912 /* Advance the line by LINE_DELTA. */
20913 void advance_line (int line_delta
)
20915 m_line
+= line_delta
;
20917 if (line_delta
!= 0)
20918 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20921 gdbarch
*m_gdbarch
;
20923 /* True if we're recording lines.
20924 Otherwise we're building partial symtabs and are just interested in
20925 finding include files mentioned by the line number program. */
20926 bool m_record_lines_p
;
20928 /* The line number header. */
20929 line_header
*m_line_header
;
20931 /* These are part of the standard DWARF line number state machine,
20932 and initialized according to the DWARF spec. */
20934 unsigned char m_op_index
= 0;
20935 /* The line table index (1-based) of the current file. */
20936 file_name_index m_file
= (file_name_index
) 1;
20937 unsigned int m_line
= 1;
20939 /* These are initialized in the constructor. */
20941 CORE_ADDR m_address
;
20943 unsigned int m_discriminator
;
20945 /* Additional bits of state we need to track. */
20947 /* The last file that we called dwarf2_start_subfile for.
20948 This is only used for TLLs. */
20949 unsigned int m_last_file
= 0;
20950 /* The last file a line number was recorded for. */
20951 struct subfile
*m_last_subfile
= NULL
;
20953 /* The function to call to record a line. */
20954 record_line_ftype
*m_record_line_callback
= NULL
;
20956 /* The last line number that was recorded, used to coalesce
20957 consecutive entries for the same line. This can happen, for
20958 example, when discriminators are present. PR 17276. */
20959 unsigned int m_last_line
= 0;
20960 bool m_line_has_non_zero_discriminator
= false;
20964 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20966 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20967 / m_line_header
->maximum_ops_per_instruction
)
20968 * m_line_header
->minimum_instruction_length
);
20969 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20970 m_op_index
= ((m_op_index
+ adjust
)
20971 % m_line_header
->maximum_ops_per_instruction
);
20975 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20977 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20978 CORE_ADDR addr_adj
= (((m_op_index
20979 + (adj_opcode
/ m_line_header
->line_range
))
20980 / m_line_header
->maximum_ops_per_instruction
)
20981 * m_line_header
->minimum_instruction_length
);
20982 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20983 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20984 % m_line_header
->maximum_ops_per_instruction
);
20986 int line_delta
= (m_line_header
->line_base
20987 + (adj_opcode
% m_line_header
->line_range
));
20988 advance_line (line_delta
);
20989 record_line (false);
20990 m_discriminator
= 0;
20994 lnp_state_machine::handle_set_file (file_name_index file
)
20998 const file_entry
*fe
= current_file ();
21000 dwarf2_debug_line_missing_file_complaint ();
21001 else if (m_record_lines_p
)
21003 const char *dir
= fe
->include_dir (m_line_header
);
21005 m_last_subfile
= current_subfile
;
21006 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21007 dwarf2_start_subfile (fe
->name
, dir
);
21012 lnp_state_machine::handle_const_add_pc ()
21015 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21018 = (((m_op_index
+ adjust
)
21019 / m_line_header
->maximum_ops_per_instruction
)
21020 * m_line_header
->minimum_instruction_length
);
21022 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21023 m_op_index
= ((m_op_index
+ adjust
)
21024 % m_line_header
->maximum_ops_per_instruction
);
21027 /* Ignore this record_line request. */
21030 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
21035 /* Return non-zero if we should add LINE to the line number table.
21036 LINE is the line to add, LAST_LINE is the last line that was added,
21037 LAST_SUBFILE is the subfile for LAST_LINE.
21038 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21039 had a non-zero discriminator.
21041 We have to be careful in the presence of discriminators.
21042 E.g., for this line:
21044 for (i = 0; i < 100000; i++);
21046 clang can emit four line number entries for that one line,
21047 each with a different discriminator.
21048 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21050 However, we want gdb to coalesce all four entries into one.
21051 Otherwise the user could stepi into the middle of the line and
21052 gdb would get confused about whether the pc really was in the
21053 middle of the line.
21055 Things are further complicated by the fact that two consecutive
21056 line number entries for the same line is a heuristic used by gcc
21057 to denote the end of the prologue. So we can't just discard duplicate
21058 entries, we have to be selective about it. The heuristic we use is
21059 that we only collapse consecutive entries for the same line if at least
21060 one of those entries has a non-zero discriminator. PR 17276.
21062 Note: Addresses in the line number state machine can never go backwards
21063 within one sequence, thus this coalescing is ok. */
21066 dwarf_record_line_p (unsigned int line
, unsigned int last_line
,
21067 int line_has_non_zero_discriminator
,
21068 struct subfile
*last_subfile
)
21070 if (current_subfile
!= last_subfile
)
21072 if (line
!= last_line
)
21074 /* Same line for the same file that we've seen already.
21075 As a last check, for pr 17276, only record the line if the line
21076 has never had a non-zero discriminator. */
21077 if (!line_has_non_zero_discriminator
)
21082 /* Use P_RECORD_LINE to record line number LINE beginning at address ADDRESS
21083 in the line table of subfile SUBFILE. */
21086 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21087 unsigned int line
, CORE_ADDR address
,
21088 record_line_ftype p_record_line
)
21090 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21092 if (dwarf_line_debug
)
21094 fprintf_unfiltered (gdb_stdlog
,
21095 "Recording line %u, file %s, address %s\n",
21096 line
, lbasename (subfile
->name
),
21097 paddress (gdbarch
, address
));
21100 (*p_record_line
) (subfile
, line
, addr
);
21103 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21104 Mark the end of a set of line number records.
21105 The arguments are the same as for dwarf_record_line_1.
21106 If SUBFILE is NULL the request is ignored. */
21109 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21110 CORE_ADDR address
, record_line_ftype p_record_line
)
21112 if (subfile
== NULL
)
21115 if (dwarf_line_debug
)
21117 fprintf_unfiltered (gdb_stdlog
,
21118 "Finishing current line, file %s, address %s\n",
21119 lbasename (subfile
->name
),
21120 paddress (gdbarch
, address
));
21123 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, p_record_line
);
21127 lnp_state_machine::record_line (bool end_sequence
)
21129 if (dwarf_line_debug
)
21131 fprintf_unfiltered (gdb_stdlog
,
21132 "Processing actual line %u: file %u,"
21133 " address %s, is_stmt %u, discrim %u\n",
21134 m_line
, to_underlying (m_file
),
21135 paddress (m_gdbarch
, m_address
),
21136 m_is_stmt
, m_discriminator
);
21139 file_entry
*fe
= current_file ();
21142 dwarf2_debug_line_missing_file_complaint ();
21143 /* For now we ignore lines not starting on an instruction boundary.
21144 But not when processing end_sequence for compatibility with the
21145 previous version of the code. */
21146 else if (m_op_index
== 0 || end_sequence
)
21148 fe
->included_p
= 1;
21149 if (m_record_lines_p
&& m_is_stmt
)
21151 if (m_last_subfile
!= current_subfile
|| end_sequence
)
21153 dwarf_finish_line (m_gdbarch
, m_last_subfile
,
21154 m_address
, m_record_line_callback
);
21159 if (dwarf_record_line_p (m_line
, m_last_line
,
21160 m_line_has_non_zero_discriminator
,
21163 dwarf_record_line_1 (m_gdbarch
, current_subfile
,
21165 m_record_line_callback
);
21167 m_last_subfile
= current_subfile
;
21168 m_last_line
= m_line
;
21174 lnp_state_machine::lnp_state_machine (gdbarch
*arch
, line_header
*lh
,
21175 bool record_lines_p
)
21178 m_record_lines_p
= record_lines_p
;
21179 m_line_header
= lh
;
21181 m_record_line_callback
= ::record_line
;
21183 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21184 was a line entry for it so that the backend has a chance to adjust it
21185 and also record it in case it needs it. This is currently used by MIPS
21186 code, cf. `mips_adjust_dwarf2_line'. */
21187 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21188 m_is_stmt
= lh
->default_is_stmt
;
21189 m_discriminator
= 0;
21193 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21194 const gdb_byte
*line_ptr
,
21195 CORE_ADDR lowpc
, CORE_ADDR address
)
21197 /* If address < lowpc then it's not a usable value, it's outside the
21198 pc range of the CU. However, we restrict the test to only address
21199 values of zero to preserve GDB's previous behaviour which is to
21200 handle the specific case of a function being GC'd by the linker. */
21202 if (address
== 0 && address
< lowpc
)
21204 /* This line table is for a function which has been
21205 GCd by the linker. Ignore it. PR gdb/12528 */
21207 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21208 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21210 complaint (&symfile_complaints
,
21211 _(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21212 line_offset
, objfile_name (objfile
));
21213 m_record_line_callback
= noop_record_line
;
21214 /* Note: record_line_callback is left as noop_record_line until
21215 we see DW_LNE_end_sequence. */
21219 /* Subroutine of dwarf_decode_lines to simplify it.
21220 Process the line number information in LH.
21221 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21222 program in order to set included_p for every referenced header. */
21225 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21226 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21228 const gdb_byte
*line_ptr
, *extended_end
;
21229 const gdb_byte
*line_end
;
21230 unsigned int bytes_read
, extended_len
;
21231 unsigned char op_code
, extended_op
;
21232 CORE_ADDR baseaddr
;
21233 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21234 bfd
*abfd
= objfile
->obfd
;
21235 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21236 /* True if we're recording line info (as opposed to building partial
21237 symtabs and just interested in finding include files mentioned by
21238 the line number program). */
21239 bool record_lines_p
= !decode_for_pst_p
;
21241 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21243 line_ptr
= lh
->statement_program_start
;
21244 line_end
= lh
->statement_program_end
;
21246 /* Read the statement sequences until there's nothing left. */
21247 while (line_ptr
< line_end
)
21249 /* The DWARF line number program state machine. Reset the state
21250 machine at the start of each sequence. */
21251 lnp_state_machine
state_machine (gdbarch
, lh
, record_lines_p
);
21252 bool end_sequence
= false;
21254 if (record_lines_p
)
21256 /* Start a subfile for the current file of the state
21258 const file_entry
*fe
= state_machine
.current_file ();
21261 dwarf2_start_subfile (fe
->name
, fe
->include_dir (lh
));
21264 /* Decode the table. */
21265 while (line_ptr
< line_end
&& !end_sequence
)
21267 op_code
= read_1_byte (abfd
, line_ptr
);
21270 if (op_code
>= lh
->opcode_base
)
21272 /* Special opcode. */
21273 state_machine
.handle_special_opcode (op_code
);
21275 else switch (op_code
)
21277 case DW_LNS_extended_op
:
21278 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21280 line_ptr
+= bytes_read
;
21281 extended_end
= line_ptr
+ extended_len
;
21282 extended_op
= read_1_byte (abfd
, line_ptr
);
21284 switch (extended_op
)
21286 case DW_LNE_end_sequence
:
21287 state_machine
.handle_end_sequence ();
21288 end_sequence
= true;
21290 case DW_LNE_set_address
:
21293 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21294 line_ptr
+= bytes_read
;
21296 state_machine
.check_line_address (cu
, line_ptr
,
21298 state_machine
.handle_set_address (baseaddr
, address
);
21301 case DW_LNE_define_file
:
21303 const char *cur_file
;
21304 unsigned int mod_time
, length
;
21307 cur_file
= read_direct_string (abfd
, line_ptr
,
21309 line_ptr
+= bytes_read
;
21310 dindex
= (dir_index
)
21311 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21312 line_ptr
+= bytes_read
;
21314 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21315 line_ptr
+= bytes_read
;
21317 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21318 line_ptr
+= bytes_read
;
21319 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21322 case DW_LNE_set_discriminator
:
21324 /* The discriminator is not interesting to the
21325 debugger; just ignore it. We still need to
21326 check its value though:
21327 if there are consecutive entries for the same
21328 (non-prologue) line we want to coalesce them.
21331 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21332 line_ptr
+= bytes_read
;
21334 state_machine
.handle_set_discriminator (discr
);
21338 complaint (&symfile_complaints
,
21339 _("mangled .debug_line section"));
21342 /* Make sure that we parsed the extended op correctly. If e.g.
21343 we expected a different address size than the producer used,
21344 we may have read the wrong number of bytes. */
21345 if (line_ptr
!= extended_end
)
21347 complaint (&symfile_complaints
,
21348 _("mangled .debug_line section"));
21353 state_machine
.handle_copy ();
21355 case DW_LNS_advance_pc
:
21358 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21359 line_ptr
+= bytes_read
;
21361 state_machine
.handle_advance_pc (adjust
);
21364 case DW_LNS_advance_line
:
21367 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21368 line_ptr
+= bytes_read
;
21370 state_machine
.handle_advance_line (line_delta
);
21373 case DW_LNS_set_file
:
21375 file_name_index file
21376 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21378 line_ptr
+= bytes_read
;
21380 state_machine
.handle_set_file (file
);
21383 case DW_LNS_set_column
:
21384 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21385 line_ptr
+= bytes_read
;
21387 case DW_LNS_negate_stmt
:
21388 state_machine
.handle_negate_stmt ();
21390 case DW_LNS_set_basic_block
:
21392 /* Add to the address register of the state machine the
21393 address increment value corresponding to special opcode
21394 255. I.e., this value is scaled by the minimum
21395 instruction length since special opcode 255 would have
21396 scaled the increment. */
21397 case DW_LNS_const_add_pc
:
21398 state_machine
.handle_const_add_pc ();
21400 case DW_LNS_fixed_advance_pc
:
21402 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21405 state_machine
.handle_fixed_advance_pc (addr_adj
);
21410 /* Unknown standard opcode, ignore it. */
21413 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21415 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21416 line_ptr
+= bytes_read
;
21423 dwarf2_debug_line_missing_end_sequence_complaint ();
21425 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21426 in which case we still finish recording the last line). */
21427 state_machine
.record_line (true);
21431 /* Decode the Line Number Program (LNP) for the given line_header
21432 structure and CU. The actual information extracted and the type
21433 of structures created from the LNP depends on the value of PST.
21435 1. If PST is NULL, then this procedure uses the data from the program
21436 to create all necessary symbol tables, and their linetables.
21438 2. If PST is not NULL, this procedure reads the program to determine
21439 the list of files included by the unit represented by PST, and
21440 builds all the associated partial symbol tables.
21442 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21443 It is used for relative paths in the line table.
21444 NOTE: When processing partial symtabs (pst != NULL),
21445 comp_dir == pst->dirname.
21447 NOTE: It is important that psymtabs have the same file name (via strcmp)
21448 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21449 symtab we don't use it in the name of the psymtabs we create.
21450 E.g. expand_line_sal requires this when finding psymtabs to expand.
21451 A good testcase for this is mb-inline.exp.
21453 LOWPC is the lowest address in CU (or 0 if not known).
21455 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21456 for its PC<->lines mapping information. Otherwise only the filename
21457 table is read in. */
21460 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21461 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21462 CORE_ADDR lowpc
, int decode_mapping
)
21464 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21465 const int decode_for_pst_p
= (pst
!= NULL
);
21467 if (decode_mapping
)
21468 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21470 if (decode_for_pst_p
)
21474 /* Now that we're done scanning the Line Header Program, we can
21475 create the psymtab of each included file. */
21476 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21477 if (lh
->file_names
[file_index
].included_p
== 1)
21479 gdb::unique_xmalloc_ptr
<char> name_holder
;
21480 const char *include_name
=
21481 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21483 if (include_name
!= NULL
)
21484 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21489 /* Make sure a symtab is created for every file, even files
21490 which contain only variables (i.e. no code with associated
21492 struct compunit_symtab
*cust
= buildsym_compunit_symtab ();
21495 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21497 file_entry
&fe
= lh
->file_names
[i
];
21499 dwarf2_start_subfile (fe
.name
, fe
.include_dir (lh
));
21501 if (current_subfile
->symtab
== NULL
)
21503 current_subfile
->symtab
21504 = allocate_symtab (cust
, current_subfile
->name
);
21506 fe
.symtab
= current_subfile
->symtab
;
21511 /* Start a subfile for DWARF. FILENAME is the name of the file and
21512 DIRNAME the name of the source directory which contains FILENAME
21513 or NULL if not known.
21514 This routine tries to keep line numbers from identical absolute and
21515 relative file names in a common subfile.
21517 Using the `list' example from the GDB testsuite, which resides in
21518 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21519 of /srcdir/list0.c yields the following debugging information for list0.c:
21521 DW_AT_name: /srcdir/list0.c
21522 DW_AT_comp_dir: /compdir
21523 files.files[0].name: list0.h
21524 files.files[0].dir: /srcdir
21525 files.files[1].name: list0.c
21526 files.files[1].dir: /srcdir
21528 The line number information for list0.c has to end up in a single
21529 subfile, so that `break /srcdir/list0.c:1' works as expected.
21530 start_subfile will ensure that this happens provided that we pass the
21531 concatenation of files.files[1].dir and files.files[1].name as the
21535 dwarf2_start_subfile (const char *filename
, const char *dirname
)
21539 /* In order not to lose the line information directory,
21540 we concatenate it to the filename when it makes sense.
21541 Note that the Dwarf3 standard says (speaking of filenames in line
21542 information): ``The directory index is ignored for file names
21543 that represent full path names''. Thus ignoring dirname in the
21544 `else' branch below isn't an issue. */
21546 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21548 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21552 start_subfile (filename
);
21558 /* Start a symtab for DWARF.
21559 NAME, COMP_DIR, LOW_PC are passed to start_symtab. */
21561 static struct compunit_symtab
*
21562 dwarf2_start_symtab (struct dwarf2_cu
*cu
,
21563 const char *name
, const char *comp_dir
, CORE_ADDR low_pc
)
21565 struct compunit_symtab
*cust
21566 = start_symtab (cu
->per_cu
->dwarf2_per_objfile
->objfile
, name
, comp_dir
,
21567 low_pc
, cu
->language
);
21569 record_debugformat ("DWARF 2");
21570 record_producer (cu
->producer
);
21572 /* We assume that we're processing GCC output. */
21573 processing_gcc_compilation
= 2;
21575 cu
->processing_has_namespace_info
= 0;
21581 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21582 struct dwarf2_cu
*cu
)
21584 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21585 struct comp_unit_head
*cu_header
= &cu
->header
;
21587 /* NOTE drow/2003-01-30: There used to be a comment and some special
21588 code here to turn a symbol with DW_AT_external and a
21589 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21590 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21591 with some versions of binutils) where shared libraries could have
21592 relocations against symbols in their debug information - the
21593 minimal symbol would have the right address, but the debug info
21594 would not. It's no longer necessary, because we will explicitly
21595 apply relocations when we read in the debug information now. */
21597 /* A DW_AT_location attribute with no contents indicates that a
21598 variable has been optimized away. */
21599 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21601 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21605 /* Handle one degenerate form of location expression specially, to
21606 preserve GDB's previous behavior when section offsets are
21607 specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index
21608 then mark this symbol as LOC_STATIC. */
21610 if (attr_form_is_block (attr
)
21611 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21612 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21613 || (DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21614 && (DW_BLOCK (attr
)->size
21615 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21617 unsigned int dummy
;
21619 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21620 SYMBOL_VALUE_ADDRESS (sym
) =
21621 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
21623 SYMBOL_VALUE_ADDRESS (sym
) =
21624 read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1, &dummy
);
21625 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21626 fixup_symbol_section (sym
, objfile
);
21627 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
21628 SYMBOL_SECTION (sym
));
21632 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21633 expression evaluator, and use LOC_COMPUTED only when necessary
21634 (i.e. when the value of a register or memory location is
21635 referenced, or a thread-local block, etc.). Then again, it might
21636 not be worthwhile. I'm assuming that it isn't unless performance
21637 or memory numbers show me otherwise. */
21639 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21641 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21642 cu
->has_loclist
= 1;
21645 /* Given a pointer to a DWARF information entry, figure out if we need
21646 to make a symbol table entry for it, and if so, create a new entry
21647 and return a pointer to it.
21648 If TYPE is NULL, determine symbol type from the die, otherwise
21649 used the passed type.
21650 If SPACE is not NULL, use it to hold the new symbol. If it is
21651 NULL, allocate a new symbol on the objfile's obstack. */
21653 static struct symbol
*
21654 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21655 struct symbol
*space
)
21657 struct dwarf2_per_objfile
*dwarf2_per_objfile
21658 = cu
->per_cu
->dwarf2_per_objfile
;
21659 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21660 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21661 struct symbol
*sym
= NULL
;
21663 struct attribute
*attr
= NULL
;
21664 struct attribute
*attr2
= NULL
;
21665 CORE_ADDR baseaddr
;
21666 struct pending
**list_to_add
= NULL
;
21668 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21670 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21672 name
= dwarf2_name (die
, cu
);
21675 const char *linkagename
;
21676 int suppress_add
= 0;
21681 sym
= allocate_symbol (objfile
);
21682 OBJSTAT (objfile
, n_syms
++);
21684 /* Cache this symbol's name and the name's demangled form (if any). */
21685 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21686 linkagename
= dwarf2_physname (name
, die
, cu
);
21687 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21689 /* Fortran does not have mangling standard and the mangling does differ
21690 between gfortran, iFort etc. */
21691 if (cu
->language
== language_fortran
21692 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21693 symbol_set_demangled_name (&(sym
->ginfo
),
21694 dwarf2_full_name (name
, die
, cu
),
21697 /* Default assumptions.
21698 Use the passed type or decode it from the die. */
21699 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21700 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21702 SYMBOL_TYPE (sym
) = type
;
21704 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21705 attr
= dwarf2_attr (die
,
21706 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21710 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21713 attr
= dwarf2_attr (die
,
21714 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21718 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21719 struct file_entry
*fe
;
21721 if (cu
->line_header
!= NULL
)
21722 fe
= cu
->line_header
->file_name_at (file_index
);
21727 complaint (&symfile_complaints
,
21728 _("file index out of range"));
21730 symbol_set_symtab (sym
, fe
->symtab
);
21736 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21741 addr
= attr_value_as_address (attr
);
21742 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21743 SYMBOL_VALUE_ADDRESS (sym
) = addr
;
21745 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21746 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21747 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21748 add_symbol_to_list (sym
, cu
->list_in_scope
);
21750 case DW_TAG_subprogram
:
21751 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21753 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21754 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21755 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21756 || cu
->language
== language_ada
)
21758 /* Subprograms marked external are stored as a global symbol.
21759 Ada subprograms, whether marked external or not, are always
21760 stored as a global symbol, because we want to be able to
21761 access them globally. For instance, we want to be able
21762 to break on a nested subprogram without having to
21763 specify the context. */
21764 list_to_add
= &global_symbols
;
21768 list_to_add
= cu
->list_in_scope
;
21771 case DW_TAG_inlined_subroutine
:
21772 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21774 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21775 SYMBOL_INLINED (sym
) = 1;
21776 list_to_add
= cu
->list_in_scope
;
21778 case DW_TAG_template_value_param
:
21780 /* Fall through. */
21781 case DW_TAG_constant
:
21782 case DW_TAG_variable
:
21783 case DW_TAG_member
:
21784 /* Compilation with minimal debug info may result in
21785 variables with missing type entries. Change the
21786 misleading `void' type to something sensible. */
21787 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21788 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21790 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21791 /* In the case of DW_TAG_member, we should only be called for
21792 static const members. */
21793 if (die
->tag
== DW_TAG_member
)
21795 /* dwarf2_add_field uses die_is_declaration,
21796 so we do the same. */
21797 gdb_assert (die_is_declaration (die
, cu
));
21802 dwarf2_const_value (attr
, sym
, cu
);
21803 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21806 if (attr2
&& (DW_UNSND (attr2
) != 0))
21807 list_to_add
= &global_symbols
;
21809 list_to_add
= cu
->list_in_scope
;
21813 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21816 var_decode_location (attr
, sym
, cu
);
21817 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21819 /* Fortran explicitly imports any global symbols to the local
21820 scope by DW_TAG_common_block. */
21821 if (cu
->language
== language_fortran
&& die
->parent
21822 && die
->parent
->tag
== DW_TAG_common_block
)
21825 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21826 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21827 && !dwarf2_per_objfile
->has_section_at_zero
)
21829 /* When a static variable is eliminated by the linker,
21830 the corresponding debug information is not stripped
21831 out, but the variable address is set to null;
21832 do not add such variables into symbol table. */
21834 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21836 /* Workaround gfortran PR debug/40040 - it uses
21837 DW_AT_location for variables in -fPIC libraries which may
21838 get overriden by other libraries/executable and get
21839 a different address. Resolve it by the minimal symbol
21840 which may come from inferior's executable using copy
21841 relocation. Make this workaround only for gfortran as for
21842 other compilers GDB cannot guess the minimal symbol
21843 Fortran mangling kind. */
21844 if (cu
->language
== language_fortran
&& die
->parent
21845 && die
->parent
->tag
== DW_TAG_module
21847 && startswith (cu
->producer
, "GNU Fortran"))
21848 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21850 /* A variable with DW_AT_external is never static,
21851 but it may be block-scoped. */
21852 list_to_add
= (cu
->list_in_scope
== &file_symbols
21853 ? &global_symbols
: cu
->list_in_scope
);
21856 list_to_add
= cu
->list_in_scope
;
21860 /* We do not know the address of this symbol.
21861 If it is an external symbol and we have type information
21862 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21863 The address of the variable will then be determined from
21864 the minimal symbol table whenever the variable is
21866 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21868 /* Fortran explicitly imports any global symbols to the local
21869 scope by DW_TAG_common_block. */
21870 if (cu
->language
== language_fortran
&& die
->parent
21871 && die
->parent
->tag
== DW_TAG_common_block
)
21873 /* SYMBOL_CLASS doesn't matter here because
21874 read_common_block is going to reset it. */
21876 list_to_add
= cu
->list_in_scope
;
21878 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21879 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21881 /* A variable with DW_AT_external is never static, but it
21882 may be block-scoped. */
21883 list_to_add
= (cu
->list_in_scope
== &file_symbols
21884 ? &global_symbols
: cu
->list_in_scope
);
21886 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21888 else if (!die_is_declaration (die
, cu
))
21890 /* Use the default LOC_OPTIMIZED_OUT class. */
21891 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21893 list_to_add
= cu
->list_in_scope
;
21897 case DW_TAG_formal_parameter
:
21898 /* If we are inside a function, mark this as an argument. If
21899 not, we might be looking at an argument to an inlined function
21900 when we do not have enough information to show inlined frames;
21901 pretend it's a local variable in that case so that the user can
21903 if (context_stack_depth
> 0
21904 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
21905 SYMBOL_IS_ARGUMENT (sym
) = 1;
21906 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21909 var_decode_location (attr
, sym
, cu
);
21911 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21914 dwarf2_const_value (attr
, sym
, cu
);
21917 list_to_add
= cu
->list_in_scope
;
21919 case DW_TAG_unspecified_parameters
:
21920 /* From varargs functions; gdb doesn't seem to have any
21921 interest in this information, so just ignore it for now.
21924 case DW_TAG_template_type_param
:
21926 /* Fall through. */
21927 case DW_TAG_class_type
:
21928 case DW_TAG_interface_type
:
21929 case DW_TAG_structure_type
:
21930 case DW_TAG_union_type
:
21931 case DW_TAG_set_type
:
21932 case DW_TAG_enumeration_type
:
21933 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21934 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21937 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21938 really ever be static objects: otherwise, if you try
21939 to, say, break of a class's method and you're in a file
21940 which doesn't mention that class, it won't work unless
21941 the check for all static symbols in lookup_symbol_aux
21942 saves you. See the OtherFileClass tests in
21943 gdb.c++/namespace.exp. */
21947 list_to_add
= (cu
->list_in_scope
== &file_symbols
21948 && cu
->language
== language_cplus
21949 ? &global_symbols
: cu
->list_in_scope
);
21951 /* The semantics of C++ state that "struct foo {
21952 ... }" also defines a typedef for "foo". */
21953 if (cu
->language
== language_cplus
21954 || cu
->language
== language_ada
21955 || cu
->language
== language_d
21956 || cu
->language
== language_rust
)
21958 /* The symbol's name is already allocated along
21959 with this objfile, so we don't need to
21960 duplicate it for the type. */
21961 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21962 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21967 case DW_TAG_typedef
:
21968 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21969 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21970 list_to_add
= cu
->list_in_scope
;
21972 case DW_TAG_base_type
:
21973 case DW_TAG_subrange_type
:
21974 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21975 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21976 list_to_add
= cu
->list_in_scope
;
21978 case DW_TAG_enumerator
:
21979 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21982 dwarf2_const_value (attr
, sym
, cu
);
21985 /* NOTE: carlton/2003-11-10: See comment above in the
21986 DW_TAG_class_type, etc. block. */
21988 list_to_add
= (cu
->list_in_scope
== &file_symbols
21989 && cu
->language
== language_cplus
21990 ? &global_symbols
: cu
->list_in_scope
);
21993 case DW_TAG_imported_declaration
:
21994 case DW_TAG_namespace
:
21995 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21996 list_to_add
= &global_symbols
;
21998 case DW_TAG_module
:
21999 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22000 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22001 list_to_add
= &global_symbols
;
22003 case DW_TAG_common_block
:
22004 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22005 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22006 add_symbol_to_list (sym
, cu
->list_in_scope
);
22009 /* Not a tag we recognize. Hopefully we aren't processing
22010 trash data, but since we must specifically ignore things
22011 we don't recognize, there is nothing else we should do at
22013 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
22014 dwarf_tag_name (die
->tag
));
22020 sym
->hash_next
= objfile
->template_symbols
;
22021 objfile
->template_symbols
= sym
;
22022 list_to_add
= NULL
;
22025 if (list_to_add
!= NULL
)
22026 add_symbol_to_list (sym
, list_to_add
);
22028 /* For the benefit of old versions of GCC, check for anonymous
22029 namespaces based on the demangled name. */
22030 if (!cu
->processing_has_namespace_info
22031 && cu
->language
== language_cplus
)
22032 cp_scan_for_anonymous_namespaces (sym
, objfile
);
22037 /* Given an attr with a DW_FORM_dataN value in host byte order,
22038 zero-extend it as appropriate for the symbol's type. The DWARF
22039 standard (v4) is not entirely clear about the meaning of using
22040 DW_FORM_dataN for a constant with a signed type, where the type is
22041 wider than the data. The conclusion of a discussion on the DWARF
22042 list was that this is unspecified. We choose to always zero-extend
22043 because that is the interpretation long in use by GCC. */
22046 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22047 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22049 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22050 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22051 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22052 LONGEST l
= DW_UNSND (attr
);
22054 if (bits
< sizeof (*value
) * 8)
22056 l
&= ((LONGEST
) 1 << bits
) - 1;
22059 else if (bits
== sizeof (*value
) * 8)
22063 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22064 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22071 /* Read a constant value from an attribute. Either set *VALUE, or if
22072 the value does not fit in *VALUE, set *BYTES - either already
22073 allocated on the objfile obstack, or newly allocated on OBSTACK,
22074 or, set *BATON, if we translated the constant to a location
22078 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22079 const char *name
, struct obstack
*obstack
,
22080 struct dwarf2_cu
*cu
,
22081 LONGEST
*value
, const gdb_byte
**bytes
,
22082 struct dwarf2_locexpr_baton
**baton
)
22084 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22085 struct comp_unit_head
*cu_header
= &cu
->header
;
22086 struct dwarf_block
*blk
;
22087 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22088 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22094 switch (attr
->form
)
22097 case DW_FORM_GNU_addr_index
:
22101 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22102 dwarf2_const_value_length_mismatch_complaint (name
,
22103 cu_header
->addr_size
,
22104 TYPE_LENGTH (type
));
22105 /* Symbols of this form are reasonably rare, so we just
22106 piggyback on the existing location code rather than writing
22107 a new implementation of symbol_computed_ops. */
22108 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22109 (*baton
)->per_cu
= cu
->per_cu
;
22110 gdb_assert ((*baton
)->per_cu
);
22112 (*baton
)->size
= 2 + cu_header
->addr_size
;
22113 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22114 (*baton
)->data
= data
;
22116 data
[0] = DW_OP_addr
;
22117 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22118 byte_order
, DW_ADDR (attr
));
22119 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22122 case DW_FORM_string
:
22124 case DW_FORM_GNU_str_index
:
22125 case DW_FORM_GNU_strp_alt
:
22126 /* DW_STRING is already allocated on the objfile obstack, point
22128 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22130 case DW_FORM_block1
:
22131 case DW_FORM_block2
:
22132 case DW_FORM_block4
:
22133 case DW_FORM_block
:
22134 case DW_FORM_exprloc
:
22135 case DW_FORM_data16
:
22136 blk
= DW_BLOCK (attr
);
22137 if (TYPE_LENGTH (type
) != blk
->size
)
22138 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22139 TYPE_LENGTH (type
));
22140 *bytes
= blk
->data
;
22143 /* The DW_AT_const_value attributes are supposed to carry the
22144 symbol's value "represented as it would be on the target
22145 architecture." By the time we get here, it's already been
22146 converted to host endianness, so we just need to sign- or
22147 zero-extend it as appropriate. */
22148 case DW_FORM_data1
:
22149 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22151 case DW_FORM_data2
:
22152 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22154 case DW_FORM_data4
:
22155 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22157 case DW_FORM_data8
:
22158 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22161 case DW_FORM_sdata
:
22162 case DW_FORM_implicit_const
:
22163 *value
= DW_SND (attr
);
22166 case DW_FORM_udata
:
22167 *value
= DW_UNSND (attr
);
22171 complaint (&symfile_complaints
,
22172 _("unsupported const value attribute form: '%s'"),
22173 dwarf_form_name (attr
->form
));
22180 /* Copy constant value from an attribute to a symbol. */
22183 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22184 struct dwarf2_cu
*cu
)
22186 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22188 const gdb_byte
*bytes
;
22189 struct dwarf2_locexpr_baton
*baton
;
22191 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22192 SYMBOL_PRINT_NAME (sym
),
22193 &objfile
->objfile_obstack
, cu
,
22194 &value
, &bytes
, &baton
);
22198 SYMBOL_LOCATION_BATON (sym
) = baton
;
22199 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22201 else if (bytes
!= NULL
)
22203 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22204 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22208 SYMBOL_VALUE (sym
) = value
;
22209 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22213 /* Return the type of the die in question using its DW_AT_type attribute. */
22215 static struct type
*
22216 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22218 struct attribute
*type_attr
;
22220 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22223 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22224 /* A missing DW_AT_type represents a void type. */
22225 return objfile_type (objfile
)->builtin_void
;
22228 return lookup_die_type (die
, type_attr
, cu
);
22231 /* True iff CU's producer generates GNAT Ada auxiliary information
22232 that allows to find parallel types through that information instead
22233 of having to do expensive parallel lookups by type name. */
22236 need_gnat_info (struct dwarf2_cu
*cu
)
22238 /* Assume that the Ada compiler was GNAT, which always produces
22239 the auxiliary information. */
22240 return (cu
->language
== language_ada
);
22243 /* Return the auxiliary type of the die in question using its
22244 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22245 attribute is not present. */
22247 static struct type
*
22248 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22250 struct attribute
*type_attr
;
22252 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22256 return lookup_die_type (die
, type_attr
, cu
);
22259 /* If DIE has a descriptive_type attribute, then set the TYPE's
22260 descriptive type accordingly. */
22263 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22264 struct dwarf2_cu
*cu
)
22266 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22268 if (descriptive_type
)
22270 ALLOCATE_GNAT_AUX_TYPE (type
);
22271 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22275 /* Return the containing type of the die in question using its
22276 DW_AT_containing_type attribute. */
22278 static struct type
*
22279 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22281 struct attribute
*type_attr
;
22282 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22284 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22286 error (_("Dwarf Error: Problem turning containing type into gdb type "
22287 "[in module %s]"), objfile_name (objfile
));
22289 return lookup_die_type (die
, type_attr
, cu
);
22292 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22294 static struct type
*
22295 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22297 struct dwarf2_per_objfile
*dwarf2_per_objfile
22298 = cu
->per_cu
->dwarf2_per_objfile
;
22299 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22300 char *message
, *saved
;
22302 message
= xstrprintf (_("<unknown type in %s, CU %s, DIE %s>"),
22303 objfile_name (objfile
),
22304 sect_offset_str (cu
->header
.sect_off
),
22305 sect_offset_str (die
->sect_off
));
22306 saved
= (char *) obstack_copy0 (&objfile
->objfile_obstack
,
22307 message
, strlen (message
));
22310 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22313 /* Look up the type of DIE in CU using its type attribute ATTR.
22314 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22315 DW_AT_containing_type.
22316 If there is no type substitute an error marker. */
22318 static struct type
*
22319 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22320 struct dwarf2_cu
*cu
)
22322 struct dwarf2_per_objfile
*dwarf2_per_objfile
22323 = cu
->per_cu
->dwarf2_per_objfile
;
22324 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22325 struct type
*this_type
;
22327 gdb_assert (attr
->name
== DW_AT_type
22328 || attr
->name
== DW_AT_GNAT_descriptive_type
22329 || attr
->name
== DW_AT_containing_type
);
22331 /* First see if we have it cached. */
22333 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22335 struct dwarf2_per_cu_data
*per_cu
;
22336 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22338 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22339 dwarf2_per_objfile
);
22340 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22342 else if (attr_form_is_ref (attr
))
22344 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22346 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22348 else if (attr
->form
== DW_FORM_ref_sig8
)
22350 ULONGEST signature
= DW_SIGNATURE (attr
);
22352 return get_signatured_type (die
, signature
, cu
);
22356 complaint (&symfile_complaints
,
22357 _("Dwarf Error: Bad type attribute %s in DIE"
22358 " at %s [in module %s]"),
22359 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22360 objfile_name (objfile
));
22361 return build_error_marker_type (cu
, die
);
22364 /* If not cached we need to read it in. */
22366 if (this_type
== NULL
)
22368 struct die_info
*type_die
= NULL
;
22369 struct dwarf2_cu
*type_cu
= cu
;
22371 if (attr_form_is_ref (attr
))
22372 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22373 if (type_die
== NULL
)
22374 return build_error_marker_type (cu
, die
);
22375 /* If we find the type now, it's probably because the type came
22376 from an inter-CU reference and the type's CU got expanded before
22378 this_type
= read_type_die (type_die
, type_cu
);
22381 /* If we still don't have a type use an error marker. */
22383 if (this_type
== NULL
)
22384 return build_error_marker_type (cu
, die
);
22389 /* Return the type in DIE, CU.
22390 Returns NULL for invalid types.
22392 This first does a lookup in die_type_hash,
22393 and only reads the die in if necessary.
22395 NOTE: This can be called when reading in partial or full symbols. */
22397 static struct type
*
22398 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22400 struct type
*this_type
;
22402 this_type
= get_die_type (die
, cu
);
22406 return read_type_die_1 (die
, cu
);
22409 /* Read the type in DIE, CU.
22410 Returns NULL for invalid types. */
22412 static struct type
*
22413 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22415 struct type
*this_type
= NULL
;
22419 case DW_TAG_class_type
:
22420 case DW_TAG_interface_type
:
22421 case DW_TAG_structure_type
:
22422 case DW_TAG_union_type
:
22423 this_type
= read_structure_type (die
, cu
);
22425 case DW_TAG_enumeration_type
:
22426 this_type
= read_enumeration_type (die
, cu
);
22428 case DW_TAG_subprogram
:
22429 case DW_TAG_subroutine_type
:
22430 case DW_TAG_inlined_subroutine
:
22431 this_type
= read_subroutine_type (die
, cu
);
22433 case DW_TAG_array_type
:
22434 this_type
= read_array_type (die
, cu
);
22436 case DW_TAG_set_type
:
22437 this_type
= read_set_type (die
, cu
);
22439 case DW_TAG_pointer_type
:
22440 this_type
= read_tag_pointer_type (die
, cu
);
22442 case DW_TAG_ptr_to_member_type
:
22443 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22445 case DW_TAG_reference_type
:
22446 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22448 case DW_TAG_rvalue_reference_type
:
22449 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22451 case DW_TAG_const_type
:
22452 this_type
= read_tag_const_type (die
, cu
);
22454 case DW_TAG_volatile_type
:
22455 this_type
= read_tag_volatile_type (die
, cu
);
22457 case DW_TAG_restrict_type
:
22458 this_type
= read_tag_restrict_type (die
, cu
);
22460 case DW_TAG_string_type
:
22461 this_type
= read_tag_string_type (die
, cu
);
22463 case DW_TAG_typedef
:
22464 this_type
= read_typedef (die
, cu
);
22466 case DW_TAG_subrange_type
:
22467 this_type
= read_subrange_type (die
, cu
);
22469 case DW_TAG_base_type
:
22470 this_type
= read_base_type (die
, cu
);
22472 case DW_TAG_unspecified_type
:
22473 this_type
= read_unspecified_type (die
, cu
);
22475 case DW_TAG_namespace
:
22476 this_type
= read_namespace_type (die
, cu
);
22478 case DW_TAG_module
:
22479 this_type
= read_module_type (die
, cu
);
22481 case DW_TAG_atomic_type
:
22482 this_type
= read_tag_atomic_type (die
, cu
);
22485 complaint (&symfile_complaints
,
22486 _("unexpected tag in read_type_die: '%s'"),
22487 dwarf_tag_name (die
->tag
));
22494 /* See if we can figure out if the class lives in a namespace. We do
22495 this by looking for a member function; its demangled name will
22496 contain namespace info, if there is any.
22497 Return the computed name or NULL.
22498 Space for the result is allocated on the objfile's obstack.
22499 This is the full-die version of guess_partial_die_structure_name.
22500 In this case we know DIE has no useful parent. */
22503 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22505 struct die_info
*spec_die
;
22506 struct dwarf2_cu
*spec_cu
;
22507 struct die_info
*child
;
22508 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22511 spec_die
= die_specification (die
, &spec_cu
);
22512 if (spec_die
!= NULL
)
22518 for (child
= die
->child
;
22520 child
= child
->sibling
)
22522 if (child
->tag
== DW_TAG_subprogram
)
22524 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22526 if (linkage_name
!= NULL
)
22529 = language_class_name_from_physname (cu
->language_defn
,
22533 if (actual_name
!= NULL
)
22535 const char *die_name
= dwarf2_name (die
, cu
);
22537 if (die_name
!= NULL
22538 && strcmp (die_name
, actual_name
) != 0)
22540 /* Strip off the class name from the full name.
22541 We want the prefix. */
22542 int die_name_len
= strlen (die_name
);
22543 int actual_name_len
= strlen (actual_name
);
22545 /* Test for '::' as a sanity check. */
22546 if (actual_name_len
> die_name_len
+ 2
22547 && actual_name
[actual_name_len
22548 - die_name_len
- 1] == ':')
22549 name
= (char *) obstack_copy0 (
22550 &objfile
->per_bfd
->storage_obstack
,
22551 actual_name
, actual_name_len
- die_name_len
- 2);
22554 xfree (actual_name
);
22563 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22564 prefix part in such case. See
22565 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22567 static const char *
22568 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22570 struct attribute
*attr
;
22573 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22574 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22577 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22580 attr
= dw2_linkage_name_attr (die
, cu
);
22581 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22584 /* dwarf2_name had to be already called. */
22585 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22587 /* Strip the base name, keep any leading namespaces/classes. */
22588 base
= strrchr (DW_STRING (attr
), ':');
22589 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22592 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22593 return (char *) obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22595 &base
[-1] - DW_STRING (attr
));
22598 /* Return the name of the namespace/class that DIE is defined within,
22599 or "" if we can't tell. The caller should not xfree the result.
22601 For example, if we're within the method foo() in the following
22611 then determine_prefix on foo's die will return "N::C". */
22613 static const char *
22614 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22616 struct dwarf2_per_objfile
*dwarf2_per_objfile
22617 = cu
->per_cu
->dwarf2_per_objfile
;
22618 struct die_info
*parent
, *spec_die
;
22619 struct dwarf2_cu
*spec_cu
;
22620 struct type
*parent_type
;
22621 const char *retval
;
22623 if (cu
->language
!= language_cplus
22624 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22625 && cu
->language
!= language_rust
)
22628 retval
= anonymous_struct_prefix (die
, cu
);
22632 /* We have to be careful in the presence of DW_AT_specification.
22633 For example, with GCC 3.4, given the code
22637 // Definition of N::foo.
22641 then we'll have a tree of DIEs like this:
22643 1: DW_TAG_compile_unit
22644 2: DW_TAG_namespace // N
22645 3: DW_TAG_subprogram // declaration of N::foo
22646 4: DW_TAG_subprogram // definition of N::foo
22647 DW_AT_specification // refers to die #3
22649 Thus, when processing die #4, we have to pretend that we're in
22650 the context of its DW_AT_specification, namely the contex of die
22653 spec_die
= die_specification (die
, &spec_cu
);
22654 if (spec_die
== NULL
)
22655 parent
= die
->parent
;
22658 parent
= spec_die
->parent
;
22662 if (parent
== NULL
)
22664 else if (parent
->building_fullname
)
22667 const char *parent_name
;
22669 /* It has been seen on RealView 2.2 built binaries,
22670 DW_TAG_template_type_param types actually _defined_ as
22671 children of the parent class:
22674 template class <class Enum> Class{};
22675 Class<enum E> class_e;
22677 1: DW_TAG_class_type (Class)
22678 2: DW_TAG_enumeration_type (E)
22679 3: DW_TAG_enumerator (enum1:0)
22680 3: DW_TAG_enumerator (enum2:1)
22682 2: DW_TAG_template_type_param
22683 DW_AT_type DW_FORM_ref_udata (E)
22685 Besides being broken debug info, it can put GDB into an
22686 infinite loop. Consider:
22688 When we're building the full name for Class<E>, we'll start
22689 at Class, and go look over its template type parameters,
22690 finding E. We'll then try to build the full name of E, and
22691 reach here. We're now trying to build the full name of E,
22692 and look over the parent DIE for containing scope. In the
22693 broken case, if we followed the parent DIE of E, we'd again
22694 find Class, and once again go look at its template type
22695 arguments, etc., etc. Simply don't consider such parent die
22696 as source-level parent of this die (it can't be, the language
22697 doesn't allow it), and break the loop here. */
22698 name
= dwarf2_name (die
, cu
);
22699 parent_name
= dwarf2_name (parent
, cu
);
22700 complaint (&symfile_complaints
,
22701 _("template param type '%s' defined within parent '%s'"),
22702 name
? name
: "<unknown>",
22703 parent_name
? parent_name
: "<unknown>");
22707 switch (parent
->tag
)
22709 case DW_TAG_namespace
:
22710 parent_type
= read_type_die (parent
, cu
);
22711 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22712 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22713 Work around this problem here. */
22714 if (cu
->language
== language_cplus
22715 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
22717 /* We give a name to even anonymous namespaces. */
22718 return TYPE_TAG_NAME (parent_type
);
22719 case DW_TAG_class_type
:
22720 case DW_TAG_interface_type
:
22721 case DW_TAG_structure_type
:
22722 case DW_TAG_union_type
:
22723 case DW_TAG_module
:
22724 parent_type
= read_type_die (parent
, cu
);
22725 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22726 return TYPE_TAG_NAME (parent_type
);
22728 /* An anonymous structure is only allowed non-static data
22729 members; no typedefs, no member functions, et cetera.
22730 So it does not need a prefix. */
22732 case DW_TAG_compile_unit
:
22733 case DW_TAG_partial_unit
:
22734 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22735 if (cu
->language
== language_cplus
22736 && !VEC_empty (dwarf2_section_info_def
, dwarf2_per_objfile
->types
)
22737 && die
->child
!= NULL
22738 && (die
->tag
== DW_TAG_class_type
22739 || die
->tag
== DW_TAG_structure_type
22740 || die
->tag
== DW_TAG_union_type
))
22742 char *name
= guess_full_die_structure_name (die
, cu
);
22747 case DW_TAG_enumeration_type
:
22748 parent_type
= read_type_die (parent
, cu
);
22749 if (TYPE_DECLARED_CLASS (parent_type
))
22751 if (TYPE_TAG_NAME (parent_type
) != NULL
)
22752 return TYPE_TAG_NAME (parent_type
);
22755 /* Fall through. */
22757 return determine_prefix (parent
, cu
);
22761 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22762 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22763 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22764 an obconcat, otherwise allocate storage for the result. The CU argument is
22765 used to determine the language and hence, the appropriate separator. */
22767 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22770 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22771 int physname
, struct dwarf2_cu
*cu
)
22773 const char *lead
= "";
22776 if (suffix
== NULL
|| suffix
[0] == '\0'
22777 || prefix
== NULL
|| prefix
[0] == '\0')
22779 else if (cu
->language
== language_d
)
22781 /* For D, the 'main' function could be defined in any module, but it
22782 should never be prefixed. */
22783 if (strcmp (suffix
, "D main") == 0)
22791 else if (cu
->language
== language_fortran
&& physname
)
22793 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22794 DW_AT_MIPS_linkage_name is preferred and used instead. */
22802 if (prefix
== NULL
)
22804 if (suffix
== NULL
)
22811 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22813 strcpy (retval
, lead
);
22814 strcat (retval
, prefix
);
22815 strcat (retval
, sep
);
22816 strcat (retval
, suffix
);
22821 /* We have an obstack. */
22822 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22826 /* Return sibling of die, NULL if no sibling. */
22828 static struct die_info
*
22829 sibling_die (struct die_info
*die
)
22831 return die
->sibling
;
22834 /* Get name of a die, return NULL if not found. */
22836 static const char *
22837 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22838 struct obstack
*obstack
)
22840 if (name
&& cu
->language
== language_cplus
)
22842 std::string canon_name
= cp_canonicalize_string (name
);
22844 if (!canon_name
.empty ())
22846 if (canon_name
!= name
)
22847 name
= (const char *) obstack_copy0 (obstack
,
22848 canon_name
.c_str (),
22849 canon_name
.length ());
22856 /* Get name of a die, return NULL if not found.
22857 Anonymous namespaces are converted to their magic string. */
22859 static const char *
22860 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22862 struct attribute
*attr
;
22863 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22865 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22866 if ((!attr
|| !DW_STRING (attr
))
22867 && die
->tag
!= DW_TAG_namespace
22868 && die
->tag
!= DW_TAG_class_type
22869 && die
->tag
!= DW_TAG_interface_type
22870 && die
->tag
!= DW_TAG_structure_type
22871 && die
->tag
!= DW_TAG_union_type
)
22876 case DW_TAG_compile_unit
:
22877 case DW_TAG_partial_unit
:
22878 /* Compilation units have a DW_AT_name that is a filename, not
22879 a source language identifier. */
22880 case DW_TAG_enumeration_type
:
22881 case DW_TAG_enumerator
:
22882 /* These tags always have simple identifiers already; no need
22883 to canonicalize them. */
22884 return DW_STRING (attr
);
22886 case DW_TAG_namespace
:
22887 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22888 return DW_STRING (attr
);
22889 return CP_ANONYMOUS_NAMESPACE_STR
;
22891 case DW_TAG_class_type
:
22892 case DW_TAG_interface_type
:
22893 case DW_TAG_structure_type
:
22894 case DW_TAG_union_type
:
22895 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22896 structures or unions. These were of the form "._%d" in GCC 4.1,
22897 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22898 and GCC 4.4. We work around this problem by ignoring these. */
22899 if (attr
&& DW_STRING (attr
)
22900 && (startswith (DW_STRING (attr
), "._")
22901 || startswith (DW_STRING (attr
), "<anonymous")))
22904 /* GCC might emit a nameless typedef that has a linkage name. See
22905 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22906 if (!attr
|| DW_STRING (attr
) == NULL
)
22908 char *demangled
= NULL
;
22910 attr
= dw2_linkage_name_attr (die
, cu
);
22911 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22914 /* Avoid demangling DW_STRING (attr) the second time on a second
22915 call for the same DIE. */
22916 if (!DW_STRING_IS_CANONICAL (attr
))
22917 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22923 /* FIXME: we already did this for the partial symbol... */
22926 obstack_copy0 (&objfile
->per_bfd
->storage_obstack
,
22927 demangled
, strlen (demangled
)));
22928 DW_STRING_IS_CANONICAL (attr
) = 1;
22931 /* Strip any leading namespaces/classes, keep only the base name.
22932 DW_AT_name for named DIEs does not contain the prefixes. */
22933 base
= strrchr (DW_STRING (attr
), ':');
22934 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22937 return DW_STRING (attr
);
22946 if (!DW_STRING_IS_CANONICAL (attr
))
22949 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22950 &objfile
->per_bfd
->storage_obstack
);
22951 DW_STRING_IS_CANONICAL (attr
) = 1;
22953 return DW_STRING (attr
);
22956 /* Return the die that this die in an extension of, or NULL if there
22957 is none. *EXT_CU is the CU containing DIE on input, and the CU
22958 containing the return value on output. */
22960 static struct die_info
*
22961 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22963 struct attribute
*attr
;
22965 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22969 return follow_die_ref (die
, attr
, ext_cu
);
22972 /* Convert a DIE tag into its string name. */
22974 static const char *
22975 dwarf_tag_name (unsigned tag
)
22977 const char *name
= get_DW_TAG_name (tag
);
22980 return "DW_TAG_<unknown>";
22985 /* Convert a DWARF attribute code into its string name. */
22987 static const char *
22988 dwarf_attr_name (unsigned attr
)
22992 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22993 if (attr
== DW_AT_MIPS_fde
)
22994 return "DW_AT_MIPS_fde";
22996 if (attr
== DW_AT_HP_block_index
)
22997 return "DW_AT_HP_block_index";
23000 name
= get_DW_AT_name (attr
);
23003 return "DW_AT_<unknown>";
23008 /* Convert a DWARF value form code into its string name. */
23010 static const char *
23011 dwarf_form_name (unsigned form
)
23013 const char *name
= get_DW_FORM_name (form
);
23016 return "DW_FORM_<unknown>";
23021 static const char *
23022 dwarf_bool_name (unsigned mybool
)
23030 /* Convert a DWARF type code into its string name. */
23032 static const char *
23033 dwarf_type_encoding_name (unsigned enc
)
23035 const char *name
= get_DW_ATE_name (enc
);
23038 return "DW_ATE_<unknown>";
23044 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23048 print_spaces (indent
, f
);
23049 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23050 dwarf_tag_name (die
->tag
), die
->abbrev
,
23051 sect_offset_str (die
->sect_off
));
23053 if (die
->parent
!= NULL
)
23055 print_spaces (indent
, f
);
23056 fprintf_unfiltered (f
, " parent at offset: %s\n",
23057 sect_offset_str (die
->parent
->sect_off
));
23060 print_spaces (indent
, f
);
23061 fprintf_unfiltered (f
, " has children: %s\n",
23062 dwarf_bool_name (die
->child
!= NULL
));
23064 print_spaces (indent
, f
);
23065 fprintf_unfiltered (f
, " attributes:\n");
23067 for (i
= 0; i
< die
->num_attrs
; ++i
)
23069 print_spaces (indent
, f
);
23070 fprintf_unfiltered (f
, " %s (%s) ",
23071 dwarf_attr_name (die
->attrs
[i
].name
),
23072 dwarf_form_name (die
->attrs
[i
].form
));
23074 switch (die
->attrs
[i
].form
)
23077 case DW_FORM_GNU_addr_index
:
23078 fprintf_unfiltered (f
, "address: ");
23079 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23081 case DW_FORM_block2
:
23082 case DW_FORM_block4
:
23083 case DW_FORM_block
:
23084 case DW_FORM_block1
:
23085 fprintf_unfiltered (f
, "block: size %s",
23086 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23088 case DW_FORM_exprloc
:
23089 fprintf_unfiltered (f
, "expression: size %s",
23090 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23092 case DW_FORM_data16
:
23093 fprintf_unfiltered (f
, "constant of 16 bytes");
23095 case DW_FORM_ref_addr
:
23096 fprintf_unfiltered (f
, "ref address: ");
23097 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23099 case DW_FORM_GNU_ref_alt
:
23100 fprintf_unfiltered (f
, "alt ref address: ");
23101 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23107 case DW_FORM_ref_udata
:
23108 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23109 (long) (DW_UNSND (&die
->attrs
[i
])));
23111 case DW_FORM_data1
:
23112 case DW_FORM_data2
:
23113 case DW_FORM_data4
:
23114 case DW_FORM_data8
:
23115 case DW_FORM_udata
:
23116 case DW_FORM_sdata
:
23117 fprintf_unfiltered (f
, "constant: %s",
23118 pulongest (DW_UNSND (&die
->attrs
[i
])));
23120 case DW_FORM_sec_offset
:
23121 fprintf_unfiltered (f
, "section offset: %s",
23122 pulongest (DW_UNSND (&die
->attrs
[i
])));
23124 case DW_FORM_ref_sig8
:
23125 fprintf_unfiltered (f
, "signature: %s",
23126 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23128 case DW_FORM_string
:
23130 case DW_FORM_line_strp
:
23131 case DW_FORM_GNU_str_index
:
23132 case DW_FORM_GNU_strp_alt
:
23133 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23134 DW_STRING (&die
->attrs
[i
])
23135 ? DW_STRING (&die
->attrs
[i
]) : "",
23136 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23139 if (DW_UNSND (&die
->attrs
[i
]))
23140 fprintf_unfiltered (f
, "flag: TRUE");
23142 fprintf_unfiltered (f
, "flag: FALSE");
23144 case DW_FORM_flag_present
:
23145 fprintf_unfiltered (f
, "flag: TRUE");
23147 case DW_FORM_indirect
:
23148 /* The reader will have reduced the indirect form to
23149 the "base form" so this form should not occur. */
23150 fprintf_unfiltered (f
,
23151 "unexpected attribute form: DW_FORM_indirect");
23153 case DW_FORM_implicit_const
:
23154 fprintf_unfiltered (f
, "constant: %s",
23155 plongest (DW_SND (&die
->attrs
[i
])));
23158 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23159 die
->attrs
[i
].form
);
23162 fprintf_unfiltered (f
, "\n");
23167 dump_die_for_error (struct die_info
*die
)
23169 dump_die_shallow (gdb_stderr
, 0, die
);
23173 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23175 int indent
= level
* 4;
23177 gdb_assert (die
!= NULL
);
23179 if (level
>= max_level
)
23182 dump_die_shallow (f
, indent
, die
);
23184 if (die
->child
!= NULL
)
23186 print_spaces (indent
, f
);
23187 fprintf_unfiltered (f
, " Children:");
23188 if (level
+ 1 < max_level
)
23190 fprintf_unfiltered (f
, "\n");
23191 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23195 fprintf_unfiltered (f
,
23196 " [not printed, max nesting level reached]\n");
23200 if (die
->sibling
!= NULL
&& level
> 0)
23202 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23206 /* This is called from the pdie macro in gdbinit.in.
23207 It's not static so gcc will keep a copy callable from gdb. */
23210 dump_die (struct die_info
*die
, int max_level
)
23212 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23216 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23220 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23221 to_underlying (die
->sect_off
),
23227 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23231 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23233 if (attr_form_is_ref (attr
))
23234 return (sect_offset
) DW_UNSND (attr
);
23236 complaint (&symfile_complaints
,
23237 _("unsupported die ref attribute form: '%s'"),
23238 dwarf_form_name (attr
->form
));
23242 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23243 * the value held by the attribute is not constant. */
23246 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23248 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23249 return DW_SND (attr
);
23250 else if (attr
->form
== DW_FORM_udata
23251 || attr
->form
== DW_FORM_data1
23252 || attr
->form
== DW_FORM_data2
23253 || attr
->form
== DW_FORM_data4
23254 || attr
->form
== DW_FORM_data8
)
23255 return DW_UNSND (attr
);
23258 /* For DW_FORM_data16 see attr_form_is_constant. */
23259 complaint (&symfile_complaints
,
23260 _("Attribute value is not a constant (%s)"),
23261 dwarf_form_name (attr
->form
));
23262 return default_value
;
23266 /* Follow reference or signature attribute ATTR of SRC_DIE.
23267 On entry *REF_CU is the CU of SRC_DIE.
23268 On exit *REF_CU is the CU of the result. */
23270 static struct die_info
*
23271 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23272 struct dwarf2_cu
**ref_cu
)
23274 struct die_info
*die
;
23276 if (attr_form_is_ref (attr
))
23277 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23278 else if (attr
->form
== DW_FORM_ref_sig8
)
23279 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23282 dump_die_for_error (src_die
);
23283 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23284 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23290 /* Follow reference OFFSET.
23291 On entry *REF_CU is the CU of the source die referencing OFFSET.
23292 On exit *REF_CU is the CU of the result.
23293 Returns NULL if OFFSET is invalid. */
23295 static struct die_info
*
23296 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23297 struct dwarf2_cu
**ref_cu
)
23299 struct die_info temp_die
;
23300 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23301 struct dwarf2_per_objfile
*dwarf2_per_objfile
23302 = cu
->per_cu
->dwarf2_per_objfile
;
23303 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23305 gdb_assert (cu
->per_cu
!= NULL
);
23309 if (cu
->per_cu
->is_debug_types
)
23311 /* .debug_types CUs cannot reference anything outside their CU.
23312 If they need to, they have to reference a signatured type via
23313 DW_FORM_ref_sig8. */
23314 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23317 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23318 || !offset_in_cu_p (&cu
->header
, sect_off
))
23320 struct dwarf2_per_cu_data
*per_cu
;
23322 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23323 dwarf2_per_objfile
);
23325 /* If necessary, add it to the queue and load its DIEs. */
23326 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23327 load_full_comp_unit (per_cu
, cu
->language
);
23329 target_cu
= per_cu
->cu
;
23331 else if (cu
->dies
== NULL
)
23333 /* We're loading full DIEs during partial symbol reading. */
23334 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23335 load_full_comp_unit (cu
->per_cu
, language_minimal
);
23338 *ref_cu
= target_cu
;
23339 temp_die
.sect_off
= sect_off
;
23340 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23342 to_underlying (sect_off
));
23345 /* Follow reference attribute ATTR of SRC_DIE.
23346 On entry *REF_CU is the CU of SRC_DIE.
23347 On exit *REF_CU is the CU of the result. */
23349 static struct die_info
*
23350 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23351 struct dwarf2_cu
**ref_cu
)
23353 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23354 struct dwarf2_cu
*cu
= *ref_cu
;
23355 struct die_info
*die
;
23357 die
= follow_die_offset (sect_off
,
23358 (attr
->form
== DW_FORM_GNU_ref_alt
23359 || cu
->per_cu
->is_dwz
),
23362 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23363 "at %s [in module %s]"),
23364 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23365 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23370 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23371 Returned value is intended for DW_OP_call*. Returned
23372 dwarf2_locexpr_baton->data has lifetime of
23373 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23375 struct dwarf2_locexpr_baton
23376 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23377 struct dwarf2_per_cu_data
*per_cu
,
23378 CORE_ADDR (*get_frame_pc
) (void *baton
),
23381 struct dwarf2_cu
*cu
;
23382 struct die_info
*die
;
23383 struct attribute
*attr
;
23384 struct dwarf2_locexpr_baton retval
;
23385 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23386 struct dwarf2_per_objfile
*dwarf2_per_objfile
23387 = get_dwarf2_per_objfile (objfile
);
23389 if (per_cu
->cu
== NULL
)
23394 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23395 Instead just throw an error, not much else we can do. */
23396 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23397 sect_offset_str (sect_off
), objfile_name (objfile
));
23400 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23402 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23403 sect_offset_str (sect_off
), objfile_name (objfile
));
23405 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23408 /* DWARF: "If there is no such attribute, then there is no effect.".
23409 DATA is ignored if SIZE is 0. */
23411 retval
.data
= NULL
;
23414 else if (attr_form_is_section_offset (attr
))
23416 struct dwarf2_loclist_baton loclist_baton
;
23417 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23420 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23422 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23424 retval
.size
= size
;
23428 if (!attr_form_is_block (attr
))
23429 error (_("Dwarf Error: DIE at %s referenced in module %s "
23430 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23431 sect_offset_str (sect_off
), objfile_name (objfile
));
23433 retval
.data
= DW_BLOCK (attr
)->data
;
23434 retval
.size
= DW_BLOCK (attr
)->size
;
23436 retval
.per_cu
= cu
->per_cu
;
23438 age_cached_comp_units (dwarf2_per_objfile
);
23443 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23446 struct dwarf2_locexpr_baton
23447 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23448 struct dwarf2_per_cu_data
*per_cu
,
23449 CORE_ADDR (*get_frame_pc
) (void *baton
),
23452 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23454 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23457 /* Write a constant of a given type as target-ordered bytes into
23460 static const gdb_byte
*
23461 write_constant_as_bytes (struct obstack
*obstack
,
23462 enum bfd_endian byte_order
,
23469 *len
= TYPE_LENGTH (type
);
23470 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23471 store_unsigned_integer (result
, *len
, byte_order
, value
);
23476 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23477 pointer to the constant bytes and set LEN to the length of the
23478 data. If memory is needed, allocate it on OBSTACK. If the DIE
23479 does not have a DW_AT_const_value, return NULL. */
23482 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23483 struct dwarf2_per_cu_data
*per_cu
,
23484 struct obstack
*obstack
,
23487 struct dwarf2_cu
*cu
;
23488 struct die_info
*die
;
23489 struct attribute
*attr
;
23490 const gdb_byte
*result
= NULL
;
23493 enum bfd_endian byte_order
;
23494 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23496 if (per_cu
->cu
== NULL
)
23501 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23502 Instead just throw an error, not much else we can do. */
23503 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23504 sect_offset_str (sect_off
), objfile_name (objfile
));
23507 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23509 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23510 sect_offset_str (sect_off
), objfile_name (objfile
));
23512 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23516 byte_order
= (bfd_big_endian (objfile
->obfd
)
23517 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23519 switch (attr
->form
)
23522 case DW_FORM_GNU_addr_index
:
23526 *len
= cu
->header
.addr_size
;
23527 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23528 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23532 case DW_FORM_string
:
23534 case DW_FORM_GNU_str_index
:
23535 case DW_FORM_GNU_strp_alt
:
23536 /* DW_STRING is already allocated on the objfile obstack, point
23538 result
= (const gdb_byte
*) DW_STRING (attr
);
23539 *len
= strlen (DW_STRING (attr
));
23541 case DW_FORM_block1
:
23542 case DW_FORM_block2
:
23543 case DW_FORM_block4
:
23544 case DW_FORM_block
:
23545 case DW_FORM_exprloc
:
23546 case DW_FORM_data16
:
23547 result
= DW_BLOCK (attr
)->data
;
23548 *len
= DW_BLOCK (attr
)->size
;
23551 /* The DW_AT_const_value attributes are supposed to carry the
23552 symbol's value "represented as it would be on the target
23553 architecture." By the time we get here, it's already been
23554 converted to host endianness, so we just need to sign- or
23555 zero-extend it as appropriate. */
23556 case DW_FORM_data1
:
23557 type
= die_type (die
, cu
);
23558 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23559 if (result
== NULL
)
23560 result
= write_constant_as_bytes (obstack
, byte_order
,
23563 case DW_FORM_data2
:
23564 type
= die_type (die
, cu
);
23565 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23566 if (result
== NULL
)
23567 result
= write_constant_as_bytes (obstack
, byte_order
,
23570 case DW_FORM_data4
:
23571 type
= die_type (die
, cu
);
23572 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23573 if (result
== NULL
)
23574 result
= write_constant_as_bytes (obstack
, byte_order
,
23577 case DW_FORM_data8
:
23578 type
= die_type (die
, cu
);
23579 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23580 if (result
== NULL
)
23581 result
= write_constant_as_bytes (obstack
, byte_order
,
23585 case DW_FORM_sdata
:
23586 case DW_FORM_implicit_const
:
23587 type
= die_type (die
, cu
);
23588 result
= write_constant_as_bytes (obstack
, byte_order
,
23589 type
, DW_SND (attr
), len
);
23592 case DW_FORM_udata
:
23593 type
= die_type (die
, cu
);
23594 result
= write_constant_as_bytes (obstack
, byte_order
,
23595 type
, DW_UNSND (attr
), len
);
23599 complaint (&symfile_complaints
,
23600 _("unsupported const value attribute form: '%s'"),
23601 dwarf_form_name (attr
->form
));
23608 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23609 valid type for this die is found. */
23612 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23613 struct dwarf2_per_cu_data
*per_cu
)
23615 struct dwarf2_cu
*cu
;
23616 struct die_info
*die
;
23618 if (per_cu
->cu
== NULL
)
23624 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23628 return die_type (die
, cu
);
23631 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23635 dwarf2_get_die_type (cu_offset die_offset
,
23636 struct dwarf2_per_cu_data
*per_cu
)
23638 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23639 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23642 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23643 On entry *REF_CU is the CU of SRC_DIE.
23644 On exit *REF_CU is the CU of the result.
23645 Returns NULL if the referenced DIE isn't found. */
23647 static struct die_info
*
23648 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23649 struct dwarf2_cu
**ref_cu
)
23651 struct die_info temp_die
;
23652 struct dwarf2_cu
*sig_cu
;
23653 struct die_info
*die
;
23655 /* While it might be nice to assert sig_type->type == NULL here,
23656 we can get here for DW_AT_imported_declaration where we need
23657 the DIE not the type. */
23659 /* If necessary, add it to the queue and load its DIEs. */
23661 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23662 read_signatured_type (sig_type
);
23664 sig_cu
= sig_type
->per_cu
.cu
;
23665 gdb_assert (sig_cu
!= NULL
);
23666 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23667 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23668 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23669 to_underlying (temp_die
.sect_off
));
23672 struct dwarf2_per_objfile
*dwarf2_per_objfile
23673 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23675 /* For .gdb_index version 7 keep track of included TUs.
23676 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23677 if (dwarf2_per_objfile
->index_table
!= NULL
23678 && dwarf2_per_objfile
->index_table
->version
<= 7)
23680 VEC_safe_push (dwarf2_per_cu_ptr
,
23681 (*ref_cu
)->per_cu
->imported_symtabs
,
23692 /* Follow signatured type referenced by ATTR in SRC_DIE.
23693 On entry *REF_CU is the CU of SRC_DIE.
23694 On exit *REF_CU is the CU of the result.
23695 The result is the DIE of the type.
23696 If the referenced type cannot be found an error is thrown. */
23698 static struct die_info
*
23699 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23700 struct dwarf2_cu
**ref_cu
)
23702 ULONGEST signature
= DW_SIGNATURE (attr
);
23703 struct signatured_type
*sig_type
;
23704 struct die_info
*die
;
23706 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23708 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23709 /* sig_type will be NULL if the signatured type is missing from
23711 if (sig_type
== NULL
)
23713 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23714 " from DIE at %s [in module %s]"),
23715 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23716 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23719 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23722 dump_die_for_error (src_die
);
23723 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23724 " from DIE at %s [in module %s]"),
23725 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23726 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23732 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23733 reading in and processing the type unit if necessary. */
23735 static struct type
*
23736 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23737 struct dwarf2_cu
*cu
)
23739 struct dwarf2_per_objfile
*dwarf2_per_objfile
23740 = cu
->per_cu
->dwarf2_per_objfile
;
23741 struct signatured_type
*sig_type
;
23742 struct dwarf2_cu
*type_cu
;
23743 struct die_info
*type_die
;
23746 sig_type
= lookup_signatured_type (cu
, signature
);
23747 /* sig_type will be NULL if the signatured type is missing from
23749 if (sig_type
== NULL
)
23751 complaint (&symfile_complaints
,
23752 _("Dwarf Error: Cannot find signatured DIE %s referenced"
23753 " from DIE at %s [in module %s]"),
23754 hex_string (signature
), sect_offset_str (die
->sect_off
),
23755 objfile_name (dwarf2_per_objfile
->objfile
));
23756 return build_error_marker_type (cu
, die
);
23759 /* If we already know the type we're done. */
23760 if (sig_type
->type
!= NULL
)
23761 return sig_type
->type
;
23764 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23765 if (type_die
!= NULL
)
23767 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23768 is created. This is important, for example, because for c++ classes
23769 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23770 type
= read_type_die (type_die
, type_cu
);
23773 complaint (&symfile_complaints
,
23774 _("Dwarf Error: Cannot build signatured type %s"
23775 " referenced from DIE at %s [in module %s]"),
23776 hex_string (signature
), sect_offset_str (die
->sect_off
),
23777 objfile_name (dwarf2_per_objfile
->objfile
));
23778 type
= build_error_marker_type (cu
, die
);
23783 complaint (&symfile_complaints
,
23784 _("Dwarf Error: Problem reading signatured DIE %s referenced"
23785 " from DIE at %s [in module %s]"),
23786 hex_string (signature
), sect_offset_str (die
->sect_off
),
23787 objfile_name (dwarf2_per_objfile
->objfile
));
23788 type
= build_error_marker_type (cu
, die
);
23790 sig_type
->type
= type
;
23795 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23796 reading in and processing the type unit if necessary. */
23798 static struct type
*
23799 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23800 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23802 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23803 if (attr_form_is_ref (attr
))
23805 struct dwarf2_cu
*type_cu
= cu
;
23806 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23808 return read_type_die (type_die
, type_cu
);
23810 else if (attr
->form
== DW_FORM_ref_sig8
)
23812 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23816 struct dwarf2_per_objfile
*dwarf2_per_objfile
23817 = cu
->per_cu
->dwarf2_per_objfile
;
23819 complaint (&symfile_complaints
,
23820 _("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23821 " at %s [in module %s]"),
23822 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23823 objfile_name (dwarf2_per_objfile
->objfile
));
23824 return build_error_marker_type (cu
, die
);
23828 /* Load the DIEs associated with type unit PER_CU into memory. */
23831 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23833 struct signatured_type
*sig_type
;
23835 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23836 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23838 /* We have the per_cu, but we need the signatured_type.
23839 Fortunately this is an easy translation. */
23840 gdb_assert (per_cu
->is_debug_types
);
23841 sig_type
= (struct signatured_type
*) per_cu
;
23843 gdb_assert (per_cu
->cu
== NULL
);
23845 read_signatured_type (sig_type
);
23847 gdb_assert (per_cu
->cu
!= NULL
);
23850 /* die_reader_func for read_signatured_type.
23851 This is identical to load_full_comp_unit_reader,
23852 but is kept separate for now. */
23855 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23856 const gdb_byte
*info_ptr
,
23857 struct die_info
*comp_unit_die
,
23861 struct dwarf2_cu
*cu
= reader
->cu
;
23863 gdb_assert (cu
->die_hash
== NULL
);
23865 htab_create_alloc_ex (cu
->header
.length
/ 12,
23869 &cu
->comp_unit_obstack
,
23870 hashtab_obstack_allocate
,
23871 dummy_obstack_deallocate
);
23874 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23875 &info_ptr
, comp_unit_die
);
23876 cu
->dies
= comp_unit_die
;
23877 /* comp_unit_die is not stored in die_hash, no need. */
23879 /* We try not to read any attributes in this function, because not
23880 all CUs needed for references have been loaded yet, and symbol
23881 table processing isn't initialized. But we have to set the CU language,
23882 or we won't be able to build types correctly.
23883 Similarly, if we do not read the producer, we can not apply
23884 producer-specific interpretation. */
23885 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23888 /* Read in a signatured type and build its CU and DIEs.
23889 If the type is a stub for the real type in a DWO file,
23890 read in the real type from the DWO file as well. */
23893 read_signatured_type (struct signatured_type
*sig_type
)
23895 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23897 gdb_assert (per_cu
->is_debug_types
);
23898 gdb_assert (per_cu
->cu
== NULL
);
23900 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1,
23901 read_signatured_type_reader
, NULL
);
23902 sig_type
->per_cu
.tu_read
= 1;
23905 /* Decode simple location descriptions.
23906 Given a pointer to a dwarf block that defines a location, compute
23907 the location and return the value.
23909 NOTE drow/2003-11-18: This function is called in two situations
23910 now: for the address of static or global variables (partial symbols
23911 only) and for offsets into structures which are expected to be
23912 (more or less) constant. The partial symbol case should go away,
23913 and only the constant case should remain. That will let this
23914 function complain more accurately. A few special modes are allowed
23915 without complaint for global variables (for instance, global
23916 register values and thread-local values).
23918 A location description containing no operations indicates that the
23919 object is optimized out. The return value is 0 for that case.
23920 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23921 callers will only want a very basic result and this can become a
23924 Note that stack[0] is unused except as a default error return. */
23927 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23931 size_t size
= blk
->size
;
23932 const gdb_byte
*data
= blk
->data
;
23933 CORE_ADDR stack
[64];
23935 unsigned int bytes_read
, unsnd
;
23941 stack
[++stacki
] = 0;
23980 stack
[++stacki
] = op
- DW_OP_lit0
;
24015 stack
[++stacki
] = op
- DW_OP_reg0
;
24017 dwarf2_complex_location_expr_complaint ();
24021 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24023 stack
[++stacki
] = unsnd
;
24025 dwarf2_complex_location_expr_complaint ();
24029 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24034 case DW_OP_const1u
:
24035 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24039 case DW_OP_const1s
:
24040 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24044 case DW_OP_const2u
:
24045 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24049 case DW_OP_const2s
:
24050 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24054 case DW_OP_const4u
:
24055 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24059 case DW_OP_const4s
:
24060 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24064 case DW_OP_const8u
:
24065 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24070 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24076 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24081 stack
[stacki
+ 1] = stack
[stacki
];
24086 stack
[stacki
- 1] += stack
[stacki
];
24090 case DW_OP_plus_uconst
:
24091 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24097 stack
[stacki
- 1] -= stack
[stacki
];
24102 /* If we're not the last op, then we definitely can't encode
24103 this using GDB's address_class enum. This is valid for partial
24104 global symbols, although the variable's address will be bogus
24107 dwarf2_complex_location_expr_complaint ();
24110 case DW_OP_GNU_push_tls_address
:
24111 case DW_OP_form_tls_address
:
24112 /* The top of the stack has the offset from the beginning
24113 of the thread control block at which the variable is located. */
24114 /* Nothing should follow this operator, so the top of stack would
24116 /* This is valid for partial global symbols, but the variable's
24117 address will be bogus in the psymtab. Make it always at least
24118 non-zero to not look as a variable garbage collected by linker
24119 which have DW_OP_addr 0. */
24121 dwarf2_complex_location_expr_complaint ();
24125 case DW_OP_GNU_uninit
:
24128 case DW_OP_GNU_addr_index
:
24129 case DW_OP_GNU_const_index
:
24130 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24137 const char *name
= get_DW_OP_name (op
);
24140 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
24143 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
24147 return (stack
[stacki
]);
24150 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24151 outside of the allocated space. Also enforce minimum>0. */
24152 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24154 complaint (&symfile_complaints
,
24155 _("location description stack overflow"));
24161 complaint (&symfile_complaints
,
24162 _("location description stack underflow"));
24166 return (stack
[stacki
]);
24169 /* memory allocation interface */
24171 static struct dwarf_block
*
24172 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24174 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24177 static struct die_info
*
24178 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24180 struct die_info
*die
;
24181 size_t size
= sizeof (struct die_info
);
24184 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24186 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24187 memset (die
, 0, sizeof (struct die_info
));
24192 /* Macro support. */
24194 /* Return file name relative to the compilation directory of file number I in
24195 *LH's file name table. The result is allocated using xmalloc; the caller is
24196 responsible for freeing it. */
24199 file_file_name (int file
, struct line_header
*lh
)
24201 /* Is the file number a valid index into the line header's file name
24202 table? Remember that file numbers start with one, not zero. */
24203 if (1 <= file
&& file
<= lh
->file_names
.size ())
24205 const file_entry
&fe
= lh
->file_names
[file
- 1];
24207 if (!IS_ABSOLUTE_PATH (fe
.name
))
24209 const char *dir
= fe
.include_dir (lh
);
24211 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24213 return xstrdup (fe
.name
);
24217 /* The compiler produced a bogus file number. We can at least
24218 record the macro definitions made in the file, even if we
24219 won't be able to find the file by name. */
24220 char fake_name
[80];
24222 xsnprintf (fake_name
, sizeof (fake_name
),
24223 "<bad macro file number %d>", file
);
24225 complaint (&symfile_complaints
,
24226 _("bad file number in macro information (%d)"),
24229 return xstrdup (fake_name
);
24233 /* Return the full name of file number I in *LH's file name table.
24234 Use COMP_DIR as the name of the current directory of the
24235 compilation. The result is allocated using xmalloc; the caller is
24236 responsible for freeing it. */
24238 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24240 /* Is the file number a valid index into the line header's file name
24241 table? Remember that file numbers start with one, not zero. */
24242 if (1 <= file
&& file
<= lh
->file_names
.size ())
24244 char *relative
= file_file_name (file
, lh
);
24246 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24248 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24249 relative
, (char *) NULL
);
24252 return file_file_name (file
, lh
);
24256 static struct macro_source_file
*
24257 macro_start_file (int file
, int line
,
24258 struct macro_source_file
*current_file
,
24259 struct line_header
*lh
)
24261 /* File name relative to the compilation directory of this source file. */
24262 char *file_name
= file_file_name (file
, lh
);
24264 if (! current_file
)
24266 /* Note: We don't create a macro table for this compilation unit
24267 at all until we actually get a filename. */
24268 struct macro_table
*macro_table
= get_macro_table ();
24270 /* If we have no current file, then this must be the start_file
24271 directive for the compilation unit's main source file. */
24272 current_file
= macro_set_main (macro_table
, file_name
);
24273 macro_define_special (macro_table
);
24276 current_file
= macro_include (current_file
, line
, file_name
);
24280 return current_file
;
24283 static const char *
24284 consume_improper_spaces (const char *p
, const char *body
)
24288 complaint (&symfile_complaints
,
24289 _("macro definition contains spaces "
24290 "in formal argument list:\n`%s'"),
24302 parse_macro_definition (struct macro_source_file
*file
, int line
,
24307 /* The body string takes one of two forms. For object-like macro
24308 definitions, it should be:
24310 <macro name> " " <definition>
24312 For function-like macro definitions, it should be:
24314 <macro name> "() " <definition>
24316 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24318 Spaces may appear only where explicitly indicated, and in the
24321 The Dwarf 2 spec says that an object-like macro's name is always
24322 followed by a space, but versions of GCC around March 2002 omit
24323 the space when the macro's definition is the empty string.
24325 The Dwarf 2 spec says that there should be no spaces between the
24326 formal arguments in a function-like macro's formal argument list,
24327 but versions of GCC around March 2002 include spaces after the
24331 /* Find the extent of the macro name. The macro name is terminated
24332 by either a space or null character (for an object-like macro) or
24333 an opening paren (for a function-like macro). */
24334 for (p
= body
; *p
; p
++)
24335 if (*p
== ' ' || *p
== '(')
24338 if (*p
== ' ' || *p
== '\0')
24340 /* It's an object-like macro. */
24341 int name_len
= p
- body
;
24342 char *name
= savestring (body
, name_len
);
24343 const char *replacement
;
24346 replacement
= body
+ name_len
+ 1;
24349 dwarf2_macro_malformed_definition_complaint (body
);
24350 replacement
= body
+ name_len
;
24353 macro_define_object (file
, line
, name
, replacement
);
24357 else if (*p
== '(')
24359 /* It's a function-like macro. */
24360 char *name
= savestring (body
, p
- body
);
24363 char **argv
= XNEWVEC (char *, argv_size
);
24367 p
= consume_improper_spaces (p
, body
);
24369 /* Parse the formal argument list. */
24370 while (*p
&& *p
!= ')')
24372 /* Find the extent of the current argument name. */
24373 const char *arg_start
= p
;
24375 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24378 if (! *p
|| p
== arg_start
)
24379 dwarf2_macro_malformed_definition_complaint (body
);
24382 /* Make sure argv has room for the new argument. */
24383 if (argc
>= argv_size
)
24386 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24389 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24392 p
= consume_improper_spaces (p
, body
);
24394 /* Consume the comma, if present. */
24399 p
= consume_improper_spaces (p
, body
);
24408 /* Perfectly formed definition, no complaints. */
24409 macro_define_function (file
, line
, name
,
24410 argc
, (const char **) argv
,
24412 else if (*p
== '\0')
24414 /* Complain, but do define it. */
24415 dwarf2_macro_malformed_definition_complaint (body
);
24416 macro_define_function (file
, line
, name
,
24417 argc
, (const char **) argv
,
24421 /* Just complain. */
24422 dwarf2_macro_malformed_definition_complaint (body
);
24425 /* Just complain. */
24426 dwarf2_macro_malformed_definition_complaint (body
);
24432 for (i
= 0; i
< argc
; i
++)
24438 dwarf2_macro_malformed_definition_complaint (body
);
24441 /* Skip some bytes from BYTES according to the form given in FORM.
24442 Returns the new pointer. */
24444 static const gdb_byte
*
24445 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24446 enum dwarf_form form
,
24447 unsigned int offset_size
,
24448 struct dwarf2_section_info
*section
)
24450 unsigned int bytes_read
;
24454 case DW_FORM_data1
:
24459 case DW_FORM_data2
:
24463 case DW_FORM_data4
:
24467 case DW_FORM_data8
:
24471 case DW_FORM_data16
:
24475 case DW_FORM_string
:
24476 read_direct_string (abfd
, bytes
, &bytes_read
);
24477 bytes
+= bytes_read
;
24480 case DW_FORM_sec_offset
:
24482 case DW_FORM_GNU_strp_alt
:
24483 bytes
+= offset_size
;
24486 case DW_FORM_block
:
24487 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24488 bytes
+= bytes_read
;
24491 case DW_FORM_block1
:
24492 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24494 case DW_FORM_block2
:
24495 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24497 case DW_FORM_block4
:
24498 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24501 case DW_FORM_sdata
:
24502 case DW_FORM_udata
:
24503 case DW_FORM_GNU_addr_index
:
24504 case DW_FORM_GNU_str_index
:
24505 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24508 dwarf2_section_buffer_overflow_complaint (section
);
24513 case DW_FORM_implicit_const
:
24518 complaint (&symfile_complaints
,
24519 _("invalid form 0x%x in `%s'"),
24520 form
, get_section_name (section
));
24528 /* A helper for dwarf_decode_macros that handles skipping an unknown
24529 opcode. Returns an updated pointer to the macro data buffer; or,
24530 on error, issues a complaint and returns NULL. */
24532 static const gdb_byte
*
24533 skip_unknown_opcode (unsigned int opcode
,
24534 const gdb_byte
**opcode_definitions
,
24535 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24537 unsigned int offset_size
,
24538 struct dwarf2_section_info
*section
)
24540 unsigned int bytes_read
, i
;
24542 const gdb_byte
*defn
;
24544 if (opcode_definitions
[opcode
] == NULL
)
24546 complaint (&symfile_complaints
,
24547 _("unrecognized DW_MACFINO opcode 0x%x"),
24552 defn
= opcode_definitions
[opcode
];
24553 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24554 defn
+= bytes_read
;
24556 for (i
= 0; i
< arg
; ++i
)
24558 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24559 (enum dwarf_form
) defn
[i
], offset_size
,
24561 if (mac_ptr
== NULL
)
24563 /* skip_form_bytes already issued the complaint. */
24571 /* A helper function which parses the header of a macro section.
24572 If the macro section is the extended (for now called "GNU") type,
24573 then this updates *OFFSET_SIZE. Returns a pointer to just after
24574 the header, or issues a complaint and returns NULL on error. */
24576 static const gdb_byte
*
24577 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24579 const gdb_byte
*mac_ptr
,
24580 unsigned int *offset_size
,
24581 int section_is_gnu
)
24583 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24585 if (section_is_gnu
)
24587 unsigned int version
, flags
;
24589 version
= read_2_bytes (abfd
, mac_ptr
);
24590 if (version
!= 4 && version
!= 5)
24592 complaint (&symfile_complaints
,
24593 _("unrecognized version `%d' in .debug_macro section"),
24599 flags
= read_1_byte (abfd
, mac_ptr
);
24601 *offset_size
= (flags
& 1) ? 8 : 4;
24603 if ((flags
& 2) != 0)
24604 /* We don't need the line table offset. */
24605 mac_ptr
+= *offset_size
;
24607 /* Vendor opcode descriptions. */
24608 if ((flags
& 4) != 0)
24610 unsigned int i
, count
;
24612 count
= read_1_byte (abfd
, mac_ptr
);
24614 for (i
= 0; i
< count
; ++i
)
24616 unsigned int opcode
, bytes_read
;
24619 opcode
= read_1_byte (abfd
, mac_ptr
);
24621 opcode_definitions
[opcode
] = mac_ptr
;
24622 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24623 mac_ptr
+= bytes_read
;
24632 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24633 including DW_MACRO_import. */
24636 dwarf_decode_macro_bytes (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
24638 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24639 struct macro_source_file
*current_file
,
24640 struct line_header
*lh
,
24641 struct dwarf2_section_info
*section
,
24642 int section_is_gnu
, int section_is_dwz
,
24643 unsigned int offset_size
,
24644 htab_t include_hash
)
24646 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24647 enum dwarf_macro_record_type macinfo_type
;
24648 int at_commandline
;
24649 const gdb_byte
*opcode_definitions
[256];
24651 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24652 &offset_size
, section_is_gnu
);
24653 if (mac_ptr
== NULL
)
24655 /* We already issued a complaint. */
24659 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24660 GDB is still reading the definitions from command line. First
24661 DW_MACINFO_start_file will need to be ignored as it was already executed
24662 to create CURRENT_FILE for the main source holding also the command line
24663 definitions. On first met DW_MACINFO_start_file this flag is reset to
24664 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24666 at_commandline
= 1;
24670 /* Do we at least have room for a macinfo type byte? */
24671 if (mac_ptr
>= mac_end
)
24673 dwarf2_section_buffer_overflow_complaint (section
);
24677 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24680 /* Note that we rely on the fact that the corresponding GNU and
24681 DWARF constants are the same. */
24683 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24684 switch (macinfo_type
)
24686 /* A zero macinfo type indicates the end of the macro
24691 case DW_MACRO_define
:
24692 case DW_MACRO_undef
:
24693 case DW_MACRO_define_strp
:
24694 case DW_MACRO_undef_strp
:
24695 case DW_MACRO_define_sup
:
24696 case DW_MACRO_undef_sup
:
24698 unsigned int bytes_read
;
24703 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24704 mac_ptr
+= bytes_read
;
24706 if (macinfo_type
== DW_MACRO_define
24707 || macinfo_type
== DW_MACRO_undef
)
24709 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24710 mac_ptr
+= bytes_read
;
24714 LONGEST str_offset
;
24716 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24717 mac_ptr
+= offset_size
;
24719 if (macinfo_type
== DW_MACRO_define_sup
24720 || macinfo_type
== DW_MACRO_undef_sup
24723 struct dwz_file
*dwz
24724 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24726 body
= read_indirect_string_from_dwz (objfile
,
24730 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24734 is_define
= (macinfo_type
== DW_MACRO_define
24735 || macinfo_type
== DW_MACRO_define_strp
24736 || macinfo_type
== DW_MACRO_define_sup
);
24737 if (! current_file
)
24739 /* DWARF violation as no main source is present. */
24740 complaint (&symfile_complaints
,
24741 _("debug info with no main source gives macro %s "
24743 is_define
? _("definition") : _("undefinition"),
24747 if ((line
== 0 && !at_commandline
)
24748 || (line
!= 0 && at_commandline
))
24749 complaint (&symfile_complaints
,
24750 _("debug info gives %s macro %s with %s line %d: %s"),
24751 at_commandline
? _("command-line") : _("in-file"),
24752 is_define
? _("definition") : _("undefinition"),
24753 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24756 parse_macro_definition (current_file
, line
, body
);
24759 gdb_assert (macinfo_type
== DW_MACRO_undef
24760 || macinfo_type
== DW_MACRO_undef_strp
24761 || macinfo_type
== DW_MACRO_undef_sup
);
24762 macro_undef (current_file
, line
, body
);
24767 case DW_MACRO_start_file
:
24769 unsigned int bytes_read
;
24772 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24773 mac_ptr
+= bytes_read
;
24774 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24775 mac_ptr
+= bytes_read
;
24777 if ((line
== 0 && !at_commandline
)
24778 || (line
!= 0 && at_commandline
))
24779 complaint (&symfile_complaints
,
24780 _("debug info gives source %d included "
24781 "from %s at %s line %d"),
24782 file
, at_commandline
? _("command-line") : _("file"),
24783 line
== 0 ? _("zero") : _("non-zero"), line
);
24785 if (at_commandline
)
24787 /* This DW_MACRO_start_file was executed in the
24789 at_commandline
= 0;
24792 current_file
= macro_start_file (file
, line
, current_file
, lh
);
24796 case DW_MACRO_end_file
:
24797 if (! current_file
)
24798 complaint (&symfile_complaints
,
24799 _("macro debug info has an unmatched "
24800 "`close_file' directive"));
24803 current_file
= current_file
->included_by
;
24804 if (! current_file
)
24806 enum dwarf_macro_record_type next_type
;
24808 /* GCC circa March 2002 doesn't produce the zero
24809 type byte marking the end of the compilation
24810 unit. Complain if it's not there, but exit no
24813 /* Do we at least have room for a macinfo type byte? */
24814 if (mac_ptr
>= mac_end
)
24816 dwarf2_section_buffer_overflow_complaint (section
);
24820 /* We don't increment mac_ptr here, so this is just
24823 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24825 if (next_type
!= 0)
24826 complaint (&symfile_complaints
,
24827 _("no terminating 0-type entry for "
24828 "macros in `.debug_macinfo' section"));
24835 case DW_MACRO_import
:
24836 case DW_MACRO_import_sup
:
24840 bfd
*include_bfd
= abfd
;
24841 struct dwarf2_section_info
*include_section
= section
;
24842 const gdb_byte
*include_mac_end
= mac_end
;
24843 int is_dwz
= section_is_dwz
;
24844 const gdb_byte
*new_mac_ptr
;
24846 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24847 mac_ptr
+= offset_size
;
24849 if (macinfo_type
== DW_MACRO_import_sup
)
24851 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24853 dwarf2_read_section (objfile
, &dwz
->macro
);
24855 include_section
= &dwz
->macro
;
24856 include_bfd
= get_section_bfd_owner (include_section
);
24857 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24861 new_mac_ptr
= include_section
->buffer
+ offset
;
24862 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24866 /* This has actually happened; see
24867 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24868 complaint (&symfile_complaints
,
24869 _("recursive DW_MACRO_import in "
24870 ".debug_macro section"));
24874 *slot
= (void *) new_mac_ptr
;
24876 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
24877 include_bfd
, new_mac_ptr
,
24878 include_mac_end
, current_file
, lh
,
24879 section
, section_is_gnu
, is_dwz
,
24880 offset_size
, include_hash
);
24882 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24887 case DW_MACINFO_vendor_ext
:
24888 if (!section_is_gnu
)
24890 unsigned int bytes_read
;
24892 /* This reads the constant, but since we don't recognize
24893 any vendor extensions, we ignore it. */
24894 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24895 mac_ptr
+= bytes_read
;
24896 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24897 mac_ptr
+= bytes_read
;
24899 /* We don't recognize any vendor extensions. */
24905 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24906 mac_ptr
, mac_end
, abfd
, offset_size
,
24908 if (mac_ptr
== NULL
)
24913 } while (macinfo_type
!= 0);
24917 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24918 int section_is_gnu
)
24920 struct dwarf2_per_objfile
*dwarf2_per_objfile
24921 = cu
->per_cu
->dwarf2_per_objfile
;
24922 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24923 struct line_header
*lh
= cu
->line_header
;
24925 const gdb_byte
*mac_ptr
, *mac_end
;
24926 struct macro_source_file
*current_file
= 0;
24927 enum dwarf_macro_record_type macinfo_type
;
24928 unsigned int offset_size
= cu
->header
.offset_size
;
24929 const gdb_byte
*opcode_definitions
[256];
24931 struct dwarf2_section_info
*section
;
24932 const char *section_name
;
24934 if (cu
->dwo_unit
!= NULL
)
24936 if (section_is_gnu
)
24938 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24939 section_name
= ".debug_macro.dwo";
24943 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24944 section_name
= ".debug_macinfo.dwo";
24949 if (section_is_gnu
)
24951 section
= &dwarf2_per_objfile
->macro
;
24952 section_name
= ".debug_macro";
24956 section
= &dwarf2_per_objfile
->macinfo
;
24957 section_name
= ".debug_macinfo";
24961 dwarf2_read_section (objfile
, section
);
24962 if (section
->buffer
== NULL
)
24964 complaint (&symfile_complaints
, _("missing %s section"), section_name
);
24967 abfd
= get_section_bfd_owner (section
);
24969 /* First pass: Find the name of the base filename.
24970 This filename is needed in order to process all macros whose definition
24971 (or undefinition) comes from the command line. These macros are defined
24972 before the first DW_MACINFO_start_file entry, and yet still need to be
24973 associated to the base file.
24975 To determine the base file name, we scan the macro definitions until we
24976 reach the first DW_MACINFO_start_file entry. We then initialize
24977 CURRENT_FILE accordingly so that any macro definition found before the
24978 first DW_MACINFO_start_file can still be associated to the base file. */
24980 mac_ptr
= section
->buffer
+ offset
;
24981 mac_end
= section
->buffer
+ section
->size
;
24983 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24984 &offset_size
, section_is_gnu
);
24985 if (mac_ptr
== NULL
)
24987 /* We already issued a complaint. */
24993 /* Do we at least have room for a macinfo type byte? */
24994 if (mac_ptr
>= mac_end
)
24996 /* Complaint is printed during the second pass as GDB will probably
24997 stop the first pass earlier upon finding
24998 DW_MACINFO_start_file. */
25002 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25005 /* Note that we rely on the fact that the corresponding GNU and
25006 DWARF constants are the same. */
25008 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25009 switch (macinfo_type
)
25011 /* A zero macinfo type indicates the end of the macro
25016 case DW_MACRO_define
:
25017 case DW_MACRO_undef
:
25018 /* Only skip the data by MAC_PTR. */
25020 unsigned int bytes_read
;
25022 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25023 mac_ptr
+= bytes_read
;
25024 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25025 mac_ptr
+= bytes_read
;
25029 case DW_MACRO_start_file
:
25031 unsigned int bytes_read
;
25034 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25035 mac_ptr
+= bytes_read
;
25036 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25037 mac_ptr
+= bytes_read
;
25039 current_file
= macro_start_file (file
, line
, current_file
, lh
);
25043 case DW_MACRO_end_file
:
25044 /* No data to skip by MAC_PTR. */
25047 case DW_MACRO_define_strp
:
25048 case DW_MACRO_undef_strp
:
25049 case DW_MACRO_define_sup
:
25050 case DW_MACRO_undef_sup
:
25052 unsigned int bytes_read
;
25054 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25055 mac_ptr
+= bytes_read
;
25056 mac_ptr
+= offset_size
;
25060 case DW_MACRO_import
:
25061 case DW_MACRO_import_sup
:
25062 /* Note that, according to the spec, a transparent include
25063 chain cannot call DW_MACRO_start_file. So, we can just
25064 skip this opcode. */
25065 mac_ptr
+= offset_size
;
25068 case DW_MACINFO_vendor_ext
:
25069 /* Only skip the data by MAC_PTR. */
25070 if (!section_is_gnu
)
25072 unsigned int bytes_read
;
25074 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25075 mac_ptr
+= bytes_read
;
25076 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25077 mac_ptr
+= bytes_read
;
25082 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25083 mac_ptr
, mac_end
, abfd
, offset_size
,
25085 if (mac_ptr
== NULL
)
25090 } while (macinfo_type
!= 0 && current_file
== NULL
);
25092 /* Second pass: Process all entries.
25094 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25095 command-line macro definitions/undefinitions. This flag is unset when we
25096 reach the first DW_MACINFO_start_file entry. */
25098 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25100 NULL
, xcalloc
, xfree
));
25101 mac_ptr
= section
->buffer
+ offset
;
25102 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25103 *slot
= (void *) mac_ptr
;
25104 dwarf_decode_macro_bytes (dwarf2_per_objfile
,
25105 abfd
, mac_ptr
, mac_end
,
25106 current_file
, lh
, section
,
25107 section_is_gnu
, 0, offset_size
,
25108 include_hash
.get ());
25111 /* Check if the attribute's form is a DW_FORM_block*
25112 if so return true else false. */
25115 attr_form_is_block (const struct attribute
*attr
)
25117 return (attr
== NULL
? 0 :
25118 attr
->form
== DW_FORM_block1
25119 || attr
->form
== DW_FORM_block2
25120 || attr
->form
== DW_FORM_block4
25121 || attr
->form
== DW_FORM_block
25122 || attr
->form
== DW_FORM_exprloc
);
25125 /* Return non-zero if ATTR's value is a section offset --- classes
25126 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25127 You may use DW_UNSND (attr) to retrieve such offsets.
25129 Section 7.5.4, "Attribute Encodings", explains that no attribute
25130 may have a value that belongs to more than one of these classes; it
25131 would be ambiguous if we did, because we use the same forms for all
25135 attr_form_is_section_offset (const struct attribute
*attr
)
25137 return (attr
->form
== DW_FORM_data4
25138 || attr
->form
== DW_FORM_data8
25139 || attr
->form
== DW_FORM_sec_offset
);
25142 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25143 zero otherwise. When this function returns true, you can apply
25144 dwarf2_get_attr_constant_value to it.
25146 However, note that for some attributes you must check
25147 attr_form_is_section_offset before using this test. DW_FORM_data4
25148 and DW_FORM_data8 are members of both the constant class, and of
25149 the classes that contain offsets into other debug sections
25150 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25151 that, if an attribute's can be either a constant or one of the
25152 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25153 taken as section offsets, not constants.
25155 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25156 cannot handle that. */
25159 attr_form_is_constant (const struct attribute
*attr
)
25161 switch (attr
->form
)
25163 case DW_FORM_sdata
:
25164 case DW_FORM_udata
:
25165 case DW_FORM_data1
:
25166 case DW_FORM_data2
:
25167 case DW_FORM_data4
:
25168 case DW_FORM_data8
:
25169 case DW_FORM_implicit_const
:
25177 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25178 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25181 attr_form_is_ref (const struct attribute
*attr
)
25183 switch (attr
->form
)
25185 case DW_FORM_ref_addr
:
25190 case DW_FORM_ref_udata
:
25191 case DW_FORM_GNU_ref_alt
:
25198 /* Return the .debug_loc section to use for CU.
25199 For DWO files use .debug_loc.dwo. */
25201 static struct dwarf2_section_info
*
25202 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25204 struct dwarf2_per_objfile
*dwarf2_per_objfile
25205 = cu
->per_cu
->dwarf2_per_objfile
;
25209 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25211 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25213 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25214 : &dwarf2_per_objfile
->loc
);
25217 /* A helper function that fills in a dwarf2_loclist_baton. */
25220 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25221 struct dwarf2_loclist_baton
*baton
,
25222 const struct attribute
*attr
)
25224 struct dwarf2_per_objfile
*dwarf2_per_objfile
25225 = cu
->per_cu
->dwarf2_per_objfile
;
25226 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25228 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25230 baton
->per_cu
= cu
->per_cu
;
25231 gdb_assert (baton
->per_cu
);
25232 /* We don't know how long the location list is, but make sure we
25233 don't run off the edge of the section. */
25234 baton
->size
= section
->size
- DW_UNSND (attr
);
25235 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25236 baton
->base_address
= cu
->base_address
;
25237 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25241 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25242 struct dwarf2_cu
*cu
, int is_block
)
25244 struct dwarf2_per_objfile
*dwarf2_per_objfile
25245 = cu
->per_cu
->dwarf2_per_objfile
;
25246 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25247 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25249 if (attr_form_is_section_offset (attr
)
25250 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25251 the section. If so, fall through to the complaint in the
25253 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25255 struct dwarf2_loclist_baton
*baton
;
25257 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25259 fill_in_loclist_baton (cu
, baton
, attr
);
25261 if (cu
->base_known
== 0)
25262 complaint (&symfile_complaints
,
25263 _("Location list used without "
25264 "specifying the CU base address."));
25266 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25267 ? dwarf2_loclist_block_index
25268 : dwarf2_loclist_index
);
25269 SYMBOL_LOCATION_BATON (sym
) = baton
;
25273 struct dwarf2_locexpr_baton
*baton
;
25275 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25276 baton
->per_cu
= cu
->per_cu
;
25277 gdb_assert (baton
->per_cu
);
25279 if (attr_form_is_block (attr
))
25281 /* Note that we're just copying the block's data pointer
25282 here, not the actual data. We're still pointing into the
25283 info_buffer for SYM's objfile; right now we never release
25284 that buffer, but when we do clean up properly this may
25286 baton
->size
= DW_BLOCK (attr
)->size
;
25287 baton
->data
= DW_BLOCK (attr
)->data
;
25291 dwarf2_invalid_attrib_class_complaint ("location description",
25292 SYMBOL_NATURAL_NAME (sym
));
25296 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25297 ? dwarf2_locexpr_block_index
25298 : dwarf2_locexpr_index
);
25299 SYMBOL_LOCATION_BATON (sym
) = baton
;
25303 /* Return the OBJFILE associated with the compilation unit CU. If CU
25304 came from a separate debuginfo file, then the master objfile is
25308 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25310 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25312 /* Return the master objfile, so that we can report and look up the
25313 correct file containing this variable. */
25314 if (objfile
->separate_debug_objfile_backlink
)
25315 objfile
= objfile
->separate_debug_objfile_backlink
;
25320 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25321 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25322 CU_HEADERP first. */
25324 static const struct comp_unit_head
*
25325 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25326 struct dwarf2_per_cu_data
*per_cu
)
25328 const gdb_byte
*info_ptr
;
25331 return &per_cu
->cu
->header
;
25333 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25335 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25336 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25337 rcuh_kind::COMPILE
);
25342 /* Return the address size given in the compilation unit header for CU. */
25345 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25347 struct comp_unit_head cu_header_local
;
25348 const struct comp_unit_head
*cu_headerp
;
25350 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25352 return cu_headerp
->addr_size
;
25355 /* Return the offset size given in the compilation unit header for CU. */
25358 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25360 struct comp_unit_head cu_header_local
;
25361 const struct comp_unit_head
*cu_headerp
;
25363 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25365 return cu_headerp
->offset_size
;
25368 /* See its dwarf2loc.h declaration. */
25371 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25373 struct comp_unit_head cu_header_local
;
25374 const struct comp_unit_head
*cu_headerp
;
25376 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25378 if (cu_headerp
->version
== 2)
25379 return cu_headerp
->addr_size
;
25381 return cu_headerp
->offset_size
;
25384 /* Return the text offset of the CU. The returned offset comes from
25385 this CU's objfile. If this objfile came from a separate debuginfo
25386 file, then the offset may be different from the corresponding
25387 offset in the parent objfile. */
25390 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25392 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25394 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25397 /* Return DWARF version number of PER_CU. */
25400 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25402 return per_cu
->dwarf_version
;
25405 /* Locate the .debug_info compilation unit from CU's objfile which contains
25406 the DIE at OFFSET. Raises an error on failure. */
25408 static struct dwarf2_per_cu_data
*
25409 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25410 unsigned int offset_in_dwz
,
25411 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25413 struct dwarf2_per_cu_data
*this_cu
;
25415 const sect_offset
*cu_off
;
25418 high
= dwarf2_per_objfile
->n_comp_units
- 1;
25421 struct dwarf2_per_cu_data
*mid_cu
;
25422 int mid
= low
+ (high
- low
) / 2;
25424 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25425 cu_off
= &mid_cu
->sect_off
;
25426 if (mid_cu
->is_dwz
> offset_in_dwz
25427 || (mid_cu
->is_dwz
== offset_in_dwz
&& *cu_off
>= sect_off
))
25432 gdb_assert (low
== high
);
25433 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25434 cu_off
= &this_cu
->sect_off
;
25435 if (this_cu
->is_dwz
!= offset_in_dwz
|| *cu_off
> sect_off
)
25437 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25438 error (_("Dwarf Error: could not find partial DIE containing "
25439 "offset %s [in module %s]"),
25440 sect_offset_str (sect_off
),
25441 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25443 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25445 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25449 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25450 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
25451 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25452 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25453 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25458 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25460 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25461 : per_cu (per_cu_
),
25464 checked_producer (0),
25465 producer_is_gxx_lt_4_6 (0),
25466 producer_is_gcc_lt_4_3 (0),
25467 producer_is_icc_lt_14 (0),
25468 processing_has_namespace_info (0)
25473 /* Destroy a dwarf2_cu. */
25475 dwarf2_cu::~dwarf2_cu ()
25480 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25483 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25484 enum language pretend_language
)
25486 struct attribute
*attr
;
25488 /* Set the language we're debugging. */
25489 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25491 set_cu_language (DW_UNSND (attr
), cu
);
25494 cu
->language
= pretend_language
;
25495 cu
->language_defn
= language_def (cu
->language
);
25498 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25501 /* Free all cached compilation units. */
25504 free_cached_comp_units (void *data
)
25506 struct dwarf2_per_objfile
*dwarf2_per_objfile
25507 = (struct dwarf2_per_objfile
*) data
;
25509 dwarf2_per_objfile
->free_cached_comp_units ();
25512 /* Increase the age counter on each cached compilation unit, and free
25513 any that are too old. */
25516 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25518 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25520 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25521 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25522 while (per_cu
!= NULL
)
25524 per_cu
->cu
->last_used
++;
25525 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25526 dwarf2_mark (per_cu
->cu
);
25527 per_cu
= per_cu
->cu
->read_in_chain
;
25530 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25531 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25532 while (per_cu
!= NULL
)
25534 struct dwarf2_per_cu_data
*next_cu
;
25536 next_cu
= per_cu
->cu
->read_in_chain
;
25538 if (!per_cu
->cu
->mark
)
25541 *last_chain
= next_cu
;
25544 last_chain
= &per_cu
->cu
->read_in_chain
;
25550 /* Remove a single compilation unit from the cache. */
25553 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25555 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25556 struct dwarf2_per_objfile
*dwarf2_per_objfile
25557 = target_per_cu
->dwarf2_per_objfile
;
25559 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25560 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25561 while (per_cu
!= NULL
)
25563 struct dwarf2_per_cu_data
*next_cu
;
25565 next_cu
= per_cu
->cu
->read_in_chain
;
25567 if (per_cu
== target_per_cu
)
25571 *last_chain
= next_cu
;
25575 last_chain
= &per_cu
->cu
->read_in_chain
;
25581 /* Release all extra memory associated with OBJFILE. */
25584 dwarf2_free_objfile (struct objfile
*objfile
)
25586 struct dwarf2_per_objfile
*dwarf2_per_objfile
25587 = get_dwarf2_per_objfile (objfile
);
25589 delete dwarf2_per_objfile
;
25592 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25593 We store these in a hash table separate from the DIEs, and preserve them
25594 when the DIEs are flushed out of cache.
25596 The CU "per_cu" pointer is needed because offset alone is not enough to
25597 uniquely identify the type. A file may have multiple .debug_types sections,
25598 or the type may come from a DWO file. Furthermore, while it's more logical
25599 to use per_cu->section+offset, with Fission the section with the data is in
25600 the DWO file but we don't know that section at the point we need it.
25601 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25602 because we can enter the lookup routine, get_die_type_at_offset, from
25603 outside this file, and thus won't necessarily have PER_CU->cu.
25604 Fortunately, PER_CU is stable for the life of the objfile. */
25606 struct dwarf2_per_cu_offset_and_type
25608 const struct dwarf2_per_cu_data
*per_cu
;
25609 sect_offset sect_off
;
25613 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25616 per_cu_offset_and_type_hash (const void *item
)
25618 const struct dwarf2_per_cu_offset_and_type
*ofs
25619 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25621 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25624 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25627 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25629 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25630 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25631 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25632 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25634 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25635 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25638 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25639 table if necessary. For convenience, return TYPE.
25641 The DIEs reading must have careful ordering to:
25642 * Not cause infite loops trying to read in DIEs as a prerequisite for
25643 reading current DIE.
25644 * Not trying to dereference contents of still incompletely read in types
25645 while reading in other DIEs.
25646 * Enable referencing still incompletely read in types just by a pointer to
25647 the type without accessing its fields.
25649 Therefore caller should follow these rules:
25650 * Try to fetch any prerequisite types we may need to build this DIE type
25651 before building the type and calling set_die_type.
25652 * After building type call set_die_type for current DIE as soon as
25653 possible before fetching more types to complete the current type.
25654 * Make the type as complete as possible before fetching more types. */
25656 static struct type
*
25657 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25659 struct dwarf2_per_objfile
*dwarf2_per_objfile
25660 = cu
->per_cu
->dwarf2_per_objfile
;
25661 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25662 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25663 struct attribute
*attr
;
25664 struct dynamic_prop prop
;
25666 /* For Ada types, make sure that the gnat-specific data is always
25667 initialized (if not already set). There are a few types where
25668 we should not be doing so, because the type-specific area is
25669 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25670 where the type-specific area is used to store the floatformat).
25671 But this is not a problem, because the gnat-specific information
25672 is actually not needed for these types. */
25673 if (need_gnat_info (cu
)
25674 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25675 && TYPE_CODE (type
) != TYPE_CODE_FLT
25676 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25677 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25678 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25679 && !HAVE_GNAT_AUX_INFO (type
))
25680 INIT_GNAT_SPECIFIC (type
);
25682 /* Read DW_AT_allocated and set in type. */
25683 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25684 if (attr_form_is_block (attr
))
25686 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25687 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25689 else if (attr
!= NULL
)
25691 complaint (&symfile_complaints
,
25692 _("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25693 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25694 sect_offset_str (die
->sect_off
));
25697 /* Read DW_AT_associated and set in type. */
25698 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25699 if (attr_form_is_block (attr
))
25701 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25702 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25704 else if (attr
!= NULL
)
25706 complaint (&symfile_complaints
,
25707 _("DW_AT_associated has the wrong form (%s) at DIE %s"),
25708 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25709 sect_offset_str (die
->sect_off
));
25712 /* Read DW_AT_data_location and set in type. */
25713 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25714 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
))
25715 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25717 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25719 dwarf2_per_objfile
->die_type_hash
=
25720 htab_create_alloc_ex (127,
25721 per_cu_offset_and_type_hash
,
25722 per_cu_offset_and_type_eq
,
25724 &objfile
->objfile_obstack
,
25725 hashtab_obstack_allocate
,
25726 dummy_obstack_deallocate
);
25729 ofs
.per_cu
= cu
->per_cu
;
25730 ofs
.sect_off
= die
->sect_off
;
25732 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25733 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25735 complaint (&symfile_complaints
,
25736 _("A problem internal to GDB: DIE %s has type already set"),
25737 sect_offset_str (die
->sect_off
));
25738 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25739 struct dwarf2_per_cu_offset_and_type
);
25744 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25745 or return NULL if the die does not have a saved type. */
25747 static struct type
*
25748 get_die_type_at_offset (sect_offset sect_off
,
25749 struct dwarf2_per_cu_data
*per_cu
)
25751 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25752 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25754 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25757 ofs
.per_cu
= per_cu
;
25758 ofs
.sect_off
= sect_off
;
25759 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25760 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25767 /* Look up the type for DIE in CU in die_type_hash,
25768 or return NULL if DIE does not have a saved type. */
25770 static struct type
*
25771 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25773 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25776 /* Add a dependence relationship from CU to REF_PER_CU. */
25779 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25780 struct dwarf2_per_cu_data
*ref_per_cu
)
25784 if (cu
->dependencies
== NULL
)
25786 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25787 NULL
, &cu
->comp_unit_obstack
,
25788 hashtab_obstack_allocate
,
25789 dummy_obstack_deallocate
);
25791 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25793 *slot
= ref_per_cu
;
25796 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25797 Set the mark field in every compilation unit in the
25798 cache that we must keep because we are keeping CU. */
25801 dwarf2_mark_helper (void **slot
, void *data
)
25803 struct dwarf2_per_cu_data
*per_cu
;
25805 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25807 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25808 reading of the chain. As such dependencies remain valid it is not much
25809 useful to track and undo them during QUIT cleanups. */
25810 if (per_cu
->cu
== NULL
)
25813 if (per_cu
->cu
->mark
)
25815 per_cu
->cu
->mark
= 1;
25817 if (per_cu
->cu
->dependencies
!= NULL
)
25818 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25823 /* Set the mark field in CU and in every other compilation unit in the
25824 cache that we must keep because we are keeping CU. */
25827 dwarf2_mark (struct dwarf2_cu
*cu
)
25832 if (cu
->dependencies
!= NULL
)
25833 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25837 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25841 per_cu
->cu
->mark
= 0;
25842 per_cu
= per_cu
->cu
->read_in_chain
;
25846 /* Trivial hash function for partial_die_info: the hash value of a DIE
25847 is its offset in .debug_info for this objfile. */
25850 partial_die_hash (const void *item
)
25852 const struct partial_die_info
*part_die
25853 = (const struct partial_die_info
*) item
;
25855 return to_underlying (part_die
->sect_off
);
25858 /* Trivial comparison function for partial_die_info structures: two DIEs
25859 are equal if they have the same offset. */
25862 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25864 const struct partial_die_info
*part_die_lhs
25865 = (const struct partial_die_info
*) item_lhs
;
25866 const struct partial_die_info
*part_die_rhs
25867 = (const struct partial_die_info
*) item_rhs
;
25869 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25872 static struct cmd_list_element
*set_dwarf_cmdlist
;
25873 static struct cmd_list_element
*show_dwarf_cmdlist
;
25876 set_dwarf_cmd (const char *args
, int from_tty
)
25878 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25883 show_dwarf_cmd (const char *args
, int from_tty
)
25885 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25888 /* The "save gdb-index" command. */
25890 /* Write SIZE bytes from the buffer pointed to by DATA to FILE, with
25894 file_write (FILE *file
, const void *data
, size_t size
)
25896 if (fwrite (data
, 1, size
, file
) != size
)
25897 error (_("couldn't data write to file"));
25900 /* Write the contents of VEC to FILE, with error checking. */
25902 template<typename Elem
, typename Alloc
>
25904 file_write (FILE *file
, const std::vector
<Elem
, Alloc
> &vec
)
25906 file_write (file
, vec
.data (), vec
.size () * sizeof (vec
[0]));
25909 /* In-memory buffer to prepare data to be written later to a file. */
25913 /* Copy DATA to the end of the buffer. */
25914 template<typename T
>
25915 void append_data (const T
&data
)
25917 std::copy (reinterpret_cast<const gdb_byte
*> (&data
),
25918 reinterpret_cast<const gdb_byte
*> (&data
+ 1),
25919 grow (sizeof (data
)));
25922 /* Copy CSTR (a zero-terminated string) to the end of buffer. The
25923 terminating zero is appended too. */
25924 void append_cstr0 (const char *cstr
)
25926 const size_t size
= strlen (cstr
) + 1;
25927 std::copy (cstr
, cstr
+ size
, grow (size
));
25930 /* Store INPUT as ULEB128 to the end of buffer. */
25931 void append_unsigned_leb128 (ULONGEST input
)
25935 gdb_byte output
= input
& 0x7f;
25939 append_data (output
);
25945 /* Accept a host-format integer in VAL and append it to the buffer
25946 as a target-format integer which is LEN bytes long. */
25947 void append_uint (size_t len
, bfd_endian byte_order
, ULONGEST val
)
25949 ::store_unsigned_integer (grow (len
), len
, byte_order
, val
);
25952 /* Return the size of the buffer. */
25953 size_t size () const
25955 return m_vec
.size ();
25958 /* Return true iff the buffer is empty. */
25959 bool empty () const
25961 return m_vec
.empty ();
25964 /* Write the buffer to FILE. */
25965 void file_write (FILE *file
) const
25967 ::file_write (file
, m_vec
);
25971 /* Grow SIZE bytes at the end of the buffer. Returns a pointer to
25972 the start of the new block. */
25973 gdb_byte
*grow (size_t size
)
25975 m_vec
.resize (m_vec
.size () + size
);
25976 return &*m_vec
.end () - size
;
25979 gdb::byte_vector m_vec
;
25982 /* An entry in the symbol table. */
25983 struct symtab_index_entry
25985 /* The name of the symbol. */
25987 /* The offset of the name in the constant pool. */
25988 offset_type index_offset
;
25989 /* A sorted vector of the indices of all the CUs that hold an object
25991 std::vector
<offset_type
> cu_indices
;
25994 /* The symbol table. This is a power-of-2-sized hash table. */
25995 struct mapped_symtab
25999 data
.resize (1024);
26002 offset_type n_elements
= 0;
26003 std::vector
<symtab_index_entry
> data
;
26006 /* Find a slot in SYMTAB for the symbol NAME. Returns a reference to
26009 Function is used only during write_hash_table so no index format backward
26010 compatibility is needed. */
26012 static symtab_index_entry
&
26013 find_slot (struct mapped_symtab
*symtab
, const char *name
)
26015 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
26017 index
= hash
& (symtab
->data
.size () - 1);
26018 step
= ((hash
* 17) & (symtab
->data
.size () - 1)) | 1;
26022 if (symtab
->data
[index
].name
== NULL
26023 || strcmp (name
, symtab
->data
[index
].name
) == 0)
26024 return symtab
->data
[index
];
26025 index
= (index
+ step
) & (symtab
->data
.size () - 1);
26029 /* Expand SYMTAB's hash table. */
26032 hash_expand (struct mapped_symtab
*symtab
)
26034 auto old_entries
= std::move (symtab
->data
);
26036 symtab
->data
.clear ();
26037 symtab
->data
.resize (old_entries
.size () * 2);
26039 for (auto &it
: old_entries
)
26040 if (it
.name
!= NULL
)
26042 auto &ref
= find_slot (symtab
, it
.name
);
26043 ref
= std::move (it
);
26047 /* Add an entry to SYMTAB. NAME is the name of the symbol.
26048 CU_INDEX is the index of the CU in which the symbol appears.
26049 IS_STATIC is one if the symbol is static, otherwise zero (global). */
26052 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
26053 int is_static
, gdb_index_symbol_kind kind
,
26054 offset_type cu_index
)
26056 offset_type cu_index_and_attrs
;
26058 ++symtab
->n_elements
;
26059 if (4 * symtab
->n_elements
/ 3 >= symtab
->data
.size ())
26060 hash_expand (symtab
);
26062 symtab_index_entry
&slot
= find_slot (symtab
, name
);
26063 if (slot
.name
== NULL
)
26066 /* index_offset is set later. */
26069 cu_index_and_attrs
= 0;
26070 DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs
, cu_index
);
26071 DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs
, is_static
);
26072 DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs
, kind
);
26074 /* We don't want to record an index value twice as we want to avoid the
26076 We process all global symbols and then all static symbols
26077 (which would allow us to avoid the duplication by only having to check
26078 the last entry pushed), but a symbol could have multiple kinds in one CU.
26079 To keep things simple we don't worry about the duplication here and
26080 sort and uniqufy the list after we've processed all symbols. */
26081 slot
.cu_indices
.push_back (cu_index_and_attrs
);
26084 /* Sort and remove duplicates of all symbols' cu_indices lists. */
26087 uniquify_cu_indices (struct mapped_symtab
*symtab
)
26089 for (auto &entry
: symtab
->data
)
26091 if (entry
.name
!= NULL
&& !entry
.cu_indices
.empty ())
26093 auto &cu_indices
= entry
.cu_indices
;
26094 std::sort (cu_indices
.begin (), cu_indices
.end ());
26095 auto from
= std::unique (cu_indices
.begin (), cu_indices
.end ());
26096 cu_indices
.erase (from
, cu_indices
.end ());
26101 /* A form of 'const char *' suitable for container keys. Only the
26102 pointer is stored. The strings themselves are compared, not the
26107 c_str_view (const char *cstr
)
26111 bool operator== (const c_str_view
&other
) const
26113 return strcmp (m_cstr
, other
.m_cstr
) == 0;
26116 /* Return the underlying C string. Note, the returned string is
26117 only a reference with lifetime of this object. */
26118 const char *c_str () const
26124 friend class c_str_view_hasher
;
26125 const char *const m_cstr
;
26128 /* A std::unordered_map::hasher for c_str_view that uses the right
26129 hash function for strings in a mapped index. */
26130 class c_str_view_hasher
26133 size_t operator () (const c_str_view
&x
) const
26135 return mapped_index_string_hash (INT_MAX
, x
.m_cstr
);
26139 /* A std::unordered_map::hasher for std::vector<>. */
26140 template<typename T
>
26141 class vector_hasher
26144 size_t operator () (const std::vector
<T
> &key
) const
26146 return iterative_hash (key
.data (),
26147 sizeof (key
.front ()) * key
.size (), 0);
26151 /* Write the mapped hash table SYMTAB to the data buffer OUTPUT, with
26152 constant pool entries going into the data buffer CPOOL. */
26155 write_hash_table (mapped_symtab
*symtab
, data_buf
&output
, data_buf
&cpool
)
26158 /* Elements are sorted vectors of the indices of all the CUs that
26159 hold an object of this name. */
26160 std::unordered_map
<std::vector
<offset_type
>, offset_type
,
26161 vector_hasher
<offset_type
>>
26164 /* We add all the index vectors to the constant pool first, to
26165 ensure alignment is ok. */
26166 for (symtab_index_entry
&entry
: symtab
->data
)
26168 if (entry
.name
== NULL
)
26170 gdb_assert (entry
.index_offset
== 0);
26172 /* Finding before inserting is faster than always trying to
26173 insert, because inserting always allocates a node, does the
26174 lookup, and then destroys the new node if another node
26175 already had the same key. C++17 try_emplace will avoid
26178 = symbol_hash_table
.find (entry
.cu_indices
);
26179 if (found
!= symbol_hash_table
.end ())
26181 entry
.index_offset
= found
->second
;
26185 symbol_hash_table
.emplace (entry
.cu_indices
, cpool
.size ());
26186 entry
.index_offset
= cpool
.size ();
26187 cpool
.append_data (MAYBE_SWAP (entry
.cu_indices
.size ()));
26188 for (const auto index
: entry
.cu_indices
)
26189 cpool
.append_data (MAYBE_SWAP (index
));
26193 /* Now write out the hash table. */
26194 std::unordered_map
<c_str_view
, offset_type
, c_str_view_hasher
> str_table
;
26195 for (const auto &entry
: symtab
->data
)
26197 offset_type str_off
, vec_off
;
26199 if (entry
.name
!= NULL
)
26201 const auto insertpair
= str_table
.emplace (entry
.name
, cpool
.size ());
26202 if (insertpair
.second
)
26203 cpool
.append_cstr0 (entry
.name
);
26204 str_off
= insertpair
.first
->second
;
26205 vec_off
= entry
.index_offset
;
26209 /* While 0 is a valid constant pool index, it is not valid
26210 to have 0 for both offsets. */
26215 output
.append_data (MAYBE_SWAP (str_off
));
26216 output
.append_data (MAYBE_SWAP (vec_off
));
26220 typedef std::unordered_map
<partial_symtab
*, unsigned int> psym_index_map
;
26222 /* Helper struct for building the address table. */
26223 struct addrmap_index_data
26225 addrmap_index_data (data_buf
&addr_vec_
, psym_index_map
&cu_index_htab_
)
26226 : addr_vec (addr_vec_
), cu_index_htab (cu_index_htab_
)
26229 struct objfile
*objfile
;
26230 data_buf
&addr_vec
;
26231 psym_index_map
&cu_index_htab
;
26233 /* Non-zero if the previous_* fields are valid.
26234 We can't write an entry until we see the next entry (since it is only then
26235 that we know the end of the entry). */
26236 int previous_valid
;
26237 /* Index of the CU in the table of all CUs in the index file. */
26238 unsigned int previous_cu_index
;
26239 /* Start address of the CU. */
26240 CORE_ADDR previous_cu_start
;
26243 /* Write an address entry to ADDR_VEC. */
26246 add_address_entry (struct objfile
*objfile
, data_buf
&addr_vec
,
26247 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
26249 CORE_ADDR baseaddr
;
26251 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
26253 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
26254 addr_vec
.append_uint (8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
26255 addr_vec
.append_data (MAYBE_SWAP (cu_index
));
26258 /* Worker function for traversing an addrmap to build the address table. */
26261 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
26263 struct addrmap_index_data
*data
= (struct addrmap_index_data
*) datap
;
26264 struct partial_symtab
*pst
= (struct partial_symtab
*) obj
;
26266 if (data
->previous_valid
)
26267 add_address_entry (data
->objfile
, data
->addr_vec
,
26268 data
->previous_cu_start
, start_addr
,
26269 data
->previous_cu_index
);
26271 data
->previous_cu_start
= start_addr
;
26274 const auto it
= data
->cu_index_htab
.find (pst
);
26275 gdb_assert (it
!= data
->cu_index_htab
.cend ());
26276 data
->previous_cu_index
= it
->second
;
26277 data
->previous_valid
= 1;
26280 data
->previous_valid
= 0;
26285 /* Write OBJFILE's address map to ADDR_VEC.
26286 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
26287 in the index file. */
26290 write_address_map (struct objfile
*objfile
, data_buf
&addr_vec
,
26291 psym_index_map
&cu_index_htab
)
26293 struct addrmap_index_data
addrmap_index_data (addr_vec
, cu_index_htab
);
26295 /* When writing the address table, we have to cope with the fact that
26296 the addrmap iterator only provides the start of a region; we have to
26297 wait until the next invocation to get the start of the next region. */
26299 addrmap_index_data
.objfile
= objfile
;
26300 addrmap_index_data
.previous_valid
= 0;
26302 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
26303 &addrmap_index_data
);
26305 /* It's highly unlikely the last entry (end address = 0xff...ff)
26306 is valid, but we should still handle it.
26307 The end address is recorded as the start of the next region, but that
26308 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
26310 if (addrmap_index_data
.previous_valid
)
26311 add_address_entry (objfile
, addr_vec
,
26312 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
26313 addrmap_index_data
.previous_cu_index
);
26316 /* Return the symbol kind of PSYM. */
26318 static gdb_index_symbol_kind
26319 symbol_kind (struct partial_symbol
*psym
)
26321 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26322 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26330 return GDB_INDEX_SYMBOL_KIND_FUNCTION
;
26332 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26334 case LOC_CONST_BYTES
:
26335 case LOC_OPTIMIZED_OUT
:
26337 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26339 /* Note: It's currently impossible to recognize psyms as enum values
26340 short of reading the type info. For now punt. */
26341 return GDB_INDEX_SYMBOL_KIND_VARIABLE
;
26343 /* There are other LOC_FOO values that one might want to classify
26344 as variables, but dwarf2read.c doesn't currently use them. */
26345 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26347 case STRUCT_DOMAIN
:
26348 return GDB_INDEX_SYMBOL_KIND_TYPE
;
26350 return GDB_INDEX_SYMBOL_KIND_OTHER
;
26354 /* Add a list of partial symbols to SYMTAB. */
26357 write_psymbols (struct mapped_symtab
*symtab
,
26358 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26359 struct partial_symbol
**psymp
,
26361 offset_type cu_index
,
26364 for (; count
-- > 0; ++psymp
)
26366 struct partial_symbol
*psym
= *psymp
;
26368 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
26369 error (_("Ada is not currently supported by the index"));
26371 /* Only add a given psymbol once. */
26372 if (psyms_seen
.insert (psym
).second
)
26374 gdb_index_symbol_kind kind
= symbol_kind (psym
);
26376 add_index_entry (symtab
, SYMBOL_SEARCH_NAME (psym
),
26377 is_static
, kind
, cu_index
);
26382 /* A helper struct used when iterating over debug_types. */
26383 struct signatured_type_index_data
26385 signatured_type_index_data (data_buf
&types_list_
,
26386 std::unordered_set
<partial_symbol
*> &psyms_seen_
)
26387 : types_list (types_list_
), psyms_seen (psyms_seen_
)
26390 struct objfile
*objfile
;
26391 struct mapped_symtab
*symtab
;
26392 data_buf
&types_list
;
26393 std::unordered_set
<partial_symbol
*> &psyms_seen
;
26397 /* A helper function that writes a single signatured_type to an
26401 write_one_signatured_type (void **slot
, void *d
)
26403 struct signatured_type_index_data
*info
26404 = (struct signatured_type_index_data
*) d
;
26405 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26406 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
26408 write_psymbols (info
->symtab
,
26410 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
26411 psymtab
->n_global_syms
, info
->cu_index
,
26413 write_psymbols (info
->symtab
,
26415 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
26416 psymtab
->n_static_syms
, info
->cu_index
,
26419 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26420 to_underlying (entry
->per_cu
.sect_off
));
26421 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
26422 to_underlying (entry
->type_offset_in_tu
));
26423 info
->types_list
.append_uint (8, BFD_ENDIAN_LITTLE
, entry
->signature
);
26430 /* Recurse into all "included" dependencies and count their symbols as
26431 if they appeared in this psymtab. */
26434 recursively_count_psymbols (struct partial_symtab
*psymtab
,
26435 size_t &psyms_seen
)
26437 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26438 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26439 recursively_count_psymbols (psymtab
->dependencies
[i
],
26442 psyms_seen
+= psymtab
->n_global_syms
;
26443 psyms_seen
+= psymtab
->n_static_syms
;
26446 /* Recurse into all "included" dependencies and write their symbols as
26447 if they appeared in this psymtab. */
26450 recursively_write_psymbols (struct objfile
*objfile
,
26451 struct partial_symtab
*psymtab
,
26452 struct mapped_symtab
*symtab
,
26453 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26454 offset_type cu_index
)
26458 for (i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26459 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26460 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26461 symtab
, psyms_seen
, cu_index
);
26463 write_psymbols (symtab
,
26465 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26466 psymtab
->n_global_syms
, cu_index
,
26468 write_psymbols (symtab
,
26470 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26471 psymtab
->n_static_syms
, cu_index
,
26475 /* DWARF-5 .debug_names builder. */
26479 debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bool is_dwarf64
,
26480 bfd_endian dwarf5_byte_order
)
26481 : m_dwarf5_byte_order (dwarf5_byte_order
),
26482 m_dwarf32 (dwarf5_byte_order
),
26483 m_dwarf64 (dwarf5_byte_order
),
26484 m_dwarf (is_dwarf64
26485 ? static_cast<dwarf
&> (m_dwarf64
)
26486 : static_cast<dwarf
&> (m_dwarf32
)),
26487 m_name_table_string_offs (m_dwarf
.name_table_string_offs
),
26488 m_name_table_entry_offs (m_dwarf
.name_table_entry_offs
),
26489 m_debugstrlookup (dwarf2_per_objfile
)
26492 int dwarf5_offset_size () const
26494 const bool dwarf5_is_dwarf64
= &m_dwarf
== &m_dwarf64
;
26495 return dwarf5_is_dwarf64
? 8 : 4;
26498 /* Is this symbol from DW_TAG_compile_unit or DW_TAG_type_unit? */
26499 enum class unit_kind
{ cu
, tu
};
26501 /* Insert one symbol. */
26502 void insert (const partial_symbol
*psym
, int cu_index
, bool is_static
,
26505 const int dwarf_tag
= psymbol_tag (psym
);
26506 if (dwarf_tag
== 0)
26508 const char *const name
= SYMBOL_SEARCH_NAME (psym
);
26509 const auto insertpair
26510 = m_name_to_value_set
.emplace (c_str_view (name
),
26511 std::set
<symbol_value
> ());
26512 std::set
<symbol_value
> &value_set
= insertpair
.first
->second
;
26513 value_set
.emplace (symbol_value (dwarf_tag
, cu_index
, is_static
, kind
));
26516 /* Build all the tables. All symbols must be already inserted.
26517 This function does not call file_write, caller has to do it
26521 /* Verify the build method has not be called twice. */
26522 gdb_assert (m_abbrev_table
.empty ());
26523 const size_t name_count
= m_name_to_value_set
.size ();
26524 m_bucket_table
.resize
26525 (std::pow (2, std::ceil (std::log2 (name_count
* 4 / 3))));
26526 m_hash_table
.reserve (name_count
);
26527 m_name_table_string_offs
.reserve (name_count
);
26528 m_name_table_entry_offs
.reserve (name_count
);
26530 /* Map each hash of symbol to its name and value. */
26531 struct hash_it_pair
26534 decltype (m_name_to_value_set
)::const_iterator it
;
26536 std::vector
<std::forward_list
<hash_it_pair
>> bucket_hash
;
26537 bucket_hash
.resize (m_bucket_table
.size ());
26538 for (decltype (m_name_to_value_set
)::const_iterator it
26539 = m_name_to_value_set
.cbegin ();
26540 it
!= m_name_to_value_set
.cend ();
26543 const char *const name
= it
->first
.c_str ();
26544 const uint32_t hash
= dwarf5_djb_hash (name
);
26545 hash_it_pair hashitpair
;
26546 hashitpair
.hash
= hash
;
26547 hashitpair
.it
= it
;
26548 auto &slot
= bucket_hash
[hash
% bucket_hash
.size()];
26549 slot
.push_front (std::move (hashitpair
));
26551 for (size_t bucket_ix
= 0; bucket_ix
< bucket_hash
.size (); ++bucket_ix
)
26553 const std::forward_list
<hash_it_pair
> &hashitlist
26554 = bucket_hash
[bucket_ix
];
26555 if (hashitlist
.empty ())
26557 uint32_t &bucket_slot
= m_bucket_table
[bucket_ix
];
26558 /* The hashes array is indexed starting at 1. */
26559 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&bucket_slot
),
26560 sizeof (bucket_slot
), m_dwarf5_byte_order
,
26561 m_hash_table
.size () + 1);
26562 for (const hash_it_pair
&hashitpair
: hashitlist
)
26564 m_hash_table
.push_back (0);
26565 store_unsigned_integer (reinterpret_cast<gdb_byte
*>
26566 (&m_hash_table
.back ()),
26567 sizeof (m_hash_table
.back ()),
26568 m_dwarf5_byte_order
, hashitpair
.hash
);
26569 const c_str_view
&name
= hashitpair
.it
->first
;
26570 const std::set
<symbol_value
> &value_set
= hashitpair
.it
->second
;
26571 m_name_table_string_offs
.push_back_reorder
26572 (m_debugstrlookup
.lookup (name
.c_str ()));
26573 m_name_table_entry_offs
.push_back_reorder (m_entry_pool
.size ());
26574 gdb_assert (!value_set
.empty ());
26575 for (const symbol_value
&value
: value_set
)
26577 int &idx
= m_indexkey_to_idx
[index_key (value
.dwarf_tag
,
26582 idx
= m_idx_next
++;
26583 m_abbrev_table
.append_unsigned_leb128 (idx
);
26584 m_abbrev_table
.append_unsigned_leb128 (value
.dwarf_tag
);
26585 m_abbrev_table
.append_unsigned_leb128
26586 (value
.kind
== unit_kind::cu
? DW_IDX_compile_unit
26587 : DW_IDX_type_unit
);
26588 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_udata
);
26589 m_abbrev_table
.append_unsigned_leb128 (value
.is_static
26590 ? DW_IDX_GNU_internal
26591 : DW_IDX_GNU_external
);
26592 m_abbrev_table
.append_unsigned_leb128 (DW_FORM_flag_present
);
26594 /* Terminate attributes list. */
26595 m_abbrev_table
.append_unsigned_leb128 (0);
26596 m_abbrev_table
.append_unsigned_leb128 (0);
26599 m_entry_pool
.append_unsigned_leb128 (idx
);
26600 m_entry_pool
.append_unsigned_leb128 (value
.cu_index
);
26603 /* Terminate the list of CUs. */
26604 m_entry_pool
.append_unsigned_leb128 (0);
26607 gdb_assert (m_hash_table
.size () == name_count
);
26609 /* Terminate tags list. */
26610 m_abbrev_table
.append_unsigned_leb128 (0);
26613 /* Return .debug_names bucket count. This must be called only after
26614 calling the build method. */
26615 uint32_t bucket_count () const
26617 /* Verify the build method has been already called. */
26618 gdb_assert (!m_abbrev_table
.empty ());
26619 const uint32_t retval
= m_bucket_table
.size ();
26621 /* Check for overflow. */
26622 gdb_assert (retval
== m_bucket_table
.size ());
26626 /* Return .debug_names names count. This must be called only after
26627 calling the build method. */
26628 uint32_t name_count () const
26630 /* Verify the build method has been already called. */
26631 gdb_assert (!m_abbrev_table
.empty ());
26632 const uint32_t retval
= m_hash_table
.size ();
26634 /* Check for overflow. */
26635 gdb_assert (retval
== m_hash_table
.size ());
26639 /* Return number of bytes of .debug_names abbreviation table. This
26640 must be called only after calling the build method. */
26641 uint32_t abbrev_table_bytes () const
26643 gdb_assert (!m_abbrev_table
.empty ());
26644 return m_abbrev_table
.size ();
26647 /* Recurse into all "included" dependencies and store their symbols
26648 as if they appeared in this psymtab. */
26649 void recursively_write_psymbols
26650 (struct objfile
*objfile
,
26651 struct partial_symtab
*psymtab
,
26652 std::unordered_set
<partial_symbol
*> &psyms_seen
,
26655 for (int i
= 0; i
< psymtab
->number_of_dependencies
; ++i
)
26656 if (psymtab
->dependencies
[i
]->user
!= NULL
)
26657 recursively_write_psymbols (objfile
, psymtab
->dependencies
[i
],
26658 psyms_seen
, cu_index
);
26660 write_psymbols (psyms_seen
,
26661 &objfile
->global_psymbols
[psymtab
->globals_offset
],
26662 psymtab
->n_global_syms
, cu_index
, false, unit_kind::cu
);
26663 write_psymbols (psyms_seen
,
26664 &objfile
->static_psymbols
[psymtab
->statics_offset
],
26665 psymtab
->n_static_syms
, cu_index
, true, unit_kind::cu
);
26668 /* Return number of bytes the .debug_names section will have. This
26669 must be called only after calling the build method. */
26670 size_t bytes () const
26672 /* Verify the build method has been already called. */
26673 gdb_assert (!m_abbrev_table
.empty ());
26674 size_t expected_bytes
= 0;
26675 expected_bytes
+= m_bucket_table
.size () * sizeof (m_bucket_table
[0]);
26676 expected_bytes
+= m_hash_table
.size () * sizeof (m_hash_table
[0]);
26677 expected_bytes
+= m_name_table_string_offs
.bytes ();
26678 expected_bytes
+= m_name_table_entry_offs
.bytes ();
26679 expected_bytes
+= m_abbrev_table
.size ();
26680 expected_bytes
+= m_entry_pool
.size ();
26681 return expected_bytes
;
26684 /* Write .debug_names to FILE_NAMES and .debug_str addition to
26685 FILE_STR. This must be called only after calling the build
26687 void file_write (FILE *file_names
, FILE *file_str
) const
26689 /* Verify the build method has been already called. */
26690 gdb_assert (!m_abbrev_table
.empty ());
26691 ::file_write (file_names
, m_bucket_table
);
26692 ::file_write (file_names
, m_hash_table
);
26693 m_name_table_string_offs
.file_write (file_names
);
26694 m_name_table_entry_offs
.file_write (file_names
);
26695 m_abbrev_table
.file_write (file_names
);
26696 m_entry_pool
.file_write (file_names
);
26697 m_debugstrlookup
.file_write (file_str
);
26700 /* A helper user data for write_one_signatured_type. */
26701 class write_one_signatured_type_data
26704 write_one_signatured_type_data (debug_names
&nametable_
,
26705 signatured_type_index_data
&&info_
)
26706 : nametable (nametable_
), info (std::move (info_
))
26708 debug_names
&nametable
;
26709 struct signatured_type_index_data info
;
26712 /* A helper function to pass write_one_signatured_type to
26713 htab_traverse_noresize. */
26715 write_one_signatured_type (void **slot
, void *d
)
26717 write_one_signatured_type_data
*data
= (write_one_signatured_type_data
*) d
;
26718 struct signatured_type_index_data
*info
= &data
->info
;
26719 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
26721 data
->nametable
.write_one_signatured_type (entry
, info
);
26728 /* Storage for symbol names mapping them to their .debug_str section
26730 class debug_str_lookup
26734 /* Object costructor to be called for current DWARF2_PER_OBJFILE.
26735 All .debug_str section strings are automatically stored. */
26736 debug_str_lookup (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
26737 : m_abfd (dwarf2_per_objfile
->objfile
->obfd
),
26738 m_dwarf2_per_objfile (dwarf2_per_objfile
)
26740 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
26741 &dwarf2_per_objfile
->str
);
26742 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
26744 for (const gdb_byte
*data
= dwarf2_per_objfile
->str
.buffer
;
26745 data
< (dwarf2_per_objfile
->str
.buffer
26746 + dwarf2_per_objfile
->str
.size
);)
26748 const char *const s
= reinterpret_cast<const char *> (data
);
26749 const auto insertpair
26750 = m_str_table
.emplace (c_str_view (s
),
26751 data
- dwarf2_per_objfile
->str
.buffer
);
26752 if (!insertpair
.second
)
26753 complaint (&symfile_complaints
,
26754 _("Duplicate string \"%s\" in "
26755 ".debug_str section [in module %s]"),
26756 s
, bfd_get_filename (m_abfd
));
26757 data
+= strlen (s
) + 1;
26761 /* Return offset of symbol name S in the .debug_str section. Add
26762 such symbol to the section's end if it does not exist there
26764 size_t lookup (const char *s
)
26766 const auto it
= m_str_table
.find (c_str_view (s
));
26767 if (it
!= m_str_table
.end ())
26769 const size_t offset
= (m_dwarf2_per_objfile
->str
.size
26770 + m_str_add_buf
.size ());
26771 m_str_table
.emplace (c_str_view (s
), offset
);
26772 m_str_add_buf
.append_cstr0 (s
);
26776 /* Append the end of the .debug_str section to FILE. */
26777 void file_write (FILE *file
) const
26779 m_str_add_buf
.file_write (file
);
26783 std::unordered_map
<c_str_view
, size_t, c_str_view_hasher
> m_str_table
;
26785 struct dwarf2_per_objfile
*m_dwarf2_per_objfile
;
26787 /* Data to add at the end of .debug_str for new needed symbol names. */
26788 data_buf m_str_add_buf
;
26791 /* Container to map used DWARF tags to their .debug_names abbreviation
26796 index_key (int dwarf_tag_
, bool is_static_
, unit_kind kind_
)
26797 : dwarf_tag (dwarf_tag_
), is_static (is_static_
), kind (kind_
)
26802 operator== (const index_key
&other
) const
26804 return (dwarf_tag
== other
.dwarf_tag
&& is_static
== other
.is_static
26805 && kind
== other
.kind
);
26808 const int dwarf_tag
;
26809 const bool is_static
;
26810 const unit_kind kind
;
26813 /* Provide std::unordered_map::hasher for index_key. */
26814 class index_key_hasher
26818 operator () (const index_key
&key
) const
26820 return (std::hash
<int>() (key
.dwarf_tag
) << 1) | key
.is_static
;
26824 /* Parameters of one symbol entry. */
26828 const int dwarf_tag
, cu_index
;
26829 const bool is_static
;
26830 const unit_kind kind
;
26832 symbol_value (int dwarf_tag_
, int cu_index_
, bool is_static_
,
26834 : dwarf_tag (dwarf_tag_
), cu_index (cu_index_
), is_static (is_static_
),
26839 operator< (const symbol_value
&other
) const
26859 /* Abstract base class to unify DWARF-32 and DWARF-64 name table
26864 const bfd_endian dwarf5_byte_order
;
26866 explicit offset_vec (bfd_endian dwarf5_byte_order_
)
26867 : dwarf5_byte_order (dwarf5_byte_order_
)
26870 /* Call std::vector::reserve for NELEM elements. */
26871 virtual void reserve (size_t nelem
) = 0;
26873 /* Call std::vector::push_back with store_unsigned_integer byte
26874 reordering for ELEM. */
26875 virtual void push_back_reorder (size_t elem
) = 0;
26877 /* Return expected output size in bytes. */
26878 virtual size_t bytes () const = 0;
26880 /* Write name table to FILE. */
26881 virtual void file_write (FILE *file
) const = 0;
26884 /* Template to unify DWARF-32 and DWARF-64 output. */
26885 template<typename OffsetSize
>
26886 class offset_vec_tmpl
: public offset_vec
26889 explicit offset_vec_tmpl (bfd_endian dwarf5_byte_order_
)
26890 : offset_vec (dwarf5_byte_order_
)
26893 /* Implement offset_vec::reserve. */
26894 void reserve (size_t nelem
) override
26896 m_vec
.reserve (nelem
);
26899 /* Implement offset_vec::push_back_reorder. */
26900 void push_back_reorder (size_t elem
) override
26902 m_vec
.push_back (elem
);
26903 /* Check for overflow. */
26904 gdb_assert (m_vec
.back () == elem
);
26905 store_unsigned_integer (reinterpret_cast<gdb_byte
*> (&m_vec
.back ()),
26906 sizeof (m_vec
.back ()), dwarf5_byte_order
, elem
);
26909 /* Implement offset_vec::bytes. */
26910 size_t bytes () const override
26912 return m_vec
.size () * sizeof (m_vec
[0]);
26915 /* Implement offset_vec::file_write. */
26916 void file_write (FILE *file
) const override
26918 ::file_write (file
, m_vec
);
26922 std::vector
<OffsetSize
> m_vec
;
26925 /* Base class to unify DWARF-32 and DWARF-64 .debug_names output
26926 respecting name table width. */
26930 offset_vec
&name_table_string_offs
, &name_table_entry_offs
;
26932 dwarf (offset_vec
&name_table_string_offs_
,
26933 offset_vec
&name_table_entry_offs_
)
26934 : name_table_string_offs (name_table_string_offs_
),
26935 name_table_entry_offs (name_table_entry_offs_
)
26940 /* Template to unify DWARF-32 and DWARF-64 .debug_names output
26941 respecting name table width. */
26942 template<typename OffsetSize
>
26943 class dwarf_tmpl
: public dwarf
26946 explicit dwarf_tmpl (bfd_endian dwarf5_byte_order_
)
26947 : dwarf (m_name_table_string_offs
, m_name_table_entry_offs
),
26948 m_name_table_string_offs (dwarf5_byte_order_
),
26949 m_name_table_entry_offs (dwarf5_byte_order_
)
26953 offset_vec_tmpl
<OffsetSize
> m_name_table_string_offs
;
26954 offset_vec_tmpl
<OffsetSize
> m_name_table_entry_offs
;
26957 /* Try to reconstruct original DWARF tag for given partial_symbol.
26958 This function is not DWARF-5 compliant but it is sufficient for
26959 GDB as a DWARF-5 index consumer. */
26960 static int psymbol_tag (const struct partial_symbol
*psym
)
26962 domain_enum domain
= PSYMBOL_DOMAIN (psym
);
26963 enum address_class aclass
= PSYMBOL_CLASS (psym
);
26971 return DW_TAG_subprogram
;
26973 return DW_TAG_typedef
;
26975 case LOC_CONST_BYTES
:
26976 case LOC_OPTIMIZED_OUT
:
26978 return DW_TAG_variable
;
26980 /* Note: It's currently impossible to recognize psyms as enum values
26981 short of reading the type info. For now punt. */
26982 return DW_TAG_variable
;
26984 /* There are other LOC_FOO values that one might want to classify
26985 as variables, but dwarf2read.c doesn't currently use them. */
26986 return DW_TAG_variable
;
26988 case STRUCT_DOMAIN
:
26989 return DW_TAG_structure_type
;
26995 /* Call insert for all partial symbols and mark them in PSYMS_SEEN. */
26996 void write_psymbols (std::unordered_set
<partial_symbol
*> &psyms_seen
,
26997 struct partial_symbol
**psymp
, int count
, int cu_index
,
26998 bool is_static
, unit_kind kind
)
27000 for (; count
-- > 0; ++psymp
)
27002 struct partial_symbol
*psym
= *psymp
;
27004 if (SYMBOL_LANGUAGE (psym
) == language_ada
)
27005 error (_("Ada is not currently supported by the index"));
27007 /* Only add a given psymbol once. */
27008 if (psyms_seen
.insert (psym
).second
)
27009 insert (psym
, cu_index
, is_static
, kind
);
27013 /* A helper function that writes a single signatured_type
27014 to a debug_names. */
27016 write_one_signatured_type (struct signatured_type
*entry
,
27017 struct signatured_type_index_data
*info
)
27019 struct partial_symtab
*psymtab
= entry
->per_cu
.v
.psymtab
;
27021 write_psymbols (info
->psyms_seen
,
27022 &info
->objfile
->global_psymbols
[psymtab
->globals_offset
],
27023 psymtab
->n_global_syms
, info
->cu_index
, false,
27025 write_psymbols (info
->psyms_seen
,
27026 &info
->objfile
->static_psymbols
[psymtab
->statics_offset
],
27027 psymtab
->n_static_syms
, info
->cu_index
, true,
27030 info
->types_list
.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order
,
27031 to_underlying (entry
->per_cu
.sect_off
));
27036 /* Store value of each symbol. */
27037 std::unordered_map
<c_str_view
, std::set
<symbol_value
>, c_str_view_hasher
>
27038 m_name_to_value_set
;
27040 /* Tables of DWARF-5 .debug_names. They are in object file byte
27042 std::vector
<uint32_t> m_bucket_table
;
27043 std::vector
<uint32_t> m_hash_table
;
27045 const bfd_endian m_dwarf5_byte_order
;
27046 dwarf_tmpl
<uint32_t> m_dwarf32
;
27047 dwarf_tmpl
<uint64_t> m_dwarf64
;
27049 offset_vec
&m_name_table_string_offs
, &m_name_table_entry_offs
;
27050 debug_str_lookup m_debugstrlookup
;
27052 /* Map each used .debug_names abbreviation tag parameter to its
27054 std::unordered_map
<index_key
, int, index_key_hasher
> m_indexkey_to_idx
;
27056 /* Next unused .debug_names abbreviation tag for
27057 m_indexkey_to_idx. */
27058 int m_idx_next
= 1;
27060 /* .debug_names abbreviation table. */
27061 data_buf m_abbrev_table
;
27063 /* .debug_names entry pool. */
27064 data_buf m_entry_pool
;
27067 /* Return iff any of the needed offsets does not fit into 32-bit
27068 .debug_names section. */
27071 check_dwarf64_offsets (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27073 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27075 const dwarf2_per_cu_data
&per_cu
= *dwarf2_per_objfile
->all_comp_units
[i
];
27077 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27080 for (int i
= 0; i
< dwarf2_per_objfile
->n_type_units
; ++i
)
27082 const signatured_type
&sigtype
= *dwarf2_per_objfile
->all_type_units
[i
];
27083 const dwarf2_per_cu_data
&per_cu
= sigtype
.per_cu
;
27085 if (to_underlying (per_cu
.sect_off
) >= (static_cast<uint64_t> (1) << 32))
27091 /* The psyms_seen set is potentially going to be largish (~40k
27092 elements when indexing a -g3 build of GDB itself). Estimate the
27093 number of elements in order to avoid too many rehashes, which
27094 require rebuilding buckets and thus many trips to
27098 psyms_seen_size (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
27100 size_t psyms_count
= 0;
27101 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27103 struct dwarf2_per_cu_data
*per_cu
27104 = dwarf2_per_objfile
->all_comp_units
[i
];
27105 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27107 if (psymtab
!= NULL
&& psymtab
->user
== NULL
)
27108 recursively_count_psymbols (psymtab
, psyms_count
);
27110 /* Generating an index for gdb itself shows a ratio of
27111 TOTAL_SEEN_SYMS/UNIQUE_SYMS or ~5. 4 seems like a good bet. */
27112 return psyms_count
/ 4;
27115 /* Write new .gdb_index section for OBJFILE into OUT_FILE.
27116 Return how many bytes were expected to be written into OUT_FILE. */
27119 write_gdbindex (struct dwarf2_per_objfile
*dwarf2_per_objfile
, FILE *out_file
)
27121 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27122 mapped_symtab symtab
;
27125 /* While we're scanning CU's create a table that maps a psymtab pointer
27126 (which is what addrmap records) to its index (which is what is recorded
27127 in the index file). This will later be needed to write the address
27129 psym_index_map cu_index_htab
;
27130 cu_index_htab
.reserve (dwarf2_per_objfile
->n_comp_units
);
27132 /* The CU list is already sorted, so we don't need to do additional
27133 work here. Also, the debug_types entries do not appear in
27134 all_comp_units, but only in their own hash table. */
27136 std::unordered_set
<partial_symbol
*> psyms_seen
27137 (psyms_seen_size (dwarf2_per_objfile
));
27138 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27140 struct dwarf2_per_cu_data
*per_cu
27141 = dwarf2_per_objfile
->all_comp_units
[i
];
27142 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27144 /* CU of a shared file from 'dwz -m' may be unused by this main file.
27145 It may be referenced from a local scope but in such case it does not
27146 need to be present in .gdb_index. */
27147 if (psymtab
== NULL
)
27150 if (psymtab
->user
== NULL
)
27151 recursively_write_psymbols (objfile
, psymtab
, &symtab
,
27154 const auto insertpair
= cu_index_htab
.emplace (psymtab
, i
);
27155 gdb_assert (insertpair
.second
);
27157 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
,
27158 to_underlying (per_cu
->sect_off
));
27159 cu_list
.append_uint (8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
27162 /* Dump the address map. */
27164 write_address_map (objfile
, addr_vec
, cu_index_htab
);
27166 /* Write out the .debug_type entries, if any. */
27167 data_buf types_cu_list
;
27168 if (dwarf2_per_objfile
->signatured_types
)
27170 signatured_type_index_data
sig_data (types_cu_list
,
27173 sig_data
.objfile
= objfile
;
27174 sig_data
.symtab
= &symtab
;
27175 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
27176 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27177 write_one_signatured_type
, &sig_data
);
27180 /* Now that we've processed all symbols we can shrink their cu_indices
27182 uniquify_cu_indices (&symtab
);
27184 data_buf symtab_vec
, constant_pool
;
27185 write_hash_table (&symtab
, symtab_vec
, constant_pool
);
27188 const offset_type size_of_contents
= 6 * sizeof (offset_type
);
27189 offset_type total_len
= size_of_contents
;
27191 /* The version number. */
27192 contents
.append_data (MAYBE_SWAP (8));
27194 /* The offset of the CU list from the start of the file. */
27195 contents
.append_data (MAYBE_SWAP (total_len
));
27196 total_len
+= cu_list
.size ();
27198 /* The offset of the types CU list from the start of the file. */
27199 contents
.append_data (MAYBE_SWAP (total_len
));
27200 total_len
+= types_cu_list
.size ();
27202 /* The offset of the address table from the start of the file. */
27203 contents
.append_data (MAYBE_SWAP (total_len
));
27204 total_len
+= addr_vec
.size ();
27206 /* The offset of the symbol table from the start of the file. */
27207 contents
.append_data (MAYBE_SWAP (total_len
));
27208 total_len
+= symtab_vec
.size ();
27210 /* The offset of the constant pool from the start of the file. */
27211 contents
.append_data (MAYBE_SWAP (total_len
));
27212 total_len
+= constant_pool
.size ();
27214 gdb_assert (contents
.size () == size_of_contents
);
27216 contents
.file_write (out_file
);
27217 cu_list
.file_write (out_file
);
27218 types_cu_list
.file_write (out_file
);
27219 addr_vec
.file_write (out_file
);
27220 symtab_vec
.file_write (out_file
);
27221 constant_pool
.file_write (out_file
);
27226 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
27227 static const gdb_byte dwarf5_gdb_augmentation
[] = { 'G', 'D', 'B', 0 };
27229 /* Write a new .debug_names section for OBJFILE into OUT_FILE, write
27230 needed addition to .debug_str section to OUT_FILE_STR. Return how
27231 many bytes were expected to be written into OUT_FILE. */
27234 write_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27235 FILE *out_file
, FILE *out_file_str
)
27237 const bool dwarf5_is_dwarf64
= check_dwarf64_offsets (dwarf2_per_objfile
);
27238 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27239 const enum bfd_endian dwarf5_byte_order
27240 = gdbarch_byte_order (get_objfile_arch (objfile
));
27242 /* The CU list is already sorted, so we don't need to do additional
27243 work here. Also, the debug_types entries do not appear in
27244 all_comp_units, but only in their own hash table. */
27246 debug_names
nametable (dwarf2_per_objfile
, dwarf5_is_dwarf64
,
27247 dwarf5_byte_order
);
27248 std::unordered_set
<partial_symbol
*>
27249 psyms_seen (psyms_seen_size (dwarf2_per_objfile
));
27250 for (int i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
27252 const dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
27253 partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
27255 /* CU of a shared file from 'dwz -m' may be unused by this main
27256 file. It may be referenced from a local scope but in such
27257 case it does not need to be present in .debug_names. */
27258 if (psymtab
== NULL
)
27261 if (psymtab
->user
== NULL
)
27262 nametable
.recursively_write_psymbols (objfile
, psymtab
, psyms_seen
, i
);
27264 cu_list
.append_uint (nametable
.dwarf5_offset_size (), dwarf5_byte_order
,
27265 to_underlying (per_cu
->sect_off
));
27268 /* Write out the .debug_type entries, if any. */
27269 data_buf types_cu_list
;
27270 if (dwarf2_per_objfile
->signatured_types
)
27272 debug_names::write_one_signatured_type_data
sig_data (nametable
,
27273 signatured_type_index_data (types_cu_list
, psyms_seen
));
27275 sig_data
.info
.objfile
= objfile
;
27276 /* It is used only for gdb_index. */
27277 sig_data
.info
.symtab
= nullptr;
27278 sig_data
.info
.cu_index
= 0;
27279 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
27280 debug_names::write_one_signatured_type
,
27284 nametable
.build ();
27286 /* No addr_vec - DWARF-5 uses .debug_aranges generated by GCC. */
27288 const offset_type bytes_of_header
27289 = ((dwarf5_is_dwarf64
? 12 : 4)
27291 + sizeof (dwarf5_gdb_augmentation
));
27292 size_t expected_bytes
= 0;
27293 expected_bytes
+= bytes_of_header
;
27294 expected_bytes
+= cu_list
.size ();
27295 expected_bytes
+= types_cu_list
.size ();
27296 expected_bytes
+= nametable
.bytes ();
27299 if (!dwarf5_is_dwarf64
)
27301 const uint64_t size64
= expected_bytes
- 4;
27302 gdb_assert (size64
< 0xfffffff0);
27303 header
.append_uint (4, dwarf5_byte_order
, size64
);
27307 header
.append_uint (4, dwarf5_byte_order
, 0xffffffff);
27308 header
.append_uint (8, dwarf5_byte_order
, expected_bytes
- 12);
27311 /* The version number. */
27312 header
.append_uint (2, dwarf5_byte_order
, 5);
27315 header
.append_uint (2, dwarf5_byte_order
, 0);
27317 /* comp_unit_count - The number of CUs in the CU list. */
27318 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_comp_units
);
27320 /* local_type_unit_count - The number of TUs in the local TU
27322 header
.append_uint (4, dwarf5_byte_order
, dwarf2_per_objfile
->n_type_units
);
27324 /* foreign_type_unit_count - The number of TUs in the foreign TU
27326 header
.append_uint (4, dwarf5_byte_order
, 0);
27328 /* bucket_count - The number of hash buckets in the hash lookup
27330 header
.append_uint (4, dwarf5_byte_order
, nametable
.bucket_count ());
27332 /* name_count - The number of unique names in the index. */
27333 header
.append_uint (4, dwarf5_byte_order
, nametable
.name_count ());
27335 /* abbrev_table_size - The size in bytes of the abbreviations
27337 header
.append_uint (4, dwarf5_byte_order
, nametable
.abbrev_table_bytes ());
27339 /* augmentation_string_size - The size in bytes of the augmentation
27340 string. This value is rounded up to a multiple of 4. */
27341 static_assert (sizeof (dwarf5_gdb_augmentation
) % 4 == 0, "");
27342 header
.append_uint (4, dwarf5_byte_order
, sizeof (dwarf5_gdb_augmentation
));
27343 header
.append_data (dwarf5_gdb_augmentation
);
27345 gdb_assert (header
.size () == bytes_of_header
);
27347 header
.file_write (out_file
);
27348 cu_list
.file_write (out_file
);
27349 types_cu_list
.file_write (out_file
);
27350 nametable
.file_write (out_file
, out_file_str
);
27352 return expected_bytes
;
27355 /* Assert that FILE's size is EXPECTED_SIZE. Assumes file's seek
27356 position is at the end of the file. */
27359 assert_file_size (FILE *file
, const char *filename
, size_t expected_size
)
27361 const auto file_size
= ftell (file
);
27362 if (file_size
== -1)
27363 error (_("Can't get `%s' size"), filename
);
27364 gdb_assert (file_size
== expected_size
);
27367 /* Create an index file for OBJFILE in the directory DIR. */
27370 write_psymtabs_to_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
27372 dw_index_kind index_kind
)
27374 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
27376 if (dwarf2_per_objfile
->using_index
)
27377 error (_("Cannot use an index to create the index"));
27379 if (VEC_length (dwarf2_section_info_def
, dwarf2_per_objfile
->types
) > 1)
27380 error (_("Cannot make an index when the file has multiple .debug_types sections"));
27382 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
27386 if (stat (objfile_name (objfile
), &st
) < 0)
27387 perror_with_name (objfile_name (objfile
));
27389 std::string
filename (std::string (dir
) + SLASH_STRING
27390 + lbasename (objfile_name (objfile
))
27391 + (index_kind
== dw_index_kind::DEBUG_NAMES
27392 ? INDEX5_SUFFIX
: INDEX4_SUFFIX
));
27394 FILE *out_file
= gdb_fopen_cloexec (filename
.c_str (), "wb").release ();
27396 error (_("Can't open `%s' for writing"), filename
.c_str ());
27398 /* Order matters here; we want FILE to be closed before FILENAME is
27399 unlinked, because on MS-Windows one cannot delete a file that is
27400 still open. (Don't call anything here that might throw until
27401 file_closer is created.) */
27402 gdb::unlinker
unlink_file (filename
.c_str ());
27403 gdb_file_up
close_out_file (out_file
);
27405 if (index_kind
== dw_index_kind::DEBUG_NAMES
)
27407 std::string
filename_str (std::string (dir
) + SLASH_STRING
27408 + lbasename (objfile_name (objfile
))
27409 + DEBUG_STR_SUFFIX
);
27411 = gdb_fopen_cloexec (filename_str
.c_str (), "wb").release ();
27413 error (_("Can't open `%s' for writing"), filename_str
.c_str ());
27414 gdb::unlinker
unlink_file_str (filename_str
.c_str ());
27415 gdb_file_up
close_out_file_str (out_file_str
);
27417 const size_t total_len
27418 = write_debug_names (dwarf2_per_objfile
, out_file
, out_file_str
);
27419 assert_file_size (out_file
, filename
.c_str (), total_len
);
27421 /* We want to keep the file .debug_str file too. */
27422 unlink_file_str
.keep ();
27426 const size_t total_len
27427 = write_gdbindex (dwarf2_per_objfile
, out_file
);
27428 assert_file_size (out_file
, filename
.c_str (), total_len
);
27431 /* We want to keep the file. */
27432 unlink_file
.keep ();
27435 /* Implementation of the `save gdb-index' command.
27437 Note that the .gdb_index file format used by this command is
27438 documented in the GDB manual. Any changes here must be documented
27442 save_gdb_index_command (const char *arg
, int from_tty
)
27444 struct objfile
*objfile
;
27445 const char dwarf5space
[] = "-dwarf-5 ";
27446 dw_index_kind index_kind
= dw_index_kind::GDB_INDEX
;
27451 arg
= skip_spaces (arg
);
27452 if (strncmp (arg
, dwarf5space
, strlen (dwarf5space
)) == 0)
27454 index_kind
= dw_index_kind::DEBUG_NAMES
;
27455 arg
+= strlen (dwarf5space
);
27456 arg
= skip_spaces (arg
);
27460 error (_("usage: save gdb-index [-dwarf-5] DIRECTORY"));
27462 ALL_OBJFILES (objfile
)
27466 /* If the objfile does not correspond to an actual file, skip it. */
27467 if (stat (objfile_name (objfile
), &st
) < 0)
27470 struct dwarf2_per_objfile
*dwarf2_per_objfile
27471 = get_dwarf2_per_objfile (objfile
);
27473 if (dwarf2_per_objfile
!= NULL
)
27477 write_psymtabs_to_index (dwarf2_per_objfile
, arg
, index_kind
);
27479 CATCH (except
, RETURN_MASK_ERROR
)
27481 exception_fprintf (gdb_stderr
, except
,
27482 _("Error while writing index for `%s': "),
27483 objfile_name (objfile
));
27493 int dwarf_always_disassemble
;
27496 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
27497 struct cmd_list_element
*c
, const char *value
)
27499 fprintf_filtered (file
,
27500 _("Whether to always disassemble "
27501 "DWARF expressions is %s.\n"),
27506 show_check_physname (struct ui_file
*file
, int from_tty
,
27507 struct cmd_list_element
*c
, const char *value
)
27509 fprintf_filtered (file
,
27510 _("Whether to check \"physname\" is %s.\n"),
27515 _initialize_dwarf2_read (void)
27517 struct cmd_list_element
*c
;
27519 dwarf2_objfile_data_key
= register_objfile_data ();
27521 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
27522 Set DWARF specific variables.\n\
27523 Configure DWARF variables such as the cache size"),
27524 &set_dwarf_cmdlist
, "maintenance set dwarf ",
27525 0/*allow-unknown*/, &maintenance_set_cmdlist
);
27527 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
27528 Show DWARF specific variables\n\
27529 Show DWARF variables such as the cache size"),
27530 &show_dwarf_cmdlist
, "maintenance show dwarf ",
27531 0/*allow-unknown*/, &maintenance_show_cmdlist
);
27533 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
27534 &dwarf_max_cache_age
, _("\
27535 Set the upper bound on the age of cached DWARF compilation units."), _("\
27536 Show the upper bound on the age of cached DWARF compilation units."), _("\
27537 A higher limit means that cached compilation units will be stored\n\
27538 in memory longer, and more total memory will be used. Zero disables\n\
27539 caching, which can slow down startup."),
27541 show_dwarf_max_cache_age
,
27542 &set_dwarf_cmdlist
,
27543 &show_dwarf_cmdlist
);
27545 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
27546 &dwarf_always_disassemble
, _("\
27547 Set whether `info address' always disassembles DWARF expressions."), _("\
27548 Show whether `info address' always disassembles DWARF expressions."), _("\
27549 When enabled, DWARF expressions are always printed in an assembly-like\n\
27550 syntax. When disabled, expressions will be printed in a more\n\
27551 conversational style, when possible."),
27553 show_dwarf_always_disassemble
,
27554 &set_dwarf_cmdlist
,
27555 &show_dwarf_cmdlist
);
27557 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
27558 Set debugging of the DWARF reader."), _("\
27559 Show debugging of the DWARF reader."), _("\
27560 When enabled (non-zero), debugging messages are printed during DWARF\n\
27561 reading and symtab expansion. A value of 1 (one) provides basic\n\
27562 information. A value greater than 1 provides more verbose information."),
27565 &setdebuglist
, &showdebuglist
);
27567 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
27568 Set debugging of the DWARF DIE reader."), _("\
27569 Show debugging of the DWARF DIE reader."), _("\
27570 When enabled (non-zero), DIEs are dumped after they are read in.\n\
27571 The value is the maximum depth to print."),
27574 &setdebuglist
, &showdebuglist
);
27576 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
27577 Set debugging of the dwarf line reader."), _("\
27578 Show debugging of the dwarf line reader."), _("\
27579 When enabled (non-zero), line number entries are dumped as they are read in.\n\
27580 A value of 1 (one) provides basic information.\n\
27581 A value greater than 1 provides more verbose information."),
27584 &setdebuglist
, &showdebuglist
);
27586 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
27587 Set cross-checking of \"physname\" code against demangler."), _("\
27588 Show cross-checking of \"physname\" code against demangler."), _("\
27589 When enabled, GDB's internal \"physname\" code is checked against\n\
27591 NULL
, show_check_physname
,
27592 &setdebuglist
, &showdebuglist
);
27594 add_setshow_boolean_cmd ("use-deprecated-index-sections",
27595 no_class
, &use_deprecated_index_sections
, _("\
27596 Set whether to use deprecated gdb_index sections."), _("\
27597 Show whether to use deprecated gdb_index sections."), _("\
27598 When enabled, deprecated .gdb_index sections are used anyway.\n\
27599 Normally they are ignored either because of a missing feature or\n\
27600 performance issue.\n\
27601 Warning: This option must be enabled before gdb reads the file."),
27604 &setlist
, &showlist
);
27606 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
27608 Save a gdb-index file.\n\
27609 Usage: save gdb-index [-dwarf-5] DIRECTORY\n\
27611 No options create one file with .gdb-index extension for pre-DWARF-5\n\
27612 compatible .gdb_index section. With -dwarf-5 creates two files with\n\
27613 extension .debug_names and .debug_str for DWARF-5 .debug_names section."),
27615 set_cmd_completer (c
, filename_completer
);
27617 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27618 &dwarf2_locexpr_funcs
);
27619 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
27620 &dwarf2_loclist_funcs
);
27622 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27623 &dwarf2_block_frame_base_locexpr_funcs
);
27624 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
27625 &dwarf2_block_frame_base_loclist_funcs
);
27628 selftests::register_test ("dw2_expand_symtabs_matching",
27629 selftests::dw2_expand_symtabs_matching::run_test
);