mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-19 19:13:22 +08:00
[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:
parent
080b705c5a
commit
b8a6996906
@ -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);
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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 );
|
||||
|
Loading…
Reference in New Issue
Block a user