diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index 5008493..642896b 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -24,7 +24,7 @@ void debugStep(); void debugStepIn(); void debugBreak(); std::string debugCommand( const std::wstring &command ); -ULONG64 evaluate( const std::wstring &expression ); +BaseTypeVariant evaluate( const std::wstring &expression, bool cplusplus = false ); // debug output void dprint( const std::wstring &str, bool dml = false ); diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 3588998..11a2d62 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -1,7 +1,7 @@ +#include /////////////////////////////////////////////////////////////////////////////// @@ -71,4 +72,12 @@ std::string printSystemVersion(SystemVersionPtr sysVer) /////////////////////////////////////////////////////////////////////////////// +std::string evaluate( const std::wstring &expression, bool cplusplus ) +{ + BaseTypeVariant var = pykd::evaluate( expression, cplusplus ); + + return boost::apply_visitor( pykd::VariantToStr(), var ); +} + +/////////////////////////////////////////////////////////////////////////////// } } //pykd::support namespace end \ No newline at end of file diff --git a/pykd/python/pysupport.h b/pykd/python/pysupport.h index b68d6b8..96aa834 100644 --- a/pykd/python/pysupport.h +++ b/pykd/python/pysupport.h @@ -20,6 +20,8 @@ python::tuple moduleFindSymbolAndDisp( pykd::Module &module, ULONG64 offset ); std::string printSystemVersion(SystemVersionPtr sysVer); +std::string evaluate( const std::wstring &expression, bool cplusplus = false ); + } } //pykd::support namespace end /////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp index b9b57d8..e5f2d0c 100644 --- a/pykd/win/dbgeng.cpp +++ b/pykd/win/dbgeng.cpp @@ -198,7 +198,7 @@ void debugBreak() /////////////////////////////////////////////////////////////////////////////// -ULONG64 evaluate( const std::wstring &expression ) +BaseTypeVariant evaluate( const std::wstring &expression, bool cplusplus ) { PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); @@ -207,41 +207,60 @@ ULONG64 evaluate( const std::wstring &expression ) DEBUG_VALUE debugValue = {}; ULONG remainderIndex = 0; - - hres = g_dbgEng->control->IsPointer64Bit(); - if ( FAILED( hres ) ) - throw DbgException( "IDebugControl::IsPointer64Bit failed" ); + ULONG expresionSyntax; - if ( hres == S_OK ) + hres = g_dbgEng->control->GetExpressionSyntax( &expresionSyntax ); + if ( FAILED(hres) ) { - 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; + throw DbgException( "IDebugControl3::GetExpressionSyntax failed" ); } - return value; + hres = g_dbgEng->control->SetExpressionSyntax( cplusplus ? DEBUG_EXPR_CPLUSPLUS : DEBUG_EXPR_MASM ); + if ( FAILED(hres) ) + { + throw DbgException( "IDebugControl3::GetExpressionSyntax failed" ); + } + + hres = g_dbgEng->control->EvaluateWide( + expression.c_str(), + DEBUG_VALUE_INVALID, + &debugValue, + &remainderIndex ); + + if ( FAILED( hres ) ) + { + g_dbgEng->control->SetExpressionSyntax( expresionSyntax ); + throw DbgException( "IDebugControl::Evaluate failed" ); + } + + BaseTypeVariant var; + + switch( debugValue.Type ) + { + case DEBUG_VALUE_INT8: + var = BaseTypeVariant( (LONG)debugValue.I8 ); + break; + + case DEBUG_VALUE_INT16: + var = BaseTypeVariant( (LONG)debugValue.I16 ); + break; + + case DEBUG_VALUE_INT32: + var = BaseTypeVariant( debugValue.I32 ); + break; + + case DEBUG_VALUE_INT64: + var = BaseTypeVariant( debugValue.I64 ); + break; + + default: + g_dbgEng->control->SetExpressionSyntax( expresionSyntax ); + throw DbgException("unsupported type"); + } + + g_dbgEng->control->SetExpressionSyntax( expresionSyntax ); + + return var; } ///////////////////////////////////////////////////////////////////////////////