From 1503c4e7f69b1c1111f2e0b6b15c406f179f7192 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Tue, 27 Mar 2012 15:16:30 +0000 Subject: [PATCH] [0.1.x] ~ python thread state restore for create process and load dump git-svn-id: https://pykd.svn.codeplex.com/svn@75087 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.cpp | 28 ++++++++++++++-------------- pykd/dbgclient.h | 2 ++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pykd/dbgclient.cpp b/pykd/dbgclient.cpp index 17b229d..cca9a98 100644 --- a/pykd/dbgclient.cpp +++ b/pykd/dbgclient.cpp @@ -168,11 +168,10 @@ void DebugClient::loadDump( const std::wstring &fileName ) hres = m_client->OpenDumpFileWide( fileName.c_str(), NULL ); if ( FAILED( hres ) ) throw DbgException( "IDebugClient4::OpenDumpFileWide failed" ); - - hres = m_control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); + + hres = safeWaitForEvent(); if ( FAILED( hres ) ) throw DbgException( "IDebugControl::WaitForEvent failed" ); - } void loadDump( const std::wstring &fileName ) { @@ -184,7 +183,7 @@ void loadDump( const std::wstring &fileName ) { void DebugClient::startProcess( const std::wstring &processName ) { HRESULT hres; - + ULONG opt; hres = m_control->GetEngineOptions( &opt ); if ( FAILED( hres ) ) @@ -202,13 +201,13 @@ void DebugClient::startProcess( const std::wstring &processName ) if ( FAILED( hres ) ) throw DbgException( "IDebugClient4::CreateProcessWide failed" ); - hres = m_control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); + hres = safeWaitForEvent(); if ( FAILED( hres ) ) throw DbgException( "IDebugControl::WaitForEvent failed" ); } void startProcess( const std::wstring &processName ) { - g_dbgClient->startProcess( processName ); + g_dbgClient->startProcess( processName ); } /////////////////////////////////////////////////////////////////////////////////// @@ -366,7 +365,6 @@ void DebugClient::setExecutionStatus( ULONG status ) if ( FAILED( hres ) ) throw DbgException( "IDebugControl::SetExecutionStatus failed" ); - } void setExecutionStatus( ULONG status ) @@ -376,15 +374,17 @@ void setExecutionStatus( ULONG status ) /////////////////////////////////////////////////////////////////////////////////// +HRESULT DebugClient::safeWaitForEvent(ULONG timeout /*= INFINITE*/, ULONG flags /*= DEBUG_WAIT_DEFAULT*/) +{ + PyThread_StateRestore pyThreadRestore( m_pyThreadState ); + return m_control->WaitForEvent( flags, timeout ); +} + +/////////////////////////////////////////////////////////////////////////////////// + void DebugClient::waitForEvent() { - HRESULT hres; - - do { - PyThread_StateRestore pyThreadRestore( m_pyThreadState ); - hres = m_control->WaitForEvent( 0, INFINITE ); - - } while( false ); + HRESULT hres = safeWaitForEvent(); if ( FAILED( hres ) ) { diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index a40647e..ab1316c 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -352,6 +352,8 @@ public: private: + HRESULT safeWaitForEvent(ULONG timeout = INFINITE, ULONG flags = DEBUG_WAIT_DEFAULT); + template python::list loadArray( ULONG64 offset, ULONG count, bool phyAddr );