[0.2.x] added : exception callback

git-svn-id: https://pykd.svn.codeplex.com/svn@80215 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-10-15 11:53:24 +00:00 committed by Mikhail I. Izmestev
parent 90f6329bec
commit b4241945a2
6 changed files with 44 additions and 3 deletions

View File

@ -76,6 +76,7 @@ struct DEBUG_EVENT_CALLBACK {
virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId ) = 0; virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId ) = 0;
virtual DEBUG_CALLBACK_RESULT OnModuleLoad( ULONG64 offset, const std::string &name ) = 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 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 ); void eventRegisterCallbacks( const DEBUG_EVENT_CALLBACK *callbacks );

View File

@ -24,6 +24,7 @@ private:
virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId ) = 0; virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId ) = 0;
virtual DEBUG_CALLBACK_RESULT OnModuleLoad( ULONG64 offset, const std::string &name ) = 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 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 ); return handler("onModuleUnload", offset, name );
} }
virtual DEBUG_CALLBACK_RESULT OnException( ULONG64 offset, ULONG code ) {
return handler("onException", offset, code );
}
private: private:
template<typename Arg1Type> template<typename Arg1Type>

View File

@ -2,7 +2,7 @@
#define PYKD_VERSION_MAJOR 0 #define PYKD_VERSION_MAJOR 0
#define PYKD_VERSION_MINOR 2 #define PYKD_VERSION_MINOR 2
#define PYKD_VERSION_SUBVERSION 0 #define PYKD_VERSION_SUBVERSION 0
#define PYKD_VERSION_BUILDNO 0 #define PYKD_VERSION_BUILDNO 1
#define __VER_STR2__(x) #x #define __VER_STR2__(x) #x

View File

@ -437,10 +437,13 @@ BOOST_PYTHON_MODULE( pykd )
"Triggered breakpoint event. Parameter is int: ID of breakpoint\n" "Triggered breakpoint event. Parameter is int: ID of breakpoint\n"
"For ignore event method must return False value" ) "For ignore event method must return False value" )
.def( "onModuleLoad", &EventHandlerWrap::OnModuleLoad, .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" ) "For ignore event method must return False value" )
.def( "onModuleUnload", &EventHandlerWrap::OnModuleUnload, .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" ); "For ignore event method must return False value" );
// wrapper for standart python exceptions // wrapper for standart python exceptions

View File

@ -971,6 +971,9 @@ HRESULT STDMETHODCALLTYPE DebugEngine::LoadModule(
return ConvertCallbackResult( result ); return ConvertCallbackResult( result );
} }
///////////////////////////////////////////////////////////////////////////////
HRESULT STDMETHODCALLTYPE DebugEngine::UnloadModule( HRESULT STDMETHODCALLTYPE DebugEngine::UnloadModule(
__in_opt PCSTR ImageBaseName, __in_opt PCSTR ImageBaseName,
__in ULONG64 BaseOffset ) __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 ULONG64
getCurrentProcess() getCurrentProcess()
{ {

View File

@ -54,6 +54,7 @@ public:
*Mask = DEBUG_EVENT_BREAKPOINT; *Mask = DEBUG_EVENT_BREAKPOINT;
*Mask |= DEBUG_EVENT_LOAD_MODULE; *Mask |= DEBUG_EVENT_LOAD_MODULE;
*Mask |= DEBUG_EVENT_UNLOAD_MODULE; *Mask |= DEBUG_EVENT_UNLOAD_MODULE;
*Mask |= DEBUG_EVENT_EXCEPTION;
return S_OK; return S_OK;
} }
@ -74,6 +75,10 @@ public:
__in_opt PCSTR ImageBaseName, __in_opt PCSTR ImageBaseName,
__in ULONG64 BaseOffset ); __in ULONG64 BaseOffset );
STDMETHOD(Exception)(
__in PEXCEPTION_RECORD64 Exception,
__in ULONG FirstChance );
DbgEngBind* DbgEngBind*
operator->() operator->()
{ {