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