Index: lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -48,6 +48,8 @@ #include "llvm/DebugInfo/PDB/Native/SymbolStream.h" #include "llvm/DebugInfo/PDB/Native/TpiStream.h" #include "llvm/DebugInfo/PDB/PDB.h" +#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" +#include "llvm/DebugInfo/PDB/PDBSymbolExe.h" #include "llvm/DebugInfo/PDB/PDBTypes.h" #include "llvm/Demangle/MicrosoftDemangle.h" #include "llvm/Object/COFF.h" @@ -307,8 +309,8 @@ auto ts_or_err = m_objfile_sp->GetModule()->GetTypeSystemForLanguage( lldb::eLanguageTypeC_plus_plus); if (auto err = ts_or_err.takeError()) { - LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_SYMBOLS), - std::move(err), "Failed to initialize"); + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS)); + LLDB_LOG_ERROR(log, std::move(err), "Failed to initialize"); } else { ts_or_err->SetSymbolFile(this); auto *clang = llvm::cast_or_null(&ts_or_err.get()); @@ -905,7 +907,63 @@ return TranslateLanguage(item->m_compile_opts->getLanguage()); } -void SymbolFileNativePDB::AddSymbols(Symtab &symtab) { return; } +void SymbolFileNativePDB::AddSymbols(Symtab &symtab) { + // Currently, we can handle only one symbol for any given address, so we'll + // use a `std::set` to keep track of known addresses. + std::set sym_addresses; + for (size_t i = 0; i < symtab.GetNumSymbols(); i++) { + sym_addresses.insert(symtab.SymbolAtIndex(i)->GetFileAddress()); + } + + std::unique_ptr session_up; + auto error = llvm::pdb::loadDataForPDB(PDB_ReaderType::Native, + GetPDBFile().getFilePath(), session_up); + if (error) return; + NativeSession *native_session = static_cast(session_up.get()); + auto global_scope_up = native_session->getGlobalScope(); + + auto results = global_scope_up->findAllChildren(); + if (!results) + return; + + auto section_list = m_objfile_sp->GetSectionList(); + if (!section_list) + return; + + while (auto pub_symbol = results->getNext()) { + auto section_id = pub_symbol->getAddressSection(); + + auto section = section_list->FindSectionByID(section_id); + if (!section) + continue; + + auto offset = pub_symbol->getAddressOffset(); + + auto file_addr = section->GetFileAddress() + offset; + if (sym_addresses.find(file_addr) != sym_addresses.end()) + continue; + sym_addresses.insert(file_addr); + + auto size = pub_symbol->getLength(); + symtab.AddSymbol( + Symbol(pub_symbol->getSymIndexId(), + pub_symbol->getName().c_str(), + pub_symbol->isCode() ? eSymbolTypeCode : eSymbolTypeData, + /* external */ true, + /* is_debug */ false, + /* is_trampoline */ false, + /* is_artificial */ false, + section, + offset, + size, + /* size_is_valid */ size != 0, + /* contains_linker_annotations */ false, + /* flags */ 0)); + } + + symtab.CalculateSymbolSizes(); + symtab.Finalize(); +} size_t SymbolFileNativePDB::ParseFunctions(CompileUnit &comp_unit) { std::lock_guard guard(GetModuleMutex());