diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index b0154d0..498f1cb 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -62,6 +62,8 @@ public: void attachKernel( const std::wstring ¶m ); + ULONG64 evaluate( const std::wstring &expression ); + Module loadModule( const std::string &moduleName ) { return Module( m_client, moduleName ); } diff --git a/pykd/dbgcmd.cpp b/pykd/dbgcmd.cpp index a0bd083..ceecc02 100644 --- a/pykd/dbgcmd.cpp +++ b/pykd/dbgcmd.cpp @@ -79,6 +79,59 @@ loadExtension( const std::wstring &extPath ) ///////////////////////////////////////////////////////////////////////////////// +ULONG64 +DebugClient::evaluate( const std::wstring &expression ) +{ + HRESULT hres; + ULONG64 value = 0; + + DEBUG_VALUE debugValue = {}; + ULONG remainderIndex = 0; + + hres = m_control->IsPointer64Bit(); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::IsPointer64Bit failed" ); + + if ( hres == S_OK ) + { + hres = m_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 = m_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 +evaluate( const std::wstring &expression ) +{ + return g_dbgClient->evaluate( expression ); +} + +///////////////////////////////////////////////////////////////////////////////// + } // end namespace pykd diff --git a/pykd/dbgcmd.h b/pykd/dbgcmd.h index 00fe161..c2af84d 100644 --- a/pykd/dbgcmd.h +++ b/pykd/dbgcmd.h @@ -11,6 +11,9 @@ namespace pykd { std::string dbgCommand( const std::wstring &command ); +ULONG64 +evaluate( const std::wstring &expression ); + /////////////////////////////////////////////////////////////////////////////////// class DbgExtension : private DbgObject { diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index a1e27d1..313ff46 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -65,6 +65,8 @@ BOOST_PYTHON_MODULE( pykd ) "Attach debugger to a exsisting process" ) .def( "attachKernel", &pykd::DebugClient::attachKernel, "Attach debugger to a target's kernel" ) + .def( "expr", &pykd::DebugClient::evaluate, + "Evaluate windbg expression" ) .def ( "loadExt", &pykd::DebugClient::loadExtension, "Load a debuger extension" ) .def( "loadModule", &pykd::DebugClient::loadModule, @@ -88,6 +90,8 @@ BOOST_PYTHON_MODULE( pykd ) "Attach debugger to a exsisting process" ); python::def( "attachKernel", &pykd::attachKernel, "Attach debugger to a kernel target" ); + python::def( "expr", &pykd::evaluate, + "Evaluate windbg expression" ); python::def( "loadExt", &pykd::loadExtension, "Load a debuger extension" ); python::def( "loadModule", &pykd::loadModule, diff --git a/test/scripts/dbgcmd.py b/test/scripts/dbgcmd.py index d68c81e..a425db4 100644 --- a/test/scripts/dbgcmd.py +++ b/test/scripts/dbgcmd.py @@ -11,3 +11,7 @@ class DbgcmdTest( unittest.TestCase ): # def testDbgExt( self ): # #ext = pykd.loadExt( "ext" ) # #self.assertNotEqual( "", ext.call("help", "") ) + + def testExpr( self ): + self.assertEqual( 8, pykd.expr( "poi(targetapp!g_ulonglongValue)" ) ) + diff --git a/test/scripts/target.py b/test/scripts/target.py index 9b4193c..8d64d02 100644 --- a/test/scripts/target.py +++ b/test/scripts/target.py @@ -2,6 +2,6 @@ # # - module = None -moduleName = None \ No newline at end of file +moduleName = None +dbgext = None \ No newline at end of file