diff options
Diffstat (limited to 'lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp')
| -rw-r--r-- | lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp | 109 |
1 files changed, 49 insertions, 60 deletions
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index cce06473d92f..24b4c64a91bc 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -16,6 +16,7 @@ #include "Plugins/ExpressionParser/Clang/ClangUtil.h" #include "Plugins/Language/CPlusPlus/MSVCUndecoratedNameParser.h" +#include "Plugins/ObjectFile/PDB/ObjectFilePDB.h" #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" #include "lldb/Core/Module.h" #include "lldb/Core/PluginManager.h" @@ -42,9 +43,11 @@ #include "llvm/DebugInfo/PDB/Native/GlobalsStream.h" #include "llvm/DebugInfo/PDB/Native/InfoStream.h" #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" +#include "llvm/DebugInfo/PDB/Native/NativeSession.h" #include "llvm/DebugInfo/PDB/Native/PDBFile.h" #include "llvm/DebugInfo/PDB/Native/SymbolStream.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" +#include "llvm/DebugInfo/PDB/PDB.h" #include "llvm/DebugInfo/PDB/PDBTypes.h" #include "llvm/Demangle/MicrosoftDemangle.h" #include "llvm/Object/COFF.h" @@ -81,32 +84,6 @@ static lldb::LanguageType TranslateLanguage(PDB_Lang lang) { } } -static std::unique_ptr<PDBFile> loadPDBFile(std::string PdbPath, - llvm::BumpPtrAllocator &Allocator) { - llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ErrorOrBuffer = - llvm::MemoryBuffer::getFile(PdbPath, /*FileSize=*/-1, - /*RequiresNullTerminator=*/false); - if (!ErrorOrBuffer) - return nullptr; - std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(*ErrorOrBuffer); - - llvm::StringRef Path = Buffer->getBufferIdentifier(); - auto Stream = std::make_unique<llvm::MemoryBufferByteStream>( - std::move(Buffer), llvm::support::little); - - auto File = std::make_unique<PDBFile>(Path, std::move(Stream), Allocator); - if (auto EC = File->parseFileHeaders()) { - llvm::consumeError(std::move(EC)); - return nullptr; - } - if (auto EC = File->parseStreamData()) { - llvm::consumeError(std::move(EC)); - return nullptr; - } - - return File; -} - static std::unique_ptr<PDBFile> loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator) { // Try to find a matching PDB for an EXE. @@ -134,13 +111,17 @@ loadMatchingPDBFile(std::string exe_path, llvm::BumpPtrAllocator &allocator) { return nullptr; } - // if the file doesn't exist, is not a pdb, or doesn't have a matching guid, - // fail. - llvm::file_magic magic; - auto ec = llvm::identify_magic(pdb_file, magic); - if (ec || magic != llvm::file_magic::pdb) - return nullptr; - std::unique_ptr<PDBFile> pdb = loadPDBFile(std::string(pdb_file), allocator); + // If the file doesn't exist, perhaps the path specified at build time + // doesn't match the PDB's current location, so check the location of the + // executable. + if (!FileSystem::Instance().Exists(pdb_file)) { + const auto exe_dir = FileSpec(exe_path).CopyByRemovingLastPathComponent(); + const auto pdb_name = FileSpec(pdb_file).GetFilename().GetCString(); + pdb_file = exe_dir.CopyByAppendingPathComponent(pdb_name).GetCString(); + } + + // If the file is not a PDB or if it doesn't have a matching GUID, fail. + auto pdb = ObjectFilePDB::loadPDBFile(std::string(pdb_file), allocator); if (!pdb) return nullptr; @@ -284,24 +265,19 @@ uint32_t SymbolFileNativePDB::CalculateAbilities() { if (!m_index) { // Lazily load and match the PDB file, but only do this once. - std::unique_ptr<PDBFile> file_up = - loadMatchingPDBFile(m_objfile_sp->GetFileSpec().GetPath(), m_allocator); - - if (!file_up) { - auto module_sp = m_objfile_sp->GetModule(); - if (!module_sp) - return 0; - // See if any symbol file is specified through `--symfile` option. - FileSpec symfile = module_sp->GetSymbolFileFileSpec(); - if (!symfile) - return 0; - file_up = loadPDBFile(symfile.GetPath(), m_allocator); + PDBFile *pdb_file; + if (auto *pdb = llvm::dyn_cast<ObjectFilePDB>(m_objfile_sp.get())) { + pdb_file = &pdb->GetPDBFile(); + } else { + m_file_up = loadMatchingPDBFile(m_objfile_sp->GetFileSpec().GetPath(), + m_allocator); + pdb_file = m_file_up.get(); } - if (!file_up) + if (!pdb_file) return 0; - auto expected_index = PdbIndex::create(std::move(file_up)); + auto expected_index = PdbIndex::create(pdb_file); if (!expected_index) { llvm::consumeError(expected_index.takeError()); return 0; @@ -321,7 +297,10 @@ uint32_t SymbolFileNativePDB::CalculateAbilities() { } void SymbolFileNativePDB::InitializeObject() { - m_obj_load_address = m_objfile_sp->GetBaseAddress().GetFileAddress(); + m_obj_load_address = m_objfile_sp->GetModule() + ->GetObjectFile() + ->GetBaseAddress() + .GetFileAddress(); m_index->SetLoadAddress(m_obj_load_address); m_index->ParseSectionContribs(); @@ -460,7 +439,7 @@ lldb::TypeSP SymbolFileNativePDB::CreateModifierType(PdbTypeSymId type_id, lldb::TypeSP modified_type = GetOrCreateType(mr.ModifiedType); return std::make_shared<Type>(toOpaqueUid(type_id), this, ConstString(name), - modified_type->GetByteSize(), nullptr, + modified_type->GetByteSize(nullptr), nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct, Type::ResolveState::Full); } @@ -584,7 +563,7 @@ lldb::TypeSP SymbolFileNativePDB::CreateTagType(PdbTypeSymId type_id, return std::make_shared<lldb_private::Type>( toOpaqueUid(type_id), this, ConstString(uname), - underlying_type->GetByteSize(), nullptr, LLDB_INVALID_UID, + underlying_type->GetByteSize(nullptr), nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ct, lldb_private::Type::ResolveState::Forward); } @@ -809,11 +788,13 @@ VariableSP SymbolFileNativePDB::CreateGlobalVariable(PdbGlobalSymId var_id) { std::string global_name("::"); global_name += name; + bool artificial = false; + bool location_is_constant_data = false; + bool static_member = false; VariableSP var_sp = std::make_shared<Variable>( toOpaqueUid(var_id), name.str().c_str(), global_name.c_str(), type_sp, - scope, comp_unit.get(), ranges, &decl, location, is_external, false, - false); - var_sp->SetLocationIsConstantValueData(false); + scope, comp_unit.get(), ranges, &decl, location, is_external, artificial, + location_is_constant_data, static_member); return var_sp; } @@ -837,11 +818,14 @@ SymbolFileNativePDB::CreateConstantSymbol(PdbGlobalSymId var_id, DWARFExpression location = MakeConstantLocationExpression( constant.Type, tpi, constant.Value, module); + bool external = false; + bool artificial = false; + bool location_is_constant_data = true; + bool static_member = false; VariableSP var_sp = std::make_shared<Variable>( toOpaqueUid(var_id), constant.Name.str().c_str(), global_name.c_str(), type_sp, eValueTypeVariableGlobal, module.get(), ranges, &decl, location, - false, false, false); - var_sp->SetLocationIsConstantValueData(true); + external, artificial, location_is_constant_data, static_member); return var_sp; } @@ -1343,10 +1327,14 @@ VariableSP SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id, ValueType var_scope = is_param ? eValueTypeVariableArgument : eValueTypeVariableLocal; + bool external = false; + bool artificial = false; + bool location_is_constant_data = false; + bool static_member = false; VariableSP var_sp = std::make_shared<Variable>( toOpaqueUid(var_id), name.c_str(), name.c_str(), sftype, var_scope, - comp_unit_sp.get(), *var_info.ranges, &decl, *var_info.location, false, - false, false); + comp_unit_sp.get(), *var_info.ranges, &decl, *var_info.location, external, + artificial, location_is_constant_data, static_member); if (!is_param) m_ast->GetOrCreateVariableDecl(scope_id, var_id); @@ -1376,9 +1364,10 @@ TypeSP SymbolFileNativePDB::CreateTypedef(PdbGlobalSymId id) { Declaration decl; return std::make_shared<lldb_private::Type>( - toOpaqueUid(id), this, ConstString(udt.Name), target_type->GetByteSize(), - nullptr, target_type->GetID(), lldb_private::Type::eEncodingIsTypedefUID, - decl, target_type->GetForwardCompilerType(), + toOpaqueUid(id), this, ConstString(udt.Name), + target_type->GetByteSize(nullptr), nullptr, target_type->GetID(), + lldb_private::Type::eEncodingIsTypedefUID, decl, + target_type->GetForwardCompilerType(), lldb_private::Type::ResolveState::Forward); } |
