Files
TheRock/compiler/amd-llvm/llvm/unittests/DebugInfo/PDB/NativeSessionTest.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

131 lines
4.4 KiB
C++

//===- 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/ConcreteSymbolEnumerator.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
#include "llvm/Support/Path.h"
#include "llvm/Testing/Support/Error.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, "SimpleTest.exe");
return std::string(InputsDir);
}
TEST(NativeSessionTest, TestCreateFromExe) {
std::unique_ptr<IPDBSession> S;
std::string ExePath = getExePath();
Expected<std::string> PdbPath = NativeSession::searchForPdb({ExePath});
ASSERT_TRUE((bool)PdbPath);
Error E = NativeSession::createFromPdbPath(PdbPath.get(), S);
ASSERT_THAT_ERROR(std::move(E), Succeeded());
}
TEST(NativeSessionTest, TestInvalidPdbMagicError) {
SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
llvm::sys::path::append(InputsDir, "SimpleTest.cpp");
std::string CppPath{InputsDir};
std::unique_ptr<IPDBSession> S;
Error E = NativeSession::createFromPdbPath(CppPath, S);
const char *FormatErr = "The record is in an unexpected format. "
"The input file did not contain the pdb file magic.";
ASSERT_THAT_ERROR(std::move(E), FailedWithMessage(FormatErr));
}
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);
}
TEST(NativeSessionTest, TestModuleIndexLookupForGaps) {
std::unique_ptr<IPDBSession> S;
Error E = pdb::loadDataForEXE(PDB_ReaderType::Native, getExePath(), S);
ASSERT_THAT_ERROR(std::move(E), Succeeded());
auto &NS = static_cast<NativeSession &>(*S);
// Populate section contributions.
S->findSymbolByAddress(0, PDB_SymType::Function);
// SimpleTest.pdb leaves a gap between two mods in section 1 at [10, 16).
uint16_t ModuleIndex;
EXPECT_TRUE(NS.moduleIndexForSectOffset(1, 9, ModuleIndex));
EXPECT_TRUE(NS.moduleIndexForVA(NS.getVAFromSectOffset(1, 9), ModuleIndex));
EXPECT_FALSE(NS.moduleIndexForSectOffset(1, 10, ModuleIndex));
EXPECT_FALSE(NS.moduleIndexForVA(NS.getVAFromSectOffset(1, 10), ModuleIndex));
EXPECT_TRUE(NS.moduleIndexForSectOffset(1, 16, ModuleIndex));
EXPECT_TRUE(NS.moduleIndexForVA(NS.getVAFromSectOffset(1, 16), ModuleIndex));
}