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
75private:
77 std::unique_ptr<llvm::DWARFDebugNames> debug_names_up,
78 DWARFDataExtractor debug_names_data,
79 DWARFDataExtractor debug_str_data,
82 m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data),
83 m_debug_names_up(std::move(debug_names_up)),
86
88
89 // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep
90 // track of the ownership here.
93
94 using DebugNames = llvm::DWARFDebugNames;
95 std::unique_ptr<DebugNames> m_debug_names_up;
97
98 DWARFUnit *GetNonSkeletonUnit(const DebugNames::Entry &entry) const;
99 DWARFDIE GetDIE(const DebugNames::Entry &entry) const;
100
101 /// Checks if an entry is a foreign TU and fetch the type unit.
102 ///
103 /// This function checks if the DebugNames::Entry refers to a foreign TU and
104 /// returns an optional with a value of the \a entry is a foreign type unit
105 /// entry. A valid pointer will be returned if this entry is from a .dwo file
106 /// or if it is from a .dwp file and it matches the type unit's originating
107 /// .dwo file by verifying that the DW_TAG_type_unit DIE has a DW_AT_dwo_name
108 /// that matches the DWO name from the originating skeleton compile unit.
109 ///
110 /// \param[in] entry
111 /// The accelerator table entry to check.
112 ///
113 /// \returns
114 /// A std::optional that has a value if this entry represents a foreign type
115 /// unit. If the pointer is valid, then we were able to find and match the
116 /// entry to the type unit in the .dwo or .dwp file. The returned value can
117 /// have a valid, yet contain NULL in the following cases:
118 /// - we were not able to load the .dwo file (missing or DWO ID mismatch)
119 /// - we were able to load the .dwp file, but the type units DWO name
120 /// doesn't match the originating skeleton compile unit's entry
121 /// Returns std::nullopt if this entry is not a foreign type unit entry.
122 std::optional<DWARFTypeUnit *>
123 GetForeignTypeUnit(const DebugNames::Entry &entry) const;
124
126 ProcessEntry(const DebugNames::Entry &entry,
127 llvm::function_ref<IterationAction(DWARFDIE die)> callback);
128
129 /// Returns true if `parent_entries` have identical names to `parent_names`.
130 bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names,
131 llvm::ArrayRef<DebugNames::Entry> parent_entries) const;
132
133 bool SameParentChain(llvm::ArrayRef<CompilerContext> parent_contexts,
134 llvm::ArrayRef<DebugNames::Entry> parent_entries) const;
135
136 /// Returns true if \a parent_contexts entries are within \a parent_chain.
137 /// This is diffferent from SameParentChain() which checks for exact match.
138 /// This function is required because \a parent_chain can contain inline
139 /// namespace entries which may not be specified in \a parent_contexts by
140 /// client.
141 ///
142 /// \param[in] parent_contexts
143 /// The list of parent contexts to check for.
144 ///
145 /// \param[in] parent_chain
146 /// The fully qualified parent chain entries from .debug_names index table
147 /// to check against.
148 ///
149 /// \returns
150 /// True if all \a parent_contexts entries are can be sequentially found
151 /// inside
152 /// \a parent_chain, otherwise False.
153 bool WithinParentChain(llvm::ArrayRef<CompilerContext> parent_contexts,
154 llvm::ArrayRef<DebugNames::Entry> parent_chain) const;
155
156 /// Returns true if .debug_names pool entry \p entry matches \p query_context.
157 bool SameAsEntryContext(const CompilerContext &query_context,
158 const DebugNames::Entry &entry) const;
159
160 llvm::SmallVector<CompilerContext>
162
163 static void MaybeLogLookupError(llvm::Error error,
164 const DebugNames::NameIndex &ni,
165 llvm::StringRef name);
166
167 static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names);
168 static llvm::DenseSet<uint64_t>
169 GetTypeUnitSignatures(const DebugNames &debug_names);
170};
171
172} // namespace dwarf
173} // namespace lldb_private::plugin
174
175#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:916
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
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.
Definition Type.h:104
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...
Definition Type.h:52