[~] moduleEvents renamed to debugEvent. now it is base class of all debug events

git-svn-id: https://pykd.svn.codeplex.com/svn@65734 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-05-23 11:35:43 +00:00
parent f5e9108187
commit 33cf487b27
9 changed files with 105 additions and 103 deletions

View File

@ -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);
}
/////////////////////////////////////////////////////////////////////////////////

54
pykd/dbgevent.h Normal file
View File

@ -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);
}
};
/////////////////////////////////////////////////////////////////////////////////

View File

@ -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 &)
{

View File

@ -28,7 +28,7 @@
#include "dbgprocess.h"
#include "dbgsynsym.h"
#include "dbgclient.h"
#include "dbgmodevent.h"
#include "dbgevent.h"
#include "dbgbreak.h"
//////////////////////////////////////////////////////////////////////////////
@ -332,12 +332,12 @@ 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" );

View File

@ -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);
}
};
/////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1 @@
#include "stdafx.h"

View File

@ -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

View File

@ -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"
>

View File

@ -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" )