From 976e43a31a9d81d742ddb048573fa5d075c09129 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Thu, 31 Oct 2013 08:10:01 +0000 Subject: [PATCH] [0.2.x] added : startProcess routine extra parameter debugChildren [0.2.x] fixed : killProcess correctly detaching from target now git-svn-id: https://pykd.svn.codeplex.com/svn@86120 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgengine.h | 2 +- pykd/pykdver.h | 2 +- pykd/python/pymod.cpp | 5 +++-- pykd/win/dbgps.cpp | 13 +++++++++++-- snippets/pykdmagic.py | 5 ++--- test/scripts/pykdtest.py | 1 - 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index f19ee5d..806e783 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -6,7 +6,7 @@ namespace pykd { // manage debug target -ULONG startProcess( const std::wstring &processName ); +ULONG startProcess( const std::wstring &processName, bool debugChildren = false ); ULONG attachProcess( ULONG pid ); void attachKernel( const std::string &connectOptions = "" ); bool isLocalKernelDebuggerEnabled(); diff --git a/pykd/pykdver.h b/pykd/pykdver.h index b4c8e7c..e2e9113 100644 --- a/pykd/pykdver.h +++ b/pykd/pykdver.h @@ -2,7 +2,7 @@ #define PYKD_VERSION_MAJOR 0 #define PYKD_VERSION_MINOR 2 #define PYKD_VERSION_SUBVERSION 0 -#define PYKD_VERSION_BUILDNO 25 +#define PYKD_VERSION_BUILDNO 26 #define __VER_STR2__(x) #x diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp index c02d8d6..412a4a8 100644 --- a/pykd/python/pymod.cpp +++ b/pykd/python/pymod.cpp @@ -38,6 +38,7 @@ static const std::string pykdVersion = PYKD_VERSION_BUILD_STR //////////////////////////////////////////////////////////////////////////////// +BOOST_PYTHON_FUNCTION_OVERLOADS( startProcess_, startProcess, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( attachKernel_, attachKernel, 0, 1 ); BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_, detachProcess, 0, 1 ); @@ -90,8 +91,8 @@ BOOST_PYTHON_MODULE( pykd ) // Manage debug target - python::def( "startProcess", &startProcess, - "Start process for debugging" ); + python::def( "startProcess", &startProcess, startProcess_( boost::python::args( "commandline", "debugChildren" ), + "Start process for debugging" ) ); python::def( "attachProcess", &attachProcess, "Attach debugger to a exsisting process" ); python::def( "attachKernel", &attachKernel, attachKernel_( boost::python::args( "connectOptions" ), diff --git a/pykd/win/dbgps.cpp b/pykd/win/dbgps.cpp index 474f5d7..745ebed 100644 --- a/pykd/win/dbgps.cpp +++ b/pykd/win/dbgps.cpp @@ -13,7 +13,7 @@ namespace pykd { /////////////////////////////////////////////////////////////////////////////////// -ULONG startProcess( const std::wstring &processName ) +ULONG startProcess( const std::wstring &processName, bool debugChildren ) { PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); @@ -32,7 +32,12 @@ ULONG startProcess( const std::wstring &processName ) std::vector< std::wstring::value_type > cmdLine( processName.size() + 1 ); wcscpy_s( &cmdLine[0], cmdLine.size(), processName.c_str() ); - hres = g_dbgEng->client->CreateProcessWide( 0, &cmdLine[0], DEBUG_PROCESS | DETACHED_PROCESS ); + hres = g_dbgEng->client->CreateProcessWide( + 0, + &cmdLine[0], + ( debugChildren ? DEBUG_PROCESS : DEBUG_ONLY_THIS_PROCESS) | DETACHED_PROCESS + ); + if ( FAILED( hres ) ) throw DbgException( "IDebugClient4::CreateProcessWide failed" ); @@ -159,6 +164,10 @@ void terminateProcess( ULONG processId ) if ( FAILED( hres ) ) throw DbgException( "IDebugClient::TerminateCurrentProcess", hres ); + hres = g_dbgEng->client->DetachCurrentProcess(); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::DetachCurrentProcess failed" ); + } /////////////////////////////////////////////////////////////////////////////// diff --git a/snippets/pykdmagic.py b/snippets/pykdmagic.py index a000ad0..427d11c 100644 --- a/snippets/pykdmagic.py +++ b/snippets/pykdmagic.py @@ -7,7 +7,7 @@ class PykdMagic (Magics): @line_magic def kd(self,line): - "any windbg command" + "magic for calling any windbg command" try: pykd.dprintln( pykd.dbgCommand(line) ) except pykd.BaseException: @@ -18,6 +18,5 @@ def load_ipython_extension(ipython): ipython.register_magics(PykdMagic) def unload_ipython_extension(ipython): - pass - + pass diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index aa2535b..25f7517 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -37,7 +37,6 @@ class StartProcessWithoutParamsTest(unittest.TestCase): class TerminateProcessTest(unittest.TestCase): def testKill(self): pykd.killProcess( target.processId ) - pykd.detachProcess( target.processId ) def getTestSuite( singleName = "" ): if singleName == "":