diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp index dc964f64a9150..3a76f8bff316f 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.cpp @@ -60,15 +60,11 @@ PdbIndex::create(llvm::pdb::PDBFile *file) { lldb::addr_t PdbIndex::MakeVirtualAddress(uint16_t segment, uint32_t offset) const { - // Segment indices are 1-based. - lldbassert(segment > 0); - uint32_t max_section = dbi().getSectionHeaders().size(); - lldbassert(segment <= max_section + 1); - + // Segment indices are 1-based. // If this is an absolute symbol, it's indicated by the magic section index // |max_section+1|. In this case, the offset is meaningless, so just return. - if (segment == max_section + 1) + if (segment == 0 || segment > max_section) return LLDB_INVALID_ADDRESS; const llvm::object::coff_section &cs = dbi().getSectionHeaders()[segment - 1]; @@ -76,10 +72,6 @@ lldb::addr_t PdbIndex::MakeVirtualAddress(uint16_t segment, static_cast(offset); } -lldb::addr_t PdbIndex::MakeVirtualAddress(const SegmentOffset &so) const { - return MakeVirtualAddress(so.segment, so.offset); -} - llvm::Optional PdbIndex::GetModuleIndexForAddr(uint16_t segment, uint32_t offset) const { return GetModuleIndexForVa(MakeVirtualAddress(segment, offset)); @@ -107,6 +99,8 @@ void PdbIndex::ParseSectionContribs() { return; uint64_t va = m_ctx.MakeVirtualAddress(C.ISect, C.Off); + if (va == LLDB_INVALID_ADDRESS) + return; uint64_t end = va + C.Size; // IntervalMap's start and end represent a closed range, not a half-open // range, so we have to subtract 1. @@ -128,7 +122,9 @@ void PdbIndex::BuildAddrToSymbolMap(CompilandIndexItem &cci) { continue; SegmentOffset so = GetSegmentAndOffset(*iter); - lldb::addr_t va = MakeVirtualAddress(so); + lldb::addr_t va = MakeVirtualAddress(so.segment, so.offset); + if (va == LLDB_INVALID_ADDRESS) + continue; PdbCompilandSymId cu_sym_id(modi, iter.offset()); @@ -175,7 +171,10 @@ std::vector PdbIndex::FindSymbolsByVa(lldb::addr_t va) { else sol.so = GetSegmentAndOffset(sym); - lldb::addr_t start = MakeVirtualAddress(sol.so); + lldb::addr_t start = MakeVirtualAddress(sol.so.segment, sol.so.offset); + if (start == LLDB_INVALID_ADDRESS) + continue; + lldb::addr_t end = start + sol.length; if (va >= start && va < end) result.push_back({std::move(sym), iter->second}); diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h index edbdd9ee290bb..138c63d79a59d 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbIndex.h @@ -143,7 +143,6 @@ class PdbIndex { const CompileUnitIndex &compilands() const { return m_cus; } lldb::addr_t MakeVirtualAddress(uint16_t segment, uint32_t offset) const; - lldb::addr_t MakeVirtualAddress(const SegmentOffset &so) const; std::vector FindSymbolsByVa(lldb::addr_t va); diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp index ee1de24383d6a..7bb7c69eece71 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/PdbUtil.cpp @@ -34,6 +34,8 @@ MakeRangeList(const PdbIndex &index, const LocalVariableAddrRange &range, llvm::ArrayRef gaps) { lldb::addr_t start = index.MakeVirtualAddress(range.ISectStart, range.OffsetStart); + if (start == LLDB_INVALID_ADDRESS) + return {}; lldb::addr_t end = start + range.Range; Variable::RangeList result; diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index b50ed5cc3c705..7dc99818c2443 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -407,7 +407,8 @@ lldb::FunctionSP SymbolFileNativePDB::CreateFunction(PdbCompilandSymId func_id, lldbassert(sym_record.kind() == S_LPROC32 || sym_record.kind() == S_GPROC32); SegmentOffsetLength sol = GetSegmentOffsetAndLength(sym_record); - auto file_vm_addr = m_index->MakeVirtualAddress(sol.so); + auto file_vm_addr = + m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset); if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0) return nullptr; @@ -807,11 +808,13 @@ VariableSP SymbolFileNativePDB::CreateGlobalVariable(PdbGlobalSymId var_id) { CompUnitSP comp_unit; llvm::Optional modi = m_index->GetModuleIndexForVa(addr); - if (modi) { - CompilandIndexItem &cci = m_index->compilands().GetOrCreateCompiland(*modi); - comp_unit = GetOrCreateCompileUnit(cci); + if (!modi) { + return nullptr; } + CompilandIndexItem &cci = m_index->compilands().GetOrCreateCompiland(*modi); + comp_unit = GetOrCreateCompileUnit(cci); + Declaration decl; PdbTypeSymId tid(ti, false); SymbolFileTypeSP type_sp = @@ -869,8 +872,12 @@ SymbolFileNativePDB::CreateConstantSymbol(PdbGlobalSymId var_id, VariableSP SymbolFileNativePDB::GetOrCreateGlobalVariable(PdbGlobalSymId var_id) { auto emplace_result = m_global_vars.try_emplace(toOpaqueUid(var_id), nullptr); - if (emplace_result.second) - emplace_result.first->second = CreateGlobalVariable(var_id); + if (emplace_result.second) { + if (VariableSP var_sp = CreateGlobalVariable(var_id)) + emplace_result.first->second = var_sp; + else + return nullptr; + } return emplace_result.first->second; } @@ -1102,6 +1109,8 @@ bool SymbolFileNativePDB::ParseLineTable(CompileUnit &comp_unit) { const LineFragmentHeader *lfh = lines.header(); uint64_t virtual_addr = m_index->MakeVirtualAddress(lfh->RelocSegment, lfh->RelocOffset); + if (virtual_addr == LLDB_INVALID_ADDRESS) + continue; for (const LineColumnEntry &group : lines) { llvm::Expected file_index_or_err = @@ -1166,7 +1175,11 @@ bool SymbolFileNativePDB::ParseLineTable(CompileUnit &comp_unit) { CVSymbol func_record = cii->m_debug_stream.readSymbolAtOffset(record_offset); SegmentOffsetLength sol = GetSegmentOffsetAndLength(func_record); - addr_t file_vm_addr = m_index->MakeVirtualAddress(sol.so); + addr_t file_vm_addr = + m_index->MakeVirtualAddress(sol.so.segment, sol.so.offset); + if (file_vm_addr == LLDB_INVALID_ADDRESS) + continue; + AddressRange func_range(file_vm_addr, sol.length, comp_unit.GetModule()->GetSectionList()); Address func_base = func_range.GetBaseAddress(); @@ -1528,7 +1541,6 @@ void SymbolFileNativePDB::FindGlobalVariables( std::vector results = m_index->globals().findRecordsByName( name.GetStringRef(), m_index->symrecords()); for (const SymbolAndOffset &result : results) { - VariableSP var; switch (result.second.kind()) { case SymbolKind::S_GDATA32: case SymbolKind::S_LDATA32: @@ -1536,8 +1548,8 @@ void SymbolFileNativePDB::FindGlobalVariables( case SymbolKind::S_LTHREAD32: case SymbolKind::S_CONSTANT: { PdbGlobalSymId global(result.first, false); - var = GetOrCreateGlobalVariable(global); - variables.AddVariable(var); + if (VariableSP var = GetOrCreateGlobalVariable(global)) + variables.AddVariable(var); break; } default: