mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-19 19:13:22 +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.
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "kdlib/kdlib.h"
|
||||
|
||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
@ -9,9 +11,15 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
kdlib::initialize();
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
kdlib::uninitialize();
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
|
@ -55,6 +55,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<TargetExt>.pyd</TargetExt>
|
||||
<PostBuildEventUseInBuild>true</PostBuildEventUseInBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
@ -72,6 +73,14 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ModuleDefinitionFile>pykd.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>
|
||||
<Command>
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug_2.7|Win32'">
|
||||
<ClCompile>
|
||||
@ -88,8 +97,12 @@
|
||||
<AdditionalLibraryDirectories>$(PYTHON_27_X86_ROOT)\libs;$(BOOST_ROOT)\stage_2.7\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>"$(ProjectDir)..\test\scripts\_run_pykdtest.cmd" "$(TargetDir)targetapp.exe" $(PlatformName)</Command>
|
||||
<Command>copy $(ProjectDir)..\Debug\targetapp.exe $(OutDir)targetapp.exe</Command>
|
||||
</PostBuildEvent>
|
||||
<CustomBuildStep>
|
||||
<Command>
|
||||
</Command>
|
||||
</CustomBuildStep>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
@ -112,6 +125,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="windbgext.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="dllmain.cpp">
|
||||
|
@ -21,6 +21,9 @@
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="windbgext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
#include "kdlib/dbgio.h"
|
||||
#include "kdlib/kdlib.h"
|
||||
|
||||
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" );
|
||||
|
||||
|
||||
// // Manage debug target
|
||||
// Manage debug target
|
||||
|
||||
// python::def( "startProcess", &startProcess,
|
||||
// "Start process for debugging" );
|
||||
// python::def( "attachProcess", &attachProcess,
|
||||
// "Attach debugger to a exsisting process" );
|
||||
// python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ),
|
||||
python::def( "startProcess", &startProcess,
|
||||
"Start process for debugging" );
|
||||
python::def( "attachProcess", &attachProcess,
|
||||
"Attach debugger to a exsisting process" );
|
||||
//python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ),
|
||||
// "Stop process debugging") );
|
||||
// python::def( "killProcess", &terminateProcess,
|
||||
// "Stop debugging and terminate current process" );
|
||||
// python::def( "loadDump", &loadDump,
|
||||
// "Load crash dump");
|
||||
// python::def( "isDumpAnalyzing", &isDumpAnalyzing,
|
||||
// "Check if it is a dump analyzing ( not living debuggee )" );
|
||||
// python::def( "isKernelDebugging", &isKernelDebugging,
|
||||
// "Check if kernel dubugging is running" );
|
||||
// python::def( "isWindbgExt", &WindbgGlobalSession::isInit,
|
||||
python::def( "killProcess", &terminateProcess,
|
||||
"Stop debugging and terminate current process" );
|
||||
python::def( "loadDump", &loadDump,
|
||||
"Load crash dump");
|
||||
python::def( "isDumpAnalyzing", &isDumpAnalyzing,
|
||||
"Check if it is a dump analyzing ( not living debuggee )" );
|
||||
python::def( "isKernelDebugging", &isKernelDebugging,
|
||||
"Check if kernel dubugging is running" );
|
||||
//python::def( "isWindbgExt", &WindbgGlobalSession::isInit,
|
||||
// "Check if script works in windbg context" );
|
||||
// python::def( "writeDump", &writeDump,
|
||||
// "Create memory dump file" );
|
||||
python::def( "writeDump", &writeDump,
|
||||
"Create memory dump file" );
|
||||
|
||||
// python::def( "breakin", &debugBreak,
|
||||
// "Break into debugger" );
|
||||
|
@ -3,24 +3,22 @@
|
||||
#include "kdlib/kdlib.h"
|
||||
#include "kdlib/windbg.h"
|
||||
|
||||
#include "windbgext.h"
|
||||
|
||||
using namespace kdlib;
|
||||
using namespace kdlib::windbg;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
KDLIB_WINDBG_EXTENSION_INIT( PykdExt );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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();
|
||||
|
||||
PyImport_AppendInittab("pykd", initpykd );
|
||||
@ -35,18 +33,16 @@ private:
|
||||
sys.attr("stdout") = python::ptr( dbgout );
|
||||
sys.attr("stderr") = python::ptr( dbgout );
|
||||
sys.attr("stdin") = python::ptr( dbgin );
|
||||
}
|
||||
}
|
||||
|
||||
virtual void tearDown()
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void PykdExt::tearDown()
|
||||
{
|
||||
Py_Finalize();
|
||||
|
||||
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):
|
||||
def testStart(self):
|
||||
target.processId = pykd.startProcess( target.appPath )
|
||||
target.module = pykd.module( target.moduleName )
|
||||
target.module.reload();
|
||||
print "\n" + str( pykd.getSystemVersion() )
|
||||
pykd.go()
|
||||
# target.module = pykd.module( target.moduleName )
|
||||
# target.module.reload();
|
||||
# print "\n" + str( pykd.getSystemVersion() )
|
||||
# pykd.go()
|
||||
|
||||
class TerminateProcessTest(unittest.TestCase):
|
||||
def testKill(self):
|
||||
pykd.killProcess( target.processId )
|
||||
pykd.detachProcess( target.processId )
|
||||
#pykd.detachProcess( target.processId )
|
||||
|
||||
def getTestSuite( singleName = "" ):
|
||||
if singleName == "":
|
||||
@ -76,6 +76,4 @@ if __name__ == "__main__":
|
||||
target.appPath = sys.argv[1]
|
||||
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