[pykd] added : routine breakin ( Break into debugger )

git-svn-id: https://pykd.svn.codeplex.com/svn@69014 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-08-15 15:24:37 +00:00
parent 9e5fe5cab5
commit 3c2903218b
3 changed files with 92 additions and 150 deletions

View File

@ -15,26 +15,13 @@ dbgCommand( const std::string &command )
{ {
HRESULT hres; 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 ); return std::string( outReader.Line() );
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";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -43,21 +30,9 @@ dbgExtensionClass::dbgExtensionClass( const char* path ) : m_path(path)
{ {
HRESULT hres; HRESULT hres;
try { hres = dbgExt->control->AddExtension( path, 0, &m_handle );
if ( FAILED( hres ) )
hres = dbgExt->control->AddExtension( path, 0, &m_handle ); throw DbgException( "IDebugControl::AddExtension failed" );
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" );
}
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -75,26 +50,13 @@ dbgExtensionClass::call( const std::string &command, const std::string params )
{ {
HRESULT hres; HRESULT hres;
try { OutputReader outReader( dbgExt->client );
OutputReader outReader( dbgExt->client ); hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::CallExtension failed" );
hres = dbgExt->control->CallExtension( m_handle, command.c_str(), params.c_str() ); return std::string( outReader.Line() );
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";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -102,22 +64,7 @@ dbgExtensionClass::call( const std::string &command, const std::string params )
std::string std::string
dbgExtensionClass::print() const dbgExtensionClass::print() const
{ {
HRESULT status = S_OK; return m_handle ? m_path : "";
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 "";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -128,51 +75,55 @@ evaluate( const std::string &expression )
HRESULT hres; HRESULT hres;
ULONG64 value = 0; ULONG64 value = 0;
try { DEBUG_VALUE debugValue = {};
ULONG remainderIndex = 0;
DEBUG_VALUE debugValue = {}; if ( is64bitSystem() )
ULONG remainderIndex = 0; {
hres = dbgExt->control->Evaluate(
expression.c_str(),
DEBUG_VALUE_INT64,
&debugValue,
&remainderIndex );
if ( is64bitSystem() ) if ( FAILED( hres ) )
{ throw DbgException( "IDebugControl::Evaluate failed" );
hres = dbgExt->control->Evaluate(
expression.c_str(),
DEBUG_VALUE_INT64,
&debugValue,
&remainderIndex );
if ( FAILED( hres ) ) if ( remainderIndex == expression.length() )
throw DbgException( "IDebugControl::Evaluate failed" ); value = debugValue.I64;
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 ) else
{ {
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); hres = dbgExt->control->Evaluate(
} expression.c_str(),
catch(...) DEBUG_VALUE_INT32,
{ &debugValue,
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); &remainderIndex );
}
return value; 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" );
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -10,53 +10,37 @@ std::string
dbgCommand( const std::string &command ); dbgCommand( const std::string &command );
template <ULONG status> template <ULONG status>
bool void
setExecutionStatus() setExecutionStatus()
{ {
HRESULT hres; HRESULT hres;
try { hres = dbgExt->control->SetExecutionStatus( status );
hres = dbgExt->control->SetExecutionStatus( status ); if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetExecutionStatus failed" );
ULONG currentStatus;
do {
{
PyThread_StateRestore state;
hres = dbgExt->control->WaitForEvent( 0, INFINITE );
}
if ( FAILED( hres ) ) if ( FAILED( hres ) )
return false; throw DbgException( "IDebugControl::WaitForEvent failed" );
ULONG currentStatus; hres = dbgExt->control->GetExecutionStatus( &currentStatus );
do { if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetExecutionStatus failed" );
{ } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
PyThread_StateRestore state;
hres = dbgExt->control->WaitForEvent( 0, INFINITE );
}
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::SetExecutionStatus failed" );
hres = dbgExt->control->GetExecutionStatus( &currentStatus );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetExecutionStatus failed" );
} while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
return true;
}
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;
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -92,3 +76,8 @@ ULONG64
evaluate( const std::string &expression ); evaluate( const std::string &expression );
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
void
breakin();
/////////////////////////////////////////////////////////////////////////////////

View File

@ -75,6 +75,8 @@ BOOST_PYTHON_MODULE( pykd )
"Change debugger status to DEBUG_STATUS_STEP_INTO" ); "Change debugger status to DEBUG_STATUS_STEP_INTO" );
boost::python::def( "step", &setExecutionStatus<DEBUG_STATUS_STEP_OVER>, boost::python::def( "step", &setExecutionStatus<DEBUG_STATUS_STEP_OVER>,
"Change debugger status to DEBUG_STATUS_STEP_OVER" ); "Change debugger status to DEBUG_STATUS_STEP_OVER" );
boost::python::def( "breakin", &breakin,
"Break into debugger" );
boost::python::def( "expr", &evaluate, boost::python::def( "expr", &evaluate,
"Evaluate windbg expression" ); "Evaluate windbg expression" );
boost::python::def( "isWindbgExt", &isWindbgExt, boost::python::def( "isWindbgExt", &isWindbgExt,