Skip to content

Commit 3779ad3

Browse files
committed
fix: strip function name in FindMangledSymbol
1 parent 20356cc commit 3779ad3

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,8 @@ lldb::FunctionSP SymbolFileNativePDB::CreateFunction(PdbCompilandSymId func_id,
502502

503503
PdbTypeSymId sig_id(proc.FunctionType, false);
504504

505-
std::optional<llvm::StringRef> mangled_opt =
506-
FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset));
507-
if (mangled_opt)
508-
mangled_opt = StripMangledFunctionName(*mangled_opt, proc.FunctionType);
505+
std::optional<llvm::StringRef> mangled_opt = FindMangledSymbol(
506+
SegmentOffset(proc.Segment, proc.CodeOffset), proc.FunctionType);
509507
Mangled mangled(mangled_opt.value_or(proc.Name));
510508

511509
FunctionSP func_sp = std::make_shared<Function>(
@@ -2682,21 +2680,26 @@ SymbolFileNativePDB::FindMangledFunctionName(PdbCompilandSymId func_id) {
26822680
ProcSym proc(static_cast<SymbolRecordKind>(sym_record.kind()));
26832681
cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc));
26842682

2685-
std::optional<llvm::StringRef> mangled =
2686-
FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset));
2687-
if (mangled)
2688-
mangled = StripMangledFunctionName(*mangled, proc.FunctionType);
2689-
return mangled;
2683+
return FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset),
2684+
proc.FunctionType);
26902685
}
26912686

26922687
std::optional<llvm::StringRef>
2693-
SymbolFileNativePDB::FindMangledSymbol(SegmentOffset so) {
2688+
SymbolFileNativePDB::FindMangledSymbol(SegmentOffset so,
2689+
TypeIndex function_type) {
26942690
auto symbol = m_index->publics().findByAddress(m_index->symrecords(),
26952691
so.segment, so.offset);
26962692
if (!symbol)
26972693
return std::nullopt;
26982694

2699-
return symbol->first.Name;
2695+
llvm::StringRef name = symbol->first.Name;
2696+
// For functions, we might need to strip the mangled name. See
2697+
// StripMangledFunctionName for more info.
2698+
if (!function_type.isNoneType() &&
2699+
(symbol->first.Flags & PublicSymFlags::Function) != PublicSymFlags::None)
2700+
name = StripMangledFunctionName(name, function_type);
2701+
2702+
return name;
27002703
}
27012704

27022705
llvm::StringRef

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,16 @@ class SymbolFileNativePDB : public SymbolFileCommon {
275275
void CacheUdtDeclarations();
276276
llvm::Expected<Declaration> ResolveUdtDeclaration(PdbTypeSymId type_id);
277277

278-
std::optional<llvm::StringRef> FindMangledSymbol(SegmentOffset so);
278+
/// Find a symbol name at a specific address (`so`).
279+
///
280+
/// \param[in] so The segment and offset where the symbol is located.
281+
/// \param[in] function_type If the symbol is expected to be a function, this
282+
/// has to be the type of the function. It's used to strip the name of
283+
/// __cdecl functions on x86.
284+
/// \returns The mangled symbol name if found, otherwise `std::nullopt`.
285+
std::optional<llvm::StringRef> FindMangledSymbol(
286+
SegmentOffset so,
287+
llvm::codeview::TypeIndex function_type = llvm::codeview::TypeIndex());
279288

280289
llvm::StringRef StripMangledFunctionName(llvm::StringRef mangled,
281290
PdbTypeSymId func_ty);

0 commit comments

Comments
 (0)