mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[+] added : locals() routine; it returns local var for current scope
git-svn-id: https://pykd.svn.codeplex.com/svn@61030 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
8cab8ae27d
commit
e65c2bf418
@ -139,6 +139,7 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
boost::python::def( "ptrSignMWord", &loadSignMWord );
|
boost::python::def( "ptrSignMWord", &loadSignMWord );
|
||||||
boost::python::def( "compareMemory", &compareMemory, compareMemoryOver( boost::python::args( "addr1", "addr2", "length", "phyAddr" ), "" ) );
|
boost::python::def( "compareMemory", &compareMemory, compareMemoryOver( boost::python::args( "addr1", "addr2", "length", "phyAddr" ), "" ) );
|
||||||
boost::python::def( "getCurrentStack", &getCurrentStack );
|
boost::python::def( "getCurrentStack", &getCurrentStack );
|
||||||
|
boost::python::def( "locals", &getLocals );
|
||||||
boost::python::def( "reloadModule", &reloadModule );
|
boost::python::def( "reloadModule", &reloadModule );
|
||||||
boost::python::def( "getPdbFile", &getPdbFile );
|
boost::python::def( "getPdbFile", &getPdbFile );
|
||||||
boost::python::def( "getImplicitThread", &getImplicitThread );
|
boost::python::def( "getImplicitThread", &getImplicitThread );
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "dbgprocess.h"
|
#include "dbgprocess.h"
|
||||||
#include "dbgext.h"
|
#include "dbgext.h"
|
||||||
#include "dbgexcept.h"
|
#include "dbgexcept.h"
|
||||||
|
#include "dbgtype.h"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -133,9 +134,14 @@ getCurrentStack()
|
|||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
PDEBUG_STACK_FRAME frames = NULL;
|
PDEBUG_STACK_FRAME frames = NULL;
|
||||||
|
ULONG currentScope = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
hres = dbgExt->symbols3->GetCurrentScopeFrameIndex( ¤tScope );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbol3::GetCurrentScopeFrameIndex failed" );
|
||||||
|
|
||||||
frames = new DEBUG_STACK_FRAME [ 1000 ];
|
frames = new DEBUG_STACK_FRAME [ 1000 ];
|
||||||
|
|
||||||
ULONG filledFrames;
|
ULONG filledFrames;
|
||||||
@ -147,12 +153,22 @@ getCurrentStack()
|
|||||||
|
|
||||||
for ( ULONG i = 0; i < filledFrames; ++i )
|
for ( ULONG i = 0; i < filledFrames; ++i )
|
||||||
{
|
{
|
||||||
frameList.append( boost::python::object( dbgStackFrameClass( frames[i] ) ) );
|
dbgStackFrameClass frame( frames[i] );
|
||||||
|
|
||||||
|
boost::python::object frameObj( frame );
|
||||||
|
|
||||||
|
hres = dbgExt->symbols->SetScope( NULL, &frames[i], NULL, sizeof(DEBUG_STACK_FRAME) );
|
||||||
|
if ( SUCCEEDED( hres ) )
|
||||||
|
frameObj.attr( "locals" ) = getLocals();
|
||||||
|
|
||||||
|
frameList.append( frameObj );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( frames )
|
if ( frames )
|
||||||
delete[] frames;
|
delete[] frames;
|
||||||
|
|
||||||
|
dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
|
||||||
|
|
||||||
return frameList;
|
return frameList;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -168,6 +184,8 @@ getCurrentStack()
|
|||||||
if ( frames )
|
if ( frames )
|
||||||
delete[] frames;
|
delete[] frames;
|
||||||
|
|
||||||
|
dbgExt->symbols3->SetScopeFrameByIndex( currentScope );
|
||||||
|
|
||||||
return boost::python::object();
|
return boost::python::object();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,3 +322,95 @@ setCurrentProcess(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
dbgStackFrameClass::dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame )
|
||||||
|
{
|
||||||
|
memcpy( static_cast<DEBUG_STACK_FRAME*>( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
boost::python::object
|
||||||
|
getLocals()
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
IDebugSymbolGroup *localSymbols = NULL;
|
||||||
|
IDebugSymbolGroup2 *localSymbols2 = NULL;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
hres = dbgExt->symbols->GetScopeSymbolGroup( DEBUG_SCOPE_GROUP_ARGUMENTS|DEBUG_SCOPE_GROUP_LOCALS, NULL, &localSymbols );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbols::GetScopeSymbolGroup failed" );
|
||||||
|
|
||||||
|
hres = localSymbols->QueryInterface( __uuidof(IDebugSymbolGroup2), (void**) &localSymbols2 );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbols::QueryInterface failed to get IDebugSymbolGroup2" );
|
||||||
|
|
||||||
|
ULONG localNumber;
|
||||||
|
hres = localSymbols->GetNumberSymbols( &localNumber );
|
||||||
|
|
||||||
|
boost::python::dict arr;
|
||||||
|
|
||||||
|
for ( ULONG i = 0; i < localNumber; ++i )
|
||||||
|
{
|
||||||
|
char varName[0x100];
|
||||||
|
|
||||||
|
hres = localSymbols->GetSymbolName( i, varName, sizeof(varName), NULL );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbolGroup::GetSymbolName failed" );
|
||||||
|
|
||||||
|
DEBUG_SYMBOL_PARAMETERS symbolParam = {};
|
||||||
|
hres = localSymbols->GetSymbolParameters( i, 1, &symbolParam );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbolGroup::GetSymbolParameters failed" );
|
||||||
|
|
||||||
|
char typeName[0x100];
|
||||||
|
hres = dbgExt->symbols->GetTypeName( symbolParam.Module, symbolParam.TypeId, typeName, sizeof(typeName), NULL );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbols::GetTypeName failed" );
|
||||||
|
|
||||||
|
char moduleName[0x100];
|
||||||
|
hres = dbgExt->symbols2->GetModuleNameString(
|
||||||
|
DEBUG_MODNAME_MODULE,
|
||||||
|
DEBUG_ANY_ID,
|
||||||
|
symbolParam.Module,
|
||||||
|
moduleName,
|
||||||
|
sizeof(moduleName),
|
||||||
|
NULL );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbols2::GetModuleNameString failed" );
|
||||||
|
|
||||||
|
|
||||||
|
ULONG64 varOffset;
|
||||||
|
hres = localSymbols2->GetSymbolOffset( i, &varOffset );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSymbolGroup2::GetSymbolOffset failed" );
|
||||||
|
|
||||||
|
arr[ varName ] = loadTypedVar( moduleName, typeName, varOffset );
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
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" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( localSymbols )
|
||||||
|
localSymbols->Release();
|
||||||
|
|
||||||
|
if ( localSymbols2 )
|
||||||
|
localSymbols2->Release();
|
||||||
|
|
||||||
|
return boost::python::object();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,6 +19,10 @@ getImplicitThread();
|
|||||||
boost::python::object
|
boost::python::object
|
||||||
getCurrentStack();
|
getCurrentStack();
|
||||||
|
|
||||||
|
boost::python::object
|
||||||
|
getLocals();
|
||||||
|
|
||||||
|
|
||||||
class dbgStackFrameClass : public DEBUG_STACK_FRAME {
|
class dbgStackFrameClass : public DEBUG_STACK_FRAME {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -28,10 +32,7 @@ public:
|
|||||||
memset( static_cast<DEBUG_STACK_FRAME*>( this ), 0, sizeof(DEBUG_STACK_FRAME) );
|
memset( static_cast<DEBUG_STACK_FRAME*>( this ), 0, sizeof(DEBUG_STACK_FRAME) );
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame )
|
dbgStackFrameClass( const DEBUG_STACK_FRAME &stackFrame );
|
||||||
{
|
|
||||||
memcpy( static_cast<DEBUG_STACK_FRAME*>( this ), &stackFrame, sizeof(DEBUG_STACK_FRAME) );
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
boost::python::object
|
boost::python::object
|
||||||
|
Loading…
Reference in New Issue
Block a user