From 3c2903218bb762a96a0eb2a0250970864e17a0c8 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 15 Aug 2011 15:24:37 +0000 Subject: [PATCH] [pykd] added : routine breakin ( Break into debugger ) git-svn-id: https://pykd.svn.codeplex.com/svn@69014 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgcmd.cpp | 177 +++++++++++++++++------------------------------- pykd/dbgcmd.h | 63 +++++++---------- pykd/dbgext.cpp | 2 + 3 files changed, 92 insertions(+), 150 deletions(-) diff --git a/pykd/dbgcmd.cpp b/pykd/dbgcmd.cpp index 2d480b1..cc89d3b 100644 --- a/pykd/dbgcmd.cpp +++ b/pykd/dbgcmd.cpp @@ -15,26 +15,13 @@ dbgCommand( const std::string &command ) { HRESULT hres; - try { - - OutputReader outReader( dbgExt->client ); + OutputReader outReader( dbgExt->client ); - hres = dbgExt->control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::Execute failed" ); + hres = dbgExt->control->Execute( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::Execute failed" ); - return std::string( outReader.Line() ); - } - catch( std::exception &e ) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); - } - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); - } - - return "error"; + return std::string( outReader.Line() ); } /////////////////////////////////////////////////////////////////////////////// @@ -43,21 +30,9 @@ dbgExtensionClass::dbgExtensionClass( const char* path ) : m_path(path) { HRESULT hres; - try { - - hres = dbgExt->control->AddExtension( path, 0, &m_handle ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::AddExtension failed" ); - - } - catch( std::exception &e ) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); - } - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); - } + hres = dbgExt->control->AddExtension( path, 0, &m_handle ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::AddExtension failed" ); } /////////////////////////////////////////////////////////////////////////////// @@ -75,26 +50,13 @@ dbgExtensionClass::call( const std::string &command, const std::string params ) { HRESULT hres; - try { - - OutputReader outReader( dbgExt->client ); - - hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::CallExtension failed" ); - - return std::string( outReader.Line() ); - } - catch( std::exception &e ) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); - } - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); - } - - return "error"; + OutputReader outReader( dbgExt->client ); + + hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::CallExtension failed" ); + + return std::string( outReader.Line() ); } /////////////////////////////////////////////////////////////////////////////// @@ -102,22 +64,7 @@ dbgExtensionClass::call( const std::string &command, const std::string params ) std::string dbgExtensionClass::print() const { - HRESULT status = S_OK; - - try - { - return m_handle ? m_path : ""; - } - catch (std::exception & e) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); - } - catch (...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); - } - - return ""; + return m_handle ? m_path : ""; } /////////////////////////////////////////////////////////////////////////////// @@ -127,52 +74,56 @@ evaluate( const std::string &expression ) { HRESULT hres; ULONG64 value = 0; + + DEBUG_VALUE debugValue = {}; + ULONG remainderIndex = 0; - try { - - DEBUG_VALUE debugValue = {}; - ULONG remainderIndex = 0; - - if ( is64bitSystem() ) - { - hres = dbgExt->control->Evaluate( - expression.c_str(), - DEBUG_VALUE_INT64, - &debugValue, - &remainderIndex ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::Evaluate failed" ); - - if ( remainderIndex == expression.length() ) - value = debugValue.I64; - } - else - { - hres = dbgExt->control->Evaluate( - expression.c_str(), - DEBUG_VALUE_INT32, - &debugValue, - &remainderIndex ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::Evaluate failed" ); - - if ( remainderIndex == expression.length() ) - value = debugValue.I32; - } - } - catch( std::exception &e ) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); - } - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); - } - - return value; + if ( is64bitSystem() ) + { + hres = dbgExt->control->Evaluate( + expression.c_str(), + DEBUG_VALUE_INT64, + &debugValue, + &remainderIndex ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::Evaluate failed" ); + + if ( remainderIndex == expression.length() ) + value = debugValue.I64; + } + else + { + hres = dbgExt->control->Evaluate( + expression.c_str(), + DEBUG_VALUE_INT32, + &debugValue, + &remainderIndex ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::Evaluate failed" ); + + if ( remainderIndex == expression.length() ) + value = debugValue.I32; + } + + return value; } /////////////////////////////////////////////////////////////////////////////// +void +breakin() +{ + HRESULT hres; + + { + PyThread_StateRestore state; + hres = dbgExt->control->SetInterrupt( DEBUG_INTERRUPT_ACTIVE ); + } + + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::SetInterrupt" ); +} + +/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgcmd.h b/pykd/dbgcmd.h index 5453b31..b9d8594 100644 --- a/pykd/dbgcmd.h +++ b/pykd/dbgcmd.h @@ -10,53 +10,37 @@ std::string dbgCommand( const std::string &command ); template -bool +void setExecutionStatus() { HRESULT hres; - - try { - - hres = dbgExt->control->SetExecutionStatus( status ); + + hres = dbgExt->control->SetExecutionStatus( status ); - if ( FAILED( hres ) ) - return false; + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::SetExecutionStatus failed" ); - ULONG currentStatus; + ULONG currentStatus; - do { + do { - { - PyThread_StateRestore state; - - hres = dbgExt->control->WaitForEvent( 0, INFINITE ); + { + PyThread_StateRestore state; - } + hres = dbgExt->control->WaitForEvent( 0, INFINITE ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::SetExecutionStatus failed" ); - - hres = dbgExt->control->GetExecutionStatus( ¤tStatus ); - - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::GetExecutionStatus failed" ); - - - } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE ); - - return true; + } + + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::WaitForEvent failed" ); + + hres = dbgExt->control->GetExecutionStatus( ¤tStatus ); - } - catch( std::exception &e ) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); - } - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); - } - - return false; + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetExecutionStatus failed" ); + + } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE ); + } ///////////////////////////////////////////////////////////////////////////////// @@ -91,4 +75,9 @@ private: ULONG64 evaluate( const std::string &expression ); +///////////////////////////////////////////////////////////////////////////////// + +void +breakin(); + ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 3e40938..03a540f 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -75,6 +75,8 @@ BOOST_PYTHON_MODULE( pykd ) "Change debugger status to DEBUG_STATUS_STEP_INTO" ); boost::python::def( "step", &setExecutionStatus, "Change debugger status to DEBUG_STATUS_STEP_OVER" ); + boost::python::def( "breakin", &breakin, + "Break into debugger" ); boost::python::def( "expr", &evaluate, "Evaluate windbg expression" ); boost::python::def( "isWindbgExt", &isWindbgExt,