[+] added : eval routine for evaluation windbg expression

git-svn-id: https://pykd.svn.codeplex.com/svn@59202 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2010-12-27 08:02:19 +00:00
parent db10c69deb
commit 8b43407e91
3 changed files with 62 additions and 1 deletions

View File

@ -4,6 +4,7 @@
#include "dbgcmd.h" #include "dbgcmd.h"
#include "dbgexcept.h" #include "dbgexcept.h"
#include "dbgcallback.h" #include "dbgcallback.h"
#include "dbgsystem.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -168,3 +169,57 @@ dbgBreakpointClass::remove()
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
ULONG64
evaluate( const std::string &expression )
{
HRESULT hres;
ULONG64 value = 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;
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -99,3 +99,8 @@ private:
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
ULONG64
evaluate( const std::string &expression );
/////////////////////////////////////////////////////////////////////////////////

View File

@ -87,7 +87,8 @@ BOOST_PYTHON_MODULE( pykd )
{ {
boost::python::def( "go", &setExecutionStatus<DEBUG_STATUS_GO> ); boost::python::def( "go", &setExecutionStatus<DEBUG_STATUS_GO> );
boost::python::def( "trace", &setExecutionStatus<DEBUG_STATUS_STEP_INTO> ); boost::python::def( "trace", &setExecutionStatus<DEBUG_STATUS_STEP_INTO> );
boost::python::def( "step", &setExecutionStatus<DEBUG_STATUS_STEP_OVER> ); boost::python::def( "step", &setExecutionStatus<DEBUG_STATUS_STEP_OVER> );
boost::python::def( "eval", &evaluate );
boost::python::def( "createSession", &dbgCreateSession ); boost::python::def( "createSession", &dbgCreateSession );
boost::python::def( "isSessionStart", &dbgIsSessionStart ); boost::python::def( "isSessionStart", &dbgIsSessionStart );
boost::python::def( "symbolsPath", &dbgSymPath ); boost::python::def( "symbolsPath", &dbgSymPath );