LLDB mainline
DebugNamesDWARFIndex.h
Go to the documentation of this file.
1//===-- DebugNamesDWARFIndex.h ---------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H
11
16#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
17#include <optional>
18
19namespace lldb_private::plugin {
20namespace dwarf {
22public:
23 static llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>>
24 Create(Module &module, DWARFDataExtractor debug_names,
26
27 void Preload() override { m_fallback.Preload(); }
28
29 void
31 llvm::function_ref<bool(DWARFDIE die)> callback) override;
32 void
34 llvm::function_ref<bool(DWARFDIE die)> callback) override;
35 void
37 llvm::function_ref<bool(DWARFDIE die)> callback) override;
38 void
40 llvm::function_ref<bool(DWARFDIE die)> callback) override {}
42 ConstString class_name, bool must_be_implementation,
43 llvm::function_ref<bool(DWARFDIE die)> callback) override;
44
45 /// Uses DWARF5's IDX_parent fields, when available, to speed up this query.
47 const DWARFDeclContext &context,
48 llvm::function_ref<bool(DWARFDIE die)> callback) override;
49 void GetTypes(ConstString name,
50 llvm::function_ref<bool(DWARFDIE die)> callback) override;
51 void GetTypes(const DWARFDeclContext &context,
52 llvm::function_ref<bool(DWARFDIE die)> callback) override;
53 void GetNamespaces(ConstString name,
54 llvm::function_ref<bool(DWARFDIE die)> callback) override;
55 void GetFunctions(const Module::LookupInfo &lookup_info,
57 const CompilerDeclContext &parent_decl_ctx,
58 llvm::function_ref<bool(DWARFDIE die)> callback) override;
59 void GetFunctions(const RegularExpression &regex,
60 llvm::function_ref<bool(DWARFDIE die)> callback) override;
61
62 void Dump(Stream &s) override;
63
64private:
66 std::unique_ptr<llvm::DWARFDebugNames> debug_names_up,
67 DWARFDataExtractor debug_names_data,
68 DWARFDataExtractor debug_str_data,
71 m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data),
72 m_debug_names_up(std::move(debug_names_up)),
75
77
78 // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep
79 // track of the ownership here.
82
83 using DebugNames = llvm::DWARFDebugNames;
84 std::unique_ptr<DebugNames> m_debug_names_up;
86
87 DWARFUnit *GetNonSkeletonUnit(const DebugNames::Entry &entry) const;
88 DWARFDIE GetDIE(const DebugNames::Entry &entry) const;
89
90 /// Checks if an entry is a foreign TU and fetch the type unit.
91 ///
92 /// This function checks if the DebugNames::Entry refers to a foreign TU and
93 /// returns an optional with a value of the \a entry is a foreign type unit
94 /// entry. A valid pointer will be returned if this entry is from a .dwo file
95 /// or if it is from a .dwp file and it matches the type unit's originating
96 /// .dwo file by verifying that the DW_TAG_type_unit DIE has a DW_AT_dwo_name
97 /// that matches the DWO name from the originating skeleton compile unit.
98 ///
99 /// \param[in] entry
100 /// The accelerator table entry to check.
101 ///
102 /// \returns
103 /// A std::optional that has a value if this entry represents a foreign type
104 /// unit. If the pointer is valid, then we were able to find and match the
105 /// entry to the type unit in the .dwo or .dwp file. The returned value can
106 /// have a valid, yet contain NULL in the following cases:
107 /// - we were not able to load the .dwo file (missing or DWO ID mismatch)
108 /// - we were able to load the .dwp file, but the type units DWO name
109 /// doesn't match the originating skeleton compile unit's entry
110 /// Returns std::nullopt if this entry is not a foreign type unit entry.
111 std::optional<DWARFTypeUnit *>
112 GetForeignTypeUnit(const DebugNames::Entry &entry) const;
113
114 bool ProcessEntry(const DebugNames::Entry &entry,
115 llvm::function_ref<bool(DWARFDIE die)> callback);
116
117 /// Returns true if `parent_entries` have identical names to `parent_names`.
118 bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names,
119 llvm::ArrayRef<DebugNames::Entry> parent_entries) const;
120
121 static void MaybeLogLookupError(llvm::Error error,
122 const DebugNames::NameIndex &ni,
123 llvm::StringRef name);
124
125 static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names);
126 static llvm::DenseSet<uint64_t>
127 GetTypeUnitSignatures(const DebugNames &debug_names);
128};
129
130} // namespace dwarf
131} // namespace lldb_private::plugin
132
133#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H
static llvm::raw_ostream & error(Stream &strm)
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition: ConstString.h:40
A class that encapsulates name lookup information.
Definition: Module.h:904
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
DebugNamesDWARFIndex(Module &module, std::unique_ptr< llvm::DWARFDebugNames > debug_names_up, DWARFDataExtractor debug_names_data, DWARFDataExtractor debug_str_data, SymbolFileDWARF &dwarf)
static llvm::Expected< std::unique_ptr< DebugNamesDWARFIndex > > Create(Module &module, DWARFDataExtractor debug_names, DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf)
static llvm::DenseSet< uint64_t > GetTypeUnitSignatures(const DebugNames &debug_names)
static void MaybeLogLookupError(llvm::Error error, const DebugNames::NameIndex &ni, llvm::StringRef name)
DWARFDIE GetDIE(const DebugNames::Entry &entry) const
std::optional< DWARFTypeUnit * > GetForeignTypeUnit(const DebugNames::Entry &entry) const
Checks if an entry is a foreign TU and fetch the type unit.
void GetTypes(ConstString name, llvm::function_ref< bool(DWARFDIE die)> callback) override
void GetFullyQualifiedType(const DWARFDeclContext &context, llvm::function_ref< bool(DWARFDIE die)> callback) override
Uses DWARF5's IDX_parent fields, when available, to speed up this query.
void GetNamespaces(ConstString name, llvm::function_ref< bool(DWARFDIE die)> callback) override
bool ProcessEntry(const DebugNames::Entry &entry, llvm::function_ref< bool(DWARFDIE die)> callback)
void GetGlobalVariables(ConstString basename, llvm::function_ref< bool(DWARFDIE die)> callback) override
Finds global variables with the given base name.
void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, llvm::function_ref< bool(DWARFDIE die)> callback) override
void GetObjCMethods(ConstString class_name, llvm::function_ref< bool(DWARFDIE die)> callback) override
void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< bool(DWARFDIE die)> callback) override
bool SameParentChain(llvm::ArrayRef< llvm::StringRef > parent_names, llvm::ArrayRef< DebugNames::Entry > parent_entries) const
Returns true if parent_entries have identical names to parent_names.
static llvm::DenseSet< dw_offset_t > GetUnits(const DebugNames &debug_names)
DWARFUnit * GetNonSkeletonUnit(const DebugNames::Entry &entry) const