From 116e45c98990a6e42007581d942f86c7ee23ee77 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Mon, 2 Sep 2013 15:11:32 +0000 Subject: [PATCH] [0.2.x] + attachKernel, isLocalKernelDebuggerEnabled git-svn-id: https://pykd.svn.codeplex.com/svn@85044 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgengine.h | 2 ++ pykd/python/pymod.cpp | 6 ++++++ pykd/win/dbgps.cpp | 30 +++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index 79baf04..5008493 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -8,6 +8,8 @@ namespace pykd { // manage debug target ULONG startProcess( const std::wstring &processName ); ULONG attachProcess( ULONG pid ); +void attachKernel( const std::string &connectOptions = "" ); +bool isLocalKernelDebuggerEnabled(); void detachProcess( ULONG processId = -1); void terminateProcess( ULONG processId = -1); diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp index 55ab7c3..0b51a1e 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( attachKernel_, attachKernel, 0, 1 ); BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_, detachProcess, 0, 1 ); BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 ); @@ -92,6 +93,11 @@ BOOST_PYTHON_MODULE( pykd ) "Start process for debugging" ); python::def( "attachProcess", &attachProcess, "Attach debugger to a exsisting process" ); + python::def( "attachKernel", &attachKernel, attachKernel_( boost::python::args( "connectOptions" ), + "Connect the debugger engine to a kernel target.\n" + "If connectOptions is not specified - attach to the local kernel") ); + python::def( "isLocalKernelDebuggerEnabled", &isLocalKernelDebuggerEnabled, + "Check whether kernel debugging is enabled for the local kernel" ); python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ), "Stop process debugging") ); python::def( "killProcess", &terminateProcess, diff --git a/pykd/win/dbgps.cpp b/pykd/win/dbgps.cpp index 3e6127f..5aa5517 100644 --- a/pykd/win/dbgps.cpp +++ b/pykd/win/dbgps.cpp @@ -65,7 +65,7 @@ ULONG attachProcess( ULONG pid ) hres = g_dbgEng->control->SetEngineOptions( opt ); if ( FAILED( hres ) ) throw DbgException( "IDebugControl::SetEngineOptions failed" ); - + hres = g_dbgEng->client->AttachProcess( 0, pid, 0 ); if ( FAILED( hres ) ) throw DbgException( "IDebugClient::AttachProcess failed" ); @@ -84,6 +84,34 @@ ULONG attachProcess( ULONG pid ) /////////////////////////////////////////////////////////////////////////////////// +void attachKernel( const std::string &connectOptions ) +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres = + g_dbgEng->client->AttachKernel( + connectOptions.empty() ? DEBUG_ATTACH_LOCAL_KERNEL : DEBUG_ATTACH_KERNEL_CONNECTION, + connectOptions.empty() ? NULL : connectOptions.c_str()); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::AttachKernel", hres ); + + hres = g_dbgEng->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::WaitForEvent", hres ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +bool isLocalKernelDebuggerEnabled() +{ + HRESULT hres = g_dbgEng->client->IsKernelDebuggerEnabled(); + if ( ( hres != S_OK ) && ( hres != S_FALSE ) ) + throw DbgException( "IDebugClient::IsKernelDebuggerEnabled", hres ); + return hres == S_OK; +} + +/////////////////////////////////////////////////////////////////////////////////// + void detachProcess( ULONG processId ) { PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );