Commit 7c3fcfbf authored by Aleksey R.'s avatar Aleksey R.

add: addSyntheticModule

add: removeSyntheticModule
add: test: of synthetic symbols and modules
parent 9126f440
......@@ -199,6 +199,10 @@ void getSyntheticSymbolInformation(
SyntheticSymbol addSyntheticSymbol( MEMOFFSET_64 offset, unsigned long size, const std::wstring &name );
void removeSyntheticSymbol(const SyntheticSymbol& syntheticSymbol);
// synthetic modules
void addSyntheticModule(MEMOFFSET_64 base, unsigned long size, const std::wstring &name, const std::wstring &path = std::wstring{});
void removeSyntheticModule(MEMOFFSET_64 base);
std::wstring loadSourceFileFromSrcSrv(MEMOFFSET_64 offset, const std::wstring& fileName);
// aux function
......
......@@ -2650,7 +2650,7 @@ std::wstring loadSourceFileFromSrcSrv(MEMOFFSET_64 offset, const std::wstring& f
///////////////////////////////////////////////////////////////////////////////
kdlib::SyntheticSymbol addSyntheticSymbol( kdlib::MEMOFFSET_64 offset, unsigned long size, const std::wstring &name )
kdlib::SyntheticSymbol addSyntheticSymbol(kdlib::MEMOFFSET_64 offset, unsigned long size, const std::wstring &name)
{
offset = addr64(offset);
......@@ -2665,15 +2665,14 @@ kdlib::SyntheticSymbol addSyntheticSymbol( kdlib::MEMOFFSET_64 offset, unsigned
if ( FAILED(hres) )
throw DbgEngException(L"IDebugSymbols::AddSyntheticSymbolWide", hres);
SyntheticSymbol syntheticSymbol = { moduleAndId.ModuleBase, moduleAndId.Id };
return std::move(syntheticSymbol);
return SyntheticSymbol{ moduleAndId.ModuleBase, moduleAndId.Id };
}
///////////////////////////////////////////////////////////////////////////////
void removeSyntheticSymbol(const kdlib::SyntheticSymbol& syntheticSymbol)
{
DEBUG_MODULE_AND_ID moduleAndId = { syntheticSymbol.moduleBase, syntheticSymbol.symbolId };
DEBUG_MODULE_AND_ID moduleAndId{ syntheticSymbol.moduleBase, syntheticSymbol.symbolId };
HRESULT hres = g_dbgMgr->symbols->RemoveSyntheticSymbol(&moduleAndId);
if ( FAILED(hres) )
......@@ -2682,6 +2681,30 @@ void removeSyntheticSymbol(const kdlib::SyntheticSymbol& syntheticSymbol)
///////////////////////////////////////////////////////////////////////////////
void addSyntheticModule(MEMOFFSET_64 base, unsigned long size, const std::wstring &name, const std::wstring &path /* = std::wstring{} */)
{
HRESULT hres =
g_dbgMgr->symbols->AddSyntheticModuleWide(
addr64(base),
size,
path.empty() ? name.c_str() : path.c_str(),
name.c_str(),
DEBUG_ADDSYNTHMOD_DEFAULT);
if ( FAILED(hres) )
throw DbgEngException(L"IDebugSymbols::AddSyntheticModuleWide", hres);
}
///////////////////////////////////////////////////////////////////////////////
void removeSyntheticModule(MEMOFFSET_64 base)
{
HRESULT hres = g_dbgMgr->symbols->RemoveSyntheticModule(addr64(base));
if (FAILED(hres))
throw DbgEngException(L"IDebugSymbols::RemoveSyntheticModule", hres);
}
///////////////////////////////////////////////////////////////////////////////
void dinput(const std::wstring &str)
{
g_dbgMgr->control->ReturnInputWide(str.c_str());
......
......@@ -215,6 +215,7 @@
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="syntest.cpp" />
<ClCompile Include="taggedtest.cpp" />
<ClCompile Include="targettest.cpp" />
<ClCompile Include="typedvartest.cpp" />
......
......@@ -69,14 +69,17 @@
<Filter>testcases</Filter>
</ClCompile>
<ClCompile Include="typeevaltest.cpp">
<Filter>testcases</Filter>
</ClCompile>
<Filter>testcases</Filter>
</ClCompile>
<ClCompile Include="arm64dumptest.cpp">
<Filter>testcases</Filter>
</ClCompile>
<ClCompile Include="armdumptest.cpp">
<Filter>testcases</Filter>
</ClCompile>
<ClCompile Include="syntest.cpp">
<Filter>testcases</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
......
#include <stdafx.h>
#include "procfixture.h"
using namespace kdlib;
class SyntheticsTest : public ProcessFixture
{
public:
SyntheticsTest()
: ProcessFixture(L"syntest")
{
}
};
TEST_F(SyntheticsTest, Symbol)
{
SyntheticSymbol synSym{};
EXPECT_NO_THROW(synSym = addSyntheticSymbol(m_targetModule->getBase() + 1, 1, L"artificial_symbol"));
EXPECT_NO_THROW(removeSyntheticSymbol(synSym));
// exception: symbol outside module
EXPECT_THROW(addSyntheticSymbol(32 * 1024, 1, L"impossible_symbol"), DbgException);
}
TEST_F(SyntheticsTest, Module)
{
constexpr MEMOFFSET_64 base = 64 * 1024;
EXPECT_NO_THROW(addSyntheticModule(base, 1024, L"artificial_module"));
SyntheticSymbol synSym{};
EXPECT_NO_THROW(synSym = addSyntheticSymbol(base + 2, 1, L"artificial_symbol"));
EXPECT_NO_THROW(removeSyntheticSymbol(synSym));
EXPECT_NO_THROW(removeSyntheticModule(base));
}
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