diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index a29aa36..de2bbb6 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -76,6 +76,7 @@ struct DEBUG_EVENT_CALLBACK { virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId ) = 0; virtual DEBUG_CALLBACK_RESULT OnModuleLoad( ULONG64 offset, const std::string &name ) = 0; virtual DEBUG_CALLBACK_RESULT OnModuleUnload( ULONG64 offset, const std::string &name ) = 0; + virtual DEBUG_CALLBACK_RESULT OnException( ULONG64 offset, ULONG code ) = 0; }; void eventRegisterCallbacks( const DEBUG_EVENT_CALLBACK *callbacks ); diff --git a/pykd/eventhandler.h b/pykd/eventhandler.h index 005d028..c09d454 100644 --- a/pykd/eventhandler.h +++ b/pykd/eventhandler.h @@ -24,6 +24,7 @@ private: virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId ) = 0; virtual DEBUG_CALLBACK_RESULT OnModuleLoad( ULONG64 offset, const std::string &name ) = 0; virtual DEBUG_CALLBACK_RESULT OnModuleUnload( ULONG64 offset, const std::string &name ) = 0; + virtual DEBUG_CALLBACK_RESULT OnException( ULONG64 offset, ULONG code ) = 0; }; ////////////////////////////////////////////////////////////////////////////////// @@ -46,6 +47,10 @@ public: return handler("onModuleUnload", offset, name ); } + virtual DEBUG_CALLBACK_RESULT OnException( ULONG64 offset, ULONG code ) { + return handler("onException", offset, code ); + } + private: template diff --git a/pykd/pykdver.h b/pykd/pykdver.h index 1212fef..064c343 100644 --- a/pykd/pykdver.h +++ b/pykd/pykdver.h @@ -2,7 +2,7 @@ #define PYKD_VERSION_MAJOR 0 #define PYKD_VERSION_MINOR 2 #define PYKD_VERSION_SUBVERSION 0 -#define PYKD_VERSION_BUILDNO 0 +#define PYKD_VERSION_BUILDNO 1 #define __VER_STR2__(x) #x diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 5b33f46..9a8b437 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -437,10 +437,13 @@ BOOST_PYTHON_MODULE( pykd ) "Triggered breakpoint event. Parameter is int: ID of breakpoint\n" "For ignore event method must return False value" ) .def( "onModuleLoad", &EventHandlerWrap::OnModuleLoad, - "Triggered module load event. Parameter is long: module base, string: module name\n" + "Triggered module load event. Parameter are long: module base, string: module name\n" "For ignore event method must return False value" ) .def( "onModuleUnload", &EventHandlerWrap::OnModuleUnload, - "Triggered module unload event. Parameter is long: module base, string: module name\n" + "Triggered module unload event. Parameter are long: module base, string: module name\n" + "For ignore event method must return False value" ) + .def( "onException", &EventHandlerWrap::OnException, + "Triggered exception event. Parameters are long: exception address, long: exception code\n" "For ignore event method must return False value" ); // wrapper for standart python exceptions diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp index 2f70f29..e5c0d2e 100644 --- a/pykd/win/dbgeng.cpp +++ b/pykd/win/dbgeng.cpp @@ -971,6 +971,9 @@ HRESULT STDMETHODCALLTYPE DebugEngine::LoadModule( return ConvertCallbackResult( result ); } + +/////////////////////////////////////////////////////////////////////////////// + HRESULT STDMETHODCALLTYPE DebugEngine::UnloadModule( __in_opt PCSTR ImageBaseName, __in ULONG64 BaseOffset ) @@ -995,6 +998,30 @@ HRESULT STDMETHODCALLTYPE DebugEngine::UnloadModule( /////////////////////////////////////////////////////////////////////////////// +HRESULT STDMETHODCALLTYPE DebugEngine::Exception( + __in PEXCEPTION_RECORD64 Exception, + __in ULONG FirstChance ) +{ + DEBUG_CALLBACK_RESULT result = DebugCallbackNoChange; + + boost::recursive_mutex::scoped_lock l(m_handlerLock); + + HandlerList::iterator it = m_handlers.begin(); + + for ( ; it != m_handlers.end(); ++it ) + { + PyThread_StateSave pyThreadSave( it->pystate ); + + DEBUG_CALLBACK_RESULT ret = it->callback->OnException( Exception->ExceptionAddress, Exception->ExceptionCode ); + + result = ret != DebugCallbackNoChange ? ret : result; + } + + return ConvertCallbackResult( result ); +} + +/////////////////////////////////////////////////////////////////////////////// + ULONG64 getCurrentProcess() { diff --git a/pykd/win/dbgeng.h b/pykd/win/dbgeng.h index 53adec6..f5e4213 100644 --- a/pykd/win/dbgeng.h +++ b/pykd/win/dbgeng.h @@ -54,6 +54,7 @@ public: *Mask = DEBUG_EVENT_BREAKPOINT; *Mask |= DEBUG_EVENT_LOAD_MODULE; *Mask |= DEBUG_EVENT_UNLOAD_MODULE; + *Mask |= DEBUG_EVENT_EXCEPTION; return S_OK; } @@ -74,6 +75,10 @@ public: __in_opt PCSTR ImageBaseName, __in ULONG64 BaseOffset ); + STDMETHOD(Exception)( + __in PEXCEPTION_RECORD64 Exception, + __in ULONG FirstChance ); + DbgEngBind* operator->() {