diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2021-02-16 20:13:02 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2021-02-16 20:13:02 +0000 |
| commit | b60736ec1405bb0a8dd40989f67ef4c93da068ab (patch) | |
| tree | 5c43fbb7c9fc45f0f87e0e6795a86267dbd12f9d /lldb/source/Plugins/SymbolFile/NativePDB | |
| parent | cfca06d7963fa0909f90483b42a6d7d194d01e08 (diff) | |
Diffstat (limited to 'lldb/source/Plugins/SymbolFile/NativePDB')
5 files changed, 57 insertions, 69 deletions
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp index 0acc77d7c67f..5b4ab78ac219 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.cpp @@ -881,8 +881,8 @@ PdbAstBuilder::GetOrCreateTypedefDecl(PdbGlobalSymId id) { std::string uname = std::string(DropNameScope(udt.Name)); - CompilerType ct = m_clang.CreateTypedefType(ToCompilerType(qt), uname.c_str(), - ToCompilerDeclContext(*scope), 0); + CompilerType ct = ToCompilerType(qt).CreateTypedef( + uname.c_str(), ToCompilerDeclContext(*scope), 0); clang::TypedefNameDecl *tnd = m_clang.GetAsTypedefDecl(ct); DeclStatus status; status.resolved = true; @@ -1015,8 +1015,7 @@ PdbAstBuilder::GetOrCreateFunctionDecl(PdbCompilandSymId func_id) { proc_name.consume_front("::"); clang::FunctionDecl *function_decl = m_clang.CreateFunctionDeclaration( - parent, OptionalClangModuleID(), proc_name.str().c_str(), func_ct, - storage, false); + parent, OptionalClangModuleID(), proc_name, func_ct, storage, false); lldbassert(m_uid_to_decl.count(toOpaqueUid(func_id)) == 0); m_uid_to_decl[toOpaqueUid(func_id)] = function_decl; diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp index 6ac6cc2da29b..dc964f64a915 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp @@ -39,7 +39,7 @@ PdbIndex::PdbIndex() : m_cus(*this), m_va_to_modi(m_allocator) {} } llvm::Expected<std::unique_ptr<PdbIndex>> -PdbIndex::create(std::unique_ptr<llvm::pdb::PDBFile> file) { +PdbIndex::create(llvm::pdb::PDBFile *file) { lldbassert(file); std::unique_ptr<PdbIndex> result(new PdbIndex()); @@ -53,7 +53,7 @@ PdbIndex::create(std::unique_ptr<llvm::pdb::PDBFile> file) { result->m_tpi->buildHashMap(); - result->m_file = std::move(file); + result->m_file = file; return std::move(result); } diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h index ccc3cc2f4538..1b382e5263c1 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h @@ -48,7 +48,7 @@ struct SegmentOffset; class PdbIndex { /// The underlying PDB file. - std::unique_ptr<llvm::pdb::PDBFile> m_file; + llvm::pdb::PDBFile *m_file = nullptr; /// The DBI stream. This contains general high level information about the /// features present in the PDB file, compile units (such as the information @@ -110,8 +110,7 @@ class PdbIndex { void BuildAddrToSymbolMap(CompilandIndexItem &cci); public: - static llvm::Expected<std::unique_ptr<PdbIndex>> - create(std::unique_ptr<llvm::pdb::PDBFile>); + static llvm::Expected<std::unique_ptr<PdbIndex>> create(llvm::pdb::PDBFile *); void SetLoadAddress(lldb::addr_t addr) { m_load_address = addr; } lldb::addr_t GetLoadAddress() const { return m_load_address; } 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); } diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h index bf5718e11a19..61c1d77164b7 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.h @@ -231,6 +231,7 @@ private: lldb::addr_t m_obj_load_address = 0; bool m_done_full_type_scan = false; + std::unique_ptr<llvm::pdb::PDBFile> m_file_up; std::unique_ptr<PdbIndex> m_index; std::unique_ptr<PdbAstBuilder> m_ast; |
