2011-10-12 15:11:54 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// user-customizing debug event handler
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include <dbgeng.h>
|
|
|
|
#include "dbgobj.h"
|
|
|
|
#include "module.h"
|
|
|
|
#include "dbgclient.h"
|
|
|
|
|
|
|
|
namespace pykd {
|
2011-10-12 15:11:54 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
class EventHandler : public DebugBaseEventCallbacks
|
2011-10-12 15:11:54 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
EventHandler();
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
EventHandler( DebugClient &client );
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
virtual ~EventHandler();
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
protected:
|
2011-10-12 15:11:54 +08:00
|
|
|
|
|
|
|
STDMETHOD_(ULONG, AddRef)() { return 1; }
|
|
|
|
STDMETHOD_(ULONG, Release)() { return 1; }
|
|
|
|
|
|
|
|
STDMETHOD(GetInterestMask)(
|
|
|
|
__out PULONG Mask
|
2011-10-14 15:03:51 +08:00
|
|
|
) {
|
|
|
|
*Mask = 0;
|
|
|
|
*Mask |= DEBUG_EVENT_LOAD_MODULE;
|
|
|
|
*Mask |= DEBUG_EVENT_UNLOAD_MODULE;
|
|
|
|
*Mask |= DEBUG_EVENT_SESSION_STATUS;
|
|
|
|
*Mask |= DEBUG_EVENT_EXCEPTION;
|
|
|
|
*Mask |= DEBUG_EVENT_BREAKPOINT;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
virtual ULONG onBreakpoint(const python::dict &/*bpParameters*/) = 0;
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
virtual ULONG onException(const python::dict &/*exceptData*/) = 0;
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
virtual ULONG onLoadModule(const Module &/* module */) = 0;
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
virtual ULONG onUnloadModule(const Module &/* module */) = 0;
|
|
|
|
|
|
|
|
virtual ULONG onChangeSessionStatus( ULONG status ) = 0;
|
|
|
|
|
|
|
|
virtual ULONG onChangeDebugeeState() = 0;
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
protected:
|
2011-10-12 15:11:54 +08:00
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
CComPtr<IDebugClient> m_client;
|
2011-10-12 15:11:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
class EventHandlerWrap : public boost::python::wrapper<EventHandler>, public EventHandler
|
2011-10-12 15:11:54 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
EventHandlerWrap()
|
|
|
|
{}
|
|
|
|
|
|
|
|
EventHandlerWrap( DebugClient &client ) : EventHandler( client )
|
|
|
|
{}
|
|
|
|
|
|
|
|
ULONG onBreakpoint(const python::dict &bpParameters) {
|
|
|
|
return handler<const python::dict&>("onBreakpoint", bpParameters);
|
2011-10-12 15:11:54 +08:00
|
|
|
}
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
ULONG onException(const python::dict &exceptData) {
|
|
|
|
return handler<const python::dict&>("onException", exceptData);
|
2011-10-12 15:11:54 +08:00
|
|
|
}
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
ULONG onLoadModule(const Module &module) {
|
|
|
|
return handler<const Module&>("onLoadModule", module );
|
2011-10-12 15:11:54 +08:00
|
|
|
}
|
|
|
|
|
2011-10-14 15:03:51 +08:00
|
|
|
ULONG onUnloadModule(const Module &module) {
|
|
|
|
return handler<const Module&>("onUnloadModule", module );
|
2011-10-12 15:11:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ULONG onChangeSessionStatus( ULONG status ) {
|
|
|
|
return handler( "onChangeSessionStatus", status );
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG onChangeDebugeeState() {
|
|
|
|
return handler( "onChangeDebugeeState" );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
template<typename Arg1Type>
|
|
|
|
ULONG handler( const char* handlerName, Arg1Type arg1 )
|
|
|
|
{
|
2011-10-14 15:03:51 +08:00
|
|
|
if (python::override pythonHandler = get_override( handlerName ))
|
2011-10-12 15:11:54 +08:00
|
|
|
return pythonHandler(arg1);
|
|
|
|
|
|
|
|
return DEBUG_STATUS_NO_CHANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG handler( const char* handlerName )
|
|
|
|
{
|
2011-10-14 15:03:51 +08:00
|
|
|
if (python::override pythonHandler = get_override( handlerName ))
|
2011-10-12 15:11:54 +08:00
|
|
|
return pythonHandler();
|
|
|
|
|
|
|
|
return DEBUG_STATUS_NO_CHANGE;
|
|
|
|
}
|
2011-10-14 15:03:51 +08:00
|
|
|
};
|
2011-10-12 15:11:54 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2011-10-14 15:03:51 +08:00
|
|
|
|
|
|
|
}; // end namespace pykd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#include "dbgeventcb.h"
|
|
|
|
//#include "dbgmodule.h"
|
|
|
|
//#include "pyaux.h"
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
//class debugEvent : public DebugBaseEventCallbacks
|
|
|
|
//{
|
|
|
|
//public:
|
|
|
|
//
|
|
|
|
// debugEvent();
|
|
|
|
//
|
|
|
|
// virtual ~debugEvent();
|
|
|
|
//
|
|
|
|
// virtual ULONG onBreakpoint(boost::python::dict &/*bpParameters*/) = 0;
|
|
|
|
//
|
|
|
|
// virtual ULONG onException(boost::python::dict &/*exceptData*/) = 0;
|
|
|
|
//
|
|
|
|
// 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:
|
|
|
|
//
|
|
|
|
// STDMETHOD_(ULONG, AddRef)() { return 1; }
|
|
|
|
// STDMETHOD_(ULONG, Release)() { return 1; }
|
|
|
|
//
|
|
|
|
// STDMETHOD(GetInterestMask)(
|
|
|
|
// __out PULONG Mask
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// STDMETHOD(Breakpoint)(
|
|
|
|
// __in PDEBUG_BREAKPOINT Bp
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// STDMETHOD(Exception)(
|
|
|
|
// __in PEXCEPTION_RECORD64 Exception,
|
|
|
|
// __in ULONG FirstChance
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// STDMETHOD(SessionStatus)(
|
|
|
|
// __in ULONG Status
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// STDMETHOD(ChangeDebuggeeState)(
|
|
|
|
// __in ULONG Flags,
|
|
|
|
// __in ULONG64 Argument );
|
|
|
|
//
|
|
|
|
//private:
|
|
|
|
//
|
|
|
|
// IDebugClient *m_debugClient;
|
|
|
|
//};
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
//class debugEventWrap : public boost::python::wrapper<debugEvent>, public debugEvent
|
|
|
|
//{
|
|
|
|
//
|
|
|
|
//public:
|
|
|
|
//
|
|
|
|
// ULONG onBreakpoint(boost::python::dict &bpParameters) {
|
|
|
|
// return handler<boost::python::dict &>("onBreakpoint", bpParameters);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ULONG onException(boost::python::dict &exceptData) {
|
|
|
|
// return handler<boost::python::dict &>("onException", exceptData);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ULONG onLoadModule(const dbgModuleClass &module) {
|
|
|
|
// return handler<const dbgModuleClass &>("onLoadModule", module );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ULONG onUnloadModule(const dbgModuleClass &module) {
|
|
|
|
// return handler<const dbgModuleClass &>("onUnloadModule", module );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ULONG onChangeSessionStatus( ULONG status ) {
|
|
|
|
// return handler( "onChangeSessionStatus", status );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ULONG onChangeDebugeeState() {
|
|
|
|
// return handler( "onChangeDebugeeState" );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//private:
|
|
|
|
//
|
|
|
|
// template<typename Arg1Type>
|
|
|
|
// 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;
|
|
|
|
// }
|
|
|
|
//};
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|