pykd/pykd/pycpucontext.h
SND\kernelnet_cp f21cda28f2 [0.3.x] added : getLocal and getLocals routines
git-svn-id: https://pykd.svn.codeplex.com/svn@87094 9b283d60-5439-405e-af05-b73fd8c4d996
2017-11-03 14:36:27 +04:00

196 lines
5.3 KiB
C++

#pragma once
#include <boost/python/tuple.hpp>
namespace python = boost::python;
#include "kdlib/dbgengine.h"
#include "kdlib/cpucontext.h"
#include "kdlib/stack.h"
#include "dbgexcept.h"
#include "pythreadstate.h"
namespace pykd {
///////////////////////////////////////////////////////////////////////////////
class StackFrameAdapter {
public:
static kdlib::MEMOFFSET_64 getIP( kdlib::StackFramePtr& frame )
{
AutoRestorePyState pystate;
return frame->getIP();
}
static kdlib::MEMOFFSET_64 getRET( kdlib::StackFramePtr& frame )
{
AutoRestorePyState pystate;
return frame->getRET();
}
static kdlib::MEMOFFSET_64 getFP( kdlib::StackFramePtr& frame )
{
AutoRestorePyState pystate;
return frame->getFP();
}
static kdlib::MEMOFFSET_64 getSP( kdlib::StackFramePtr& frame )
{
AutoRestorePyState pystate;
return frame->getSP();
}
static std::wstring print( kdlib::StackFramePtr& frame );
static python::list getParamsList( kdlib::StackFramePtr& frame);
static python::dict getParamsDict( kdlib::StackFramePtr& frame);
static kdlib::TypedVarPtr getParam( kdlib::StackFramePtr& frame, const std::wstring &paramName )
{
AutoRestorePyState pystate;
return frame->getTypedParam(paramName);
}
static python::list getLocalsList(kdlib::StackFramePtr& frame);
static python::dict getLocalsDict(kdlib::StackFramePtr& frame);
static kdlib::TypedVarPtr getLocal( kdlib::StackFramePtr& frame, const std::wstring &paramName ) {
AutoRestorePyState pystate;
return frame->getLocalVar(paramName);
}
};
///////////////////////////////////////////////////////////////////////////////
inline kdlib::CPUContextPtr loadCPUCurrentContext() {
AutoRestorePyState pystate;
return kdlib::loadCPUCurrentContext();
}
inline kdlib::CPUContextPtr loadCPUContextByIndex( unsigned long index ) {
AutoRestorePyState pystate;
return kdlib::loadCPUContextByIndex(index);
}
inline unsigned long long loadMSR( unsigned long msrIndex )
{
AutoRestorePyState pystate;
return kdlib::loadCPUCurrentContext()->loadMSR( msrIndex );
}
inline void setMSR( unsigned long msrIndex, unsigned long long value )
{
AutoRestorePyState pystate;
return kdlib::loadCPUCurrentContext()->setMSR( msrIndex, value );
}
inline kdlib::CPUType getProcessorMode() {
AutoRestorePyState pystate;
return kdlib::loadCPUCurrentContext()->getCPUMode();
}
inline kdlib::CPUType getProcessorType() {
AutoRestorePyState pystate;
return kdlib::loadCPUCurrentContext()->getCPUType();
}
inline void setProcessorMode( kdlib::CPUType mode ) {
AutoRestorePyState pystate;
kdlib::loadCPUCurrentContext()->setCPUMode(mode);
}
inline void switchProcessorMode() {
AutoRestorePyState pystate;
kdlib::loadCPUCurrentContext()->switchCPUMode();
}
inline kdlib::StackFramePtr getCurrentFrame() {
AutoRestorePyState pystate;
return kdlib::getStack()->getFrame(0);
}
inline python::list getParams() {
return StackFrameAdapter::getParamsList( getCurrentFrame() );
}
inline kdlib::TypedVarPtr getParam( const std::wstring &name ) {
return StackFrameAdapter::getParam( getCurrentFrame(), name );
}
inline python::list getLocals() {
return StackFrameAdapter::getLocalsList( getCurrentFrame() );
}
inline kdlib::TypedVarPtr getLocal( const std::wstring &name ) {
return StackFrameAdapter::getLocal( getCurrentFrame(), name );
}
class CPUContextAdapter
{
public:
static python::object getRegisterByName( kdlib::CPUContextPtr& cpu, const std::wstring &name );
static python::object getRegisterByIndex( kdlib::CPUContextPtr& cpu, unsigned long index );
static python::list getStack( kdlib::CPUContextPtr& cpu );
static kdlib::MEMOFFSET_64 getIP( kdlib::CPUContextPtr& cpu )
{
AutoRestorePyState pystate;
return cpu->getIP();
}
static kdlib::MEMOFFSET_64 getSP( kdlib::CPUContextPtr& cpu )
{
AutoRestorePyState pystate;
return cpu->getSP();
}
static kdlib::MEMOFFSET_64 getFP( kdlib::CPUContextPtr& cpu )
{
AutoRestorePyState pystate;
return cpu->getFP();
}
static kdlib::CPUType getCPUType( kdlib::CPUContextPtr& cpu )
{
AutoRestorePyState pystate;
return cpu->getCPUType();
}
static kdlib::CPUType getCPUMode( kdlib::CPUContextPtr& cpu )
{
AutoRestorePyState pystate;
return cpu->getCPUMode();
}
static void setCPUMode( kdlib::CPUContextPtr& cpu, kdlib::CPUType mode )
{
AutoRestorePyState pystate;
cpu->setCPUMode(mode);
}
static void switchCPUMode( kdlib::CPUContextPtr& cpu )
{
AutoRestorePyState pystate;
cpu->switchCPUMode();
}
};
inline python::object getRegisterByName( const std::wstring &name )
{
return CPUContextAdapter::getRegisterByName( kdlib::loadCPUCurrentContext(), name );
}
inline python::list getCurrentStack() {
return CPUContextAdapter::getStack( kdlib::loadCPUCurrentContext() );
}
///////////////////////////////////////////////////////////////////////////////
} //end namespace pykd