mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 12:53:23 +08:00
[0.3.x] added process manipulations
git-svn-id: https://pykd.svn.codeplex.com/svn@83697 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
54b6e5f15f
commit
f17e190978
@ -1,6 +1,8 @@
|
|||||||
// dllmain.cpp : Defines the entry point for the DLL application.
|
// dllmain.cpp : Defines the entry point for the DLL application.
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
#include "kdlib/kdlib.h"
|
||||||
|
|
||||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||||
DWORD ul_reason_for_call,
|
DWORD ul_reason_for_call,
|
||||||
LPVOID lpReserved
|
LPVOID lpReserved
|
||||||
@ -9,9 +11,15 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
|||||||
switch (ul_reason_for_call)
|
switch (ul_reason_for_call)
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
|
kdlib::initialize();
|
||||||
|
break;
|
||||||
|
|
||||||
case DLL_THREAD_ATTACH:
|
case DLL_THREAD_ATTACH:
|
||||||
case DLL_THREAD_DETACH:
|
case DLL_THREAD_DETACH:
|
||||||
|
break;
|
||||||
|
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
|
kdlib::uninitialize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -55,6 +55,7 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">
|
||||||
<LinkIncremental>true</LinkIncremental>
|
<LinkIncremental>true</LinkIncremental>
|
||||||
<TargetExt>.pyd</TargetExt>
|
<TargetExt>.pyd</TargetExt>
|
||||||
|
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
@ -72,6 +73,14 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<ModuleDefinitionFile>pykd.def</ModuleDefinitionFile>
|
<ModuleDefinitionFile>pykd.def</ModuleDefinitionFile>
|
||||||
</Link>
|
</Link>
|
||||||
|
<PreBuildEvent>
|
||||||
|
<Command>
|
||||||
|
</Command>
|
||||||
|
</PreBuildEvent>
|
||||||
|
<PostBuildEvent>
|
||||||
|
<Command>
|
||||||
|
</Command>
|
||||||
|
</PostBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@ -88,8 +97,12 @@
|
|||||||
<AdditionalLibraryDirectories>$(PYTHON_27_X86_ROOT)\libs;$(BOOST_ROOT)\stage_2.7\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>$(PYTHON_27_X86_ROOT)\libs;$(BOOST_ROOT)\stage_2.7\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
<PostBuildEvent>
|
<PostBuildEvent>
|
||||||
<Command>"$(ProjectDir)..\test\scripts\_run_pykdtest.cmd" "$(TargetDir)targetapp.exe" $(PlatformName)</Command>
|
<Command>copy $(ProjectDir)..\Debug\targetapp.exe $(OutDir)targetapp.exe</Command>
|
||||||
</PostBuildEvent>
|
</PostBuildEvent>
|
||||||
|
<CustomBuildStep>
|
||||||
|
<Command>
|
||||||
|
</Command>
|
||||||
|
</CustomBuildStep>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@ -112,6 +125,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="stdafx.h" />
|
<ClInclude Include="stdafx.h" />
|
||||||
<ClInclude Include="targetver.h" />
|
<ClInclude Include="targetver.h" />
|
||||||
|
<ClInclude Include="windbgext.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<ClCompile Include="dllmain.cpp">
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
<ClInclude Include="targetver.h">
|
<ClInclude Include="targetver.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="windbgext.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="stdafx.cpp">
|
<ClCompile Include="stdafx.cpp">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
|
||||||
#include "kdlib/dbgio.h"
|
#include "kdlib/kdlib.h"
|
||||||
|
|
||||||
using namespace kdlib;
|
using namespace kdlib;
|
||||||
|
|
||||||
@ -95,26 +95,26 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
// "Call a WinDBG extension's routine. Parameters: handle returned by loadExt; string command line" );
|
// "Call a WinDBG extension's routine. Parameters: handle returned by loadExt; string command line" );
|
||||||
|
|
||||||
|
|
||||||
// // Manage debug target
|
// Manage debug target
|
||||||
|
|
||||||
// python::def( "startProcess", &startProcess,
|
python::def( "startProcess", &startProcess,
|
||||||
// "Start process for debugging" );
|
"Start process for debugging" );
|
||||||
// python::def( "attachProcess", &attachProcess,
|
python::def( "attachProcess", &attachProcess,
|
||||||
// "Attach debugger to a exsisting process" );
|
"Attach debugger to a exsisting process" );
|
||||||
// python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ),
|
//python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ),
|
||||||
// "Stop process debugging") );
|
// "Stop process debugging") );
|
||||||
// python::def( "killProcess", &terminateProcess,
|
python::def( "killProcess", &terminateProcess,
|
||||||
// "Stop debugging and terminate current process" );
|
"Stop debugging and terminate current process" );
|
||||||
// python::def( "loadDump", &loadDump,
|
python::def( "loadDump", &loadDump,
|
||||||
// "Load crash dump");
|
"Load crash dump");
|
||||||
// python::def( "isDumpAnalyzing", &isDumpAnalyzing,
|
python::def( "isDumpAnalyzing", &isDumpAnalyzing,
|
||||||
// "Check if it is a dump analyzing ( not living debuggee )" );
|
"Check if it is a dump analyzing ( not living debuggee )" );
|
||||||
// python::def( "isKernelDebugging", &isKernelDebugging,
|
python::def( "isKernelDebugging", &isKernelDebugging,
|
||||||
// "Check if kernel dubugging is running" );
|
"Check if kernel dubugging is running" );
|
||||||
// python::def( "isWindbgExt", &WindbgGlobalSession::isInit,
|
//python::def( "isWindbgExt", &WindbgGlobalSession::isInit,
|
||||||
// "Check if script works in windbg context" );
|
// "Check if script works in windbg context" );
|
||||||
// python::def( "writeDump", &writeDump,
|
python::def( "writeDump", &writeDump,
|
||||||
// "Create memory dump file" );
|
"Create memory dump file" );
|
||||||
|
|
||||||
// python::def( "breakin", &debugBreak,
|
// python::def( "breakin", &debugBreak,
|
||||||
// "Break into debugger" );
|
// "Break into debugger" );
|
||||||
|
@ -3,24 +3,22 @@
|
|||||||
#include "kdlib/kdlib.h"
|
#include "kdlib/kdlib.h"
|
||||||
#include "kdlib/windbg.h"
|
#include "kdlib/windbg.h"
|
||||||
|
|
||||||
|
#include "windbgext.h"
|
||||||
|
|
||||||
using namespace kdlib;
|
using namespace kdlib;
|
||||||
using namespace kdlib::windbg;
|
using namespace kdlib::windbg;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
KDLIB_WINDBG_EXTENSION_INIT( PykdExt );
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
extern "C" void initpykd();
|
extern "C" void initpykd();
|
||||||
|
|
||||||
class PykdExt : public WindbgExtension
|
void PykdExt::setUp()
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
KDLIB_EXT_COMMAND_METHOD(py);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void startConsole();
|
|
||||||
|
|
||||||
virtual void setUp()
|
|
||||||
{
|
|
||||||
WindbgExtension::setUp();
|
WindbgExtension::setUp();
|
||||||
|
|
||||||
PyImport_AppendInittab("pykd", initpykd );
|
PyImport_AppendInittab("pykd", initpykd );
|
||||||
@ -35,18 +33,16 @@ private:
|
|||||||
sys.attr("stdout") = python::ptr( dbgout );
|
sys.attr("stdout") = python::ptr( dbgout );
|
||||||
sys.attr("stderr") = python::ptr( dbgout );
|
sys.attr("stderr") = python::ptr( dbgout );
|
||||||
sys.attr("stdin") = python::ptr( dbgin );
|
sys.attr("stdin") = python::ptr( dbgin );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void tearDown()
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
{
|
|
||||||
|
void PykdExt::tearDown()
|
||||||
|
{
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
|
|
||||||
WindbgExtension::tearDown();
|
WindbgExtension::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
KDLIB_WINDBG_EXTENSION_INIT( PykdExt );
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
24
pykd/windbgext.h
Normal file
24
pykd/windbgext.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "kdlib/windbg.h"
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class PykdExt : public kdlib::windbg::WindbgExtension
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
KDLIB_EXT_COMMAND_METHOD(py);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void startConsole();
|
||||||
|
|
||||||
|
virtual void setUp();
|
||||||
|
|
||||||
|
virtual void tearDown();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -29,15 +29,15 @@ import target
|
|||||||
class StartProcessWithoutParamsTest(unittest.TestCase):
|
class StartProcessWithoutParamsTest(unittest.TestCase):
|
||||||
def testStart(self):
|
def testStart(self):
|
||||||
target.processId = pykd.startProcess( target.appPath )
|
target.processId = pykd.startProcess( target.appPath )
|
||||||
target.module = pykd.module( target.moduleName )
|
# target.module = pykd.module( target.moduleName )
|
||||||
target.module.reload();
|
# target.module.reload();
|
||||||
print "\n" + str( pykd.getSystemVersion() )
|
# print "\n" + str( pykd.getSystemVersion() )
|
||||||
pykd.go()
|
# pykd.go()
|
||||||
|
|
||||||
class TerminateProcessTest(unittest.TestCase):
|
class TerminateProcessTest(unittest.TestCase):
|
||||||
def testKill(self):
|
def testKill(self):
|
||||||
pykd.killProcess( target.processId )
|
pykd.killProcess( target.processId )
|
||||||
pykd.detachProcess( target.processId )
|
#pykd.detachProcess( target.processId )
|
||||||
|
|
||||||
def getTestSuite( singleName = "" ):
|
def getTestSuite( singleName = "" ):
|
||||||
if singleName == "":
|
if singleName == "":
|
||||||
@ -76,6 +76,4 @@ if __name__ == "__main__":
|
|||||||
target.appPath = sys.argv[1]
|
target.appPath = sys.argv[1]
|
||||||
target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0]
|
target.moduleName = os.path.splitext(os.path.basename(target.appPath))[0]
|
||||||
|
|
||||||
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() )
|
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( getTestSuite() )\
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user