Commit ba80c2ca authored by Mikhail I. Izmestev's avatar Mikhail I. Izmestev
Browse files

Add test cases for getRegRealativeId for CV_ALLREG_VFRAME

parent a02b6bf3
......@@ -15,6 +15,8 @@ public:
static constexpr wchar_t* STACKTEST_WOW64 = L"targetapp_stacktest_wow64";
static constexpr wchar_t* STACKTEST_X64_RELEASE = L"targetapp_stacktest_x64_release";
static constexpr wchar_t* STACKTEST_WOW64_RELEASE = L"targetapp_stacktest_wow64_release";
static constexpr wchar_t* STACKTEST_CV_ALLREG_I386 = L"targetapp_test_cv_allreg_i386";
static constexpr wchar_t* STACKTEST_CV_ALLREG_AMD64 = L"targetapp_test_cv_allreg_amd64";
static constexpr wchar_t* WIN10_ARM64 = L"win10_arm64_mem";
static constexpr wchar_t* WIN10_ARM = L"win10_arm_rpi3_mem";
static constexpr wchar_t* WIN8_X64 = L"win8_x64_mem";
......
......@@ -432,3 +432,41 @@ INSTANTIATE_TEST_CASE_P(ReleaseStackDumps, InlineStackTest, ::testing::Values(
MemDumps::STACKTEST_X64_RELEASE
,MemDumps::STACKTEST_WOW64_RELEASE
));
class DiaRegToRegRelativei386Test : public MemDumpFixture
{
public:
DiaRegToRegRelativei386Test() :
MemDumpFixture(makeDumpFullName(MemDumps::STACKTEST_CV_ALLREG_I386))
{
}
};
TEST_F(DiaRegToRegRelativei386Test, CV_ALLREG_VFRAME)
{
auto stack = getStack(true);
auto frame = stack->getFrame(0);
unsigned long paramCount = frame->getTypedParamCount();
EXPECT_NE(0, paramCount);
for (unsigned long i = 0; i < paramCount; ++i)
ASSERT_NO_THROW(frame->getTypedParam(i));
}
class DiaRegToRegRelativeAmd64Test : public MemDumpFixture
{
public:
DiaRegToRegRelativeAmd64Test() :
MemDumpFixture(makeDumpFullName(MemDumps::STACKTEST_CV_ALLREG_AMD64))
{
}
};
TEST_F(DiaRegToRegRelativeAmd64Test, CV_ALLREG_VFRAME)
{
auto stack = getStack(true);
auto frame = stack->getFrame(0);
unsigned long localCount = frame->getLocalVarCount();
EXPECT_NE(0, localCount);
for (unsigned long i = 0; i < localCount; ++i)
ASSERT_NO_THROW(frame->getLocalVar(i));
}
......@@ -13,6 +13,7 @@
#include "test/testfunc.h"
#include "test/testvars.h"
#include "test_cv_allreg.h"
int breakOnRun();
int breakpointTestRun();
......@@ -95,6 +96,9 @@ int _tmain(int argc, _TCHAR* argv[])
if ( testGroup == L"childprocess" )
return startChildProcess();
if ( testGroup == L"test_cv_allreg" )
return test_cv_allreg();
return breakOnRun();
}
......
......@@ -155,6 +155,7 @@
<ClInclude Include="..\..\include\test\testvars.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="test_cv_allreg.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\comdate\testfunc.cpp">
......@@ -171,6 +172,9 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="targetapp.cpp" />
<ClCompile Include="test_cv_allreg.cpp">
<WholeProgramOptimization Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</WholeProgramOptimization>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
#include "stdafx.h"
#ifndef _WIN64
#include <vector>
#include <sstream>
typedef unsigned long long MEMOFFSET_64;
#define FAILED(x) x != 0
#define S_OK 0
typedef int HRESULT;
typedef void *PVOID;
typedef unsigned long ULONG;
typedef unsigned long long ULONG64;
typedef HRESULT(*write_mem_func_t)(MEMOFFSET_64, void*, ULONG, unsigned long *);
write_mem_func_t WriteVirtual = 0;
write_mem_func_t WritePhysical = 0;
typedef HRESULT(*valid_region_virtual_func_t)(MEMOFFSET_64, ULONG, ULONG64 *, ULONG *);
valid_region_virtual_func_t GetValidRegionVirtual = 0;
__declspec(dllexport) void setWriteFunc(write_mem_func_t a, write_mem_func_t b, valid_region_virtual_func_t c)
{
WriteVirtual = a;
WritePhysical = b;
GetValidRegionVirtual = c;
}
__declspec(dllexport) MEMOFFSET_64 addr64(MEMOFFSET_64 offset)
{
return offset;
}
template <typename Dst, typename Src>
Dst numeric_cast(Src a)
{
return (Dst)a;
}
class MemoryException : public std::exception
{
public:
MemoryException( MEMOFFSET_64 targetAddr, bool phyAddr = false ) :
m_targetAddress(targetAddr)
{}
MEMOFFSET_64 m_targetAddress;
};
__declspec(noinline) bool isVaRegionValid(MEMOFFSET_64 addr, size_t length)
{
addr = addr64(addr);
HRESULT hres;
ULONG64 validBase = 0;
ULONG validSize = 0;
if (length > 0xFFFFFFFF)
return false;
hres = GetValidRegionVirtual(addr, numeric_cast<ULONG>(length), &validBase, &validSize);
return hres == S_OK && validBase == addr && validSize == length;
}
__declspec(noinline)
void writeMemory(MEMOFFSET_64 offset, const void* buffer, size_t length, bool phyAddr = false, unsigned long *written = 0)
{
offset = addr64(offset);
if (written)
*written = 0;
HRESULT hres;
if (phyAddr == false)
{
offset = addr64(offset);
hres = WriteVirtual(offset, const_cast<PVOID>(buffer), numeric_cast<ULONG>(length), written);
}
else
{
hres = WritePhysical(offset, const_cast<PVOID>(buffer), numeric_cast<ULONG>(length), written);
}
if (FAILED(hres))
throw MemoryException(offset, phyAddr);
}
template<typename T>
void writeArray( MEMOFFSET_64 offset, const std::vector<T> &values, bool phyAddr )
{
if (values.empty())
return;
const auto length = values.size() * sizeof(T);
if (!phyAddr && !isVaRegionValid(offset, length))
throw MemoryException(offset);
writeMemory( offset, &values[0], length, phyAddr );
}
__declspec(dllexport) void __fastcall test_cv_allreg_i386(MEMOFFSET_64 offset, const std::vector<unsigned char> &values, bool phyAddr )
{
__debugbreak();
writeArray(offset, values, phyAddr);
}
int test_cv_allreg()
{
test_cv_allreg_i386(0, { 0, 0 }, 0);
return 0;
}
#else
typedef int (*dummy_subcall_t)(char* firstptr, char* lastptr);
dummy_subcall_t dummy_subcall = 0;
__declspec(noinline) int test_cv_allreg_amd64(char *aa, char* ab)
{
char l = 0, r = aa[0];
char* e = ab + r * r;
__debugbreak();
char *f, *lt, *le;
le = aa + aa[0];
f = lt = e;
while (f > aa && dummy_subcall(ab, f - r))
f -= r;
while (lt < le && dummy_subcall(ab, lt + r))
lt += r;
return (f == lt) ? e[0] : 0;
}
int test_cv_allreg()
{
test_cv_allreg_amd64("test", 0);
return 0;
}
#endif
#pragma once
int test_cv_allreg();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment