Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement some functions in NativeSession.
Summary: This change implements readFromExe, and calculating VA and RVA, which are some of the functionalities that will be used for native PDB reading for llvm symbolizer. bug: https://bugs.llvm.org/show_bug.cgi?id=41795 Reviewers: hans, amccarth, rnk Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78128
- Loading branch information
Showing
8 changed files
with
247 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,4 @@ | ||
// Compile with "cl /c /Zi SimpleTest.cpp" | ||
// Link with "link SimpleTest.obj /debug /nodefaultlib /entry:main" | ||
|
||
int main() { return 0; } |
Binary file not shown.
Binary file not shown.
This file contains 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,93 @@ | ||
//===- llvm/unittest/DebugInfo/PDB/NativeSessionTest.cpp ------------------===// | ||
// | ||
// 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/NativeSession.h" | ||
#include "llvm/DebugInfo/PDB/IPDBSession.h" | ||
#include "llvm/DebugInfo/PDB/PDB.h" | ||
#include "llvm/Support/Path.h" | ||
|
||
#include "llvm/Testing/Support/Error.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#include <vector> | ||
|
||
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, "SimpleTest.exe"); | ||
return std::string(InputsDir); | ||
} | ||
|
||
TEST(NativeSessionTest, TestCreateFromExe) { | ||
std::unique_ptr<IPDBSession> S; | ||
Error E = pdb::loadDataForEXE(PDB_ReaderType::Native, getExePath(), S); | ||
ASSERT_THAT_ERROR(std::move(E), Succeeded()); | ||
} | ||
|
||
TEST(NativeSessionTest, TestSetLoadAddress) { | ||
std::unique_ptr<IPDBSession> S; | ||
Error E = pdb::loadDataForEXE(PDB_ReaderType::Native, getExePath(), S); | ||
ASSERT_THAT_ERROR(std::move(E), Succeeded()); | ||
|
||
S->setLoadAddress(123); | ||
EXPECT_EQ(S->getLoadAddress(), 123U); | ||
} | ||
|
||
TEST(NativeSessionTest, TestAddressForVA) { | ||
std::unique_ptr<IPDBSession> S; | ||
Error E = pdb::loadDataForEXE(PDB_ReaderType::Native, getExePath(), S); | ||
ASSERT_THAT_ERROR(std::move(E), Succeeded()); | ||
|
||
uint64_t LoadAddr = S->getLoadAddress(); | ||
uint32_t Section; | ||
uint32_t Offset; | ||
ASSERT_TRUE(S->addressForVA(LoadAddr + 5000, Section, Offset)); | ||
EXPECT_EQ(1U, Section); | ||
EXPECT_EQ(904U, Offset); | ||
|
||
ASSERT_TRUE(S->addressForVA(-1, Section, Offset)); | ||
EXPECT_EQ(0U, Section); | ||
EXPECT_EQ(0U, Offset); | ||
|
||
ASSERT_TRUE(S->addressForVA(4, Section, Offset)); | ||
EXPECT_EQ(0U, Section); | ||
EXPECT_EQ(4U, Offset); | ||
|
||
ASSERT_TRUE(S->addressForVA(LoadAddr + 100000, Section, Offset)); | ||
EXPECT_EQ(3U, Section); | ||
EXPECT_EQ(83616U, Offset); | ||
} | ||
|
||
TEST(NativeSessionTest, TestAddressForRVA) { | ||
std::unique_ptr<IPDBSession> S; | ||
Error E = pdb::loadDataForEXE(PDB_ReaderType::Native, getExePath(), S); | ||
ASSERT_THAT_ERROR(std::move(E), Succeeded()); | ||
|
||
uint32_t Section; | ||
uint32_t Offset; | ||
ASSERT_TRUE(S->addressForVA(5000, Section, Offset)); | ||
EXPECT_EQ(1U, Section); | ||
EXPECT_EQ(904U, Offset); | ||
|
||
ASSERT_TRUE(S->addressForVA(-1, Section, Offset)); | ||
EXPECT_EQ(0U, Section); | ||
EXPECT_EQ(0U, Offset); | ||
|
||
ASSERT_TRUE(S->addressForVA(4, Section, Offset)); | ||
EXPECT_EQ(0U, Section); | ||
EXPECT_EQ(4U, Offset); | ||
|
||
ASSERT_TRUE(S->addressForVA(100000, Section, Offset)); | ||
EXPECT_EQ(3U, Section); | ||
EXPECT_EQ(83616U, Offset); | ||
} |