diff options
Diffstat (limited to 'lldb/source')
-rw-r--r-- | lldb/source/API/SystemInitializerFull.cpp | 17 | ||||
-rw-r--r-- | lldb/source/Host/common/FileSpec.cpp | 24 | ||||
-rw-r--r-- | lldb/source/Host/windows/HostInfoWindows.cpp | 16 | ||||
-rw-r--r-- | lldb/source/Initialization/SystemInitializerCommon.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt | 6 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp | 549 | ||||
-rw-r--r-- | lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h | 190 |
8 files changed, 790 insertions, 15 deletions
diff --git a/lldb/source/API/SystemInitializerFull.cpp b/lldb/source/API/SystemInitializerFull.cpp index 1376774f962..bf445c9b0c1 100644 --- a/lldb/source/API/SystemInitializerFull.cpp +++ b/lldb/source/API/SystemInitializerFull.cpp @@ -28,18 +28,18 @@ #include "lldb/Symbol/GoASTContext.h" #include "lldb/Symbol/JavaASTContext.h" -#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h" #include "Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.h" #include "Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.h" +#include "Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.h" #include "Plugins/ABI/SysV-arm/ABISysV_arm.h" #include "Plugins/ABI/SysV-arm64/ABISysV_arm64.h" #include "Plugins/ABI/SysV-hexagon/ABISysV_hexagon.h" #include "Plugins/ABI/SysV-i386/ABISysV_i386.h" -#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h" -#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h" -#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h" #include "Plugins/ABI/SysV-mips/ABISysV_mips.h" #include "Plugins/ABI/SysV-mips64/ABISysV_mips64.h" +#include "Plugins/ABI/SysV-ppc/ABISysV_ppc.h" +#include "Plugins/ABI/SysV-ppc64/ABISysV_ppc64.h" +#include "Plugins/ABI/SysV-x86_64/ABISysV_x86_64.h" #include "Plugins/Disassembler/llvm/DisassemblerLLVMC.h" #include "Plugins/DynamicLoader/Static/DynamicLoaderStatic.h" #include "Plugins/Instruction/ARM64/EmulateInstructionARM64.h" @@ -51,10 +51,10 @@ #include "Plugins/Language/ObjC/ObjCLanguage.h" #include "Plugins/Language/ObjCPlusPlus/ObjCPlusPlusLanguage.h" #include "Plugins/LanguageRuntime/CPlusPlus/ItaniumABI/ItaniumABILanguageRuntime.h" -#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" -#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" #include "Plugins/LanguageRuntime/Go/GoLanguageRuntime.h" #include "Plugins/LanguageRuntime/Java/JavaLanguageRuntime.h" +#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h" +#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h" #include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h" #include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h" #include "Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h" @@ -63,11 +63,12 @@ #include "Plugins/ScriptInterpreter/None/ScriptInterpreterNone.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h" +#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h" #include "Plugins/SymbolFile/Symtab/SymbolFileSymtab.h" #include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h" #include "Plugins/SystemRuntime/MacOSX/SystemRuntimeMacOSX.h" -#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h" #include "Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.h" +#include "Plugins/UnwindAssembly/x86/UnwindAssembly-x86.h" #if defined(__APPLE__) #include "Plugins/Process/mach-core/ProcessMachCore.h" @@ -301,6 +302,7 @@ SystemInitializerFull::Initialize() SymbolVendorELF::Initialize(); SymbolFileDWARF::Initialize(); + SymbolFilePDB::Initialize(); SymbolFileSymtab::Initialize(); UnwindAssemblyInstEmulation::Initialize(); UnwindAssembly_x86::Initialize(); @@ -422,6 +424,7 @@ SystemInitializerFull::Terminate() AddressSanitizerRuntime::Terminate(); SymbolVendorELF::Terminate(); SymbolFileDWARF::Terminate(); + SymbolFilePDB::Terminate(); SymbolFileSymtab::Terminate(); UnwindAssembly_x86::Terminate(); UnwindAssemblyInstEmulation::Terminate(); diff --git a/lldb/source/Host/common/FileSpec.cpp b/lldb/source/Host/common/FileSpec.cpp index 281a9df96f1..b8d35480d0f 100644 --- a/lldb/source/Host/common/FileSpec.cpp +++ b/lldb/source/Host/common/FileSpec.cpp @@ -390,19 +390,29 @@ FileSpec::operator!() const return !m_directory && !m_filename; } +bool +FileSpec::DirectoryEquals(const FileSpec &rhs) const +{ + const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive(); + return ConstString::Equals(m_directory, rhs.m_directory, case_sensitive); +} + +bool +FileSpec::FileEquals(const FileSpec &rhs) const +{ + const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive(); + return ConstString::Equals(m_filename, rhs.m_filename, case_sensitive); +} + //------------------------------------------------------------------ // Equal to operator //------------------------------------------------------------------ bool FileSpec::operator== (const FileSpec& rhs) const { - // case sensitivity of equality test - const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive(); - - if (!ConstString::Equals(m_filename, rhs.m_filename, case_sensitive)) + if (!FileEquals(rhs)) return false; - - if (ConstString::Equals(m_directory, rhs.m_directory, case_sensitive)) + if (DirectoryEquals(rhs)) return true; // TODO: determine if we want to keep this code in here. @@ -451,7 +461,7 @@ FileSpec::operator== (const FileSpec& rhs) const // If we reach this point in the code we were able to resolve both paths // and since we only resolve the paths if the basenames are equal, then // we can just check if both directories are equal... - return ConstString::Equals(m_directory, rhs.m_directory, case_sensitive); + return DirectoryEquals(rhs); } //------------------------------------------------------------------ diff --git a/lldb/source/Host/windows/HostInfoWindows.cpp b/lldb/source/Host/windows/HostInfoWindows.cpp index 6dce71d9172..a9fc4fb9ede 100644 --- a/lldb/source/Host/windows/HostInfoWindows.cpp +++ b/lldb/source/Host/windows/HostInfoWindows.cpp @@ -9,6 +9,8 @@ #include "lldb/Host/windows/windows.h" +#include <objbase.h> + #include <mutex> // std::once #include "lldb/Host/windows/HostInfoWindows.h" @@ -21,6 +23,20 @@ using namespace lldb_private; FileSpec HostInfoWindows::m_program_filespec; +void +HostInfoWindows::Initialize() +{ + ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); + HostInfoBase::Initialize(); +} + +void +HostInfoWindows::Terminate() +{ + HostInfoBase::Terminate(); + ::CoUninitialize(); +} + size_t HostInfoWindows::GetPageSize() { diff --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp index 810b81d0d7b..d63b19b8398 100644 --- a/lldb/source/Initialization/SystemInitializerCommon.cpp +++ b/lldb/source/Initialization/SystemInitializerCommon.cpp @@ -49,8 +49,8 @@ #endif #if defined(_MSC_VER) -#include "lldb/Host/windows/windows.h" #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h" +#include "lldb/Host/windows/windows.h" #endif #include "llvm/Support/TargetSelect.h" diff --git a/lldb/source/Plugins/SymbolFile/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/CMakeLists.txt index add6697389f..98510704ce7 100644 --- a/lldb/source/Plugins/SymbolFile/CMakeLists.txt +++ b/lldb/source/Plugins/SymbolFile/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(DWARF) add_subdirectory(Symtab) +add_subdirectory(PDB) diff --git a/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt new file mode 100644 index 00000000000..4e7913b610a --- /dev/null +++ b/lldb/source/Plugins/SymbolFile/PDB/CMakeLists.txt @@ -0,0 +1,6 @@ +set(LLVM_PRIVATE_LINK_COMPONENTS + DebugInfoPDB) + +add_lldb_library(lldbPluginSymbolFilePDB + SymbolFilePDB.cpp + ) diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp new file mode 100644 index 00000000000..a626a806151 --- /dev/null +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -0,0 +1,549 @@ +//===-- SymbolFilePDB.cpp ---------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "SymbolFilePDB.h" + +#include "lldb/Core/Module.h" +#include "lldb/Core/PluginManager.h" +#include "lldb/Symbol/CompileUnit.h" +#include "lldb/Symbol/LineTable.h" +#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Symbol/SymbolContext.h" + +#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" +#include "llvm/DebugInfo/PDB/IPDBLineNumber.h" +#include "llvm/DebugInfo/PDB/IPDBSourceFile.h" +#include "llvm/DebugInfo/PDB/PDBSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" +#include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" +#include "llvm/DebugInfo/PDB/PDBSymbolExe.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" +#include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" + +using namespace lldb_private; + +namespace +{ + lldb::LanguageType TranslateLanguage(llvm::PDB_Lang lang) + { + switch (lang) + { + case llvm::PDB_Lang::Cpp: + return lldb::LanguageType::eLanguageTypeC_plus_plus; + case llvm::PDB_Lang::C: + return lldb::LanguageType::eLanguageTypeC; + default: + return lldb::LanguageType::eLanguageTypeUnknown; + } + } +} + +void +SymbolFilePDB::Initialize() +{ + PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, + DebuggerInitialize); +} + +void +SymbolFilePDB::Terminate() +{ + PluginManager::UnregisterPlugin(CreateInstance); +} + +void +SymbolFilePDB::DebuggerInitialize(lldb_private::Debugger &debugger) +{ +} + +lldb_private::ConstString +SymbolFilePDB::GetPluginNameStatic() +{ + static ConstString g_name("pdb"); + return g_name; +} + +const char * +SymbolFilePDB::GetPluginDescriptionStatic() +{ + return "Microsoft PDB debug symbol file reader."; +} + +lldb_private::SymbolFile * +SymbolFilePDB::CreateInstance(lldb_private::ObjectFile *obj_file) +{ + return new SymbolFilePDB(obj_file); +} + +SymbolFilePDB::SymbolFilePDB(lldb_private::ObjectFile *object_file) + : SymbolFile(object_file), m_cached_compile_unit_count(0) +{ +} + +SymbolFilePDB::~SymbolFilePDB() +{ +} + +uint32_t +SymbolFilePDB::CalculateAbilities() +{ + if (!m_session_up) + { + // Lazily load and match the PDB file, but only do this once. + std::string exePath = m_obj_file->GetFileSpec().GetPath(); + auto error = llvm::loadDataForEXE(llvm::PDB_ReaderType::DIA, llvm::StringRef(exePath), m_session_up); + if (error != llvm::PDB_ErrorCode::Success) + return 0; + } + return CompileUnits | LineTables; +} + +void +SymbolFilePDB::InitializeObject() +{ + lldb::addr_t obj_load_address = m_obj_file->GetFileOffset(); + m_session_up->setLoadAddress(obj_load_address); +} + +uint32_t +SymbolFilePDB::GetNumCompileUnits() +{ + if (m_cached_compile_unit_count == 0) + { + auto global = m_session_up->getGlobalScope(); + auto compilands = global->findAllChildren<llvm::PDBSymbolCompiland>(); + m_cached_compile_unit_count = compilands->getChildCount(); + + // The linker can inject an additional "dummy" compilation unit into the PDB. + // Ignore this special compile unit for our purposes, if it is there. It is + // always the last one. + auto last_cu = compilands->getChildAtIndex(m_cached_compile_unit_count - 1); + std::string name = last_cu->getName(); + if (name == "* Linker *") + --m_cached_compile_unit_count; + } + return m_cached_compile_unit_count; +} + +lldb::CompUnitSP +SymbolFilePDB::ParseCompileUnitAtIndex(uint32_t index) +{ + auto global = m_session_up->getGlobalScope(); + auto compilands = global->findAllChildren<llvm::PDBSymbolCompiland>(); + auto cu = compilands->getChildAtIndex(index); + + uint32_t id = cu->getSymIndexId(); + + return ParseCompileUnitForSymIndex(id); +} + +lldb::LanguageType +SymbolFilePDB::ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) +{ + // What fields should I expect to be filled out on the SymbolContext? Is it + // safe to assume that `sc.comp_unit` is valid? + if (!sc.comp_unit) + return lldb::eLanguageTypeUnknown; + + auto cu = m_session_up->getConcreteSymbolById<llvm::PDBSymbolCompiland>(sc.comp_unit->GetID()); + if (!cu) + return lldb::eLanguageTypeUnknown; + auto details = cu->findOneChild<llvm::PDBSymbolCompilandDetails>(); + if (!details) + return lldb::eLanguageTypeUnknown; + return TranslateLanguage(details->getLanguage()); +} + +size_t +SymbolFilePDB::ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) +{ + // TODO: Implement this + return size_t(); +} + +bool +SymbolFilePDB::ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) +{ + return ParseCompileUnitLineTable(sc, 0); +} + +bool +SymbolFilePDB::ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) +{ + // PDB doesn't contain information about macros + return false; +} + +bool +SymbolFilePDB::ParseCompileUnitSupportFiles(const lldb_private::SymbolContext &sc, + lldb_private::FileSpecList &support_files) +{ + if (!sc.comp_unit) + return false; + + // In theory this is unnecessary work for us, because all of this information is easily + // (and quickly) accessible from DebugInfoPDB, so caching it a second time seems like a waste. + // Unfortunately, there's no good way around this short of a moderate refactor, since SymbolVendor + // depends on being able to cache this list. + auto cu = m_session_up->getConcreteSymbolById<llvm::PDBSymbolCompiland>(sc.comp_unit->GetID()); + if (!cu) + return false; + auto files = m_session_up->getSourceFilesForCompiland(*cu); + if (!files || files->getChildCount() == 0) + return false; + + while (auto file = files->getNext()) + { + FileSpec spec(file->getFileName(), false); + support_files.Append(spec); + } + return true; +} + +bool +SymbolFilePDB::ParseImportedModules(const lldb_private::SymbolContext &sc, + std::vector<lldb_private::ConstString> &imported_modules) +{ + // PDB does not yet support module debug info + return false; +} + +size_t +SymbolFilePDB::ParseFunctionBlocks(const lldb_private::SymbolContext &sc) +{ + // TODO: Implement this + return size_t(); +} + +size_t +SymbolFilePDB::ParseTypes(const lldb_private::SymbolContext &sc) +{ + // TODO: Implement this + return size_t(); +} + +size_t +SymbolFilePDB::ParseVariablesForContext(const lldb_private::SymbolContext &sc) +{ + // TODO: Implement this + return size_t(); +} + +lldb_private::Type * +SymbolFilePDB::ResolveTypeUID(lldb::user_id_t type_uid) +{ + return nullptr; +} + +bool +SymbolFilePDB::CompleteType(lldb_private::CompilerType &compiler_type) +{ + // TODO: Implement this + return false; +} + +lldb_private::CompilerDecl +SymbolFilePDB::GetDeclForUID(lldb::user_id_t uid) +{ + return lldb_private::CompilerDecl(); +} + +lldb_private::CompilerDeclContext +SymbolFilePDB::GetDeclContextForUID(lldb::user_id_t uid) +{ + return lldb_private::CompilerDeclContext(); +} + +lldb_private::CompilerDeclContext +SymbolFilePDB::GetDeclContextContainingUID(lldb::user_id_t uid) +{ + return lldb_private::CompilerDeclContext(); +} + +void +SymbolFilePDB::ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) +{ +} + +uint32_t +SymbolFilePDB::ResolveSymbolContext(const lldb_private::Address &so_addr, uint32_t resolve_scope, + lldb_private::SymbolContext &sc) +{ + return uint32_t(); +} + +uint32_t +SymbolFilePDB::ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line, bool check_inlines, + uint32_t resolve_scope, lldb_private::SymbolContextList &sc_list) +{ + if (resolve_scope & lldb::eSymbolContextCompUnit) + { + // Locate all compilation units with line numbers referencing the specified file. For example, if + // `file_spec` is <vector>, then this should return all source files and header files that reference + // <vector>, either directly or indirectly. + auto compilands = + m_session_up->findCompilandsForSourceFile(file_spec.GetPath(), llvm::PDB_NameSearchFlags::NS_CaseInsensitive); + + // For each one, either find get its previously parsed data, or parse it afresh and add it to + // the symbol context list. + while (auto compiland = compilands->getNext()) + { + // If we're not checking inlines, then don't add line information for this file unless the FileSpec + // matches. + if (!check_inlines) + { + // `getSourceFileName` returns the basename of the original source file used to generate this compiland. + // It does not return the full path. Currently the only way to get that is to do a basename lookup to + // get the IPDBSourceFile, but this is ambiguous in the case of two source files with the same name + // contributing to the same compiland. This is a moderately extreme edge case, so we consider this ok + // for now, although we need to find a long term solution. + std::string source_file = compiland->getSourceFileName(); + auto pdb_file = m_session_up->findOneSourceFile(compiland.get(), source_file, + llvm::PDB_NameSearchFlags::NS_CaseInsensitive); + source_file = pdb_file->getFileName(); + FileSpec this_spec(source_file, false, FileSpec::ePathSyntaxWindows); + if (!file_spec.FileEquals(this_spec)) + continue; + } + + SymbolContext sc; + auto cu = ParseCompileUnitForSymIndex(compiland->getSymIndexId()); + sc.comp_unit = cu.get(); + sc.module_sp = cu->GetModule(); + sc_list.Append(sc); + + // If we were asked to resolve line entries, add all entries to the line table that match the requested + // line (or all lines if `line` == 0) + if (resolve_scope & lldb::eSymbolContextLineEntry) + ParseCompileUnitLineTable(sc, line); + } + } + return sc_list.GetSize(); +} + +uint32_t +SymbolFilePDB::FindGlobalVariables(const lldb_private::ConstString &name, + const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, + uint32_t max_matches, lldb_private::VariableList &variables) +{ + return uint32_t(); +} + +uint32_t +SymbolFilePDB::FindGlobalVariables(const lldb_private::RegularExpression ®ex, bool append, uint32_t max_matches, + lldb_private::VariableList &variables) +{ + return uint32_t(); +} + +uint32_t +SymbolFilePDB::FindFunctions(const lldb_private::ConstString &name, + const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, + bool include_inlines, bool append, lldb_private::SymbolContextList &sc_list) +{ + return uint32_t(); +} + +uint32_t +SymbolFilePDB::FindFunctions(const lldb_private::RegularExpression ®ex, bool include_inlines, bool append, + lldb_private::SymbolContextList &sc_list) +{ + return uint32_t(); +} + +void +SymbolFilePDB::GetMangledNamesForFunction(const std::string &scope_qualified_name, + std::vector<lldb_private::ConstString> &mangled_names) +{ +} + +uint32_t +SymbolFilePDB::FindTypes(const lldb_private::SymbolContext &sc, const lldb_private::ConstString &name, + const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, + llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, + lldb_private::TypeMap &types) +{ + return uint32_t(); +} + +size_t +SymbolFilePDB::FindTypes(const std::vector<lldb_private::CompilerContext> &context, bool append, + lldb_private::TypeMap &types) +{ + return size_t(); +} + +lldb_private::TypeList * +SymbolFilePDB::GetTypeList() +{ + return nullptr; +} + +size_t +SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, uint32_t type_mask, + lldb_private::TypeList &type_list) +{ + return size_t(); +} + +lldb_private::TypeSystem * +SymbolFilePDB::GetTypeSystemForLanguage(lldb::LanguageType language) +{ + auto type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language); + if (type_system) + type_system->SetSymbolFile(this); + return type_system; +} + +lldb_private::CompilerDeclContext +SymbolFilePDB::FindNamespace(const lldb_private::SymbolContext &sc, const lldb_private::ConstString &name, + const lldb_private::CompilerDeclContext *parent_decl_ctx) +{ + return lldb_private::CompilerDeclContext(); +} + +lldb_private::ConstString +SymbolFilePDB::GetPluginName() +{ + static ConstString g_name("pdb"); + return g_name; +} + +uint32_t +SymbolFilePDB::GetPluginVersion() +{ + return 1; +} + +lldb::CompUnitSP +SymbolFilePDB::ParseCompileUnitForSymIndex(uint32_t id) +{ + auto found_cu = m_comp_units.find(id); + if (found_cu != m_comp_units.end()) + return found_cu->second; + + auto cu = m_session_up->getConcreteSymbolById<llvm::PDBSymbolCompiland>(id); + + // `getSourceFileName` returns the basename of the original source file used to generate this compiland. It does + // not return the full path. Currently the only way to get that is to do a basename lookup to get the + // IPDBSourceFile, but this is ambiguous in the case of two source files with the same name contributing to the + // same compiland. This is a moderately extreme edge case, so we consider this ok for now, although we need to find + // a long term solution. + auto file = m_session_up->findOneSourceFile(cu.get(), cu->getSourceFileName(), + llvm::PDB_NameSearchFlags::NS_CaseInsensitive); + std::string path = file->getFileName(); + + lldb::LanguageType lang; + auto details = cu->findOneChild<llvm::PDBSymbolCompilandDetails>(); + if (!details) + lang = lldb::eLanguageTypeC_plus_plus; + else + lang = TranslateLanguage(details->getLanguage()); + + // Don't support optimized code for now, DebugInfoPDB does not return this information. + bool optimized = false; + auto result = std::make_shared<CompileUnit>(m_obj_file->GetModule(), nullptr, path.c_str(), id, lang, optimized); + m_comp_units.insert(std::make_pair(id, result)); + return result; +} + +bool +SymbolFilePDB::ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc, uint32_t match_line) +{ + auto global = m_session_up->getGlobalScope(); + auto cu = m_session_up->getConcreteSymbolById<llvm::PDBSymbolCompiland>(sc.comp_unit->GetID()); + + // LineEntry needs the *index* of the file into the list of support files returned by + // ParseCompileUnitSupportFiles. But the underlying SDK gives us a globally unique + // idenfitifier in the namespace of the PDB. So, we have to do a mapping so that we + // can hand out indices. + std::unordered_map<uint32_t, uint32_t> index_map; + BuildSupportFileIdToSupportFileIndexMap(*cu, index_map); + auto line_table = llvm::make_unique<LineTable>(sc.comp_unit); + + // Find contributions to `cu` from all source and header files. + std::string path = sc.comp_unit->GetPath(); + auto files = m_session_up->getSourceFilesForCompiland(*cu); + + // For each source and header file, create a LineSequence for contributions to the cu + // from that file, and add the sequence. + while (auto file = files->getNext()) + { + std::unique_ptr<LineSequence> sequence(line_table->CreateLineSequenceContainer()); + auto lines = m_session_up->findLineNumbers(*cu, *file); + int entry_count = lines->getChildCount(); + + for (int i = 0; i < entry_count; ++i) + { + auto line = lines->getChildAtIndex(i); + uint32_t lno = line->getLineNumber(); + + // If `match_line` == 0 we add any line no matter what. Otherwise, we only add + // lines that match the requested line number. + if (match_line != 0 && lno != match_line) + continue; + + uint64_t va = line->getVirtualAddress(); + uint32_t cno = line->getColumnNumber(); + uint32_t source_id = line->getSourceFileId(); + uint32_t source_idx = index_map[source_id]; + + bool is_basic_block = false; // PDB doesn't even have this concept, but LLDB doesn't use it anyway. + bool is_prologue = false; + bool is_epilogue = false; + bool is_statement = line->isStatement(); + auto func = m_session_up->findSymbolByAddress(va, llvm::PDB_SymType::Function); + if (func) + { + auto prologue = func->findOneChild<llvm::PDBSymbolFuncDebugStart>(); + is_prologue = (va == prologue->getVirtualAddress()); + + auto epilogue = func->findOneChild<llvm::PDBSymbolFuncDebugEnd>(); + is_epilogue = (va == epilogue->getVirtualAddress()); + + if (is_epilogue) + { + // Once per function, add a termination entry after the last byte of the function. + // TODO: This makes the assumption that all functions are laid out contiguously in + // memory and have no gaps. This is a wrong assumption in the general case, but is + // good enough to allow simple scenarios to work. This needs to be revisited. + auto concrete_func = llvm::dyn_cast<llvm::PDBSymbolFunc>(func.get()); + lldb::addr_t end_addr = concrete_func->getVirtualAddress() + concrete_func->getLength(); + line_table->InsertLineEntry(end_addr, lno, 0, source_idx, false, false, false, false, true); + } + } + + line_table->InsertLineEntry(va, lno, cno, source_idx, is_statement, is_basic_block, is_prologue, + is_epilogue, false); + } + } + + sc.comp_unit->SetLineTable(line_table.release()); + return true; +} + +void +SymbolFilePDB::BuildSupportFileIdToSupportFileIndexMap(const llvm::PDBSymbolCompiland &cu, + std::unordered_map<uint32_t, uint32_t> &index_map) const +{ + // This is a hack, but we need to convert the source id into an index into the support + // files array. We don't want to do path comparisons to avoid basename / full path + // issues that may or may not even be a problem, so we use the globally unique source + // file identifiers. Ideally we could use the global identifiers everywhere, but LineEntry + // currently assumes indices. + auto source_files = m_session_up->getSourceFilesForCompiland(cu); + int index = 0; + + while (auto file = source_files->getNext()) + { + uint32_t source_id = file->getUniqueId(); + index_map[source_id] = index++; + } +} diff --git a/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h new file mode 100644 index 00000000000..019b4767955 --- /dev/null +++ b/lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.h @@ -0,0 +1,190 @@ +//===-- SymbolFilePDB.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ +#define lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ + +#include <unordered_map> + +#include "lldb/Core/UserID.h" +#include "lldb/Symbol/SymbolFile.h" + +#include "llvm/DebugInfo/PDB/IPDBSession.h" +#include "llvm/DebugInfo/PDB/PDB.h" + +class SymbolFilePDB : public lldb_private::SymbolFile +{ +public: + //------------------------------------------------------------------ + // Static Functions + //------------------------------------------------------------------ + static void + Initialize(); + + static void + Terminate(); + + static void + DebuggerInitialize(lldb_private::Debugger &debugger); + + static lldb_private::ConstString + GetPluginNameStatic(); + + static const char * + GetPluginDescriptionStatic(); + + static lldb_private::SymbolFile * + CreateInstance(lldb_private::ObjectFile *obj_file); + + //------------------------------------------------------------------ + // Constructors and Destructors + //------------------------------------------------------------------ + SymbolFilePDB(lldb_private::ObjectFile *ofile); + + ~SymbolFilePDB() override; + + uint32_t + CalculateAbilities() override; + + void + InitializeObject() override; + + //------------------------------------------------------------------ + // Compile Unit function calls + //------------------------------------------------------------------ + + uint32_t + GetNumCompileUnits() override; + + lldb::CompUnitSP + ParseCompileUnitAtIndex(uint32_t index) override; + + lldb::LanguageType + ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override; + + size_t + ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override; + + bool + ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override; + + bool + ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override; + + bool + ParseCompileUnitSupportFiles(const lldb_private::SymbolContext &sc, + lldb_private::FileSpecList &support_files) override; + + bool + ParseImportedModules(const lldb_private::SymbolContext &sc, + std::vector<lldb_private::ConstString> &imported_modules) override; + + size_t + ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override; + + size_t + ParseTypes(const lldb_private::SymbolContext &sc) override; + + size_t + ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; + + lldb_private::Type * + ResolveTypeUID(lldb::user_id_t type_uid) override; + + bool + CompleteType(lldb_private::CompilerType &compiler_type) override; + + lldb_private::CompilerDecl + GetDeclForUID(lldb::user_id_t uid) override; + + lldb_private::CompilerDeclContext + GetDeclContextForUID(lldb::user_id_t uid) override; + + lldb_private::CompilerDeclContext + GetDeclContextContainingUID(lldb::user_id_t uid) override; + + void + ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; + + uint32_t + ResolveSymbolContext(const lldb_private::Address &so_addr, uint32_t resolve_scope, + lldb_private::SymbolContext &sc) override; + + uint32_t + ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line, bool check_inlines, + uint32_t resolve_scope, lldb_private::SymbolContextList &sc_list) override; + + uint32_t + FindGlobalVariables(const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, + bool append, uint32_t max_matches, lldb_private::VariableList &variables) override; + + uint32_t + FindGlobalVariables(const lldb_private::RegularExpression ®ex, bool append, uint32_t max_matches, + lldb_private::VariableList &variables) override; + + uint32_t + FindFunctions(const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, + uint32_t name_type_mask, bool include_inlines, bool append, + lldb_private::SymbolContextList &sc_list) override; + + uint32_t + FindFunctions(const lldb_private::RegularExpression ®ex, bool include_inlines, bool append, + lldb_private::SymbolContextList &sc_list) override; + + void + GetMangledNamesForFunction(const std::string &scope_qualified_name, + std::vector<lldb_private::ConstString> &mangled_names) override; + + uint32_t + FindTypes(const lldb_private::SymbolContext &sc, const lldb_private::ConstString &name, + const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, + llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, lldb_private::TypeMap &types) override; + + size_t + FindTypes(const std::vector<lldb_private::CompilerContext> &context, bool append, + lldb_private::TypeMap &types) override; + + lldb_private::TypeList * + GetTypeList() override; + + size_t + GetTypes(lldb_private::SymbolContextScope *sc_scope, uint32_t type_mask, + lldb_private::TypeList &type_list) override; + + lldb_private::TypeSystem * + GetTypeSystemForLanguage(lldb::LanguageType language) override; + + lldb_private::CompilerDeclContext + FindNamespace(const lldb_private::SymbolContext &sc, const lldb_private::ConstString &name, + const lldb_private::CompilerDeclContext *parent_decl_ctx) override; + + lldb_private::ConstString + GetPluginName() override; + + uint32_t + GetPluginVersion() override; + +private: + lldb::CompUnitSP + ParseCompileUnitForSymIndex(uint32_t id); + + bool + ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc, uint32_t match_line); + + void + BuildSupportFileIdToSupportFileIndexMap(const llvm::PDBSymbolCompiland &cu, + std::unordered_map<uint32_t, uint32_t> &index_map) const; + + std::unordered_map<uint32_t, lldb::CompUnitSP> m_comp_units; + + std::unique_ptr<llvm::IPDBSession> m_session_up; + uint32_t m_cached_compile_unit_count; +}; + +#endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ |