1 //===-- SymbolFileNativePDB.h -----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H
11 #define LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H
12 
13 #include "lldb/Symbol/SymbolFile.h"
14 
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"
19 
20 #include "CompileUnitIndex.h"
21 #include "PdbIndex.h"
22 
23 namespace clang {
24 class TagDecl;
25 }
26 
27 namespace llvm {
28 namespace codeview {
29 class ClassRecord;
30 class EnumRecord;
31 class ModifierRecord;
32 class PointerRecord;
33 struct UnionRecord;
34 } // namespace codeview
35 } // namespace llvm
36 
37 namespace lldb_private {
38 class ClangASTImporter;
39 
40 namespace npdb {
41 
42 struct DeclStatus {
43   DeclStatus() = default;
44   DeclStatus(lldb::user_id_t uid, Type::ResolveStateTag status)
45       : uid(uid), status(status) {}
46   lldb::user_id_t uid = 0;
47   Type::ResolveStateTag status = Type::eResolveStateForward;
48 };
49 
50 class SymbolFileNativePDB : public SymbolFile {
51   friend class UdtRecordCompleter;
52 
53 public:
54   //------------------------------------------------------------------
55   // Static Functions
56   //------------------------------------------------------------------
57   static void Initialize();
58 
59   static void Terminate();
60 
61   static void DebuggerInitialize(Debugger &debugger);
62 
63   static ConstString GetPluginNameStatic();
64 
65   static const char *GetPluginDescriptionStatic();
66 
67   static SymbolFile *CreateInstance(ObjectFile *obj_file);
68 
69   //------------------------------------------------------------------
70   // Constructors and Destructors
71   //------------------------------------------------------------------
72   SymbolFileNativePDB(ObjectFile *ofile);
73 
74   ~SymbolFileNativePDB() override;
75 
76   uint32_t CalculateAbilities() override;
77 
78   void InitializeObject() override;
79 
80   //------------------------------------------------------------------
81   // Compile Unit function calls
82   //------------------------------------------------------------------
83 
84   uint32_t GetNumCompileUnits() override;
85 
86   lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
87 
88   lldb::LanguageType ParseCompileUnitLanguage(const SymbolContext &sc) override;
89 
90   size_t ParseCompileUnitFunctions(const SymbolContext &sc) override;
91 
92   bool ParseCompileUnitLineTable(const SymbolContext &sc) override;
93 
94   bool ParseCompileUnitDebugMacros(const SymbolContext &sc) override;
95 
96   bool ParseCompileUnitSupportFiles(const SymbolContext &sc,
97                                     FileSpecList &support_files) override;
98 
99   bool
100   ParseImportedModules(const SymbolContext &sc,
101                        std::vector<ConstString> &imported_modules) override;
102 
103   size_t ParseFunctionBlocks(const SymbolContext &sc) override;
104 
105   size_t ParseTypes(const SymbolContext &sc) override;
106   size_t ParseVariablesForContext(const SymbolContext &sc) override {
107     return 0;
108   }
109   Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
110   bool CompleteType(CompilerType &compiler_type) override;
111   uint32_t ResolveSymbolContext(const Address &so_addr, uint32_t resolve_scope,
112                                 SymbolContext &sc) override;
113 
114   size_t GetTypes(SymbolContextScope *sc_scope, uint32_t type_mask,
115                   TypeList &type_list) override;
116 
117   uint32_t FindFunctions(const ConstString &name,
118                          const CompilerDeclContext *parent_decl_ctx,
119                          uint32_t name_type_mask, bool include_inlines,
120                          bool append, SymbolContextList &sc_list) override;
121 
122   uint32_t FindFunctions(const RegularExpression &regex, bool include_inlines,
123                          bool append, SymbolContextList &sc_list) override;
124 
125   uint32_t FindTypes(const SymbolContext &sc, const ConstString &name,
126                      const CompilerDeclContext *parent_decl_ctx, bool append,
127                      uint32_t max_matches,
128                      llvm::DenseSet<SymbolFile *> &searched_symbol_files,
129                      TypeMap &types) override;
130 
131   size_t FindTypes(const std::vector<CompilerContext> &context, bool append,
132                    TypeMap &types) override;
133 
134   TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override;
135 
136   CompilerDeclContext
137   FindNamespace(const SymbolContext &sc, const ConstString &name,
138                 const CompilerDeclContext *parent_decl_ctx) override;
139 
140   ConstString GetPluginName() override;
141 
142   uint32_t GetPluginVersion() override;
143 
144   llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); }
145   const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); }
146 
147 private:
148   lldb::FunctionSP GetOrCreateFunction(PdbSymUid func_uid,
149                                        const SymbolContext &sc);
150   lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci);
151 
152   lldb::FunctionSP CreateFunction(PdbSymUid func_uid, const SymbolContext &sc);
153   lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci);
154 
155   llvm::BumpPtrAllocator m_allocator;
156 
157   lldb::addr_t m_obj_load_address = 0;
158 
159   std::unique_ptr<PdbIndex> m_index;
160 
161   llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions;
162   llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands;
163 };
164 
165 } // namespace npdb
166 } // namespace lldb_private
167 
168 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
169