-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[PDB] Add public symbol lookup by address #157361
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
76a14bb
[PDB] Add public symbol lookup by address
Nerixyz ce02ae1
fix: make unsigned
Nerixyz 51fde81
fix: use lower_bound to find the element
Nerixyz d2bddeb
fix: use tuples
Nerixyz e5ec29b
refactor: generate publics programmatically
Nerixyz c17d0cf
fix: use tuples in the last equality check
Nerixyz b27edeb
test: add check for corrupted debug info
Nerixyz 413ebd1
fix: comparison
Nerixyz 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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// clang-format off | ||
Nerixyz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
// Compile with | ||
// cl /Z7 /GR- /GS- PublicSymbols.cpp -c /Gy | ||
// link .\PublicSymbols.obj /DEBUG /NODEFAULTLIB /out:PublicSymbols.exe /ENTRY:main /OPT:ICF | ||
// llvm-pdbutil pdb2yaml --publics-stream PublicSymbols.pdb > PublicSymbols.yaml | ||
// llvm-pdbutil yaml2pdb PublicSymbols.yaml | ||
Nerixyz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// | ||
// rm PublicSymbols.exe && rm PublicSymbols.obj && rm PublicSymbols.yaml | ||
|
||
int foobar(int i){ return i + 1; } | ||
// these should be merged with ICF | ||
int dup1(int i){ return i + 2; } | ||
int dup2(int i){ return i + 2; } | ||
int dup3(int i){ return i + 2; } | ||
|
||
class AClass { | ||
public: | ||
void AMethod(int, char*) {} | ||
static bool Something(char c) { | ||
return c == ' '; | ||
} | ||
}; | ||
|
||
struct Base { | ||
virtual ~Base() = default; | ||
}; | ||
struct Derived : public Base {}; | ||
struct Derived2 : public Base {}; | ||
struct Derived3 : public Derived2, public Derived {}; | ||
|
||
int AGlobal; | ||
|
||
void operator delete(void *,unsigned __int64) {} | ||
|
||
int main() { | ||
foobar(1); | ||
dup1(1); | ||
dup2(1); | ||
dup3(1); | ||
AClass a; | ||
a.AMethod(1, nullptr); | ||
AClass::Something(' '); | ||
Derived3 d3; | ||
return AGlobal; | ||
} |
Nerixyz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/DebugInfo/PDB/Native/PublicsStream.h" | ||
#include "llvm/DebugInfo/CodeView/SymbolRecord.h" | ||
#include "llvm/DebugInfo/PDB/Native/PDBFile.h" | ||
#include "llvm/Support/BinaryByteStream.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
|
||
#include "llvm/Testing/Support/SupportHelpers.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::pdb; | ||
|
||
extern const char *TestMainArgv0; | ||
|
||
static std::string getExePath() { | ||
SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0); | ||
llvm::sys::path::append(InputsDir, "PublicSymbols.pdb"); | ||
return std::string(InputsDir); | ||
} | ||
|
||
TEST(PublicsStreamTest, FindByAddress) { | ||
std::string ExePath = getExePath(); | ||
auto Buffer = MemoryBuffer::getFile(ExePath, /*IsText=*/false, | ||
/*RequiresNullTerminator=*/false); | ||
ASSERT_TRUE(bool(Buffer)); | ||
auto Stream = std::make_unique<MemoryBufferByteStream>( | ||
std::move(*Buffer), llvm::endianness::little); | ||
|
||
BumpPtrAllocator Alloc; | ||
PDBFile File(ExePath, std::move(Stream), Alloc); | ||
ASSERT_FALSE(bool(File.parseFileHeaders())); | ||
ASSERT_FALSE(bool(File.parseStreamData())); | ||
|
||
auto Publics = File.getPDBPublicsStream(); | ||
ASSERT_TRUE(bool(Publics)); | ||
auto Symbols = File.getPDBSymbolStream(); | ||
ASSERT_TRUE(bool(Symbols)); | ||
|
||
auto VTableDerived = Publics->findByAddress(*Symbols, 2, 8); | ||
ASSERT_TRUE(VTableDerived.has_value()); | ||
// both derived and derived2 have their vftables there - but derived2 is first | ||
// (due to ICF) | ||
ASSERT_EQ(VTableDerived->first.Name, "??_7Derived2@@6B@"); | ||
ASSERT_EQ(VTableDerived->second, 26u); | ||
|
||
ASSERT_FALSE(Publics->findByAddress(*Symbols, 2, 7).has_value()); | ||
ASSERT_FALSE(Publics->findByAddress(*Symbols, 2, 9).has_value()); | ||
|
||
auto GlobalSym = Publics->findByAddress(*Symbols, 3, 0); | ||
ASSERT_TRUE(GlobalSym.has_value()); | ||
ASSERT_EQ(GlobalSym->first.Name, "?AGlobal@@3HA"); | ||
ASSERT_EQ(GlobalSym->second, 30u); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.