[0.2.x] added : expr support cplusplus syntax

git-svn-id: https://pykd.svn.codeplex.com/svn@85176 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2013-09-11 16:21:50 +00:00 committed by Mikhail I. Izmestev
parent 17e82d1ee1
commit 1f45804a5b
6 changed files with 71 additions and 40 deletions

View File

@ -24,7 +24,7 @@ void debugStep();
void debugStepIn(); void debugStepIn();
void debugBreak(); void debugBreak();
std::string debugCommand( const std::wstring &command ); std::string debugCommand( const std::wstring &command );
ULONG64 evaluate( const std::wstring &expression ); BaseTypeVariant evaluate( const std::wstring &expression, bool cplusplus = false );
// debug output // debug output
void dprint( const std::wstring &str, bool dml = false ); void dprint( const std::wstring &str, bool dml = false );

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1251"?> <?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="pykd" Name="pykd"
ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}" ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}"
RootNamespace="pykd" RootNamespace="pykd"
@ -71,7 +71,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib" AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib comsuppw.lib"
OutputFile="$(OutDir)\$(ProjectName).pyd" OutputFile="$(OutDir)\$(ProjectName).pyd"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib&quot;;&quot;$(DBG_SDK_ROOT)\lib\i386&quot;;&quot;$(PYTHON_ROOT)\x86\libs&quot;;&quot;$(BOOST_ROOT)\stage\lib&quot;" AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib&quot;;&quot;$(DBG_SDK_ROOT)\lib\i386&quot;;&quot;$(PYTHON_ROOT)\x86\libs&quot;;&quot;$(BOOST_ROOT)\stage\lib&quot;"
@ -153,7 +153,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib" AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib comsuppw.lib"
OutputFile="$(OutDir)\$(ProjectName).pyd" OutputFile="$(OutDir)\$(ProjectName).pyd"
LinkIncremental="2" LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib\amd64&quot;;&quot;$(DBG_SDK_ROOT)\lib\amd64&quot;;&quot;$(PYTHON_ROOT)\x64\libs&quot;;&quot;$(BOOST_ROOT)\stage64\lib&quot;" AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib\amd64&quot;;&quot;$(DBG_SDK_ROOT)\lib\amd64&quot;;&quot;$(PYTHON_ROOT)\x64\libs&quot;;&quot;$(BOOST_ROOT)\stage64\lib&quot;"
@ -230,7 +230,7 @@
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalOptions="/pdbpath:none" AdditionalOptions="/pdbpath:none"
AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib" AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib comsuppw.lib"
OutputFile="$(OutDir)\$(ProjectName).pyd" OutputFile="$(OutDir)\$(ProjectName).pyd"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib&quot;;&quot;$(DBG_SDK_ROOT)\lib\i386&quot;;&quot;$(PYTHON_ROOT)\x86\libs&quot;;&quot;$(BOOST_ROOT)\stage\lib&quot;" AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib&quot;;&quot;$(DBG_SDK_ROOT)\lib\i386&quot;;&quot;$(PYTHON_ROOT)\x86\libs&quot;;&quot;$(BOOST_ROOT)\stage\lib&quot;"
@ -310,7 +310,7 @@
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalOptions="/pdbpath:none" AdditionalOptions="/pdbpath:none"
AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib" AdditionalDependencies="dbgeng.lib diaguids.lib psapi.lib comsuppw.lib"
OutputFile="$(OutDir)\$(ProjectName).pyd" OutputFile="$(OutDir)\$(ProjectName).pyd"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib\amd64&quot;;&quot;$(DBG_SDK_ROOT)\lib\amd64&quot;;&quot;$(PYTHON_ROOT)\x64\libs&quot;;&quot;$(BOOST_ROOT)\stage64\lib&quot;" AdditionalLibraryDirectories="&quot;$(DIA_SDK_ROOT)\lib\amd64&quot;;&quot;$(DBG_SDK_ROOT)\lib\amd64&quot;;&quot;$(PYTHON_ROOT)\x64\libs&quot;;&quot;$(BOOST_ROOT)\stage64\lib&quot;"

View File

@ -41,6 +41,7 @@ static const std::string pykdVersion = PYKD_VERSION_BUILD_STR
BOOST_PYTHON_FUNCTION_OVERLOADS( attachKernel_, attachKernel, 0, 1 ); BOOST_PYTHON_FUNCTION_OVERLOADS( attachKernel_, attachKernel, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_, detachProcess, 0, 1 ); BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_, detachProcess, 0, 1 );
BOOST_PYTHON_FUNCTION_OVERLOADS( evaluate_, pykd::pysupport::evaluate, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, dprintln, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, dprintln, 1, 2 );
@ -115,8 +116,8 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "breakin", &debugBreak, python::def( "breakin", &debugBreak,
"Break into debugger" ); "Break into debugger" );
python::def( "expr", &evaluate, python::def( "expr", &pykd::pysupport::evaluate, evaluate_( boost::python::args( "expression", "cplusplus" ),
"Evaluate windbg expression" ); "Evaluate windbg expression" ) );
python::def( "dbgCommand", &debugCommand, python::def( "dbgCommand", &debugCommand,
"Run a debugger's command and return it's result as a string" ); "Run a debugger's command and return it's result as a string" );
python::def( "go", &debugGo, python::def( "go", &debugGo,

View File

@ -4,6 +4,7 @@
#include "dbgengine.h" #include "dbgengine.h"
#include "typeinfo.h" #include "typeinfo.h"
#include <vector> #include <vector>
#include <variant.h>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -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 } } //pykd::support namespace end

View File

@ -20,6 +20,8 @@ python::tuple moduleFindSymbolAndDisp( pykd::Module &module, ULONG64 offset );
std::string printSystemVersion(SystemVersionPtr sysVer); std::string printSystemVersion(SystemVersionPtr sysVer);
std::string evaluate( const std::wstring &expression, bool cplusplus = false );
} } //pykd::support namespace end } } //pykd::support namespace end
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -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 ); PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
@ -207,41 +207,60 @@ ULONG64 evaluate( const std::wstring &expression )
DEBUG_VALUE debugValue = {}; DEBUG_VALUE debugValue = {};
ULONG remainderIndex = 0; ULONG remainderIndex = 0;
ULONG expresionSyntax;
hres = g_dbgEng->control->GetExpressionSyntax( &expresionSyntax );
if ( FAILED(hres) )
{
throw DbgException( "IDebugControl3::GetExpressionSyntax failed" );
}
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 );
hres = g_dbgEng->control->IsPointer64Bit();
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException( "IDebugControl::IsPointer64Bit failed" );
if ( hres == S_OK )
{ {
hres = g_dbgEng->control->EvaluateWide( g_dbgEng->control->SetExpressionSyntax( expresionSyntax );
expression.c_str(), throw DbgException( "IDebugControl::Evaluate failed" );
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; 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;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////