19
19
#include " lldb/Symbol/SymbolFile.h"
20
20
#include " lldb/Symbol/TypeSystem.h"
21
21
22
+ #include " llvm/DebugInfo/PDB/IPDBLineNumber.h"
23
+ #include " llvm/DebugInfo/PDB/IPDBSourceFile.h"
22
24
#include " llvm/DebugInfo/PDB/PDBSymbol.h"
23
25
#include " llvm/DebugInfo/PDB/PDBSymbolData.h"
26
+ #include " llvm/DebugInfo/PDB/PDBSymbolFunc.h"
24
27
#include " llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
25
28
#include " llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
26
29
#include " llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
@@ -166,6 +169,28 @@ ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin *pdb_type,
166
169
}
167
170
return compiler_type.GetTypeName ();
168
171
}
172
+
173
+ bool GetDeclarationForSymbol (const PDBSymbol &symbol, Declaration &decl) {
174
+ auto &raw_sym = symbol.getRawSymbol ();
175
+ auto lines_up = symbol.getSession ().findLineNumbersByAddress (
176
+ raw_sym.getVirtualAddress (), raw_sym.getLength ());
177
+ if (!lines_up)
178
+ return false ;
179
+ auto first_line_up = lines_up->getNext ();
180
+ if (!first_line_up)
181
+ return false ;
182
+
183
+ uint32_t src_file_id = first_line_up->getSourceFileId ();
184
+ auto src_file_up = symbol.getSession ().getSourceFileById (src_file_id);
185
+ if (!src_file_up)
186
+ return false ;
187
+
188
+ FileSpec spec (src_file_up->getFileName (), /* resolve_path*/ false );
189
+ decl.SetFile (spec);
190
+ decl.SetColumn (first_line_up->getColumnNumber ());
191
+ decl.SetLine (first_line_up->getLineNumber ());
192
+ return true ;
193
+ }
169
194
}
170
195
171
196
PDBASTParser::PDBASTParser (lldb_private::ClangASTContext &ast) : m_ast(ast) {}
@@ -182,7 +207,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
182
207
clang::DeclContext *tu_decl_ctx = m_ast.GetTranslationUnitDecl ();
183
208
Declaration decl;
184
209
185
- if (auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type)) {
210
+ switch (type.getSymTag ()) {
211
+ case PDB_SymType::UDT: {
212
+ auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type);
213
+ assert (udt);
186
214
AccessType access = lldb::eAccessPublic;
187
215
PDB_UdtType udt_kind = udt->getUdtKind ();
188
216
auto tag_type_kind = TranslateUdtKind (udt_kind);
@@ -203,7 +231,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
203
231
ConstString (udt->getName ()), udt->getLength (), nullptr ,
204
232
LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, clang_type,
205
233
lldb_private::Type::eResolveStateForward);
206
- } else if (auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type)) {
234
+ } break ;
235
+ case PDB_SymType::Enum: {
236
+ auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type);
237
+ assert (enum_type);
207
238
auto underlying_type_up = enum_type->getUnderlyingType ();
208
239
if (!underlying_type_up)
209
240
return nullptr ;
@@ -244,7 +275,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
244
275
type.getSymIndexId (), m_ast.GetSymbolFile (), ConstString (name), bytes,
245
276
nullptr , LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
246
277
ast_enum, lldb_private::Type::eResolveStateFull);
247
- } else if (auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type)) {
278
+ } break ;
279
+ case PDB_SymType::Typedef: {
280
+ auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type);
281
+ assert (type_def);
248
282
lldb_private::Type *target_type =
249
283
m_ast.GetSymbolFile ()->ResolveTypeUID (type_def->getTypeId ());
250
284
if (!target_type)
@@ -261,7 +295,24 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
261
295
bytes, nullptr , target_type->GetID (),
262
296
lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef,
263
297
lldb_private::Type::eResolveStateFull);
264
- } else if (auto func_sig = llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) {
298
+ } break ;
299
+ case PDB_SymType::Function:
300
+ case PDB_SymType::FunctionSig: {
301
+ std::string name;
302
+ PDBSymbolTypeFunctionSig *func_sig = nullptr ;
303
+ if (auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(&type)) {
304
+ auto sig = pdb_func->getSignature ();
305
+ if (!sig)
306
+ return nullptr ;
307
+ func_sig = sig.release ();
308
+ // Function type is named.
309
+ name = pdb_func->getName ();
310
+ } else if (auto pdb_func_sig =
311
+ llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) {
312
+ func_sig = const_cast <PDBSymbolTypeFunctionSig*>(pdb_func_sig);
313
+ } else
314
+ llvm_unreachable (" Unexpected PDB symbol!" );
315
+
265
316
auto arg_enum = func_sig->getArguments ();
266
317
uint32_t num_args = arg_enum->getChildCount ();
267
318
std::vector<CompilerType> arg_list;
@@ -302,11 +353,15 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
302
353
return_ast_type, arg_list.data (), arg_list.size (), is_variadic,
303
354
type_quals);
304
355
356
+ GetDeclarationForSymbol (type, decl);
305
357
return std::make_shared<lldb_private::Type>(
306
- func_sig-> getSymIndexId (), m_ast.GetSymbolFile (), ConstString (), 0 ,
358
+ type. getSymIndexId (), m_ast.GetSymbolFile (), ConstString (name ), 0 ,
307
359
nullptr , LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl,
308
360
func_sig_ast_type, lldb_private::Type::eResolveStateFull);
309
- } else if (auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type)) {
361
+ } break ;
362
+ case PDB_SymType::ArrayType: {
363
+ auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type);
364
+ assert (array_type);
310
365
uint32_t num_elements = array_type->getCount ();
311
366
uint32_t element_uid = array_type->getElementType ()->getSymIndexId ();
312
367
uint32_t bytes = array_type->getLength ();
@@ -322,7 +377,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
322
377
array_type->getSymIndexId (), m_ast.GetSymbolFile (), ConstString (),
323
378
bytes, nullptr , LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID,
324
379
decl, array_ast_type, lldb_private::Type::eResolveStateFull);
325
- } else if (auto *builtin_type = llvm::dyn_cast<PDBSymbolTypeBuiltin>(&type)) {
380
+ } break ;
381
+ case PDB_SymType::BuiltinType: {
382
+ auto *builtin_type = llvm::dyn_cast<PDBSymbolTypeBuiltin>(&type);
383
+ assert (builtin_type);
326
384
PDB_BuiltinType builtin_kind = builtin_type->getBuiltinType ();
327
385
if (builtin_kind == PDB_BuiltinType::None)
328
386
return nullptr ;
@@ -347,7 +405,10 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
347
405
builtin_type->getSymIndexId (), m_ast.GetSymbolFile (), type_name,
348
406
bytes, nullptr , LLDB_INVALID_UID, encoding_data_type,
349
407
decl, builtin_ast_type, lldb_private::Type::eResolveStateFull);
350
- } else if (auto *pointer_type = llvm::dyn_cast<PDBSymbolTypePointer>(&type)) {
408
+ } break ;
409
+ case PDB_SymType::PointerType: {
410
+ auto *pointer_type = llvm::dyn_cast<PDBSymbolTypePointer>(&type);
411
+ assert (pointer_type);
351
412
Type *pointee_type = m_ast.GetSymbolFile ()->ResolveTypeUID (
352
413
pointer_type->getPointeeType ()->getSymIndexId ());
353
414
if (!pointee_type)
@@ -367,6 +428,8 @@ lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) {
367
428
pointer_type->getLength (), nullptr , LLDB_INVALID_UID,
368
429
encoding_data_type, decl, pointer_ast_type,
369
430
lldb_private::Type::eResolveStateFull);
431
+ } break ;
432
+ default : break ;
370
433
}
371
434
return nullptr ;
372
435
}
0 commit comments