mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 12:53:23 +08:00
[0.2.x] added : load/unload module callbacks
git-svn-id: https://pykd.svn.codeplex.com/svn@80212 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
b4564ca827
commit
212a79fb7a
@ -74,6 +74,8 @@ enum DEBUG_CALLBACK_RESULT {
|
||||
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;
|
||||
};
|
||||
|
||||
void eventRegisterCallbacks( const DEBUG_EVENT_CALLBACK *callbacks );
|
||||
|
@ -22,6 +22,8 @@ public:
|
||||
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;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
@ -36,6 +38,14 @@ public:
|
||||
return handler("onBreakpoint", Id);
|
||||
}
|
||||
|
||||
virtual DEBUG_CALLBACK_RESULT OnModuleLoad( ULONG64 offset, const std::string &name ) {
|
||||
return handler("onModuleLoad", offset, name );
|
||||
}
|
||||
|
||||
virtual DEBUG_CALLBACK_RESULT OnModuleUnload( ULONG64 offset, const std::string &name ) {
|
||||
return handler("onModuleUnload", offset, name );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
template<typename Arg1Type>
|
||||
@ -53,6 +63,21 @@ private:
|
||||
return DebugCallbackNoChange;
|
||||
}
|
||||
|
||||
template<typename Arg1Type, typename Arg2Type>
|
||||
DEBUG_CALLBACK_RESULT handler( const char* handlerName, Arg1Type arg1, Arg2Type arg2 )
|
||||
{
|
||||
if (python::override pythonHandler = get_override( handlerName ))
|
||||
{
|
||||
try {
|
||||
return pythonHandler(arg1,arg2);
|
||||
}
|
||||
catch (const python::error_already_set &) {
|
||||
//onHandlerException();
|
||||
}
|
||||
}
|
||||
return DebugCallbackNoChange;
|
||||
}
|
||||
|
||||
DEBUG_CALLBACK_RESULT handler( const char* handlerName )
|
||||
{
|
||||
if (python::override pythonHandler = get_override( handlerName ))
|
||||
|
1063
pykd/pymod.cpp
1063
pykd/pymod.cpp
File diff suppressed because it is too large
Load Diff
@ -919,6 +919,7 @@ HRESULT STDMETHODCALLTYPE DebugEngine::Breakpoint(
|
||||
{
|
||||
HRESULT hres;
|
||||
ULONG id;
|
||||
DEBUG_CALLBACK_RESULT result = DebugCallbackNoChange;
|
||||
|
||||
hres = bp->GetId( &id );
|
||||
if ( FAILED( hres ) )
|
||||
@ -932,13 +933,64 @@ HRESULT STDMETHODCALLTYPE DebugEngine::Breakpoint(
|
||||
{
|
||||
PyThread_StateSave pyThreadSave( it->pystate );
|
||||
|
||||
DEBUG_CALLBACK_RESULT result = it->callback->OnBreakpoint( id );
|
||||
DEBUG_CALLBACK_RESULT ret = it->callback->OnBreakpoint( id );
|
||||
|
||||
if ( DebugCallbackNoChange != result )
|
||||
return ConvertCallbackResult( result );
|
||||
result = ret != DebugCallbackNoChange ? ret : result;
|
||||
}
|
||||
|
||||
return DEBUG_STATUS_NO_CHANGE;
|
||||
return ConvertCallbackResult( result );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DebugEngine::LoadModule(
|
||||
__in ULONG64 ImageFileHandle,
|
||||
__in ULONG64 BaseOffset,
|
||||
__in ULONG ModuleSize,
|
||||
__in_opt PCSTR ModuleName,
|
||||
__in_opt PCSTR ImageName,
|
||||
__in ULONG CheckSum,
|
||||
__in ULONG TimeDateStamp
|
||||
)
|
||||
{
|
||||
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->OnModuleLoad( BaseOffset, std::string(ModuleName) );
|
||||
|
||||
result = ret != DebugCallbackNoChange ? ret : result;
|
||||
}
|
||||
|
||||
return ConvertCallbackResult( result );
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DebugEngine::UnloadModule(
|
||||
__in_opt PCSTR ImageBaseName,
|
||||
__in ULONG64 BaseOffset )
|
||||
{
|
||||
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->OnModuleUnload( BaseOffset, getModuleName(BaseOffset) );
|
||||
|
||||
result = ret != DebugCallbackNoChange ? ret : result;
|
||||
}
|
||||
|
||||
return ConvertCallbackResult( result );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -52,6 +52,8 @@ public:
|
||||
)
|
||||
{
|
||||
*Mask = DEBUG_EVENT_BREAKPOINT;
|
||||
*Mask |= DEBUG_EVENT_LOAD_MODULE;
|
||||
*Mask |= DEBUG_EVENT_UNLOAD_MODULE;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@ -59,6 +61,19 @@ public:
|
||||
__in IDebugBreakpoint *bp
|
||||
);
|
||||
|
||||
STDMETHOD(LoadModule)(
|
||||
__in ULONG64 ImageFileHandle,
|
||||
__in ULONG64 BaseOffset,
|
||||
__in ULONG ModuleSize,
|
||||
__in_opt PCSTR ModuleName,
|
||||
__in_opt PCSTR ImageName,
|
||||
__in ULONG CheckSum,
|
||||
__in ULONG TimeDateStamp);
|
||||
|
||||
STDMETHOD(UnloadModule)(
|
||||
__in_opt PCSTR ImageBaseName,
|
||||
__in ULONG64 BaseOffset );
|
||||
|
||||
DbgEngBind*
|
||||
operator->()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user