1 //===-- SymbolFilePDB.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_PDB_SymbolFilePDB_h_
11 #define lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
12 
13 #include "lldb/Symbol/SymbolFile.h"
14 #include "lldb/Utility/UserID.h"
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/DebugInfo/PDB/IPDBSession.h"
18 #include "llvm/DebugInfo/PDB/PDB.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
20 
21 class SymbolFilePDB : public lldb_private::SymbolFile {
22 public:
23   //------------------------------------------------------------------
24   // Static Functions
25   //------------------------------------------------------------------
26   static void Initialize();
27 
28   static void Terminate();
29 
30   static void DebuggerInitialize(lldb_private::Debugger &debugger);
31 
32   static lldb_private::ConstString GetPluginNameStatic();
33 
34   static const char *GetPluginDescriptionStatic();
35 
36   static lldb_private::SymbolFile *
37   CreateInstance(lldb_private::ObjectFile *obj_file);
38 
39   //------------------------------------------------------------------
40   // Constructors and Destructors
41   //------------------------------------------------------------------
42   SymbolFilePDB(lldb_private::ObjectFile *ofile);
43 
44   ~SymbolFilePDB() override;
45 
46   uint32_t CalculateAbilities() override;
47 
48   void InitializeObject() override;
49 
50   //------------------------------------------------------------------
51   // Compile Unit function calls
52   //------------------------------------------------------------------
53 
54   uint32_t GetNumCompileUnits() override;
55 
56   lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
57 
58   lldb::LanguageType
59   ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
60 
61   size_t
62   ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
63 
64   bool
65   ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
66 
67   bool
68   ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
69 
70   bool ParseCompileUnitSupportFiles(
71       const lldb_private::SymbolContext &sc,
72       lldb_private::FileSpecList &support_files) override;
73 
74   bool ParseImportedModules(
75       const lldb_private::SymbolContext &sc,
76       std::vector<lldb_private::ConstString> &imported_modules) override;
77 
78   size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
79 
80   size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
81 
82   size_t
83   ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
84 
85   lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
86 
87   bool CompleteType(lldb_private::CompilerType &compiler_type) override;
88 
89   lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
90 
91   lldb_private::CompilerDeclContext
92   GetDeclContextForUID(lldb::user_id_t uid) override;
93 
94   lldb_private::CompilerDeclContext
95   GetDeclContextContainingUID(lldb::user_id_t uid) override;
96 
97   void
98   ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
99 
100   uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
101                                 uint32_t resolve_scope,
102                                 lldb_private::SymbolContext &sc) override;
103 
104   uint32_t
105   ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
106                        bool check_inlines, uint32_t resolve_scope,
107                        lldb_private::SymbolContextList &sc_list) override;
108 
109   uint32_t
110   FindGlobalVariables(const lldb_private::ConstString &name,
111                       const lldb_private::CompilerDeclContext *parent_decl_ctx,
112                       bool append, uint32_t max_matches,
113                       lldb_private::VariableList &variables) override;
114 
115   uint32_t FindGlobalVariables(const lldb_private::RegularExpression &regex,
116                                bool append, uint32_t max_matches,
117                                lldb_private::VariableList &variables) override;
118 
119   uint32_t
120   FindFunctions(const lldb_private::ConstString &name,
121                 const lldb_private::CompilerDeclContext *parent_decl_ctx,
122                 uint32_t name_type_mask, bool include_inlines, bool append,
123                 lldb_private::SymbolContextList &sc_list) override;
124 
125   uint32_t FindFunctions(const lldb_private::RegularExpression &regex,
126                          bool include_inlines, bool append,
127                          lldb_private::SymbolContextList &sc_list) override;
128 
129   void GetMangledNamesForFunction(
130       const std::string &scope_qualified_name,
131       std::vector<lldb_private::ConstString> &mangled_names) override;
132 
133   uint32_t
134   FindTypes(const lldb_private::SymbolContext &sc,
135             const lldb_private::ConstString &name,
136             const lldb_private::CompilerDeclContext *parent_decl_ctx,
137             bool append, uint32_t max_matches,
138             llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
139             lldb_private::TypeMap &types) override;
140 
141   size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
142                    bool append, lldb_private::TypeMap &types) override;
143 
144   void FindTypesByRegex(const lldb_private::RegularExpression &regex,
145                         uint32_t max_matches,
146                         lldb_private::TypeMap &types);
147 
148   lldb_private::TypeList *GetTypeList() override;
149 
150   size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
151                   uint32_t type_mask,
152                   lldb_private::TypeList &type_list) override;
153 
154   lldb_private::TypeSystem *
155   GetTypeSystemForLanguage(lldb::LanguageType language) override;
156 
157   lldb_private::CompilerDeclContext FindNamespace(
158       const lldb_private::SymbolContext &sc,
159       const lldb_private::ConstString &name,
160       const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
161 
162   lldb_private::ConstString GetPluginName() override;
163 
164   uint32_t GetPluginVersion() override;
165 
166   llvm::pdb::IPDBSession &GetPDBSession();
167 
168   const llvm::pdb::IPDBSession &GetPDBSession() const;
169 
170 private:
171   lldb::CompUnitSP
172   ParseCompileUnitForUID(uint32_t id, uint32_t index = UINT32_MAX);
173 
174   bool ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc,
175                                  uint32_t match_line);
176 
177   void BuildSupportFileIdToSupportFileIndexMap(
178       const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
179       llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
180 
181   void FindTypesByName(const std::string &name, uint32_t max_matches,
182                        lldb_private::TypeMap &types);
183 
184   void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland *pdb_compiland,
185                            uint32_t &index);
186 
187   std::string GetSourceFileNameForPDBCompiland(
188       const llvm::pdb::PDBSymbolCompiland *pdb_compiland);
189 
190   std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
191   GetPDBCompilandByUID(uint32_t uid);
192 
193   llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units;
194   llvm::DenseMap<uint32_t, lldb::TypeSP> m_types;
195 
196   std::vector<lldb::TypeSP> m_builtin_types;
197   std::unique_ptr<llvm::pdb::IPDBSession> m_session_up;
198   std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up;
199   uint32_t m_cached_compile_unit_count;
200   std::unique_ptr<lldb_private::CompilerDeclContext> m_tu_decl_ctx_up;
201 };
202 
203 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
204