mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[~] 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:
parent
f5e9108187
commit
33cf487b27
@ -8,16 +8,16 @@
|
|||||||
|
|
||||||
#include "dbgmodule.h"
|
#include "dbgmodule.h"
|
||||||
#include "dbgcallback.h"
|
#include "dbgcallback.h"
|
||||||
#include "dbgmodevent.h"
|
#include "dbgevent.h"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
moduleEvents::modCallbacksColl moduleEvents::modCallbacks;
|
debugEvent::modCallbacksColl debugEvent::modCallbacks;
|
||||||
moduleEvents::modCallbacksLock moduleEvents::modCallbacksMtx;
|
debugEvent::modCallbacksLock debugEvent::modCallbacksMtx;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
moduleEvents::moduleEvents()
|
debugEvent::debugEvent()
|
||||||
{
|
{
|
||||||
modCallbacksScopedLock lock(modCallbacksMtx);
|
modCallbacksScopedLock lock(modCallbacksMtx);
|
||||||
modCallbacks.insert(this);
|
modCallbacks.insert(this);
|
||||||
@ -25,7 +25,7 @@ moduleEvents::moduleEvents()
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
moduleEvents::~moduleEvents()
|
debugEvent::~debugEvent()
|
||||||
{
|
{
|
||||||
modCallbacksScopedLock lock(modCallbacksMtx);
|
modCallbacksScopedLock lock(modCallbacksMtx);
|
||||||
modCallbacks.erase(this);
|
modCallbacks.erase(this);
|
||||||
@ -33,7 +33,7 @@ moduleEvents::~moduleEvents()
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ULONG moduleEvents::onLoadModule(__in ULONG64 addr)
|
ULONG debugEvent::moduleLoaded(__in ULONG64 addr)
|
||||||
{
|
{
|
||||||
modCallbacksScopedLock lock(modCallbacksMtx);
|
modCallbacksScopedLock lock(modCallbacksMtx);
|
||||||
if (modCallbacks.empty())
|
if (modCallbacks.empty())
|
||||||
@ -51,7 +51,7 @@ ULONG moduleEvents::onLoadModule(__in ULONG64 addr)
|
|||||||
modCallbacksColl::iterator itCallback = modCallbacks.begin();
|
modCallbacksColl::iterator itCallback = modCallbacks.begin();
|
||||||
while (itCallback != modCallbacks.end())
|
while (itCallback != modCallbacks.end())
|
||||||
{
|
{
|
||||||
const ULONG retValue = (*itCallback)->onLoad(module);
|
const ULONG retValue = (*itCallback)->onLoadModule(module);
|
||||||
if (DEBUG_STATUS_NO_CHANGE != retValue)
|
if (DEBUG_STATUS_NO_CHANGE != retValue)
|
||||||
return 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);
|
modCallbacksScopedLock lock(modCallbacksMtx);
|
||||||
if (modCallbacks.empty())
|
if (modCallbacks.empty())
|
||||||
@ -80,7 +80,7 @@ ULONG moduleEvents::onUnloadModule(__in ULONG64 addr)
|
|||||||
modCallbacksColl::iterator itCallback = modCallbacks.begin();
|
modCallbacksColl::iterator itCallback = modCallbacks.begin();
|
||||||
while (itCallback != modCallbacks.end())
|
while (itCallback != modCallbacks.end())
|
||||||
{
|
{
|
||||||
const ULONG retValue = (*itCallback)->onUnload(module);
|
const ULONG retValue = (*itCallback)->onUnloadModule(module);
|
||||||
if (DEBUG_STATUS_NO_CHANGE != retValue)
|
if (DEBUG_STATUS_NO_CHANGE != retValue)
|
||||||
return retValue;
|
return retValue;
|
||||||
|
|
||||||
@ -91,26 +91,22 @@ ULONG moduleEvents::onUnloadModule(__in ULONG64 addr)
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ULONG moduleEventsWrap::onLoad(
|
ULONG debugEventWrap::onLoadModule(const dbgModuleClass &module)
|
||||||
const dbgModuleClass &module
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (boost::python::override override = get_override("onLoad"))
|
if (boost::python::override override = get_override("onLoadModule"))
|
||||||
return override(module);
|
return override(module);
|
||||||
|
|
||||||
return moduleEvents::onLoad(module);
|
return debugEvent::onLoadModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ULONG moduleEventsWrap::onUnload(
|
ULONG debugEventWrap::onUnloadModule(const dbgModuleClass &module)
|
||||||
const dbgModuleClass &module
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
if (boost::python::override override = get_override("onUnload"))
|
if (boost::python::override override = get_override("onUnloadModule"))
|
||||||
return override(module);
|
return override(module);
|
||||||
|
|
||||||
return moduleEvents::onUnload(module);
|
return debugEvent::onUnloadModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
54
pykd/dbgevent.h
Normal file
54
pykd/dbgevent.h
Normal 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
@ -7,7 +7,7 @@
|
|||||||
#include "dbgmodule.h"
|
#include "dbgmodule.h"
|
||||||
#include "dbgsynsym.h"
|
#include "dbgsynsym.h"
|
||||||
#include "dbgbreak.h"
|
#include "dbgbreak.h"
|
||||||
#include "dbgmodevent.h"
|
#include "dbgevent.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ HRESULT DbgEventCallbacksManager::LoadModule(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return moduleEvents::onLoadModule(BaseOffset);
|
return debugEvent::moduleLoaded(BaseOffset);
|
||||||
}
|
}
|
||||||
catch (std::exception &)
|
catch (std::exception &)
|
||||||
{
|
{
|
||||||
@ -136,7 +136,7 @@ HRESULT DbgEventCallbacksManager::UnloadModule(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return moduleEvents::onUnloadModule(BaseOffset);
|
return debugEvent::moduleUnloaded(BaseOffset);
|
||||||
}
|
}
|
||||||
catch (std::exception &)
|
catch (std::exception &)
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include "dbgprocess.h"
|
#include "dbgprocess.h"
|
||||||
#include "dbgsynsym.h"
|
#include "dbgsynsym.h"
|
||||||
#include "dbgclient.h"
|
#include "dbgclient.h"
|
||||||
#include "dbgmodevent.h"
|
#include "dbgevent.h"
|
||||||
#include "dbgbreak.h"
|
#include "dbgbreak.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
@ -332,29 +332,29 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def( "__str__", &dbgBreakpointClass::print,
|
.def( "__str__", &dbgBreakpointClass::print,
|
||||||
"Return a nice string represention of the breakpoint class" );
|
"Return a nice string represention of the breakpoint class" );
|
||||||
|
|
||||||
boost::python::class_<moduleEventsWrap, boost::noncopyable>( "modEvents",
|
boost::python::class_<debugEventWrap, boost::noncopyable>( "debugEvent",
|
||||||
"Class for processing of events: loading and unloading modules" )
|
"Base class for debug events handlers" )
|
||||||
.def( "onLoad", &moduleEvents::onLoad, &moduleEventsWrap::onLoadDef,
|
.def( "onLoadModule", &debugEvent::onLoadModule, &debugEventWrap::onLoadModuleDef,
|
||||||
"Load module event. Parameter is instance of dbgModuleClass. "
|
"Load module event. Parameter is instance of dbgModuleClass. "
|
||||||
"For ignore event method must return DEBUG_STATUS_NO_CHANGE value" )
|
"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. "
|
"Unload module event. Parameter is instance of dbgModuleClass. "
|
||||||
"For ignore event method must return DEBUG_STATUS_NO_CHANGE value" );
|
"For ignore event method must return DEBUG_STATUS_NO_CHANGE value" );
|
||||||
|
|
||||||
// èñêëþ÷åíèÿ
|
// èñêëþ÷åíèÿ
|
||||||
boost::python::class_<DbgException> dbgExceptionClass( "BaseException",
|
boost::python::class_<DbgException> dbgExceptionClass( "BaseException",
|
||||||
"Pykd base exception class",
|
"Pykd base exception class",
|
||||||
boost::python::no_init );
|
boost::python::no_init );
|
||||||
//boost::python::init<std::string>() );
|
//boost::python::init<std::string>() );
|
||||||
|
|
||||||
dbgExceptionClass
|
dbgExceptionClass
|
||||||
.def( boost::python::init<std::string>( boost::python::args("desc"), "constructor" ) )
|
.def( boost::python::init<std::string>( boost::python::args("desc"), "constructor" ) )
|
||||||
.def( "desc", &DbgException::getDesc,
|
.def( "desc", &DbgException::getDesc,
|
||||||
"Get exception description" );
|
"Get exception description" );
|
||||||
|
|
||||||
boost::python::class_<TypeException, boost::python::bases<DbgException> > typeExceptionClass( "TypeException",
|
boost::python::class_<TypeException, boost::python::bases<DbgException> > typeExceptionClass( "TypeException",
|
||||||
"Type exception class",
|
"Type exception class",
|
||||||
boost::python::no_init );
|
boost::python::no_init );
|
||||||
|
|
||||||
boost::python::class_<MemoryException, boost::python::bases<DbgException> > memoryExceptionClass( "MemoryException",
|
boost::python::class_<MemoryException, boost::python::bases<DbgException> > memoryExceptionClass( "MemoryException",
|
||||||
"Memory exception class",
|
"Memory exception class",
|
||||||
@ -365,7 +365,7 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def( "getAddress", &MemoryException::getAddress,
|
.def( "getAddress", &MemoryException::getAddress,
|
||||||
"Return target address" );
|
"Return target address" );
|
||||||
|
|
||||||
baseExceptionType = dbgExceptionClass.ptr();
|
baseExceptionType = dbgExceptionClass.ptr();
|
||||||
typeExceptionType = typeExceptionClass.ptr();
|
typeExceptionType = typeExceptionClass.ptr();
|
||||||
memoryExceptionType = memoryExceptionClass.ptr();
|
memoryExceptionType = memoryExceptionClass.ptr();
|
||||||
|
|
||||||
@ -373,7 +373,7 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
boost::python::register_exception_translator<TypeException>( &TypeException::exceptionTranslate );
|
boost::python::register_exception_translator<TypeException>( &TypeException::exceptionTranslate );
|
||||||
boost::python::register_exception_translator<IndexException>( &IndexException::translate);
|
boost::python::register_exception_translator<IndexException>( &IndexException::translate);
|
||||||
boost::python::register_exception_translator<MemoryException>( &MemoryException::translate );
|
boost::python::register_exception_translator<MemoryException>( &MemoryException::translate );
|
||||||
|
|
||||||
|
|
||||||
// debug status
|
// debug status
|
||||||
DEF_PY_CONST(DEBUG_STATUS_NO_CHANGE);
|
DEF_PY_CONST(DEBUG_STATUS_NO_CHANGE);
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
@ -0,0 +1 @@
|
|||||||
|
#include "stdafx.h"
|
@ -385,7 +385,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgmodevent.cpp"
|
RelativePath=".\dbgevent.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -511,7 +511,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgmodevent.h"
|
RelativePath=".\dbgevent.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -357,6 +357,10 @@
|
|||||||
RelativePath=".\dbgdump.cpp"
|
RelativePath=".\dbgdump.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\dbgevent.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgeventcb.cpp"
|
RelativePath=".\dbgeventcb.cpp"
|
||||||
>
|
>
|
||||||
@ -373,10 +377,6 @@
|
|||||||
RelativePath=".\dbgmem.cpp"
|
RelativePath=".\dbgmem.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\dbgmodevent.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgmodule.cpp"
|
RelativePath=".\dbgmodule.cpp"
|
||||||
>
|
>
|
||||||
@ -413,6 +413,10 @@
|
|||||||
RelativePath=".\dbgtype.cpp"
|
RelativePath=".\dbgtype.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\pykd.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\pykd.def"
|
RelativePath=".\pykd.def"
|
||||||
>
|
>
|
||||||
@ -479,6 +483,10 @@
|
|||||||
RelativePath=".\dbgdump.h"
|
RelativePath=".\dbgdump.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\dbgevent.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgeventcb.h"
|
RelativePath=".\dbgeventcb.h"
|
||||||
>
|
>
|
||||||
@ -499,10 +507,6 @@
|
|||||||
RelativePath=".\dbgmem.h"
|
RelativePath=".\dbgmem.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\dbgmodevent.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\dbgmodule.h"
|
RelativePath=".\dbgmodule.h"
|
||||||
>
|
>
|
||||||
|
@ -6,19 +6,19 @@ from pykd import *
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class modLoad(modEvents):
|
class loadHandler(debugEvent):
|
||||||
def __init__(self, mask):
|
def __init__(self, mask):
|
||||||
modEvents.__init__(self)
|
debugEvent.__init__(self)
|
||||||
self.mask = mask
|
self.mask = mask
|
||||||
|
|
||||||
def onLoad(self, module):
|
def onLoadModule(self, module):
|
||||||
if fnmatch.fnmatch( module.name(), self.mask ):
|
if fnmatch.fnmatch( module.name(), self.mask ):
|
||||||
return DEBUG_STATUS_BREAK
|
return DEBUG_STATUS_BREAK
|
||||||
return DEBUG_STATUS_NO_CHANGE
|
return DEBUG_STATUS_NO_CHANGE
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
loadHandler = modLoad( sys.argv[1] )
|
loadHandler = loadHandler( sys.argv[1] )
|
||||||
go()
|
go()
|
||||||
else:
|
else:
|
||||||
dprintln( "Wait (execute) for load target module\nInvalid command line" )
|
dprintln( "Wait (execute) for load target module\nInvalid command line" )
|
||||||
|
Loading…
Reference in New Issue
Block a user