Index: source/Plugins/SymbolFile/PDB/PDBASTParser.cpp =================================================================== --- source/Plugins/SymbolFile/PDB/PDBASTParser.cpp +++ source/Plugins/SymbolFile/PDB/PDBASTParser.cpp @@ -94,24 +94,20 @@ } CompilerType GetBuiltinTypeForPDBEncodingAndBitSize( - ClangASTContext *clang_ast, const PDBSymbolTypeBuiltin *pdb_type, + ClangASTContext &clang_ast, const PDBSymbolTypeBuiltin &pdb_type, Encoding encoding, uint32_t width) { - if (!pdb_type) - return CompilerType(); - if (!clang_ast) - return CompilerType(); - auto *ast = clang_ast->getASTContext(); + auto *ast = clang_ast.getASTContext(); if (!ast) return CompilerType(); - switch (pdb_type->getBuiltinType()) { + switch (pdb_type.getBuiltinType()) { default: break; case PDB_BuiltinType::None: return CompilerType(); case PDB_BuiltinType::Void: - return clang_ast->GetBasicType(eBasicTypeVoid); + return clang_ast.GetBasicType(eBasicTypeVoid); case PDB_BuiltinType::Bool: - return clang_ast->GetBasicType(eBasicTypeBool); + return clang_ast.GetBasicType(eBasicTypeBool); case PDB_BuiltinType::Long: if (width == ast->getTypeSize(ast->LongTy)) return CompilerType(ast, ast->LongTy); @@ -141,15 +137,12 @@ } // If there is no match on PDB_BuiltinType, fall back to default search // by encoding and width only - return clang_ast->GetBuiltinTypeForEncodingAndBitSize(encoding, width); + return clang_ast.GetBuiltinTypeForEncodingAndBitSize(encoding, width); } -ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin *pdb_type, +ConstString GetPDBBuiltinTypeName(const PDBSymbolTypeBuiltin &pdb_type, CompilerType &compiler_type) { - if (!pdb_type) - return compiler_type.GetTypeName(); - - PDB_BuiltinType kind = pdb_type->getBuiltinType(); + PDB_BuiltinType kind = pdb_type.getBuiltinType(); switch (kind) { default: break; case PDB_BuiltinType::Currency: @@ -262,7 +255,7 @@ CompilerType builtin_type; if (bytes > 0) builtin_type = GetBuiltinTypeForPDBEncodingAndBitSize( - &m_ast, underlying_type_up.get(), encoding, bytes * 8); + m_ast, *underlying_type_up, encoding, bytes * 8); else builtin_type = m_ast.GetBasicType(eBasicTypeInt); // FIXME: PDB does not have information about scoped enumeration (Enum Class). @@ -418,7 +411,7 @@ uint64_t bytes = builtin_type->getLength(); Encoding encoding = TranslateBuiltinEncoding(builtin_kind); CompilerType builtin_ast_type = GetBuiltinTypeForPDBEncodingAndBitSize( - &m_ast, builtin_type, encoding, bytes * 8); + m_ast, *builtin_type, encoding, bytes * 8); if (builtin_type->isConstType()) builtin_ast_type = builtin_ast_type.AddConstModifier(); @@ -426,7 +419,7 @@ if (builtin_type->isVolatileType()) builtin_ast_type = builtin_ast_type.AddVolatileModifier(); - auto type_name = GetPDBBuiltinTypeName(builtin_type, builtin_ast_type); + auto type_name = GetPDBBuiltinTypeName(*builtin_type, builtin_ast_type); return std::make_shared( builtin_type->getSymIndexId(), m_ast.GetSymbolFile(), type_name, Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.h =================================================================== --- source/Plugins/SymbolFile/PDB/SymbolFilePDB.h +++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.h @@ -188,14 +188,14 @@ typedef std::vector TypeCollection; void - GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol *pdb_symbol, + GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, uint32_t type_mask, TypeCollection &type_collection); lldb_private::Function* ParseCompileUnitFunctionForPDBFunc( - const llvm::pdb::PDBSymbolFunc *pdb_func, + const llvm::pdb::PDBSymbolFunc &pdb_func, const lldb_private::SymbolContext &sc); - void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland *pdb_compiland, + void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index); std::string GetSourceFileNameForPDBCompiland( @@ -205,9 +205,9 @@ GetPDBCompilandByUID(uint32_t uid); lldb_private::Mangled - GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc *pdb_func); + GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func); - bool ResolveFunction(llvm::pdb::PDBSymbolFunc *pdb_func, + bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, bool include_inlines, lldb_private::SymbolContextList &sc_list); Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp =================================================================== --- source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -205,15 +205,12 @@ } void SymbolFilePDB::GetCompileUnitIndex( - const llvm::pdb::PDBSymbolCompiland *pdb_compiland, + const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index) { - if (!pdb_compiland) - return; - auto results_up = m_global_scope_up->findAllChildren(); if (!results_up) return; - auto uid = pdb_compiland->getSymIndexId(); + auto uid = pdb_compiland.getSymIndexId(); for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) { auto compiland_up = results_up->getChildAtIndex(cu_idx); if (!compiland_up) @@ -266,32 +263,31 @@ lldb_private::Function * SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc( - const PDBSymbolFunc *pdb_func, + const PDBSymbolFunc &pdb_func, const lldb_private::SymbolContext &sc) { - assert(pdb_func != nullptr); lldbassert(sc.comp_unit && sc.module_sp.get()); - auto file_vm_addr = pdb_func->getVirtualAddress(); + auto file_vm_addr = pdb_func.getVirtualAddress(); if (file_vm_addr == LLDB_INVALID_ADDRESS) return nullptr; - auto func_length = pdb_func->getLength(); + auto func_length = pdb_func.getLength(); AddressRange func_range = AddressRange(file_vm_addr, func_length, sc.module_sp->GetSectionList()); if (!func_range.GetBaseAddress().IsValid()) return nullptr; - lldb_private::Type* func_type = ResolveTypeUID(pdb_func->getSymIndexId()); + lldb_private::Type* func_type = ResolveTypeUID(pdb_func.getSymIndexId()); if (!func_type) return nullptr; - user_id_t func_type_uid = pdb_func->getSignatureId(); + user_id_t func_type_uid = pdb_func.getSignatureId(); Mangled mangled = GetMangledForPDBFunc(pdb_func); FunctionSP func_sp = std::make_shared(sc.comp_unit, - pdb_func->getSymIndexId(), + pdb_func.getSymIndexId(), func_type_uid, mangled, func_type, @@ -315,7 +311,7 @@ auto func_sp = sc.comp_unit->FindFunctionByUID(pdb_func_up->getSymIndexId()); if (!func_sp) { - if (ParseCompileUnitFunctionForPDBFunc(pdb_func_up.get(), sc)) + if (ParseCompileUnitFunctionForPDBFunc(*pdb_func_up, sc)) ++func_added; } } @@ -562,7 +558,7 @@ auto func_uid = pdb_func->getSymIndexId(); sc.function = sc.comp_unit->FindFunctionByUID(func_uid).get(); if (sc.function == nullptr) - sc.function = ParseCompileUnitFunctionForPDBFunc(pdb_func, sc); + sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc); if (sc.function) { resolved_flags |= eSymbolContextFunction; if (resolve_scope & eSymbolContextBlock) { @@ -736,7 +732,7 @@ if (sc.function == nullptr) { auto pdb_func = llvm::dyn_cast(symbol_up.get()); assert(pdb_func); - sc.function = ParseCompileUnitFunctionForPDBFunc(pdb_func, sc); + sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc); } if (sc.function && (resolve_scope & eSymbolContextBlock)) { Block &block = sc.function->GetBlock(true); @@ -774,13 +770,11 @@ return uint32_t(); } -bool SymbolFilePDB::ResolveFunction(llvm::pdb::PDBSymbolFunc *pdb_func, +bool SymbolFilePDB::ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, bool include_inlines, lldb_private::SymbolContextList &sc_list) { - if (!pdb_func) - return false; lldb_private::SymbolContext sc; - auto file_vm_addr = pdb_func->getVirtualAddress(); + auto file_vm_addr = pdb_func.getVirtualAddress(); if (file_vm_addr == LLDB_INVALID_ADDRESS) return false; @@ -796,7 +790,7 @@ auto *func = llvm::dyn_cast(symbol_up.get()); assert(func); - sc.function = ParseCompileUnitFunctionForPDBFunc(func, sc); + sc.function = ParseCompileUnitFunctionForPDBFunc(*func, sc); if (!sc.function) return false; @@ -810,7 +804,7 @@ m_session_up->getConcreteSymbolById(uid); if (!pdb_func_up && !(include_inlines && pdb_func_up->hasInlineAttribute())) return false; - return ResolveFunction(pdb_func_up.get(), include_inlines, sc_list); + return ResolveFunction(*pdb_func_up, include_inlines, sc_list); } void SymbolFilePDB::CacheFunctionNames() { @@ -1134,14 +1128,11 @@ } void -SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol *pdb_symbol, +SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, uint32_t type_mask, TypeCollection &type_collection) { - if (!pdb_symbol) - return; - bool can_parse = false; - switch (pdb_symbol->getSymTag()) { + switch (pdb_symbol.getSymTag()) { case PDB_SymType::ArrayType: can_parse = ((type_mask & eTypeClassArray) != 0); break; @@ -1163,7 +1154,7 @@ can_parse = ((type_mask & eTypeClassTypedef) != 0); break; case PDB_SymType::UDT: { - auto *udt = llvm::dyn_cast(pdb_symbol); + auto *udt = llvm::dyn_cast(&pdb_symbol); assert(udt); can_parse = (udt->getUdtKind() != PDB_UdtType::Interface && ((type_mask & (eTypeClassClass | eTypeClassStruct | @@ -1173,7 +1164,7 @@ } if (can_parse) { - if (auto *type = ResolveTypeUID(pdb_symbol->getSymIndexId())) { + if (auto *type = ResolveTypeUID(pdb_symbol.getSymIndexId())) { auto result = std::find(type_collection.begin(), type_collection.end(), type); if (result == type_collection.end()) @@ -1181,9 +1172,9 @@ } } - auto results_up = pdb_symbol->findAllChildren(); + auto results_up = pdb_symbol.findAllChildren(); while (auto symbol_up = results_up->getNext()) - GetTypesForPDBSymbol(symbol_up.get(), type_mask, type_collection); + GetTypesForPDBSymbol(*symbol_up, type_mask, type_collection); } size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, @@ -1195,13 +1186,15 @@ sc_scope->CalculateSymbolContextCompileUnit() : nullptr; if (cu) { auto compiland_up = GetPDBCompilandByUID(cu->GetID()); - GetTypesForPDBSymbol(compiland_up.get(), type_mask, type_collection); + if (!compiland_up) + return 0; + GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection); } else { for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) { auto cu_sp = ParseCompileUnitAtIndex(cu_idx); if (cu_sp.get()) { - auto compiland_up = GetPDBCompilandByUID(cu_sp->GetID()); - GetTypesForPDBSymbol(compiland_up.get(), type_mask, type_collection); + if (auto compiland_up = GetPDBCompilandByUID(cu_sp->GetID())) + GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection); } } } @@ -1277,7 +1270,7 @@ m_comp_units.insert(std::make_pair(id, cu_sp)); if (index == UINT32_MAX) - GetCompileUnitIndex(compiland_up.get(), index); + GetCompileUnitIndex(*compiland_up, index); lldbassert(index != UINT32_MAX); m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex( index, cu_sp); @@ -1430,13 +1423,10 @@ } Mangled -SymbolFilePDB::GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc *pdb_func) { +SymbolFilePDB::GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func) { Mangled mangled; - if (!pdb_func) - return mangled; - - auto func_name = pdb_func->getName(); - auto func_undecorated_name = pdb_func->getUndecoratedName(); + auto func_name = pdb_func.getName(); + auto func_undecorated_name = pdb_func.getUndecoratedName(); std::string func_decorated_name; // Seek from public symbols for non-static function's decorated name if any.