1 //===-- PDBASTParser.cpp ----------------------------------------*- 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 #include "PDBASTParser.h" 11 12 #include "SymbolFilePDB.h" 13 14 #include "clang/AST/CharUnits.h" 15 #include "clang/AST/Decl.h" 16 #include "clang/AST/DeclCXX.h" 17 18 #include "lldb/Core/Module.h" 19 #include "lldb/Symbol/ClangASTContext.h" 20 #include "lldb/Symbol/ClangExternalASTSourceCommon.h" 21 #include "lldb/Symbol/ClangUtil.h" 22 #include "lldb/Symbol/Declaration.h" 23 #include "lldb/Symbol/SymbolFile.h" 24 #include "lldb/Symbol/TypeMap.h" 25 #include "lldb/Symbol/TypeSystem.h" 26 27 #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" 28 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" 29 #include "llvm/DebugInfo/PDB/PDBSymbol.h" 30 #include "llvm/DebugInfo/PDB/PDBSymbolData.h" 31 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" 32 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h" 33 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h" 34 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" 35 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h" 36 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" 37 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h" 38 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" 39 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" 40 41 using namespace lldb; 42 using namespace lldb_private; 43 using namespace llvm::pdb; 44 45 static int TranslateUdtKind(PDB_UdtType pdb_kind) { 46 switch (pdb_kind) { 47 case PDB_UdtType::Class: 48 return clang::TTK_Class; 49 case PDB_UdtType::Struct: 50 return clang::TTK_Struct; 51 case PDB_UdtType::Union: 52 return clang::TTK_Union; 53 case PDB_UdtType::Interface: 54 return clang::TTK_Interface; 55 } 56 llvm_unreachable("unsuported PDB UDT type"); 57 } 58 59 static lldb::Encoding TranslateBuiltinEncoding(PDB_BuiltinType type) { 60 switch (type) { 61 case PDB_BuiltinType::Float: 62 return lldb::eEncodingIEEE754; 63 case PDB_BuiltinType::Int: 64 case PDB_BuiltinType::Long: 65 case PDB_BuiltinType::Char: 66 return lldb::eEncodingSint; 67 case PDB_BuiltinType::Bool: 68 case PDB_BuiltinType::Char16: 69 case PDB_BuiltinType::Char32: 70 case PDB_BuiltinType::UInt: 71 case PDB_BuiltinType::ULong: 72 case PDB_BuiltinType::HResult: 73 case PDB_BuiltinType::WCharT: 74 return lldb::eEncodingUint; 75 default: 76 return lldb::eEncodingInvalid; 77 } 78 } 79 80 static lldb::Encoding TranslateEnumEncoding(PDB_VariantType type) { 81 switch (type) { 82 case PDB_VariantType::Int8: 83 case PDB_VariantType::Int16: 84 case PDB_VariantType::Int32: 85 case PDB_VariantType::Int64: 86 return lldb::eEncodingSint; 87 88 case PDB_VariantType::UInt8: 89 case PDB_VariantType::UInt16: 90 case PDB_VariantType::UInt32: 91 case PDB_VariantType::UInt64: 92 return lldb::eEncodingUint; 93 94 default: 95 break; 96 } 97 98 return lldb::eEncodingSint; 99 } 100 101 static CompilerType 102 GetBuiltinTypeForPDBEncodingAndBitSize(ClangASTContext &clang_ast, 103 const PDBSymbolTypeBuiltin &pdb_type, 104 Encoding encoding, uint32_t width) { 105 auto *ast = clang_ast.getASTContext(); 106 if (!ast) 107 return CompilerType(); 108 109 switch (pdb_type.getBuiltinType()) { 110 default: 111 break; 112 case PDB_BuiltinType::None: 113 return CompilerType(); 114 case PDB_BuiltinType::Void: 115 return clang_ast.GetBasicType(eBasicTypeVoid); 116 case PDB_BuiltinType::Bool: 117 return clang_ast.GetBasicType(eBasicTypeBool); 118 case PDB_BuiltinType::Long: 119 if (width == ast->getTypeSize(ast->LongTy)) 120 return CompilerType(ast, ast->LongTy); 121 if (width == ast->getTypeSize(ast->LongLongTy)) 122 return CompilerType(ast, ast->LongLongTy); 123 break; 124 case PDB_BuiltinType::ULong: 125 if (width == ast->getTypeSize(ast->UnsignedLongTy)) 126 return CompilerType(ast, ast->UnsignedLongTy); 127 if (width == ast->getTypeSize(ast->UnsignedLongLongTy)) 128 return CompilerType(ast, ast->UnsignedLongLongTy); 129 break; 130 case PDB_BuiltinType::WCharT: 131 if (width == ast->getTypeSize(ast->WCharTy)) 132 return CompilerType(ast, ast->WCharTy); 133 break; 134 case PDB_BuiltinType::Char16: 135 return CompilerType(ast, ast->Char16Ty); 136 case PDB_BuiltinType::Char32: 137 return CompilerType(ast, ast->Char32Ty); 138 case PDB_BuiltinType::Float: 139 // Note: types `long double` and `double` have same bit size in MSVC and 140 // there is no information in the PDB to distinguish them. So when falling 141 // back to default search, the compiler type of `long double` will be 142 // represented by the one generated for `double`. 143 break; 144 } 145 // If there is no match on PDB_BuiltinType, fall back to default search by 146 // encoding and width only 147 return clang_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, width); 148 } 149 150 static ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin &pdb_type, 151 CompilerType &compiler_type) { 152 PDB_BuiltinType kind = pdb_type.getBuiltinType(); 153 switch (kind) { 154 default: 155 break; 156 case PDB_BuiltinType::Currency: 157 return ConstString("CURRENCY"); 158 case PDB_BuiltinType::Date: 159 return ConstString("DATE"); 160 case PDB_BuiltinType::Variant: 161 return ConstString("VARIANT"); 162 case PDB_BuiltinType::Complex: 163 return ConstString("complex"); 164 case PDB_BuiltinType::Bitfield: 165 return ConstString("bitfield"); 166 case PDB_BuiltinType::BSTR: 167 return ConstString("BSTR"); 168 case PDB_BuiltinType::HResult: 169 return ConstString("HRESULT"); 170 case PDB_BuiltinType::BCD: 171 return ConstString("BCD"); 172 case PDB_BuiltinType::Char16: 173 return ConstString("char16_t"); 174 case PDB_BuiltinType::Char32: 175 return ConstString("char32_t"); 176 case PDB_BuiltinType::None: 177 return ConstString("..."); 178 } 179 return compiler_type.GetTypeName(); 180 } 181 182 static bool GetDeclarationForSymbol(const PDBSymbol &symbol, 183 Declaration &decl) { 184 auto &raw_sym = symbol.getRawSymbol(); 185 auto first_line_up = raw_sym.getSrcLineOnTypeDefn(); 186 187 if (!first_line_up) { 188 auto lines_up = symbol.getSession().findLineNumbersByAddress( 189 raw_sym.getVirtualAddress(), raw_sym.getLength()); 190 if (!lines_up) 191 return false; 192 first_line_up = lines_up->getNext(); 193 if (!first_line_up) 194 return false; 195 } 196 uint32_t src_file_id = first_line_up->getSourceFileId(); 197 auto src_file_up = symbol.getSession().getSourceFileById(src_file_id); 198 if (!src_file_up) 199 return false; 200 201 FileSpec spec(src_file_up->getFileName(), /*resolve_path*/ false); 202 decl.SetFile(spec); 203 decl.SetColumn(first_line_up->getColumnNumber()); 204 decl.SetLine(first_line_up->getLineNumber()); 205 return true; 206 } 207 208 static AccessType TranslateMemberAccess(PDB_MemberAccess access) { 209 switch (access) { 210 case PDB_MemberAccess::Private: 211 return eAccessPrivate; 212 case PDB_MemberAccess::Protected: 213 return eAccessProtected; 214 case PDB_MemberAccess::Public: 215 return eAccessPublic; 216 } 217 return eAccessNone; 218 } 219 220 static AccessType GetDefaultAccessibilityForUdtKind(PDB_UdtType udt_kind) { 221 switch (udt_kind) { 222 case PDB_UdtType::Struct: 223 case PDB_UdtType::Union: 224 return eAccessPublic; 225 case PDB_UdtType::Class: 226 case PDB_UdtType::Interface: 227 return eAccessPrivate; 228 } 229 llvm_unreachable("unsupported PDB UDT type"); 230 } 231 232 static AccessType GetAccessibilityForUdt(const PDBSymbolTypeUDT &udt) { 233 AccessType access = TranslateMemberAccess(udt.getAccess()); 234 if (access != lldb::eAccessNone || !udt.isNested()) 235 return access; 236 237 auto parent = udt.getClassParent(); 238 if (!parent) 239 return lldb::eAccessNone; 240 241 auto parent_udt = llvm::dyn_cast<PDBSymbolTypeUDT>(parent.get()); 242 if (!parent_udt) 243 return lldb::eAccessNone; 244 245 return GetDefaultAccessibilityForUdtKind(parent_udt->getUdtKind()); 246 } 247 248 static clang::MSInheritanceAttr::Spelling 249 GetMSInheritance(const PDBSymbolTypeUDT &udt) { 250 int base_count = 0; 251 bool has_virtual = false; 252 253 auto bases_enum = udt.findAllChildren<PDBSymbolTypeBaseClass>(); 254 if (bases_enum) { 255 while (auto base = bases_enum->getNext()) { 256 base_count++; 257 has_virtual |= base->isVirtualBaseClass(); 258 } 259 } 260 261 if (has_virtual) 262 return clang::MSInheritanceAttr::Keyword_virtual_inheritance; 263 if (base_count > 1) 264 return clang::MSInheritanceAttr::Keyword_multiple_inheritance; 265 return clang::MSInheritanceAttr::Keyword_single_inheritance; 266 } 267 268 static std::unique_ptr<llvm::pdb::PDBSymbol> 269 GetClassOrFunctionParent(const llvm::pdb::PDBSymbol &symbol) { 270 const IPDBSession &session = symbol.getSession(); 271 const IPDBRawSymbol &raw = symbol.getRawSymbol(); 272 auto tag = symbol.getSymTag(); 273 274 // For items that are nested inside of a class, return the class that it is 275 // nested inside of. 276 // Note that only certain items can be nested inside of classes. 277 switch (tag) { 278 case PDB_SymType::Function: 279 case PDB_SymType::Data: 280 case PDB_SymType::UDT: 281 case PDB_SymType::Enum: 282 case PDB_SymType::FunctionSig: 283 case PDB_SymType::Typedef: 284 case PDB_SymType::BaseClass: 285 case PDB_SymType::VTable: { 286 auto class_parent_id = raw.getClassParentId(); 287 if (auto class_parent = session.getSymbolById(class_parent_id)) 288 return class_parent; 289 } 290 default: 291 break; 292 } 293 294 // Otherwise, if it is nested inside of a function, return the function. 295 // Note that only certain items can be nested inside of functions. 296 switch (tag) { 297 case PDB_SymType::Block: 298 case PDB_SymType::Data: { 299 auto lexical_parent_id = raw.getLexicalParentId(); 300 auto lexical_parent = session.getSymbolById(lexical_parent_id); 301 if (!lexical_parent) 302 return nullptr; 303 304 auto lexical_parent_tag = lexical_parent->getSymTag(); 305 if (lexical_parent_tag == PDB_SymType::Function) 306 return lexical_parent; 307 if (lexical_parent_tag == PDB_SymType::Exe) 308 return nullptr; 309 310 return GetClassOrFunctionParent(*lexical_parent); 311 } 312 default: 313 return nullptr; 314 } 315 } 316 317 static clang::NamedDecl * 318 GetDeclFromContextByName(const clang::ASTContext &ast, 319 const clang::DeclContext &decl_context, 320 llvm::StringRef name) { 321 clang::IdentifierInfo &ident = ast.Idents.get(name); 322 clang::DeclarationName decl_name = ast.DeclarationNames.getIdentifier(&ident); 323 clang::DeclContext::lookup_result result = decl_context.lookup(decl_name); 324 if (result.empty()) 325 return nullptr; 326 327 return result[0]; 328 } 329 330 static bool IsAnonymousNamespaceName(const std::string &name) { 331 return name == "`anonymous namespace'" || name == "`anonymous-namespace'"; 332 } 333 334 PDBASTParser::PDBASTParser(lldb_private::ClangASTContext &ast) : m_ast(ast) {} 335 336 PDBASTParser::~PDBASTParser() {} 337 338 // DebugInfoASTParser interface 339 340 lldb::TypeSP PDBASTParser::CreateLLDBTypeFromPDBType(const PDBSymbol &type) { 341 Declaration decl; 342 switch (type.getSymTag()) { 343 case PDB_SymType::BaseClass: { 344 auto symbol_file = m_ast.GetSymbolFile(); 345 if (!symbol_file) 346 return nullptr; 347 348 auto ty = symbol_file->ResolveTypeUID(type.getRawSymbol().getTypeId()); 349 return ty ? ty->shared_from_this() : nullptr; 350 } break; 351 case PDB_SymType::UDT: { 352 auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&type); 353 assert(udt); 354 355 // Note that, unnamed UDT being typedef-ed is generated as a UDT symbol 356 // other than a Typedef symbol in PDB. For example, 357 // typedef union { short Row; short Col; } Union; 358 // is generated as a named UDT in PDB: 359 // union Union { short Row; short Col; } 360 // Such symbols will be handled here. 361 362 // Some UDT with trival ctor has zero length. Just ignore. 363 if (udt->getLength() == 0) 364 return nullptr; 365 366 // Ignore unnamed-tag UDTs. 367 auto name = PDBNameDropScope(udt->getName()); 368 if (name.empty()) 369 return nullptr; 370 371 auto decl_context = GetDeclContextContainingSymbol(type); 372 373 // Check if such an UDT already exists in the current context. 374 // This may occur with const or volatile types. There are separate type 375 // symbols in PDB for types with const or volatile modifiers, but we need 376 // to create only one declaration for them all. 377 Type::ResolveStateTag type_resolve_state_tag; 378 CompilerType clang_type = m_ast.GetTypeForIdentifier<clang::CXXRecordDecl>( 379 ConstString(name), decl_context); 380 if (!clang_type.IsValid()) { 381 auto access = GetAccessibilityForUdt(*udt); 382 383 auto tag_type_kind = TranslateUdtKind(udt->getUdtKind()); 384 385 ClangASTMetadata metadata; 386 metadata.SetUserID(type.getSymIndexId()); 387 metadata.SetIsDynamicCXXType(false); 388 389 clang_type = m_ast.CreateRecordType( 390 decl_context, access, name.c_str(), tag_type_kind, 391 lldb::eLanguageTypeC_plus_plus, &metadata); 392 assert(clang_type.IsValid()); 393 394 auto record_decl = 395 m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType()); 396 assert(record_decl); 397 m_uid_to_decl[type.getSymIndexId()] = record_decl; 398 399 auto inheritance_attr = clang::MSInheritanceAttr::CreateImplicit( 400 *m_ast.getASTContext(), GetMSInheritance(*udt)); 401 record_decl->addAttr(inheritance_attr); 402 403 ClangASTContext::StartTagDeclarationDefinition(clang_type); 404 405 auto children = udt->findAllChildren(); 406 if (!children || children->getChildCount() == 0) { 407 // PDB does not have symbol of forwarder. We assume we get an udt w/o 408 // any fields. Just complete it at this point. 409 ClangASTContext::CompleteTagDeclarationDefinition(clang_type); 410 411 ClangASTContext::SetHasExternalStorage(clang_type.GetOpaqueQualType(), 412 false); 413 414 type_resolve_state_tag = Type::eResolveStateFull; 415 } else { 416 // Add the type to the forward declarations. It will help us to avoid 417 // an endless recursion in CompleteTypeFromUdt function. 418 m_forward_decl_to_uid[record_decl] = type.getSymIndexId(); 419 420 ClangASTContext::SetHasExternalStorage(clang_type.GetOpaqueQualType(), 421 true); 422 423 type_resolve_state_tag = Type::eResolveStateForward; 424 } 425 } else 426 type_resolve_state_tag = Type::eResolveStateForward; 427 428 if (udt->isConstType()) 429 clang_type = clang_type.AddConstModifier(); 430 431 if (udt->isVolatileType()) 432 clang_type = clang_type.AddVolatileModifier(); 433 434 GetDeclarationForSymbol(type, decl); 435 return std::make_shared<lldb_private::Type>( 436 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), 437 udt->getLength(), nullptr, LLDB_INVALID_UID, 438 lldb_private::Type::eEncodingIsUID, decl, clang_type, 439 type_resolve_state_tag); 440 } break; 441 case PDB_SymType::Enum: { 442 auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(&type); 443 assert(enum_type); 444 445 std::string name = PDBNameDropScope(enum_type->getName()); 446 auto decl_context = GetDeclContextContainingSymbol(type); 447 uint64_t bytes = enum_type->getLength(); 448 449 // Check if such an enum already exists in the current context 450 CompilerType ast_enum = m_ast.GetTypeForIdentifier<clang::EnumDecl>( 451 ConstString(name), decl_context); 452 if (!ast_enum.IsValid()) { 453 auto underlying_type_up = enum_type->getUnderlyingType(); 454 if (!underlying_type_up) 455 return nullptr; 456 457 lldb::Encoding encoding = 458 TranslateBuiltinEncoding(underlying_type_up->getBuiltinType()); 459 // FIXME: Type of underlying builtin is always `Int`. We correct it with 460 // the very first enumerator's encoding if any. 461 auto first_child = enum_type->findOneChild<PDBSymbolData>(); 462 if (first_child) 463 encoding = TranslateEnumEncoding(first_child->getValue().Type); 464 465 CompilerType builtin_type; 466 if (bytes > 0) 467 builtin_type = GetBuiltinTypeForPDBEncodingAndBitSize( 468 m_ast, *underlying_type_up, encoding, bytes * 8); 469 else 470 builtin_type = m_ast.GetBasicType(eBasicTypeInt); 471 472 // FIXME: PDB does not have information about scoped enumeration (Enum 473 // Class). Set it false for now. 474 bool isScoped = false; 475 476 ast_enum = m_ast.CreateEnumerationType(name.c_str(), decl_context, decl, 477 builtin_type, isScoped); 478 479 auto enum_decl = ClangASTContext::GetAsEnumDecl(ast_enum); 480 assert(enum_decl); 481 m_uid_to_decl[type.getSymIndexId()] = enum_decl; 482 483 auto enum_values = enum_type->findAllChildren<PDBSymbolData>(); 484 if (enum_values) { 485 while (auto enum_value = enum_values->getNext()) { 486 if (enum_value->getDataKind() != PDB_DataKind::Constant) 487 continue; 488 AddEnumValue(ast_enum, *enum_value); 489 } 490 } 491 492 if (ClangASTContext::StartTagDeclarationDefinition(ast_enum)) 493 ClangASTContext::CompleteTagDeclarationDefinition(ast_enum); 494 } 495 496 if (enum_type->isConstType()) 497 ast_enum = ast_enum.AddConstModifier(); 498 499 if (enum_type->isVolatileType()) 500 ast_enum = ast_enum.AddVolatileModifier(); 501 502 GetDeclarationForSymbol(type, decl); 503 return std::make_shared<lldb_private::Type>( 504 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), bytes, 505 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, 506 ast_enum, lldb_private::Type::eResolveStateFull); 507 } break; 508 case PDB_SymType::Typedef: { 509 auto type_def = llvm::dyn_cast<PDBSymbolTypeTypedef>(&type); 510 assert(type_def); 511 512 lldb_private::Type *target_type = 513 m_ast.GetSymbolFile()->ResolveTypeUID(type_def->getTypeId()); 514 if (!target_type) 515 return nullptr; 516 517 std::string name = PDBNameDropScope(type_def->getName()); 518 auto decl_ctx = GetDeclContextContainingSymbol(type); 519 520 // Check if such a typedef already exists in the current context 521 CompilerType ast_typedef = 522 m_ast.GetTypeForIdentifier<clang::TypedefNameDecl>(ConstString(name), 523 decl_ctx); 524 if (!ast_typedef.IsValid()) { 525 CompilerType target_ast_type = target_type->GetFullCompilerType(); 526 527 ast_typedef = m_ast.CreateTypedefType( 528 target_ast_type, name.c_str(), CompilerDeclContext(&m_ast, decl_ctx)); 529 if (!ast_typedef) 530 return nullptr; 531 532 auto typedef_decl = ClangASTContext::GetAsTypedefDecl(ast_typedef); 533 assert(typedef_decl); 534 m_uid_to_decl[type.getSymIndexId()] = typedef_decl; 535 } 536 537 if (type_def->isConstType()) 538 ast_typedef = ast_typedef.AddConstModifier(); 539 540 if (type_def->isVolatileType()) 541 ast_typedef = ast_typedef.AddVolatileModifier(); 542 543 GetDeclarationForSymbol(type, decl); 544 return std::make_shared<lldb_private::Type>( 545 type_def->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), 546 type_def->getLength(), nullptr, target_type->GetID(), 547 lldb_private::Type::eEncodingIsTypedefUID, decl, ast_typedef, 548 lldb_private::Type::eResolveStateFull); 549 } break; 550 case PDB_SymType::Function: 551 case PDB_SymType::FunctionSig: { 552 std::string name; 553 PDBSymbolTypeFunctionSig *func_sig = nullptr; 554 if (auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(&type)) { 555 if (pdb_func->isCompilerGenerated()) 556 return nullptr; 557 558 auto sig = pdb_func->getSignature(); 559 if (!sig) 560 return nullptr; 561 func_sig = sig.release(); 562 // Function type is named. 563 name = PDBNameDropScope(pdb_func->getName()); 564 } else if (auto pdb_func_sig = 565 llvm::dyn_cast<PDBSymbolTypeFunctionSig>(&type)) { 566 func_sig = const_cast<PDBSymbolTypeFunctionSig *>(pdb_func_sig); 567 } else 568 llvm_unreachable("Unexpected PDB symbol!"); 569 570 auto arg_enum = func_sig->getArguments(); 571 uint32_t num_args = arg_enum->getChildCount(); 572 std::vector<CompilerType> arg_list; 573 574 bool is_variadic = func_sig->isCVarArgs(); 575 // Drop last variadic argument. 576 if (is_variadic) 577 --num_args; 578 for (uint32_t arg_idx = 0; arg_idx < num_args; arg_idx++) { 579 auto arg = arg_enum->getChildAtIndex(arg_idx); 580 if (!arg) 581 break; 582 lldb_private::Type *arg_type = 583 m_ast.GetSymbolFile()->ResolveTypeUID(arg->getSymIndexId()); 584 // If there's some error looking up one of the dependent types of this 585 // function signature, bail. 586 if (!arg_type) 587 return nullptr; 588 CompilerType arg_ast_type = arg_type->GetFullCompilerType(); 589 arg_list.push_back(arg_ast_type); 590 } 591 lldbassert(arg_list.size() <= num_args); 592 593 auto pdb_return_type = func_sig->getReturnType(); 594 lldb_private::Type *return_type = 595 m_ast.GetSymbolFile()->ResolveTypeUID(pdb_return_type->getSymIndexId()); 596 // If there's some error looking up one of the dependent types of this 597 // function signature, bail. 598 if (!return_type) 599 return nullptr; 600 CompilerType return_ast_type = return_type->GetFullCompilerType(); 601 uint32_t type_quals = 0; 602 if (func_sig->isConstType()) 603 type_quals |= clang::Qualifiers::Const; 604 if (func_sig->isVolatileType()) 605 type_quals |= clang::Qualifiers::Volatile; 606 CompilerType func_sig_ast_type = 607 m_ast.CreateFunctionType(return_ast_type, arg_list.data(), 608 arg_list.size(), is_variadic, type_quals); 609 610 GetDeclarationForSymbol(type, decl); 611 return std::make_shared<lldb_private::Type>( 612 type.getSymIndexId(), m_ast.GetSymbolFile(), ConstString(name), 0, 613 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, 614 func_sig_ast_type, lldb_private::Type::eResolveStateFull); 615 } break; 616 case PDB_SymType::ArrayType: { 617 auto array_type = llvm::dyn_cast<PDBSymbolTypeArray>(&type); 618 assert(array_type); 619 uint32_t num_elements = array_type->getCount(); 620 uint32_t element_uid = array_type->getElementTypeId(); 621 uint32_t bytes = array_type->getLength(); 622 623 // If array rank > 0, PDB gives the element type at N=0. So element type 624 // will parsed in the order N=0, N=1,..., N=rank sequentially. 625 lldb_private::Type *element_type = 626 m_ast.GetSymbolFile()->ResolveTypeUID(element_uid); 627 if (!element_type) 628 return nullptr; 629 630 CompilerType element_ast_type = element_type->GetForwardCompilerType(); 631 // If element type is UDT, it needs to be complete. 632 if (ClangASTContext::IsCXXClassType(element_ast_type) && 633 element_ast_type.GetCompleteType() == false) { 634 if (ClangASTContext::StartTagDeclarationDefinition(element_ast_type)) { 635 ClangASTContext::CompleteTagDeclarationDefinition(element_ast_type); 636 } else { 637 // We are not able to start defintion. 638 return nullptr; 639 } 640 } 641 CompilerType array_ast_type = m_ast.CreateArrayType( 642 element_ast_type, num_elements, /*is_gnu_vector*/ false); 643 TypeSP type_sp = std::make_shared<lldb_private::Type>( 644 array_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), 645 bytes, nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, 646 decl, array_ast_type, lldb_private::Type::eResolveStateFull); 647 type_sp->SetEncodingType(element_type); 648 return type_sp; 649 } break; 650 case PDB_SymType::BuiltinType: { 651 auto *builtin_type = llvm::dyn_cast<PDBSymbolTypeBuiltin>(&type); 652 assert(builtin_type); 653 PDB_BuiltinType builtin_kind = builtin_type->getBuiltinType(); 654 if (builtin_kind == PDB_BuiltinType::None) 655 return nullptr; 656 657 uint64_t bytes = builtin_type->getLength(); 658 Encoding encoding = TranslateBuiltinEncoding(builtin_kind); 659 CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize( 660 m_ast, *builtin_type, encoding, bytes * 8); 661 662 if (builtin_type->isConstType()) 663 builtin_ast_type = builtin_ast_type.AddConstModifier(); 664 665 if (builtin_type->isVolatileType()) 666 builtin_ast_type = builtin_ast_type.AddVolatileModifier(); 667 668 auto type_name = GetPDBBuiltinTypeName(*builtin_type, builtin_ast_type); 669 670 return std::make_shared<lldb_private::Type>( 671 builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), type_name, bytes, 672 nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, 673 builtin_ast_type, lldb_private::Type::eResolveStateFull); 674 } break; 675 case PDB_SymType::PointerType: { 676 auto *pointer_type = llvm::dyn_cast<PDBSymbolTypePointer>(&type); 677 assert(pointer_type); 678 Type *pointee_type = m_ast.GetSymbolFile()->ResolveTypeUID( 679 pointer_type->getPointeeType()->getSymIndexId()); 680 if (!pointee_type) 681 return nullptr; 682 683 if (pointer_type->isPointerToDataMember() || 684 pointer_type->isPointerToMemberFunction()) { 685 auto class_parent_uid = pointer_type->getRawSymbol().getClassParentId(); 686 auto class_parent_type = 687 m_ast.GetSymbolFile()->ResolveTypeUID(class_parent_uid); 688 assert(class_parent_type); 689 690 CompilerType pointer_ast_type; 691 pointer_ast_type = ClangASTContext::CreateMemberPointerType( 692 class_parent_type->GetLayoutCompilerType(), 693 pointee_type->GetForwardCompilerType()); 694 assert(pointer_ast_type); 695 696 return std::make_shared<lldb_private::Type>( 697 pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), 698 pointer_type->getLength(), nullptr, LLDB_INVALID_UID, 699 lldb_private::Type::eEncodingIsUID, decl, pointer_ast_type, 700 lldb_private::Type::eResolveStateForward); 701 } 702 703 CompilerType pointer_ast_type; 704 pointer_ast_type = pointee_type->GetFullCompilerType(); 705 if (pointer_type->isReference()) 706 pointer_ast_type = pointer_ast_type.GetLValueReferenceType(); 707 else if (pointer_type->isRValueReference()) 708 pointer_ast_type = pointer_ast_type.GetRValueReferenceType(); 709 else 710 pointer_ast_type = pointer_ast_type.GetPointerType(); 711 712 if (pointer_type->isConstType()) 713 pointer_ast_type = pointer_ast_type.AddConstModifier(); 714 715 if (pointer_type->isVolatileType()) 716 pointer_ast_type = pointer_ast_type.AddVolatileModifier(); 717 718 if (pointer_type->isRestrictedType()) 719 pointer_ast_type = pointer_ast_type.AddRestrictModifier(); 720 721 return std::make_shared<lldb_private::Type>( 722 pointer_type->getSymIndexId(), m_ast.GetSymbolFile(), ConstString(), 723 pointer_type->getLength(), nullptr, LLDB_INVALID_UID, 724 lldb_private::Type::eEncodingIsUID, decl, pointer_ast_type, 725 lldb_private::Type::eResolveStateFull); 726 } break; 727 default: 728 break; 729 } 730 return nullptr; 731 } 732 733 bool PDBASTParser::CompleteTypeFromPDB( 734 lldb_private::CompilerType &compiler_type) { 735 if (GetClangASTImporter().CanImport(compiler_type)) 736 return GetClangASTImporter().CompleteType(compiler_type); 737 738 // Remove the type from the forward declarations to avoid 739 // an endless recursion for types like a linked list. 740 clang::CXXRecordDecl *record_decl = 741 m_ast.GetAsCXXRecordDecl(compiler_type.GetOpaqueQualType()); 742 auto uid_it = m_forward_decl_to_uid.find(record_decl); 743 if (uid_it == m_forward_decl_to_uid.end()) 744 return true; 745 746 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile()); 747 if (!symbol_file) 748 return false; 749 750 std::unique_ptr<PDBSymbol> symbol = 751 symbol_file->GetPDBSession().getSymbolById(uid_it->getSecond()); 752 if (!symbol) 753 return false; 754 755 m_forward_decl_to_uid.erase(uid_it); 756 757 ClangASTContext::SetHasExternalStorage(compiler_type.GetOpaqueQualType(), 758 false); 759 760 switch (symbol->getSymTag()) { 761 case PDB_SymType::UDT: { 762 auto udt = llvm::dyn_cast<PDBSymbolTypeUDT>(symbol.get()); 763 if (!udt) 764 return false; 765 766 return CompleteTypeFromUDT(*symbol_file, compiler_type, *udt); 767 } 768 default: 769 llvm_unreachable("not a forward clang type decl!"); 770 } 771 } 772 773 clang::Decl * 774 PDBASTParser::GetDeclForSymbol(const llvm::pdb::PDBSymbol &symbol) { 775 auto it = m_uid_to_decl.find(symbol.getSymIndexId()); 776 if (it != m_uid_to_decl.end()) 777 return it->second; 778 779 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile()); 780 if (!symbol_file) 781 return nullptr; 782 783 // First of all, check if the symbol is a member of a class. Resolve the full 784 // class type and return the declaration from the cache if so. 785 auto tag = symbol.getSymTag(); 786 if (tag == PDB_SymType::Data || tag == PDB_SymType::Function) { 787 const IPDBSession &session = symbol.getSession(); 788 const IPDBRawSymbol &raw = symbol.getRawSymbol(); 789 790 auto class_parent_id = raw.getClassParentId(); 791 if (session.getSymbolById(class_parent_id)) { 792 auto class_parent_type = symbol_file->ResolveTypeUID(class_parent_id); 793 if (!class_parent_type) 794 return nullptr; 795 796 class_parent_type->GetFullCompilerType(); 797 798 return m_uid_to_decl.lookup(symbol.getSymIndexId()); 799 } 800 } 801 802 // If we are here, then the symbol is not belonging to a class and is not 803 // contained in the cache. So create a declaration for it. 804 switch (symbol.getSymTag()) { 805 case PDB_SymType::Data: { 806 auto data = llvm::dyn_cast<PDBSymbolData>(&symbol); 807 assert(data); 808 809 auto decl_context = GetDeclContextContainingSymbol(symbol); 810 assert(decl_context); 811 812 // May be the current context is a class really, but we haven't found 813 // any class parent. This happens e.g. in the case of class static 814 // variables - they has two symbols, one is a child of the class when 815 // another is a child of the exe. So always complete the parent and use 816 // an existing declaration if possible. 817 if (auto parent_decl = llvm::dyn_cast_or_null<clang::TagDecl>(decl_context)) 818 m_ast.GetCompleteDecl(parent_decl); 819 820 auto name = PDBNameDropScope(data->getName()); 821 822 // Check if the current context already contains the symbol with the name. 823 clang::Decl *decl = 824 GetDeclFromContextByName(*m_ast.getASTContext(), *decl_context, name); 825 if (!decl) { 826 auto type = symbol_file->ResolveTypeUID(data->getTypeId()); 827 if (!type) 828 return nullptr; 829 830 decl = m_ast.CreateVariableDeclaration( 831 decl_context, name.c_str(), 832 ClangUtil::GetQualType(type->GetLayoutCompilerType())); 833 } 834 835 m_uid_to_decl[data->getSymIndexId()] = decl; 836 837 return decl; 838 } 839 case PDB_SymType::Function: { 840 auto func = llvm::dyn_cast<PDBSymbolFunc>(&symbol); 841 assert(func); 842 843 auto decl_context = GetDeclContextContainingSymbol(symbol); 844 assert(decl_context); 845 846 auto name = PDBNameDropScope(func->getName()); 847 848 auto type = symbol_file->ResolveTypeUID(func->getSymIndexId()); 849 if (!type) 850 return nullptr; 851 852 auto storage = func->isStatic() ? clang::StorageClass::SC_Static 853 : clang::StorageClass::SC_None; 854 855 auto decl = m_ast.CreateFunctionDeclaration( 856 decl_context, name.c_str(), type->GetForwardCompilerType(), storage, 857 func->hasInlineAttribute()); 858 859 m_uid_to_decl[func->getSymIndexId()] = decl; 860 861 return decl; 862 } 863 default: { 864 // It's not a variable and not a function, check if it's a type 865 auto type = symbol_file->ResolveTypeUID(symbol.getSymIndexId()); 866 if (!type) 867 return nullptr; 868 869 return m_uid_to_decl.lookup(symbol.getSymIndexId()); 870 } 871 } 872 } 873 874 clang::DeclContext * 875 PDBASTParser::GetDeclContextForSymbol(const llvm::pdb::PDBSymbol &symbol) { 876 if (symbol.getSymTag() == PDB_SymType::Function) { 877 clang::DeclContext *result = 878 llvm::dyn_cast_or_null<clang::FunctionDecl>(GetDeclForSymbol(symbol)); 879 880 if (result) 881 m_decl_context_to_uid[result] = symbol.getSymIndexId(); 882 883 return result; 884 } 885 886 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile()); 887 if (!symbol_file) 888 return nullptr; 889 890 auto type = symbol_file->ResolveTypeUID(symbol.getSymIndexId()); 891 if (!type) 892 return nullptr; 893 894 clang::DeclContext *result = 895 m_ast.GetDeclContextForType(type->GetForwardCompilerType()); 896 897 if (result) 898 m_decl_context_to_uid[result] = symbol.getSymIndexId(); 899 900 return result; 901 } 902 903 clang::DeclContext *PDBASTParser::GetDeclContextContainingSymbol( 904 const llvm::pdb::PDBSymbol &symbol) { 905 auto parent = GetClassOrFunctionParent(symbol); 906 while (parent) { 907 if (auto parent_context = GetDeclContextForSymbol(*parent)) 908 return parent_context; 909 910 parent = GetClassOrFunctionParent(*parent); 911 } 912 913 // We can't find any class or function parent of the symbol. So analyze 914 // the full symbol name. The symbol may be belonging to a namespace 915 // or function (or even to a class if it's e.g. a static variable symbol). 916 // We do not use CPlusPlusNameParser because it fails on things like 917 // `anonymous namespace'. 918 919 // TODO: Make clang to emit full names for variables in namespaces 920 // (as MSVC does) 921 922 auto context = symbol.getRawSymbol().getName(); 923 auto context_size = context.rfind("::"); 924 if (context_size == std::string::npos) 925 context_size = 0; 926 context = context.substr(0, context_size); 927 928 // Check if there is a symbol with the name of the context. 929 930 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile()); 931 if (!symbol_file) 932 return m_ast.GetTranslationUnitDecl(); 933 934 auto global = symbol_file->GetPDBSession().getGlobalScope(); 935 if (!global) 936 return m_ast.GetTranslationUnitDecl(); 937 938 TypeMap types; 939 if (auto children_enum = 940 global->findChildren(PDB_SymType::None, context, NS_CaseSensitive)) 941 while (auto child = children_enum->getNext()) 942 if (auto child_context = GetDeclContextForSymbol(*child)) 943 return child_context; 944 945 // Split context and retrieve nested namespaces 946 auto curr_context = m_ast.GetTranslationUnitDecl(); 947 std::string::size_type from = 0; 948 while (from < context_size) { 949 auto to = context.find("::", from); 950 if (to == std::string::npos) 951 to = context_size; 952 953 auto namespace_name = context.substr(from, to - from); 954 auto namespace_name_c_str = IsAnonymousNamespaceName(namespace_name) 955 ? nullptr 956 : namespace_name.c_str(); 957 auto namespace_decl = 958 m_ast.GetUniqueNamespaceDeclaration(namespace_name_c_str, curr_context); 959 960 m_parent_to_namespaces[curr_context].insert(namespace_decl); 961 962 curr_context = namespace_decl; 963 from = to + 2; 964 } 965 966 return curr_context; 967 } 968 969 void PDBASTParser::ParseDeclsForDeclContext( 970 const clang::DeclContext *decl_context) { 971 auto symbol_file = static_cast<SymbolFilePDB *>(m_ast.GetSymbolFile()); 972 if (!symbol_file) 973 return; 974 975 IPDBSession &session = symbol_file->GetPDBSession(); 976 auto symbol_up = 977 session.getSymbolById(m_decl_context_to_uid.lookup(decl_context)); 978 auto global_up = session.getGlobalScope(); 979 980 PDBSymbol *symbol; 981 if (symbol_up) 982 symbol = symbol_up.get(); 983 else if (global_up) 984 symbol = global_up.get(); 985 else 986 return; 987 988 if (auto children = symbol->findAllChildren()) 989 while (auto child = children->getNext()) 990 GetDeclForSymbol(*child); 991 } 992 993 clang::NamespaceDecl * 994 PDBASTParser::FindNamespaceDecl(const clang::DeclContext *parent, 995 llvm::StringRef name) { 996 if (!parent) 997 parent = m_ast.GetTranslationUnitDecl(); 998 999 auto it = m_parent_to_namespaces.find(parent); 1000 if (it == m_parent_to_namespaces.end()) 1001 return nullptr; 1002 1003 for (auto namespace_decl : it->second) 1004 if (namespace_decl->getName().equals(name)) 1005 return namespace_decl; 1006 1007 for (auto namespace_decl : it->second) 1008 if (namespace_decl->isAnonymousNamespace()) 1009 return FindNamespaceDecl(namespace_decl, name); 1010 1011 return nullptr; 1012 } 1013 1014 std::string PDBASTParser::PDBNameDropScope(const std::string &name) { 1015 // Not all PDB names can be parsed with CPlusPlusNameParser. 1016 // E.g. it fails on names containing `anonymous namespace'. 1017 // So we simply drop everything before '::' 1018 1019 auto offset = name.rfind("::"); 1020 if (offset == std::string::npos) 1021 return name; 1022 assert(offset + 2 <= name.size()); 1023 1024 return name.substr(offset + 2); 1025 } 1026 1027 bool PDBASTParser::AddEnumValue(CompilerType enum_type, 1028 const PDBSymbolData &enum_value) { 1029 Declaration decl; 1030 Variant v = enum_value.getValue(); 1031 std::string name = PDBNameDropScope(enum_value.getName()); 1032 int64_t raw_value; 1033 switch (v.Type) { 1034 case PDB_VariantType::Int8: 1035 raw_value = v.Value.Int8; 1036 break; 1037 case PDB_VariantType::Int16: 1038 raw_value = v.Value.Int16; 1039 break; 1040 case PDB_VariantType::Int32: 1041 raw_value = v.Value.Int32; 1042 break; 1043 case PDB_VariantType::Int64: 1044 raw_value = v.Value.Int64; 1045 break; 1046 case PDB_VariantType::UInt8: 1047 raw_value = v.Value.UInt8; 1048 break; 1049 case PDB_VariantType::UInt16: 1050 raw_value = v.Value.UInt16; 1051 break; 1052 case PDB_VariantType::UInt32: 1053 raw_value = v.Value.UInt32; 1054 break; 1055 case PDB_VariantType::UInt64: 1056 raw_value = v.Value.UInt64; 1057 break; 1058 default: 1059 return false; 1060 } 1061 CompilerType underlying_type = 1062 m_ast.GetEnumerationIntegerType(enum_type.GetOpaqueQualType()); 1063 uint32_t byte_size = m_ast.getASTContext()->getTypeSize( 1064 ClangUtil::GetQualType(underlying_type)); 1065 auto enum_constant_decl = m_ast.AddEnumerationValueToEnumerationType( 1066 enum_type.GetOpaqueQualType(), underlying_type, decl, name.c_str(), 1067 raw_value, byte_size * 8); 1068 if (!enum_constant_decl) 1069 return false; 1070 1071 m_uid_to_decl[enum_value.getSymIndexId()] = enum_constant_decl; 1072 1073 return true; 1074 } 1075 1076 bool PDBASTParser::CompleteTypeFromUDT( 1077 lldb_private::SymbolFile &symbol_file, 1078 lldb_private::CompilerType &compiler_type, 1079 llvm::pdb::PDBSymbolTypeUDT &udt) { 1080 ClangASTImporter::LayoutInfo layout_info; 1081 layout_info.bit_size = udt.getLength() * 8; 1082 1083 auto nested_enums = udt.findAllChildren<PDBSymbolTypeUDT>(); 1084 if (nested_enums) 1085 while (auto nested = nested_enums->getNext()) 1086 symbol_file.ResolveTypeUID(nested->getSymIndexId()); 1087 1088 auto bases_enum = udt.findAllChildren<PDBSymbolTypeBaseClass>(); 1089 if (bases_enum) 1090 AddRecordBases(symbol_file, compiler_type, 1091 TranslateUdtKind(udt.getUdtKind()), *bases_enum, 1092 layout_info); 1093 1094 auto members_enum = udt.findAllChildren<PDBSymbolData>(); 1095 if (members_enum) 1096 AddRecordMembers(symbol_file, compiler_type, *members_enum, layout_info); 1097 1098 auto methods_enum = udt.findAllChildren<PDBSymbolFunc>(); 1099 if (methods_enum) 1100 AddRecordMethods(symbol_file, compiler_type, *methods_enum); 1101 1102 m_ast.AddMethodOverridesForCXXRecordType(compiler_type.GetOpaqueQualType()); 1103 ClangASTContext::BuildIndirectFields(compiler_type); 1104 ClangASTContext::CompleteTagDeclarationDefinition(compiler_type); 1105 1106 clang::CXXRecordDecl *record_decl = 1107 m_ast.GetAsCXXRecordDecl(compiler_type.GetOpaqueQualType()); 1108 if (!record_decl) 1109 return static_cast<bool>(compiler_type); 1110 1111 GetClangASTImporter().InsertRecordDecl(record_decl, layout_info); 1112 1113 return static_cast<bool>(compiler_type); 1114 } 1115 1116 void PDBASTParser::AddRecordMembers( 1117 lldb_private::SymbolFile &symbol_file, 1118 lldb_private::CompilerType &record_type, 1119 PDBDataSymbolEnumerator &members_enum, 1120 lldb_private::ClangASTImporter::LayoutInfo &layout_info) { 1121 while (auto member = members_enum.getNext()) { 1122 if (member->isCompilerGenerated()) 1123 continue; 1124 1125 auto member_name = member->getName(); 1126 1127 auto member_type = symbol_file.ResolveTypeUID(member->getTypeId()); 1128 if (!member_type) 1129 continue; 1130 1131 auto member_comp_type = member_type->GetLayoutCompilerType(); 1132 if (!member_comp_type.GetCompleteType()) { 1133 symbol_file.GetObjectFile()->GetModule()->ReportError( 1134 ":: Class '%s' has a member '%s' of type '%s' " 1135 "which does not have a complete definition.", 1136 record_type.GetTypeName().GetCString(), member_name.c_str(), 1137 member_comp_type.GetTypeName().GetCString()); 1138 if (ClangASTContext::StartTagDeclarationDefinition(member_comp_type)) 1139 ClangASTContext::CompleteTagDeclarationDefinition(member_comp_type); 1140 } 1141 1142 auto access = TranslateMemberAccess(member->getAccess()); 1143 1144 switch (member->getDataKind()) { 1145 case PDB_DataKind::Member: { 1146 auto location_type = member->getLocationType(); 1147 1148 auto bit_size = member->getLength(); 1149 if (location_type == PDB_LocType::ThisRel) 1150 bit_size *= 8; 1151 1152 auto decl = ClangASTContext::AddFieldToRecordType( 1153 record_type, member_name.c_str(), member_comp_type, access, bit_size); 1154 if (!decl) 1155 continue; 1156 1157 m_uid_to_decl[member->getSymIndexId()] = decl; 1158 1159 auto offset = member->getOffset() * 8; 1160 if (location_type == PDB_LocType::BitField) 1161 offset += member->getBitPosition(); 1162 1163 layout_info.field_offsets.insert(std::make_pair(decl, offset)); 1164 1165 break; 1166 } 1167 case PDB_DataKind::StaticMember: { 1168 auto decl = ClangASTContext::AddVariableToRecordType( 1169 record_type, member_name.c_str(), member_comp_type, access); 1170 if (!decl) 1171 continue; 1172 1173 m_uid_to_decl[member->getSymIndexId()] = decl; 1174 1175 break; 1176 } 1177 default: 1178 llvm_unreachable("unsupported PDB data kind"); 1179 } 1180 } 1181 } 1182 1183 void PDBASTParser::AddRecordBases( 1184 lldb_private::SymbolFile &symbol_file, 1185 lldb_private::CompilerType &record_type, int record_kind, 1186 PDBBaseClassSymbolEnumerator &bases_enum, 1187 lldb_private::ClangASTImporter::LayoutInfo &layout_info) const { 1188 std::vector<clang::CXXBaseSpecifier *> base_classes; 1189 while (auto base = bases_enum.getNext()) { 1190 auto base_type = symbol_file.ResolveTypeUID(base->getTypeId()); 1191 if (!base_type) 1192 continue; 1193 1194 auto base_comp_type = base_type->GetFullCompilerType(); 1195 if (!base_comp_type.GetCompleteType()) { 1196 symbol_file.GetObjectFile()->GetModule()->ReportError( 1197 ":: Class '%s' has a base class '%s' " 1198 "which does not have a complete definition.", 1199 record_type.GetTypeName().GetCString(), 1200 base_comp_type.GetTypeName().GetCString()); 1201 if (ClangASTContext::StartTagDeclarationDefinition(base_comp_type)) 1202 ClangASTContext::CompleteTagDeclarationDefinition(base_comp_type); 1203 } 1204 1205 auto access = TranslateMemberAccess(base->getAccess()); 1206 1207 auto is_virtual = base->isVirtualBaseClass(); 1208 1209 auto base_class_spec = m_ast.CreateBaseClassSpecifier( 1210 base_comp_type.GetOpaqueQualType(), access, is_virtual, 1211 record_kind == clang::TTK_Class); 1212 if (!base_class_spec) 1213 continue; 1214 1215 base_classes.push_back(base_class_spec); 1216 1217 if (is_virtual) 1218 continue; 1219 1220 auto decl = m_ast.GetAsCXXRecordDecl(base_comp_type.GetOpaqueQualType()); 1221 if (!decl) 1222 continue; 1223 1224 auto offset = clang::CharUnits::fromQuantity(base->getOffset()); 1225 layout_info.base_offsets.insert(std::make_pair(decl, offset)); 1226 } 1227 if (!base_classes.empty()) { 1228 m_ast.SetBaseClassesForClassType(record_type.GetOpaqueQualType(), 1229 &base_classes.front(), 1230 base_classes.size()); 1231 ClangASTContext::DeleteBaseClassSpecifiers(&base_classes.front(), 1232 base_classes.size()); 1233 } 1234 } 1235 1236 void PDBASTParser::AddRecordMethods(lldb_private::SymbolFile &symbol_file, 1237 lldb_private::CompilerType &record_type, 1238 PDBFuncSymbolEnumerator &methods_enum) { 1239 while (auto method = methods_enum.getNext()) { 1240 auto name = PDBNameDropScope(method->getName().c_str()); 1241 1242 auto method_type = symbol_file.ResolveTypeUID(method->getSymIndexId()); 1243 // MSVC specific __vecDelDtor. 1244 if (!method_type) 1245 continue; 1246 1247 auto method_comp_type = method_type->GetFullCompilerType(); 1248 if (!method_comp_type.GetCompleteType()) { 1249 symbol_file.GetObjectFile()->GetModule()->ReportError( 1250 ":: Class '%s' has a method '%s' whose type cannot be completed.", 1251 record_type.GetTypeName().GetCString(), 1252 method_comp_type.GetTypeName().GetCString()); 1253 if (ClangASTContext::StartTagDeclarationDefinition(method_comp_type)) 1254 ClangASTContext::CompleteTagDeclarationDefinition(method_comp_type); 1255 } 1256 1257 // TODO: get mangled name for the method. 1258 auto decl = m_ast.AddMethodToCXXRecordType( 1259 record_type.GetOpaqueQualType(), name.c_str(), 1260 /*mangled_name*/ nullptr, method_comp_type, 1261 TranslateMemberAccess(method->getAccess()), method->isVirtual(), 1262 method->isStatic(), method->hasInlineAttribute(), 1263 /*is_explicit*/ false, // FIXME: Need this field in CodeView. 1264 /*is_attr_used*/ false, 1265 /*is_artificial*/ method->isCompilerGenerated()); 1266 if (!decl) 1267 continue; 1268 1269 m_uid_to_decl[method->getSymIndexId()] = decl; 1270 } 1271 } 1272