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