From 679b315aacca25aafdfe4288a3844e76fa3fede0 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 22 Jul 2011 06:55:01 +0000 Subject: [PATCH] [pykd] added: cpuReg class based on intBase [pykd] updated: debugEvent class git-svn-id: https://pykd.svn.codeplex.com/svn@68108 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgevent.cpp | 307 +++++++++++++++++++++++++++++++++----------- pykd/dbgevent.h | 187 +++++++++++++++++++++------ pykd/dbgeventcb.cpp | 128 +++++++++--------- pykd/dbgeventcb.h | 10 +- pykd/dbgext.cpp | 107 ++++++++++++++- pykd/dbgreg.cpp | 46 +++++++ pykd/dbgreg.h | 37 ++++++ pykd/dbgtype.h | 300 ------------------------------------------- pykd/pykd.vcproj | 8 +- 9 files changed, 649 insertions(+), 481 deletions(-) diff --git a/pykd/dbgevent.cpp b/pykd/dbgevent.cpp index c84558c..7794bd4 100644 --- a/pykd/dbgevent.cpp +++ b/pykd/dbgevent.cpp @@ -1,112 +1,265 @@ -///////////////////////////////////////////////////////////////////////////////// -// Load/Unload module events -///////////////////////////////////////////////////////////////////////////////// - +/////////////////////////////////////////////////////////////////////////////////// +//// Load/Unload module events +/////////////////////////////////////////////////////////////////////////////////// +// #include "stdafx.h" -#include -#include - -#include "dbgmodule.h" -#include "dbgio.h" #include "dbgevent.h" +#include "dbgio.h" +#include "dbgexcept.h" -///////////////////////////////////////////////////////////////////////////////// - -debugEvent::modCallbacksColl debugEvent::modCallbacks; -debugEvent::modCallbacksLock debugEvent::modCallbacksMtx; - -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// debugEvent::debugEvent() { - modCallbacksScopedLock lock(modCallbacksMtx); - modCallbacks.insert(this); + HRESULT hres; + + hres = dbgExt->client->CreateClient( &m_debugClient ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::CreateClient" ); + + hres = m_debugClient->SetEventCallbacks(this); + if (FAILED(hres)) + throw DbgException( "IDebugClient::SetEventCallbacks" ); } -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// debugEvent::~debugEvent() { - modCallbacksScopedLock lock(modCallbacksMtx); - modCallbacks.erase(this); + m_debugClient->SetEventCallbacks( NULL ); + + m_debugClient->Release(); } -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// -ULONG debugEvent::moduleLoaded(__in ULONG64 addr) +HRESULT debugEvent::GetInterestMask( + __out PULONG Mask +) { - modCallbacksScopedLock lock(modCallbacksMtx); - if (modCallbacks.empty()) - return DEBUG_STATUS_NO_CHANGE; + *Mask = 0; - ULONG64 moduleBase; - ULONG moduleSize; - std::string moduleName; + *Mask |= DEBUG_EVENT_LOAD_MODULE; + *Mask |= DEBUG_EVENT_UNLOAD_MODULE; + *Mask |= DEBUG_EVENT_SESSION_STATUS; + + return S_OK; +} +/////////////////////////////////////////////////////////////////////////////////// + +HRESULT debugEvent::LoadModule( + __in ULONG64 ImageFileHandle, + __in ULONG64 BaseOffset, + __in ULONG ModuleSize, + __in PCSTR ModuleName, + __in PCSTR ImageName, + __in ULONG CheckSum, + __in ULONG TimeDateStamp +) +{ std::auto_ptr silentMode( new OutputReader(dbgExt->client) ); - queryModuleParams(addr, moduleName, moduleBase, moduleSize); + + ULONG64 moduleBase; + ULONG moduleSize; + std::string moduleName; + + queryModuleParams(BaseOffset, moduleName, moduleBase, moduleSize); dbgModuleClass module(moduleName, moduleBase, moduleSize); - silentMode.reset(); - - modCallbacksColl::iterator itCallback = modCallbacks.begin(); - while (itCallback != modCallbacks.end()) - { - const ULONG retValue = (*itCallback)->onLoadModule(module); - if (DEBUG_STATUS_NO_CHANGE != retValue) - return retValue; - - ++itCallback; - } - return DEBUG_STATUS_NO_CHANGE; + silentMode.reset(); + + return onLoadModule( module ); } -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// -ULONG debugEvent::moduleUnloaded(__in ULONG64 addr) +HRESULT debugEvent::UnloadModule( + __in PCSTR ImageBaseName, + __in ULONG64 BaseOffset +) { - modCallbacksScopedLock lock(modCallbacksMtx); - if (modCallbacks.empty()) - return DEBUG_STATUS_NO_CHANGE; - - ULONG64 moduleBase; - ULONG moduleSize; - std::string moduleName; - std::auto_ptr silentMode( new OutputReader(dbgExt->client) ); - queryModuleParams(addr, moduleName, moduleBase, moduleSize); + + ULONG64 moduleBase; + ULONG moduleSize; + std::string moduleName; + + queryModuleParams(BaseOffset, moduleName, moduleBase, moduleSize); dbgModuleClass module(moduleName, moduleBase, moduleSize); - silentMode.reset(); - - modCallbacksColl::iterator itCallback = modCallbacks.begin(); - while (itCallback != modCallbacks.end()) - { - const ULONG retValue = (*itCallback)->onUnloadModule(module); - if (DEBUG_STATUS_NO_CHANGE != retValue) - return retValue; - - ++itCallback; - } - return DEBUG_STATUS_NO_CHANGE; + silentMode.reset(); + + return onUnloadModule( module ); } -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// -ULONG debugEventWrap::onLoadModule(const dbgModuleClass &module) +HRESULT debugEvent::SessionStatus( + __in ULONG Status +) { - if (boost::python::override override = get_override("onLoadModule")) - return override(module); - - return debugEvent::onLoadModule(module); + return onChangeSessionStatus( Status ); } -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// -ULONG debugEventWrap::onUnloadModule(const dbgModuleClass &module) +HRESULT debugEvent::ChangeDebuggeeState( + __in ULONG Flags, + __in ULONG64 Argument +) { - if (boost::python::override override = get_override("onUnloadModule")) - return override(module); - - return debugEvent::onUnloadModule(module); + return onChangeDebugeeState(); } -///////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////// + + + + + + + +// +// STDMETHOD(GetInterestMask)( +// __out PULONG Mask +// ); +// +// STDMETHOD(LoadModule)( +// __in ULONG64 ImageFileHandle, +// __in ULONG64 BaseOffset, +// __in ULONG ModuleSize, +// __in PCSTR ModuleName, +// __in PCSTR ImageName, +// __in ULONG CheckSum, +// __in ULONG TimeDateStamp +// ); +// +// STDMETHOD(UnloadModule)( +// __in PCSTR ImageBaseName, +// __in ULONG64 BaseOffset +// ); +// +//public: +// +// ULONG onLoadModule(const dbgModuleClass &module); +// +// ULONG onUnloadModule(const dbgModuleClass &module); +// + + + + + +//#include +//#include +// +//#include "dbgmodule.h" +//#include "dbgio.h" +//#include "dbgevent.h" +// +/////////////////////////////////////////////////////////////////////////////////// +// +//debugEvent::modCallbacksColl debugEvent::modCallbacks; +//debugEvent::modCallbacksLock debugEvent::modCallbacksMtx; +// +/////////////////////////////////////////////////////////////////////////////////// +// +//debugEvent::debugEvent() +//{ +// modCallbacksScopedLock lock(modCallbacksMtx); +// modCallbacks.insert(this); +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//debugEvent::~debugEvent() +//{ +// modCallbacksScopedLock lock(modCallbacksMtx); +// modCallbacks.erase(this); +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG debugEvent::moduleLoaded(__in ULONG64 addr) +//{ +// modCallbacksScopedLock lock(modCallbacksMtx); +// if (modCallbacks.empty()) +// return DEBUG_STATUS_NO_CHANGE; +// +// ULONG64 moduleBase; +// ULONG moduleSize; +// std::string moduleName; +// +// std::auto_ptr silentMode( new OutputReader(dbgExt->client) ); +// queryModuleParams(addr, moduleName, moduleBase, moduleSize); +// dbgModuleClass module(moduleName, moduleBase, moduleSize); +// silentMode.reset(); +// +// modCallbacksColl::iterator itCallback = modCallbacks.begin(); +// while (itCallback != modCallbacks.end()) +// { +// const ULONG retValue = (*itCallback)->onLoadModule(module); +// if (DEBUG_STATUS_NO_CHANGE != retValue) +// return retValue; +// +// ++itCallback; +// } +// return DEBUG_STATUS_NO_CHANGE; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG debugEvent::moduleUnloaded(__in ULONG64 addr) +//{ +// modCallbacksScopedLock lock(modCallbacksMtx); +// if (modCallbacks.empty()) +// return DEBUG_STATUS_NO_CHANGE; +// +// ULONG64 moduleBase; +// ULONG moduleSize; +// std::string moduleName; +// +// std::auto_ptr silentMode( new OutputReader(dbgExt->client) ); +// queryModuleParams(addr, moduleName, moduleBase, moduleSize); +// dbgModuleClass module(moduleName, moduleBase, moduleSize); +// silentMode.reset(); +// +// modCallbacksColl::iterator itCallback = modCallbacks.begin(); +// while (itCallback != modCallbacks.end()) +// { +// const ULONG retValue = (*itCallback)->onUnloadModule(module); +// if (DEBUG_STATUS_NO_CHANGE != retValue) +// return retValue; +// +// ++itCallback; +// } +// return DEBUG_STATUS_NO_CHANGE; +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG debugEvent::sessionStatus(__in ULONG status ) +//{ +// +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG debugEventWrap::onLoadModule(const dbgModuleClass &module) +//{ +// if (boost::python::override override = get_override("onLoadModule")) +// return override(module); +// +// return debugEvent::onLoadModule(module); +//} +// +/////////////////////////////////////////////////////////////////////////////////// +// +//ULONG debugEventWrap::onUnloadModule(const dbgModuleClass &module) +//{ +// if (boost::python::override override = get_override("onUnloadModule")) +// return override(module); +// +// return debugEvent::onUnloadModule(module); +//} +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgevent.h b/pykd/dbgevent.h index 67b0fff..7ca1c09 100644 --- a/pykd/dbgevent.h +++ b/pykd/dbgevent.h @@ -1,54 +1,169 @@ ///////////////////////////////////////////////////////////////////////////////// -// Load/Unload module events +// user-customizing debug event handler ///////////////////////////////////////////////////////////////////////////////// -#include +#include "dbgeventcb.h" +#include "dbgmodule.h" -#include -#include +///////////////////////////////////////////////////////////////////////////////// -interface debugEvent +class debugEvent : public DebugBaseEventCallbacks { +public: + debugEvent(); + virtual ~debugEvent(); - virtual ULONG onLoadModule(const dbgModuleClass &/* module */) - { - return DEBUG_STATUS_NO_CHANGE; - } - virtual ULONG onUnloadModule(const dbgModuleClass &/* module */) - { - return DEBUG_STATUS_NO_CHANGE; - } - - // call from debug engine - static ULONG moduleLoaded(__in ULONG64 addr); - static ULONG moduleUnloaded(__in ULONG64 addr); + virtual ULONG onLoadModule(const dbgModuleClass &/* module */) = 0; + virtual ULONG onUnloadModule(const dbgModuleClass &/* module */) = 0; + + virtual ULONG onChangeSessionStatus( ULONG status ) = 0; + + virtual ULONG onChangeDebugeeState() = 0; + private: - typedef std::set modCallbacksColl; - static modCallbacksColl modCallbacks; + STDMETHOD_(ULONG, AddRef)() { return 1; } + STDMETHOD_(ULONG, Release)() { return 1; } - typedef boost::interprocess::interprocess_recursive_mutex modCallbacksLock; - static modCallbacksLock modCallbacksMtx; - typedef boost::interprocess::scoped_lock modCallbacksScopedLock; -}; + STDMETHOD(GetInterestMask)( + __out PULONG Mask + ); + + STDMETHOD(LoadModule)( + __in ULONG64 ImageFileHandle, + __in ULONG64 BaseOffset, + __in ULONG ModuleSize, + __in PCSTR ModuleName, + __in PCSTR ImageName, + __in ULONG CheckSum, + __in ULONG TimeDateStamp + ); -// python wrapper for debugEvent -struct debugEventWrap : debugEvent, boost::python::wrapper -{ - ULONG onLoadModule(const dbgModuleClass &module); - ULONG onLoadModuleDef(const dbgModuleClass &module) - { - return debugEvent::onLoadModule(module); - } + STDMETHOD(UnloadModule)( + __in PCSTR ImageBaseName, + __in ULONG64 BaseOffset + ); + + STDMETHOD(SessionStatus)( + __in ULONG Status + ); + + STDMETHOD(ChangeDebuggeeState)( + __in ULONG Flags, + __in ULONG64 Argument ); + +private: - ULONG onUnloadModule(const dbgModuleClass &module); - ULONG onUnloadModuleDef(const dbgModuleClass &module) - { - return debugEvent::onUnloadModule(module); - } + IDebugClient *m_debugClient; }; ///////////////////////////////////////////////////////////////////////////////// + +class debugEventWrap : public boost::python::wrapper, public debugEvent +{ + +public: + + + ULONG onLoadModule(const dbgModuleClass &module) { + return handler("onLoadModule", module ); + } + + ULONG onUnloadModule(const dbgModuleClass &module) { + return handler("onUnloadModule", module ); + } + + ULONG onChangeSessionStatus( ULONG status ) { + return handler( "onChangeSessionStatus", status ); + } + + ULONG onChangeDebugeeState() { + return handler( "onChangeDebugeeState" ); + } + +private: + + template + ULONG handler( const char* handlerName, Arg1Type arg1 ) + { + if (boost::python::override pythonHandler = get_override( handlerName )) + return pythonHandler(arg1); + + return DEBUG_STATUS_NO_CHANGE; + } + + ULONG handler( const char* handlerName ) + { + if (boost::python::override pythonHandler = get_override( handlerName )) + return pythonHandler(); + + return DEBUG_STATUS_NO_CHANGE; + } +}; + +///////////////////////////////////////////////////////////////////////////////// + + +// +//#include +// +//#include +//#include +// +//class debugEvent +//{ +// debugEvent(); +// virtual ~debugEvent(); +// +// virtual ULONG onLoadModule(const dbgModuleClass &/* module */) +// { +// return DEBUG_STATUS_NO_CHANGE; +// } +// +// virtual ULONG onUnloadModule(const dbgModuleClass &/* module */) +// { +// return DEBUG_STATUS_NO_CHANGE; +// } +// +// virtual ULONG onChangeSessionState( ULONG state ) +// { +// return DEBUG_STATUS_NO_CHANGE; +// } +// +// +// // call from debug engine +// static ULONG moduleLoaded(__in ULONG64 addr); +// static ULONG moduleUnloaded(__in ULONG64 addr); +// static ULONG sessionStatus(__in ULONG status ); +// +//private: +// +// typedef std::set modCallbacksColl; +// static modCallbacksColl modCallbacks; +// +// +// //typedef boost::interprocess::interprocess_recursive_mutex modCallbacksLock; +// //static modCallbacksLock modCallbacksMtx; +// //typedef boost::interprocess::scoped_lock modCallbacksScopedLock; +//}; +// +//// python wrapper for debugEvent +//struct debugEventWrap : debugEvent, boost::python::wrapper +//{ +// ULONG onLoadModule(const dbgModuleClass &module); +// ULONG onLoadModuleDef(const dbgModuleClass &module) +// { +// return debugEvent::onLoadModule(module); +// } +// +// ULONG onUnloadModule(const dbgModuleClass &module); +// ULONG onUnloadModuleDef(const dbgModuleClass &module) +// { +// return debugEvent::onUnloadModule(module); +// } +//}; +// +/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgeventcb.cpp b/pykd/dbgeventcb.cpp index 602cee1..d80112a 100644 --- a/pykd/dbgeventcb.cpp +++ b/pykd/dbgeventcb.cpp @@ -13,26 +13,14 @@ DbgEventCallbacksManager::DbgEventCallbacksManager( IDebugClient *client ) { + m_debugClient = client; + m_debugClient->AddRef(); + HRESULT hres; - - try { - m_debugClient = client; - m_debugClient->AddRef(); - - hres = m_debugClient->SetEventCallbacks(this); - if (FAILED(hres)) - throw DbgException( "IDebugClient::SetEventCallbacks" ); - - } - 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" ); - } + hres = m_debugClient->SetEventCallbacks(this); + if (FAILED(hres)) + throw DbgException( "IDebugClient::SetEventCallbacks" ); } /////////////////////////////////////////////////////////////////////////////////// @@ -46,6 +34,7 @@ DbgEventCallbacksManager::~DbgEventCallbacksManager() } } + /////////////////////////////////////////////////////////////////////////////////// HRESULT DbgEventCallbacksManager::GetInterestMask( @@ -54,9 +43,9 @@ HRESULT DbgEventCallbacksManager::GetInterestMask( { *Mask = DEBUG_EVENT_CHANGE_SYMBOL_STATE | - DEBUG_EVENT_BREAKPOINT | - DEBUG_EVENT_LOAD_MODULE | - DEBUG_EVENT_UNLOAD_MODULE; + DEBUG_EVENT_BREAKPOINT; +// DEBUG_EVENT_LOAD_MODULE | +// DEBUG_EVENT_UNLOAD_MODULE return S_OK; } @@ -93,7 +82,7 @@ HRESULT DbgEventCallbacksManager::ChangeSymbolState( return S_OK; } - return S_OK; + return DEBUG_STATUS_NO_CHANGE; } /////////////////////////////////////////////////////////////////////////////////// @@ -106,42 +95,59 @@ HRESULT DbgEventCallbacksManager::Breakpoint( } /////////////////////////////////////////////////////////////////////////////////// - -HRESULT DbgEventCallbacksManager::LoadModule( - __in ULONG64 ImageFileHandle, - __in ULONG64 BaseOffset, - __in ULONG ModuleSize, - __in PCSTR ModuleName, - __in PCSTR ImageName, - __in ULONG CheckSum, - __in ULONG TimeDateStamp -) -{ - try - { - return debugEvent::moduleLoaded(BaseOffset); - } - catch (std::exception &) - { - } - return DEBUG_STATUS_NO_CHANGE; -} - -/////////////////////////////////////////////////////////////////////////////////// - -HRESULT DbgEventCallbacksManager::UnloadModule( - __in PCSTR ImageBaseName, - __in ULONG64 BaseOffset -) -{ - try - { - return debugEvent::moduleUnloaded(BaseOffset); - } - catch (std::exception &) - { - } - return DEBUG_STATUS_NO_CHANGE; -} - -/////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT DbgEventCallbacksManager::LoadModule( +// __in ULONG64 ImageFileHandle, +// __in ULONG64 BaseOffset, +// __in ULONG ModuleSize, +// __in PCSTR ModuleName, +// __in PCSTR ImageName, +// __in ULONG CheckSum, +// __in ULONG TimeDateStamp +//) +//{ +// try +// { +// return debugEvent::moduleLoaded(BaseOffset); +// } +// catch (std::exception &) +// { +// } +// return DEBUG_STATUS_NO_CHANGE; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT DbgEventCallbacksManager::UnloadModule( +// __in PCSTR ImageBaseName, +// __in ULONG64 BaseOffset +//) +//{ +// try +// { +// return debugEvent::moduleUnloaded(BaseOffset); +// } +// catch (std::exception &) +// { +// } +// return DEBUG_STATUS_NO_CHANGE; +//} +// +///////////////////////////////////////////////////////////////////////////////////// +// +//HRESULT DbgEventCallbacksManager::SessionStatus( +// __in ULONG status +//) +//{ +// try +// { +// return debugEvent::sessionStatus( status ); +// } +// catch( std::exception& ) +// { +// } +// +// return DEBUG_STATUS_NO_CHANGE; +//} +// +///////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgeventcb.h b/pykd/dbgeventcb.h index 35ba683..3ed5e1c 100644 --- a/pykd/dbgeventcb.h +++ b/pykd/dbgeventcb.h @@ -1,6 +1,8 @@ #pragma once +#include + ////////////////////////////////////////////////////////////////////////////// // monitoring and processing debug events @@ -11,7 +13,7 @@ public: DbgEventCallbacksManager( IDebugClient *client = NULL ); virtual ~DbgEventCallbacksManager(); - + private: ///////////////////////////////////////////////////////////////////////////////// @@ -36,7 +38,7 @@ private: __in PDEBUG_BREAKPOINT Bp ); - STDMETHOD(LoadModule)( +/* STDMETHOD(LoadModule)( __in ULONG64 ImageFileHandle, __in ULONG64 BaseOffset, __in ULONG ModuleSize, @@ -50,6 +52,10 @@ private: __in PCSTR ImageBaseName, __in ULONG64 BaseOffset ); + + STDMETHOD(SessionStatus)( + __in ULONG status + ); */ private: IDebugClient *m_debugClient; diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 747922e..9570b7a 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -27,6 +27,7 @@ #include "dbgevent.h" #include "dbgbreak.h" #include "dbgio.h" +#include "intbase.h" ////////////////////////////////////////////////////////////////////////////// @@ -211,6 +212,7 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "delSynSymbolsMask", &delSyntheticSymbolsMask, "Delete synthetic symbols by mask of module and symbol name"); + boost::python::class_( "typeInfo", "Class representing non-primitive type info: structure, union, etc. attributes is a fields of non-primitive type" ) .def(boost::python::init( boost::python::args("module", "type"), "constructor" ) ) @@ -258,7 +260,7 @@ BOOST_PYTHON_MODULE( pykd ) .def("data", &TypedVar::data, "Return raw string object with data stream" ) .def("__getattr__", &TypedVar::getFieldWrap, - "Return field of structure as a object attribute" ) + "Return field of structure as an object attribute" ) .def("__str__", &TypedVar::print, "Return a nice string represention: print names and offsets of fields" ); @@ -337,10 +339,10 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::class_( "debugEvent", "Base class for debug events handlers" ) - .def( "onLoadModule", &debugEvent::onLoadModule, &debugEventWrap::onLoadModuleDef, + .def( "onLoadModule", &debugEventWrap::onLoadModule, "Load module event. Parameter is instance of dbgModuleClass. " "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) - .def( "onUnloadModule", &debugEvent::onUnloadModule, &debugEventWrap::onUnloadModuleDef, + .def( "onUnloadModule", &debugEventWrap::onUnloadModule, "Unload module event. Parameter is instance of dbgModuleClass. " "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); @@ -376,7 +378,103 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::register_exception_translator( &TypeException::exceptionTranslate ); boost::python::register_exception_translator( &IndexException::translate); boost::python::register_exception_translator( &MemoryException::translate ); + + boost::python::class_( + "intBase", + "intBase") + .def( boost::python::init<>() ) + .def( boost::python::init( boost::python::args("value"), "constructor" ) ) + + .def( "value", &intBase::value ) + .def( int_( boost::python::self ) ) + //.def( boost::python::self = long() ) + + .def( boost::python::self + long() ) + .def( long() + boost::python::self ) + .def( boost::python::self += long() ) + .def( boost::python::self + boost::python::self ) + .def( boost::python::self += boost::python::self ) + + .def( boost::python::self - long() ) + .def( long() - boost::python::self ) + .def( boost::python::self -= long() ) + .def( boost::python::self - boost::python::self ) + .def( boost::python::self -= boost::python::self ) + + .def( boost::python::self * long() ) + .def( long() * boost::python::self ) + .def( boost::python::self *= long() ) + .def( boost::python::self * boost::python::self ) + .def( boost::python::self *= boost::python::self ) + + .def( boost::python::self / long() ) + .def( long() / boost::python::self ) + .def( boost::python::self /= long() ) + .def( boost::python::self / boost::python::self ) + .def( boost::python::self /= boost::python::self ) + + .def( boost::python::self % long() ) + .def( long() % boost::python::self ) + .def( boost::python::self %= long() ) + .def( boost::python::self % boost::python::self ) + .def( boost::python::self %= boost::python::self ) + + .def( boost::python::self & long() ) + .def( long() & boost::python::self ) + .def( boost::python::self &= long() ) + .def( boost::python::self & boost::python::self ) + .def( boost::python::self &= boost::python::self ) + + .def( boost::python::self | long() ) + .def( long() | boost::python::self ) + .def( boost::python::self |= long() ) + .def( boost::python::self | boost::python::self ) + .def( boost::python::self |= boost::python::self ) + + .def( boost::python::self ^ long() ) + .def( long() ^ boost::python::self ) + .def( boost::python::self ^= long() ) + .def( boost::python::self ^ boost::python::self ) + .def( boost::python::self ^= boost::python::self ) + + .def( boost::python::self << long() ) + .def( boost::python::self <<= long() ) + + .def( boost::python::self >> long() ) + .def( boost::python::self >>= long() ) + + .def( boost::python::self < long() ) + .def( boost::python::self < boost::python::self ) + + .def( boost::python::self <= long() ) + .def( boost::python::self <= boost::python::self ) + + .def( boost::python::self == long() ) + .def( boost::python::self == boost::python::self ) + + .def( boost::python::self >= long() ) + .def( boost::python::self >= boost::python::self ) + + .def( boost::python::self > long() ) + .def( boost::python::self > boost::python::self ) + + .def( boost::python::self != long() ) + .def( boost::python::self != boost::python::self ) + + .def( ~boost::python::self ) + .def( !boost::python::self ) + .def( "__str__", &intBase::str ) + .def( "__hex__", &intBase::hex ); + + boost::python::class_ >( + "cpuReg", + "CPU regsiter class", + boost::python::no_init ) + .def( boost::python::init(boost::python::args("name"), "constructor" ) ) + .def( "name", &cpuReg::name, "The name of the regsiter" ) + .def( "beLive", &cpuReg::beLive, "Turn the object to live: its value will be following thr target register value" ); + // debug status DEF_PY_CONST(DEBUG_STATUS_NO_CHANGE); @@ -636,6 +734,9 @@ DbgExt::~DbgExt() if ( client4 ) client4->Release(); + if ( client5 ) + client5->Release(); + if ( control ) control->Release(); diff --git a/pykd/dbgreg.cpp b/pykd/dbgreg.cpp index 2fa2c42..c16c109 100644 --- a/pykd/dbgreg.cpp +++ b/pykd/dbgreg.cpp @@ -8,6 +8,52 @@ using namespace std; /////////////////////////////////////////////////////////////////////////////////// +cpuReg::cpuReg( std::string regName ) +{ + m_name = regName; + m_lived = false; + + reloadValue(); +} + +/////////////////////////////////////////////////////////////////////////////////// + +void cpuReg::reloadValue() const +{ + HRESULT hres; + ULONG registerIndex = 0; + + hres = dbgExt->registers->GetIndexByName( m_name.c_str(), ®isterIndex ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugRegister::GetIndexByName failed" ); + + DEBUG_VALUE debugValue; + hres = dbgExt->registers->GetValue( registerIndex, &debugValue ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugRegister::GetValue failed" ); + + switch( debugValue.Type ) + { + case DEBUG_VALUE_INT8: + m_value = debugValue.I8; + break; + + case DEBUG_VALUE_INT16: + m_value = debugValue.I16; + break; + + case DEBUG_VALUE_INT32: + m_value = debugValue.I32; + break; + + case DEBUG_VALUE_INT64: + m_value = debugValue.I64; + break; + } +} + +/////////////////////////////////////////////////////////////////////////////////// + boost::python::object loadRegister( const std::string ®isterName ) { diff --git a/pykd/dbgreg.h b/pykd/dbgreg.h index eeba89e..0a31a83 100644 --- a/pykd/dbgreg.h +++ b/pykd/dbgreg.h @@ -1,6 +1,43 @@ #pragma once #include +#include + +#include "intbase.h" + +///////////////////////////////////////////////////////////////////////////////// + +class cpuReg : public intBase { + +public : + + cpuReg( std::string regName ); + + std::string + name() const { + return m_name; + } + + void beLive() { + m_lived = true; + } + + ULONG64 value() const + { + if ( m_lived ) + reloadValue(); + + return intBase::value(); + } + +private: + + void reloadValue() const; + + std::string m_name; + + bool m_lived; +}; ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgtype.h b/pykd/dbgtype.h index 3ccd619..7c87c8e 100644 --- a/pykd/dbgtype.h +++ b/pykd/dbgtype.h @@ -267,303 +267,3 @@ sizeofType( const std::string &moduleName, const std::string &typeName ); /////////////////////////////////////////////////////////////////////////////////// - - - -//public: -// -// typedVarClass() : m_addr(0) -// {} -// -// typedVarClass( const TypeInfo &typeInfo, ULONG64 addr) : -// m_typeInfo( typeInfo ), -// m_addr( addr ) -// {} -// -// ULONG64 -// getAddress() const { -// return m_addr; -// } -// -// //virtual void -// //printField( const TypeInfo::TypeField &field, std::stringstream &sstr ) const override; -// -// //virtual void -// //printSelf( std::stringstream &sstr ) const override -// //{ -// // sstr << std::hex << "0x" << getAddress() << std::dec << " "; -// //} -// -//private: -// -// TypeInfo m_typeInfo; -// -// ULONG64 m_addr; -//}; - -/////////////////////////////////////////////////////////////////////////////////// - - - - - -// -//boost::python::object -//loadTypedVar( const std::string &moduleName, const std::string &typeName, ULONG64 address ); -// -//boost::python::object -//loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName ); -// -//boost::python::object -//loadTypedVarArray( ULONG64 address, const std::string &moduleName, const std::string &typeName, long number ); -// -//boost::python::object -//containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName ); -// -//boost::python::object -//getTypeClass( const std::string &moduleName, const std::string &typeName ); -// -//ULONG -//sizeofType( const std::string &moduleName, const std::string &typeName ); -// -// -/////////////////////////////////////////////////////////////////////////////////// -// -//class TypeInfo { -// -//public: -// -// template< typename TTypeInfo> -// struct TypeFieldT { -// ULONG size; -// ULONG offset; -// TTypeInfo type; -// std::string name; -// -// TypeFieldT( const std::string &name_, const TTypeInfo &type_, ULONG size_, ULONG offset_ ) : -// name( name_ ), -// size( size_ ), -// offset( offset_ ), -// type( type_ ) -// {} -// }; -// -// struct TypeName { -// std::string module; -// std::string symbol; -// -// TypeName( const std::string &module_, const std::string &symbol_ ) : -// module( module_ ), -// symbol( symbol_ ) -// {} -// -// bool -// operator < ( const TypeName &typeName ) const { -// -// if ( typeName.module < module ) -// return true; -// -// if ( typeName.module > module ) -// return false; -// -// return typeName.symbol < symbol; -// } -// -// }; -// -// typedef TypeFieldT TypeField; -// -// typedef std::map TypeInfoMap; -// -// typedef std::list TypeFieldList; -// -//public: -// -// TypeInfo() : -// m_size( 0 ), -// m_baseType( false ), -// m_pointer( false ) -// {} -// -// TypeInfo( const std::string &typeName ) : -// m_size( 0 ), -// m_baseType( false ), -// m_pointer( false ), -// m_typeName( typeName ) -// {} -// -// boost::python::object -// load( ULONG64 targetAddr, PVOID cacheBuffer = NULL, ULONG offset = 0 ) const; -// -// boost::python::object -// build( ULONG offset = 0 ) const; -// -// ULONG64 -// size() const -// { -// return m_size; -// } -// -// const std::string& -// name() const -// { -// return m_typeName; -// } -// -// const TypeFieldList& -// getFields() const { -// return m_fields; -// } -// -// bool -// isComplex() const { -// return !m_baseType; -// } -// -// bool -// isPtr() const { -// return m_pointer; -// } -// -// static const TypeInfo* -// get( const std::string &moduleName, const std::string &typeName ); -// -//private: -// -// static TypeInfoMap g_typeInfoCache; -// -// boost::python::object -// loadBaseType( PVOID addr ) const; -// -// boost::python::object -// ptrLoader( PVOID addr ) const { -// if ( is64bitSystem() ) -// return boost::python::object( *(PULONG64)addr ); -// else -// return boost::python::object( addr64( *(PULONG)addr ) ); -// } -// -// void -// setupBaseType(); -// -// static bool -// getById( const std::string &moduleName, ULONG typeId, TypeInfo& typeInfo ); -// -//private: -// -// bool m_baseType; -// bool m_pointer; -// TypeFieldList m_fields; -// std::string m_typeName; -// ULONG m_size; -//}; -// -/////////////////////////////////////////////////////////////////////////////////// -// -//class typeClass -//{ -//public: -// -// typeClass() -// : m_offset(0) -// { -// } -// -// typeClass( -// const TypeInfo &typeInfo, -// ULONG offset -// ) : m_typeInfo(typeInfo) -// , m_offset(offset) -// { -// } -// -// // sizeof(TYPE) -// ULONG size() const -// { -// return (ULONG)m_typeInfo.size(); -// } -// -// void setPyObj( const boost::python::object &obj ) -// { -// m_pyobj = obj; -// } -// -// // TypeInfo getter -// TypeInfo &getTypeInfo() -// { -// return m_typeInfo; -// } -// const TypeInfo &getTypeInfo() const -// { -// return m_typeInfo; -// } -// -// // boost::python::object getter -// boost::python::object &getPyObj() -// { -// return m_pyobj; -// } -// const boost::python::object &getPyObj() const -// { -// return m_pyobj; -// } -// -// std::string print() const; -// -// virtual void printField( -// const TypeInfo::TypeField &field, -// std::stringstream &sstr -// ) const -// { -// // no data - nothing print -// } -// virtual void printSelf( -// std::stringstream &sstr -// ) const -// { -// // no data - nothing print -// } -// -// // field offset getter/setter -// ULONG getOffset() const { return m_offset; } -// -//private: -// TypeInfo m_typeInfo; -// ULONG m_offset; -// boost::python::object m_pyobj; -//}; -// -/////////////////////////////////////////////////////////////////////////////////// -// -//class typedVarClass : public typeClass { -// -//public: -// -// typedVarClass() : m_addr(0) -// {} -// -// typedVarClass( const TypeInfo &typeInfo, ULONG offset, ULONG64 addr) : -// typeClass( typeInfo, offset ), -// m_addr( addr ) -// {} -// -// ULONG64 -// getAddress() const { -// return m_addr; -// } -// -// virtual void -// printField( const TypeInfo::TypeField &field, std::stringstream &sstr ) const override; -// -// virtual void -// printSelf( std::stringstream &sstr ) const override -// { -// sstr << std::hex << "0x" << getAddress() << std::dec << " "; -// } -// -//private: -// -// ULONG64 m_addr; -//}; -// -/////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/pykd.vcproj b/pykd/pykd.vcproj index c9435ae..458d194 100644 --- a/pykd/pykd.vcproj +++ b/pykd/pykd.vcproj @@ -151,7 +151,7 @@ /> + +