Skip to content

Commit 5847701

Browse files
committed
fix: use LLVM's symbol lookup
1 parent ebbe796 commit 5847701

File tree

1 file changed

+4
-43
lines changed

1 file changed

+4
-43
lines changed

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,52 +2634,13 @@ SymbolFileNativePDB::FindMangledFunctionName(PdbCompilandSymId func_id) {
26342634
return FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset));
26352635
}
26362636

2637-
/// Find the mangled name of a function at \a so.
2638-
///
2639-
/// This is similar to the NearestSym function from Microsoft's PDB reference:
2640-
/// https://github.com/microsoft/microsoft-pdb/blob/805655a28bd8198004be2ac27e6e0290121a5e89/PDB/dbi/gsi.cpp#L1492-L1581
2641-
/// The main difference is that we search for the exact symbol.
2642-
///
2643-
/// \param so[in] The address of the function given by its segment and code
2644-
/// offset.
2645-
/// \return The mangled function name if found. Otherwise an empty optional.
26462637
std::optional<llvm::StringRef>
26472638
SymbolFileNativePDB::FindMangledSymbol(SegmentOffset so) {
2648-
// The address map is sorted by address, so we do binary search.
2649-
// Each element is an offset into the symbols for a public symbol.
2650-
auto lo = m_index->publics().getAddressMap().begin();
2651-
auto hi = m_index->publics().getAddressMap().end();
2652-
hi -= 1;
2653-
2654-
while (lo < hi) {
2655-
auto tgt = lo + ((hi - lo + 1) / 2);
2656-
auto val = tgt->value();
2657-
auto sym = m_index->symrecords().readRecord(val);
2658-
if (sym.kind() != S_PUB32)
2659-
return std::nullopt; // this is most likely corrupted debug info
2660-
2661-
PublicSym32 psym =
2662-
llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
2663-
SegmentOffset cur(psym.Segment, psym.Offset);
2664-
if (so < cur) {
2665-
tgt -= 1;
2666-
hi = tgt;
2667-
} else if (so == cur)
2668-
return psym.Name;
2669-
else
2670-
lo = tgt;
2671-
}
2672-
2673-
// We might've found something, check if it's the symbol we're searching for
2674-
auto val = lo->value();
2675-
auto sym = m_index->symrecords().readRecord(val);
2676-
if (sym.kind() != S_PUB32)
2677-
return std::nullopt;
2678-
PublicSym32 psym =
2679-
llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym));
2680-
if (psym.Segment != so.segment || psym.Offset != so.offset)
2639+
auto symbol = m_index->publics().findByAddress(m_index->symrecords(),
2640+
so.segment, so.offset);
2641+
if (!symbol)
26812642
return std::nullopt;
2682-
return psym.Name;
2643+
return symbol->first.Name;
26832644
}
26842645

26852646
void SymbolFileNativePDB::CacheUdtDeclarations() {

0 commit comments

Comments
 (0)