diff --git a/pykd/dbgmodevent.cpp b/pykd/dbgevent.cpp similarity index 75% rename from pykd/dbgmodevent.cpp rename to pykd/dbgevent.cpp index 62e81b2..79eeb10 100644 --- a/pykd/dbgmodevent.cpp +++ b/pykd/dbgevent.cpp @@ -8,16 +8,16 @@ #include "dbgmodule.h" #include "dbgcallback.h" -#include "dbgmodevent.h" +#include "dbgevent.h" ///////////////////////////////////////////////////////////////////////////////// -moduleEvents::modCallbacksColl moduleEvents::modCallbacks; -moduleEvents::modCallbacksLock moduleEvents::modCallbacksMtx; +debugEvent::modCallbacksColl debugEvent::modCallbacks; +debugEvent::modCallbacksLock debugEvent::modCallbacksMtx; ///////////////////////////////////////////////////////////////////////////////// -moduleEvents::moduleEvents() +debugEvent::debugEvent() { modCallbacksScopedLock lock(modCallbacksMtx); modCallbacks.insert(this); @@ -25,7 +25,7 @@ moduleEvents::moduleEvents() ///////////////////////////////////////////////////////////////////////////////// -moduleEvents::~moduleEvents() +debugEvent::~debugEvent() { modCallbacksScopedLock lock(modCallbacksMtx); modCallbacks.erase(this); @@ -33,7 +33,7 @@ moduleEvents::~moduleEvents() ///////////////////////////////////////////////////////////////////////////////// -ULONG moduleEvents::onLoadModule(__in ULONG64 addr) +ULONG debugEvent::moduleLoaded(__in ULONG64 addr) { modCallbacksScopedLock lock(modCallbacksMtx); if (modCallbacks.empty()) @@ -51,7 +51,7 @@ ULONG moduleEvents::onLoadModule(__in ULONG64 addr) modCallbacksColl::iterator itCallback = modCallbacks.begin(); while (itCallback != modCallbacks.end()) { - const ULONG retValue = (*itCallback)->onLoad(module); + const ULONG retValue = (*itCallback)->onLoadModule(module); if (DEBUG_STATUS_NO_CHANGE != retValue) return retValue; @@ -62,7 +62,7 @@ ULONG moduleEvents::onLoadModule(__in ULONG64 addr) ///////////////////////////////////////////////////////////////////////////////// -ULONG moduleEvents::onUnloadModule(__in ULONG64 addr) +ULONG debugEvent::moduleUnloaded(__in ULONG64 addr) { modCallbacksScopedLock lock(modCallbacksMtx); if (modCallbacks.empty()) @@ -80,7 +80,7 @@ ULONG moduleEvents::onUnloadModule(__in ULONG64 addr) modCallbacksColl::iterator itCallback = modCallbacks.begin(); while (itCallback != modCallbacks.end()) { - const ULONG retValue = (*itCallback)->onUnload(module); + const ULONG retValue = (*itCallback)->onUnloadModule(module); if (DEBUG_STATUS_NO_CHANGE != retValue) return retValue; @@ -91,26 +91,22 @@ ULONG moduleEvents::onUnloadModule(__in ULONG64 addr) ///////////////////////////////////////////////////////////////////////////////// -ULONG moduleEventsWrap::onLoad( - const dbgModuleClass &module -) +ULONG debugEventWrap::onLoadModule(const dbgModuleClass &module) { - if (boost::python::override override = get_override("onLoad")) + if (boost::python::override override = get_override("onLoadModule")) return override(module); - return moduleEvents::onLoad(module); + return debugEvent::onLoadModule(module); } ///////////////////////////////////////////////////////////////////////////////// -ULONG moduleEventsWrap::onUnload( - const dbgModuleClass &module -) +ULONG debugEventWrap::onUnloadModule(const dbgModuleClass &module) { - if (boost::python::override override = get_override("onUnload")) + if (boost::python::override override = get_override("onUnloadModule")) return override(module); - return moduleEvents::onUnload(module); + return debugEvent::onUnloadModule(module); } ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgevent.h b/pykd/dbgevent.h new file mode 100644 index 0000000..67b0fff --- /dev/null +++ b/pykd/dbgevent.h @@ -0,0 +1,54 @@ +///////////////////////////////////////////////////////////////////////////////// +// Load/Unload module events +///////////////////////////////////////////////////////////////////////////////// + +#include <set> + +#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp> +#include <boost/interprocess/sync/scoped_lock.hpp> + +interface 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; + } + + // call from debug engine + static ULONG moduleLoaded(__in ULONG64 addr); + static ULONG moduleUnloaded(__in ULONG64 addr); + +private: + + typedef std::set<debugEvent *> modCallbacksColl; + static modCallbacksColl modCallbacks; + + typedef boost::interprocess::interprocess_recursive_mutex modCallbacksLock; + static modCallbacksLock modCallbacksMtx; + typedef boost::interprocess::scoped_lock<modCallbacksLock> modCallbacksScopedLock; +}; + +// python wrapper for debugEvent +struct debugEventWrap : debugEvent, boost::python::wrapper<debugEvent> +{ + 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 9587dbc..602cee1 100644 --- a/pykd/dbgeventcb.cpp +++ b/pykd/dbgeventcb.cpp @@ -7,7 +7,7 @@ #include "dbgmodule.h" #include "dbgsynsym.h" #include "dbgbreak.h" -#include "dbgmodevent.h" +#include "dbgevent.h" /////////////////////////////////////////////////////////////////////////////////// @@ -119,7 +119,7 @@ HRESULT DbgEventCallbacksManager::LoadModule( { try { - return moduleEvents::onLoadModule(BaseOffset); + return debugEvent::moduleLoaded(BaseOffset); } catch (std::exception &) { @@ -136,7 +136,7 @@ HRESULT DbgEventCallbacksManager::UnloadModule( { try { - return moduleEvents::onUnloadModule(BaseOffset); + return debugEvent::moduleUnloaded(BaseOffset); } catch (std::exception &) { diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 678b567..24f6b1f 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -28,7 +28,7 @@ #include "dbgprocess.h" #include "dbgsynsym.h" #include "dbgclient.h" -#include "dbgmodevent.h" +#include "dbgevent.h" #include "dbgbreak.h" ////////////////////////////////////////////////////////////////////////////// @@ -332,29 +332,29 @@ BOOST_PYTHON_MODULE( pykd ) .def( "__str__", &dbgBreakpointClass::print, "Return a nice string represention of the breakpoint class" ); - boost::python::class_<moduleEventsWrap, boost::noncopyable>( "modEvents", - "Class for processing of events: loading and unloading modules" ) - .def( "onLoad", &moduleEvents::onLoad, &moduleEventsWrap::onLoadDef, + boost::python::class_<debugEventWrap, boost::noncopyable>( "debugEvent", + "Base class for debug events handlers" ) + .def( "onLoadModule", &debugEvent::onLoadModule, &debugEventWrap::onLoadModuleDef, "Load module event. Parameter is instance of dbgModuleClass. " "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ) - .def( "onUnload", &moduleEvents::onUnload, &moduleEventsWrap::onUnloadDef, + .def( "onUnloadModule", &debugEvent::onUnloadModule, &debugEventWrap::onUnloadModuleDef, "Unload module event. Parameter is instance of dbgModuleClass. " - "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); - - // ���������� + "For ignore event method must return DEBUG_STATUS_NO_CHANGE value" ); + + // ���������� boost::python::class_<DbgException> dbgExceptionClass( "BaseException", "Pykd base exception class", boost::python::no_init ); //boost::python::init<std::string>() ); - + dbgExceptionClass .def( boost::python::init<std::string>( boost::python::args("desc"), "constructor" ) ) .def( "desc", &DbgException::getDesc, - "Get exception description" ); - + "Get exception description" ); + boost::python::class_<TypeException, boost::python::bases<DbgException> > typeExceptionClass( "TypeException", "Type exception class", - boost::python::no_init ); + boost::python::no_init ); boost::python::class_<MemoryException, boost::python::bases<DbgException> > memoryExceptionClass( "MemoryException", "Memory exception class", @@ -365,7 +365,7 @@ BOOST_PYTHON_MODULE( pykd ) .def( "getAddress", &MemoryException::getAddress, "Return target address" ); - baseExceptionType = dbgExceptionClass.ptr(); + baseExceptionType = dbgExceptionClass.ptr(); typeExceptionType = typeExceptionClass.ptr(); memoryExceptionType = memoryExceptionClass.ptr(); @@ -373,7 +373,7 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::register_exception_translator<TypeException>( &TypeException::exceptionTranslate ); boost::python::register_exception_translator<IndexException>( &IndexException::translate); boost::python::register_exception_translator<MemoryException>( &MemoryException::translate ); - + // debug status DEF_PY_CONST(DEBUG_STATUS_NO_CHANGE); diff --git a/pykd/dbgmodevent.h b/pykd/dbgmodevent.h deleted file mode 100644 index 70aff00..0000000 --- a/pykd/dbgmodevent.h +++ /dev/null @@ -1,53 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////// -// Load/Unload module events -///////////////////////////////////////////////////////////////////////////////// - -#include <set> - -#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp> -#include <boost/interprocess/sync/scoped_lock.hpp> - -interface moduleEvents -{ - moduleEvents(); - virtual ~moduleEvents(); - - virtual ULONG onLoad(const dbgModuleClass &/* module */) - { - return DEBUG_STATUS_NO_CHANGE; - } - virtual ULONG onUnload(const dbgModuleClass &/* module */) - { - return DEBUG_STATUS_NO_CHANGE; - } - - static ULONG onLoadModule(__in ULONG64 addr); - static ULONG onUnloadModule(__in ULONG64 addr); - -private: - - typedef std::set<moduleEvents *> modCallbacksColl; - static modCallbacksColl modCallbacks; - - typedef boost::interprocess::interprocess_recursive_mutex modCallbacksLock; - static modCallbacksLock modCallbacksMtx; - typedef boost::interprocess::scoped_lock<modCallbacksLock> modCallbacksScopedLock; -}; - -// python wrapper for moduleEvents -struct moduleEventsWrap : moduleEvents, boost::python::wrapper<moduleEvents> -{ - ULONG onLoad(const dbgModuleClass &module); - ULONG onLoadDef(const dbgModuleClass &module) - { - return moduleEvents::onLoad(module); - } - - ULONG onUnload(const dbgModuleClass &module); - ULONG onUnloadDef(const dbgModuleClass &module) - { - return moduleEvents::onUnload(module); - } -}; - -///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/pykd.cpp b/pykd/pykd.cpp index e69de29..1577c4e 100644 --- a/pykd/pykd.cpp +++ b/pykd/pykd.cpp @@ -0,0 +1 @@ +#include "stdafx.h" \ No newline at end of file diff --git a/pykd/pykd.vcproj b/pykd/pykd.vcproj index 363d9fb..95ab0c4 100644 --- a/pykd/pykd.vcproj +++ b/pykd/pykd.vcproj @@ -385,7 +385,7 @@ > </File> <File - RelativePath=".\dbgmodevent.cpp" + RelativePath=".\dbgevent.cpp" > </File> <File @@ -511,7 +511,7 @@ > </File> <File - RelativePath=".\dbgmodevent.h" + RelativePath=".\dbgevent.h" > </File> <File diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 38c7582..9fa6662 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -357,6 +357,10 @@ RelativePath=".\dbgdump.cpp" > </File> + <File + RelativePath=".\dbgevent.cpp" + > + </File> <File RelativePath=".\dbgeventcb.cpp" > @@ -373,10 +377,6 @@ RelativePath=".\dbgmem.cpp" > </File> - <File - RelativePath=".\dbgmodevent.cpp" - > - </File> <File RelativePath=".\dbgmodule.cpp" > @@ -413,6 +413,10 @@ RelativePath=".\dbgtype.cpp" > </File> + <File + RelativePath=".\pykd.cpp" + > + </File> <File RelativePath=".\pykd.def" > @@ -479,6 +483,10 @@ RelativePath=".\dbgdump.h" > </File> + <File + RelativePath=".\dbgevent.h" + > + </File> <File RelativePath=".\dbgeventcb.h" > @@ -499,10 +507,6 @@ RelativePath=".\dbgmem.h" > </File> - <File - RelativePath=".\dbgmodevent.h" - > - </File> <File RelativePath=".\dbgmodule.h" > diff --git a/samples/goLoad.py b/samples/goLoad.py index b76fb4b..50a3e3e 100644 --- a/samples/goLoad.py +++ b/samples/goLoad.py @@ -6,19 +6,19 @@ from pykd import * import fnmatch import sys -class modLoad(modEvents): +class loadHandler(debugEvent): def __init__(self, mask): - modEvents.__init__(self) + debugEvent.__init__(self) self.mask = mask - def onLoad(self, module): + def onLoadModule(self, module): if fnmatch.fnmatch( module.name(), self.mask ): return DEBUG_STATUS_BREAK return DEBUG_STATUS_NO_CHANGE if __name__ == "__main__": if len(sys.argv) == 2: - loadHandler = modLoad( sys.argv[1] ) + loadHandler = loadHandler( sys.argv[1] ) go() else: dprintln( "Wait (execute) for load target module\nInvalid command line" )