-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[LLDB][NativePDB] Create functions with mangled name #149701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nerixyz
wants to merge
1
commit into
llvm:main
Choose a base branch
from
Nerixyz:fix/npdb-use-mangled-name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
#include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" | ||
#include "llvm/DebugInfo/PDB/Native/NativeSession.h" | ||
#include "llvm/DebugInfo/PDB/Native/PDBFile.h" | ||
#include "llvm/DebugInfo/PDB/Native/PublicsStream.h" | ||
#include "llvm/DebugInfo/PDB/Native/SymbolStream.h" | ||
#include "llvm/DebugInfo/PDB/Native/TpiStream.h" | ||
#include "llvm/DebugInfo/PDB/PDB.h" | ||
|
@@ -496,7 +497,9 @@ lldb::FunctionSP SymbolFileNativePDB::CreateFunction(PdbCompilandSymId func_id, | |
return nullptr; | ||
|
||
PdbTypeSymId sig_id(proc.FunctionType, false); | ||
Mangled mangled(proc.Name); | ||
auto mangled_opt = | ||
FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset)); | ||
Mangled mangled(mangled_opt.value_or(proc.Name)); | ||
FunctionSP func_sp = std::make_shared<Function>( | ||
&comp_unit, toOpaqueUid(func_id), toOpaqueUid(sig_id), mangled, | ||
func_type.get(), func_addr, | ||
|
@@ -2353,3 +2356,67 @@ SymbolFileNativePDB::GetParentType(llvm::codeview::TypeIndex ti) { | |
return std::nullopt; | ||
return parent_iter->second; | ||
} | ||
|
||
std::optional<llvm::StringRef> | ||
SymbolFileNativePDB::FindMangledFunctionName(PdbCompilandSymId func_id) { | ||
const CompilandIndexItem *cci = | ||
m_index->compilands().GetCompiland(func_id.modi); | ||
if (!cci) | ||
return std::nullopt; | ||
|
||
CVSymbol sym_record = cci->m_debug_stream.readSymbolAtOffset(func_id.offset); | ||
if (sym_record.kind() != S_LPROC32 && sym_record.kind() != S_GPROC32) | ||
return std::nullopt; | ||
|
||
ProcSym proc(static_cast<SymbolRecordKind>(sym_record.kind())); | ||
cantFail(SymbolDeserializer::deserializeAs<ProcSym>(sym_record, proc)); | ||
return FindMangledSymbol(SegmentOffset(proc.Segment, proc.CodeOffset)); | ||
} | ||
|
||
/// Find the mangled name of a function at \a so. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rnk any thoughts on this? Could this live somewhere in LLVM's PDB support? |
||
/// | ||
/// This is similar to the NearestSym function from Microsoft's PDB reference: | ||
/// https://github.com/microsoft/microsoft-pdb/blob/805655a28bd8198004be2ac27e6e0290121a5e89/PDB/dbi/gsi.cpp#L1492-L1581 | ||
/// The main difference is that we search for the exact symbol. | ||
/// | ||
/// \param so[in] The address of the function given by its segment and code | ||
/// offset. | ||
/// \return The mangled function name if found. Otherwise an empty optional. | ||
std::optional<llvm::StringRef> | ||
SymbolFileNativePDB::FindMangledSymbol(SegmentOffset so) { | ||
// The address map is sorted by address, so we do binary search. | ||
// Each element is an offset into the symbols for a public symbol. | ||
auto lo = m_index->publics().getAddressMap().begin(); | ||
auto hi = m_index->publics().getAddressMap().end(); | ||
hi -= 1; | ||
|
||
while (lo < hi) { | ||
auto tgt = lo + ((hi - lo + 1) / 2); | ||
auto val = tgt->value(); | ||
auto sym = m_index->symrecords().readRecord(val); | ||
if (sym.kind() != S_PUB32) | ||
return std::nullopt; // this is most likely corrupted debug info | ||
|
||
PublicSym32 psym = | ||
llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym)); | ||
SegmentOffset cur(psym.Segment, psym.Offset); | ||
if (so < cur) { | ||
tgt -= 1; | ||
hi = tgt; | ||
} else if (so == cur) | ||
return psym.Name; | ||
else | ||
lo = tgt; | ||
} | ||
|
||
// We might've found something, check if it's the symbol we're searching for | ||
auto val = lo->value(); | ||
auto sym = m_index->symrecords().readRecord(val); | ||
if (sym.kind() != S_PUB32) | ||
return std::nullopt; | ||
PublicSym32 psym = | ||
llvm::cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(sym)); | ||
if (psym.Segment != so.segment || psym.Offset != so.offset) | ||
return std::nullopt; | ||
return psym.Name; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be: