[0.2.x] + attachKernel, isLocalKernelDebuggerEnabled

git-svn-id: https://pykd.svn.codeplex.com/svn@85044 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2013-09-02 15:11:32 +00:00 committed by Mikhail I. Izmestev
parent 772dd6cac7
commit 116e45c989
3 changed files with 37 additions and 1 deletions

View File

@ -8,6 +8,8 @@ namespace pykd {
// manage debug target // manage debug target
ULONG startProcess( const std::wstring &processName ); ULONG startProcess( const std::wstring &processName );
ULONG attachProcess( ULONG pid ); ULONG attachProcess( ULONG pid );
void attachKernel( const std::string &connectOptions = "" );
bool isLocalKernelDebuggerEnabled();
void detachProcess( ULONG processId = -1); void detachProcess( ULONG processId = -1);
void terminateProcess( ULONG processId = -1); void terminateProcess( ULONG processId = -1);

View File

@ -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( detachProcess_, detachProcess, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 );
@ -92,6 +93,11 @@ BOOST_PYTHON_MODULE( pykd )
"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( "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" ), python::def( "detachProcess", &detachProcess, detachProcess_( boost::python::args( "pid" ),
"Stop process debugging") ); "Stop process debugging") );
python::def( "killProcess", &terminateProcess, python::def( "killProcess", &terminateProcess,

View File

@ -65,7 +65,7 @@ ULONG attachProcess( ULONG pid )
hres = g_dbgEng->control->SetEngineOptions( opt ); hres = g_dbgEng->control->SetEngineOptions( opt );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetEngineOptions failed" ); throw DbgException( "IDebugControl::SetEngineOptions failed" );
hres = g_dbgEng->client->AttachProcess( 0, pid, 0 ); hres = g_dbgEng->client->AttachProcess( 0, pid, 0 );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException( "IDebugClient::AttachProcess failed" ); 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 ) void detachProcess( ULONG processId )
{ {
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );