From 8b43407e91aedc68ea2421cad2e4828030aa83ed Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 27 Dec 2010 08:02:19 +0000 Subject: [PATCH] [+] added : eval routine for evaluation windbg expression git-svn-id: https://pykd.svn.codeplex.com/svn@59202 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgcmd.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ pykd/dbgcmd.h | 5 +++++ pykd/dbgext.cpp | 3 ++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/pykd/dbgcmd.cpp b/pykd/dbgcmd.cpp index 7024283..3779089 100644 --- a/pykd/dbgcmd.cpp +++ b/pykd/dbgcmd.cpp @@ -4,6 +4,7 @@ #include "dbgcmd.h" #include "dbgexcept.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; +} + +/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgcmd.h b/pykd/dbgcmd.h index a245d21..de93b82 100644 --- a/pykd/dbgcmd.h +++ b/pykd/dbgcmd.h @@ -99,3 +99,8 @@ private: }; ///////////////////////////////////////////////////////////////////////////////// + +ULONG64 +evaluate( const std::string &expression ); + +///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 9dd4271..648bf7b 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -87,7 +87,8 @@ BOOST_PYTHON_MODULE( pykd ) { boost::python::def( "go", &setExecutionStatus ); boost::python::def( "trace", &setExecutionStatus ); - boost::python::def( "step", &setExecutionStatus ); + boost::python::def( "step", &setExecutionStatus ); + boost::python::def( "eval", &evaluate ); boost::python::def( "createSession", &dbgCreateSession ); boost::python::def( "isSessionStart", &dbgIsSessionStart ); boost::python::def( "symbolsPath", &dbgSymPath );