Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / SymbolFile / NativePDB / SymbolFileNativePDB.h
blobbf64cd330c1f987f047e79617e81eba424762f15
1 //===-- SymbolFileNativePDB.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 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H
12 #include "lldb/Symbol/LineTable.h"
13 #include "lldb/Symbol/SymbolFile.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/DebugInfo/CodeView/CVRecord.h"
17 #include "llvm/DebugInfo/CodeView/SymbolRecord.h"
18 #include "llvm/DebugInfo/PDB/PDBTypes.h"
20 #include "CompileUnitIndex.h"
21 #include "PdbIndex.h"
22 #include "PdbAstBuilder.h"
23 #include <optional>
25 namespace clang {
26 class TagDecl;
29 namespace llvm {
30 namespace codeview {
31 class ClassRecord;
32 class EnumRecord;
33 class ModifierRecord;
34 class PointerRecord;
35 struct UnionRecord;
36 } // namespace codeview
37 } // namespace llvm
39 namespace lldb_private {
41 namespace npdb {
43 class SymbolFileNativePDB : public SymbolFileCommon {
44 friend class UdtRecordCompleter;
46 /// LLVM RTTI support.
47 static char ID;
49 public:
50 /// LLVM RTTI support.
51 /// \{
52 bool isA(const void *ClassID) const override {
53 return ClassID == &ID || SymbolFileCommon::isA(ClassID);
55 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
56 /// \}
58 // Static Functions
59 static void Initialize();
61 static void Terminate();
63 static void DebuggerInitialize(Debugger &debugger);
65 static llvm::StringRef GetPluginNameStatic() { return "native-pdb"; }
67 static llvm::StringRef GetPluginDescriptionStatic();
69 static SymbolFile *CreateInstance(lldb::ObjectFileSP objfile_sp);
71 // Constructors and Destructors
72 SymbolFileNativePDB(lldb::ObjectFileSP objfile_sp);
74 ~SymbolFileNativePDB() override;
76 uint32_t CalculateAbilities() override;
78 void InitializeObject() override;
80 uint64_t GetDebugInfoSize() override;
82 // Compile Unit function calls
84 void
85 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
87 lldb::LanguageType
88 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
90 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
92 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
94 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
96 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
97 FileSpecList &support_files) override;
98 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
100 bool ParseImportedModules(
101 const SymbolContext &sc,
102 std::vector<lldb_private::SourceModule> &imported_modules) override;
104 size_t ParseBlocksRecursive(Function &func) override;
106 void FindGlobalVariables(ConstString name,
107 const CompilerDeclContext &parent_decl_ctx,
108 uint32_t max_matches,
109 VariableList &variables) override;
111 size_t ParseVariablesForContext(const SymbolContext &sc) override;
113 void AddSymbols(Symtab &symtab) override;
115 CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
116 CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override;
117 CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override;
118 Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
119 std::optional<ArrayInfo> GetDynamicArrayInfoForUID(
120 lldb::user_id_t type_uid,
121 const lldb_private::ExecutionContext *exe_ctx) override;
123 bool CompleteType(CompilerType &compiler_type) override;
124 uint32_t ResolveSymbolContext(const Address &so_addr,
125 lldb::SymbolContextItem resolve_scope,
126 SymbolContext &sc) override;
127 uint32_t ResolveSymbolContext(const SourceLocationSpec &src_location_spec,
128 lldb::SymbolContextItem resolve_scope,
129 SymbolContextList &sc_list) override;
131 void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
132 TypeList &type_list) override;
134 void FindFunctions(const Module::LookupInfo &lookup_info,
135 const CompilerDeclContext &parent_decl_ctx,
136 bool include_inlines, SymbolContextList &sc_list) override;
138 void FindFunctions(const RegularExpression &regex, bool include_inlines,
139 SymbolContextList &sc_list) override;
141 std::optional<PdbCompilandSymId> FindSymbolScope(PdbCompilandSymId id);
143 void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx,
144 uint32_t max_matches,
145 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
146 TypeMap &types) override;
148 void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
149 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
150 TypeMap &types) override;
152 llvm::Expected<lldb::TypeSystemSP>
153 GetTypeSystemForLanguage(lldb::LanguageType language) override;
155 CompilerDeclContext FindNamespace(ConstString name,
156 const CompilerDeclContext &parent_decl_ctx,
157 bool only_root_namespaces) override;
159 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
161 llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); }
162 const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); }
164 PdbIndex &GetIndex() { return *m_index; };
166 void DumpClangAST(Stream &s) override;
168 std::optional<llvm::codeview::TypeIndex>
169 GetParentType(llvm::codeview::TypeIndex ti);
171 private:
172 struct LineTableEntryComparator {
173 bool operator()(const lldb_private::LineTable::Entry &lhs,
174 const lldb_private::LineTable::Entry &rhs) const {
175 return lhs.file_addr < rhs.file_addr;
179 // From address range relative to function base to source line number.
180 using RangeSourceLineVector =
181 lldb_private::RangeDataVector<uint32_t, uint32_t, int32_t>;
182 // InlineSite contains information in a S_INLINESITE record.
183 struct InlineSite {
184 PdbCompilandSymId parent_id;
185 std::shared_ptr<InlineFunctionInfo> inline_function_info;
186 RangeSourceLineVector ranges;
187 std::vector<lldb_private::LineTable::Entry> line_entries;
188 InlineSite(PdbCompilandSymId parent_id) : parent_id(parent_id){};
191 void BuildParentMap();
193 uint32_t CalculateNumCompileUnits() override;
195 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
197 void FindTypesByName(llvm::StringRef name, uint32_t max_matches,
198 TypeMap &types);
200 lldb::TypeSP CreateModifierType(PdbTypeSymId type_id,
201 const llvm::codeview::ModifierRecord &mr,
202 CompilerType ct);
203 lldb::TypeSP CreatePointerType(PdbTypeSymId type_id,
204 const llvm::codeview::PointerRecord &pr,
205 CompilerType ct);
206 lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct);
207 lldb::TypeSP CreateTagType(PdbTypeSymId type_id,
208 const llvm::codeview::ClassRecord &cr,
209 CompilerType ct);
210 lldb::TypeSP CreateTagType(PdbTypeSymId type_id,
211 const llvm::codeview::EnumRecord &er,
212 CompilerType ct);
213 lldb::TypeSP CreateTagType(PdbTypeSymId type_id,
214 const llvm::codeview::UnionRecord &ur,
215 CompilerType ct);
216 lldb::TypeSP CreateArrayType(PdbTypeSymId type_id,
217 const llvm::codeview::ArrayRecord &ar,
218 CompilerType ct);
219 lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id,
220 const llvm::codeview::MemberFunctionRecord &pr,
221 CompilerType ct);
222 lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id,
223 const llvm::codeview::ProcedureRecord &pr,
224 CompilerType ct);
225 lldb::TypeSP CreateClassStructUnion(PdbTypeSymId type_id,
226 const llvm::codeview::TagRecord &record,
227 size_t size, CompilerType ct);
229 lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id,
230 CompileUnit &comp_unit);
231 lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci);
232 lldb::TypeSP GetOrCreateType(PdbTypeSymId type_id);
233 lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti);
234 lldb::VariableSP GetOrCreateGlobalVariable(PdbGlobalSymId var_id);
235 Block &GetOrCreateBlock(PdbCompilandSymId block_id);
236 lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id,
237 PdbCompilandSymId var_id,
238 bool is_param);
239 lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id);
241 lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id,
242 CompileUnit &comp_unit);
243 Block &CreateBlock(PdbCompilandSymId block_id);
244 lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id,
245 PdbCompilandSymId var_id, bool is_param);
246 lldb::TypeSP CreateTypedef(PdbGlobalSymId id);
247 lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci);
248 lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct);
249 lldb::TypeSP CreateAndCacheType(PdbTypeSymId type_id);
250 lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id);
251 lldb::VariableSP CreateConstantSymbol(PdbGlobalSymId var_id,
252 const llvm::codeview::CVSymbol &cvs);
253 size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit,
254 VariableList &variables);
255 size_t ParseVariablesForBlock(PdbCompilandSymId block_id);
257 llvm::Expected<uint32_t> GetFileIndex(const CompilandIndexItem &cii,
258 uint32_t file_id);
260 size_t ParseSymbolArrayInScope(
261 PdbCompilandSymId parent,
262 llvm::function_ref<bool(llvm::codeview::SymbolKind, PdbCompilandSymId)>
263 fn);
265 void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr);
267 llvm::BumpPtrAllocator m_allocator;
269 lldb::addr_t m_obj_load_address = 0;
270 bool m_done_full_type_scan = false;
271 // UID for anonymous union and anonymous struct as they don't have entities in
272 // pdb debug info.
273 lldb::user_id_t anonymous_id = LLDB_INVALID_UID - 1;
275 std::unique_ptr<llvm::pdb::PDBFile> m_file_up;
276 std::unique_ptr<PdbIndex> m_index;
278 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_global_vars;
279 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_local_variables;
280 llvm::DenseMap<lldb::user_id_t, lldb::BlockSP> m_blocks;
281 llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions;
282 llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands;
283 llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types;
284 llvm::DenseMap<lldb::user_id_t, std::shared_ptr<InlineSite>> m_inline_sites;
285 llvm::DenseMap<llvm::codeview::TypeIndex, llvm::codeview::TypeIndex>
286 m_parent_types;
289 } // namespace npdb
290 } // namespace lldb_private
292 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H