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
17#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
18#include <optional>
19
20namespace lldb_private::plugin {
21namespace dwarf {
23public:
24 static llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>>
25 Create(Module &module, DWARFDataExtractor debug_names,
27
28 void Preload() override { m_fallback.Preload(); }
29
31 ConstString basename,
32 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
34 const RegularExpression &regex,
35 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
37 DWARFUnit &cu,
38 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
40 ConstString class_name,
41 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override {}
43 ConstString class_name, bool must_be_implementation,
44 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
45
46 /// Uses DWARF5's IDX_parent fields, when available, to speed up this query.
48 const DWARFDeclContext &context,
49 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
50 void
52 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
53 void
54 GetTypes(const DWARFDeclContext &context,
55 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
56 void GetNamespaces(
57 ConstString name,
58 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
60 TypeQuery &query,
61 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
63 ConstString name, const CompilerDeclContext &parent_decl_ctx,
64 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
65 void GetFunctions(
66 const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,
67 const CompilerDeclContext &parent_decl_ctx,
68 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
69 void GetFunctions(
70 const RegularExpression &regex,
71 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
72
73 void Dump(Stream &s) override;
74
76 return DWARFIndex::GetIndexTime() + m_fallback.GetIndexTime();
77 }
78
79 void ResetStatistics() override {
81 m_fallback.ResetStatistics();
82 }
83
84private:
86 std::unique_ptr<llvm::DWARFDebugNames> debug_names_up,
87 DWARFDataExtractor debug_names_data,
88 DWARFDataExtractor debug_str_data,
91 m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data),
92 m_debug_names_up(std::move(debug_names_up)),
95
97
98 // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep
99 // track of the ownership here.
102
103 using DebugNames = llvm::DWARFDebugNames;
104 std::unique_ptr<DebugNames> m_debug_names_up;
106
107 DWARFUnit *GetNonSkeletonUnit(const DebugNames::Entry &entry) const;
108 DWARFDIE GetDIE(const DebugNames::Entry &entry) const;
109
110 /// Checks if an entry is a foreign TU and fetch the type unit.
111 ///
112 /// This function checks if the DebugNames::Entry refers to a foreign TU and
113 /// returns an optional with a value of the \a entry is a foreign type unit
114 /// entry. A valid pointer will be returned if this entry is from a .dwo file
115 /// or if it is from a .dwp file and it matches the type unit's originating
116 /// .dwo file by verifying that the DW_TAG_type_unit DIE has a DW_AT_dwo_name
117 /// that matches the DWO name from the originating skeleton compile unit.
118 ///
119 /// \param[in] entry
120 /// The accelerator table entry to check.
121 ///
122 /// \returns
123 /// A std::optional that has a value if this entry represents a foreign type
124 /// unit. If the pointer is valid, then we were able to find and match the
125 /// entry to the type unit in the .dwo or .dwp file. The returned value can
126 /// have a valid, yet contain NULL in the following cases:
127 /// - we were not able to load the .dwo file (missing or DWO ID mismatch)
128 /// - we were able to load the .dwp file, but the type units DWO name
129 /// doesn't match the originating skeleton compile unit's entry
130 /// Returns std::nullopt if this entry is not a foreign type unit entry.
131 std::optional<DWARFTypeUnit *>
132 GetForeignTypeUnit(const DebugNames::Entry &entry) const;
133
135 ProcessEntry(const DebugNames::Entry &entry,
136 llvm::function_ref<IterationAction(DWARFDIE die)> callback);
137
138 /// Returns true if `parent_entries` have identical names to `parent_names`.
139 bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names,
140 llvm::ArrayRef<DebugNames::Entry> parent_entries) const;
141
142 bool SameParentChain(llvm::ArrayRef<CompilerContext> parent_contexts,
143 llvm::ArrayRef<DebugNames::Entry> parent_entries) const;
144
145 /// Returns true if \a parent_contexts entries are within \a parent_chain.
146 /// This is diffferent from SameParentChain() which checks for exact match.
147 /// This function is required because \a parent_chain can contain inline
148 /// namespace entries which may not be specified in \a parent_contexts by
149 /// client.
150 ///
151 /// \param[in] parent_contexts
152 /// The list of parent contexts to check for.
153 ///
154 /// \param[in] parent_chain
155 /// The fully qualified parent chain entries from .debug_names index table
156 /// to check against.
157 ///
158 /// \returns
159 /// True if all \a parent_contexts entries are can be sequentially found
160 /// inside
161 /// \a parent_chain, otherwise False.
162 bool WithinParentChain(llvm::ArrayRef<CompilerContext> parent_contexts,
163 llvm::ArrayRef<DebugNames::Entry> parent_chain) const;
164
165 /// Returns true if .debug_names pool entry \p entry matches \p query_context.
166 bool SameAsEntryContext(const CompilerContext &query_context,
167 const DebugNames::Entry &entry) const;
168
169 llvm::SmallVector<CompilerContext>
171
172 static void MaybeLogLookupError(llvm::Error error,
173 const DebugNames::NameIndex &ni,
174 llvm::StringRef name);
175
176 static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names);
177 static llvm::DenseSet<uint64_t>
178 GetTypeUnitSignatures(const DebugNames &debug_names);
179};
180
181} // namespace dwarf
182} // namespace lldb_private::plugin
183
184#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:973
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:92
std::chrono::duration< double > Duration
Definition Statistics.h:37
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A class that contains all state required for type lookups.
virtual StatsDuration::Duration GetIndexTime()
Time spent creating this index and any index it falls back to, including loading them from or saving ...
Definition DWARFIndex.h:101
StatsDuration::Duration GetIndexTime() override
Time spent creating this index and any index it falls back to, including loading them from or saving ...
llvm::SmallVector< CompilerContext > GetTypeQueryParentContexts(TypeQuery &query)
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)
void GetObjCMethods(ConstString class_name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
IterationAction ProcessEntry(const DebugNames::Entry &entry, llvm::function_ref< IterationAction(DWARFDIE die)> callback)
void GetTypes(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
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.
bool WithinParentChain(llvm::ArrayRef< CompilerContext > parent_contexts, llvm::ArrayRef< DebugNames::Entry > parent_chain) const
Returns true if parent_contexts entries are within parent_chain.
void GetFullyQualifiedType(const DWARFDeclContext &context, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
Uses DWARF5's IDX_parent fields, when available, to speed up this query.
void GetTypesWithQuery(TypeQuery &query, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
Get type DIEs meeting requires of query.
void GetNamespacesWithParents(ConstString name, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
Get namespace DIEs whose base name match.
void GetNamespaces(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
bool SameAsEntryContext(const CompilerContext &query_context, const DebugNames::Entry &entry) const
Returns true if .debug_names pool entry entry matches query_context.
void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void GetGlobalVariables(ConstString basename, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
Finds global variables with the given base name.
void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, llvm::function_ref< IterationAction(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
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
CompilerContext allows an array of these items to be passed to perform detailed lookups in SymbolVend...