[0.2.x] added : attachProcess routine

git-svn-id: https://pykd.svn.codeplex.com/svn@80240 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-10-16 05:57:48 +00:00 committed by Mikhail I. Izmestev
parent 080b705c5a
commit b8a6996906
3 changed files with 37 additions and 0 deletions

View File

@ -7,6 +7,7 @@ namespace pykd {
// manage debug target
ULONG startProcess( const std::wstring &processName );
ULONG attachProcess( ULONG pid );
void detachProcess( ULONG processId = -1);
void terminateProcess( ULONG processId = -1);

View File

@ -70,6 +70,8 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "startProcess", &startProcess,
"Start process for debugging");
python::def( "attachProcess", &attachProcess,
"Attach debugger to a exsisting process" );
python::def( "detachProcess", &detachProcess,
"Stop process debugging");
python::def( "killProcess", &terminateProcess,

View File

@ -51,6 +51,40 @@ ULONG startProcess( const std::wstring &processName )
///////////////////////////////////////////////////////////////////////////////////
ULONG attachProcess( ULONG pid )
{
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
HRESULT hres;
ULONG opt;
hres = g_dbgEng->control->GetEngineOptions( &opt );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetEngineOptions failed" );
opt |= DEBUG_ENGOPT_INITIAL_BREAK;
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" );
hres = g_dbgEng->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::WaitForEvent failed" );
ULONG processId = -1;
hres = g_dbgEng->system->GetCurrentProcessId( &processId );
if ( FAILED( hres ) )
throw DbgException( "IDebugSystemObjects::GetCurrentProcessId failed" );
return processId;
}
///////////////////////////////////////////////////////////////////////////////////
void detachProcess( ULONG processId )
{
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );