[0.2.x] added : eval routine

git-svn-id: https://pykd.svn.codeplex.com/svn@78887 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-08-16 15:41:49 +00:00 committed by Mikhail I. Izmestev
parent 048becd504
commit be7d58a4e8
3 changed files with 53 additions and 2 deletions

View File

@ -17,6 +17,7 @@ bool isKernelDebugging();
void debugGo(); void debugGo();
void debugBreak(); void debugBreak();
ULONG64 evaluate( const std::wstring &expression );
// debug output // debug output
void dprint( const std::wstring &str, bool dml = false ); void dprint( const std::wstring &str, bool dml = false );

View File

@ -73,6 +73,8 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "breakin", &debugBreak, python::def( "breakin", &debugBreak,
"Break into debugger" ); "Break into debugger" );
python::def( "expr", &evaluate,
"Evaluate windbg expression" );
python::def( "go", &debugGo, python::def( "go", &debugGo,
"Go debugging" ); "Go debugging" );

View File

@ -168,7 +168,7 @@ void debugGo()
} while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE ); } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
} }
///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void debugBreak() void debugBreak()
{ {
@ -184,7 +184,55 @@ void debugBreak()
throw DbgException( "IDebugControl::SetInterrupt" ); throw DbgException( "IDebugControl::SetInterrupt" );
} }
///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
ULONG64 evaluate( const std::wstring &expression )
{
PyThreadState *pystate = PyEval_SaveThread();
HRESULT hres;
ULONG64 value = 0;
DEBUG_VALUE debugValue = {};
ULONG remainderIndex = 0;
hres = g_dbgEng->control->IsPointer64Bit();
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::IsPointer64Bit failed" );
if ( hres == S_OK )
{
hres = g_dbgEng->control->EvaluateWide(
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 = g_dbgEng->control->EvaluateWide(
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;
}
///////////////////////////////////////////////////////////////////////////////
ULONG64 findModuleBase( const std::string &moduleName ) ULONG64 findModuleBase( const std::string &moduleName )
{ {