[0.2.x] added : module obejcts cache

git-svn-id: https://pykd.svn.codeplex.com/svn@81471 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-11-26 06:32:19 +00:00 committed by Mikhail I. Izmestev
parent b7a7f97ea4
commit 00faeae705
4 changed files with 70 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#include "stdafx.h"
#include "eventhandler.h"
#include "module.h"
namespace pykd {
@ -56,6 +57,15 @@ DEBUG_CALLBACK_RESULT EventHandlerImpl::OnBreakpoint( ULONG bpId )
///////////////////////////////////////////////////////////////////////////////
DEBUG_CALLBACK_RESULT EventHandlerImpl::OnModuleUnload( ULONG64 offset, const std::string &name )
{
Module::onUnloadModule( offset );
return DebugCallbackNoChange;
}
///////////////////////////////////////////////////////////////////////////////
}; // namespace pykd

View File

@ -132,6 +132,8 @@ private:
virtual DEBUG_CALLBACK_RESULT OnBreakpoint( ULONG bpId );
virtual DEBUG_CALLBACK_RESULT OnModuleUnload( ULONG64 offset, const std::string &name );
private:
typedef std::map<ULONG, python::object> BpMap;

View File

@ -8,12 +8,58 @@ namespace pykd {
///////////////////////////////////////////////////////////////////////////////////
ModulePtr Module::loadModuleByName( const std::string &moduleName ) {
return ModulePtr( new Module( moduleName ) );
Module::ModuleList Module::m_moduleList;
///////////////////////////////////////////////////////////////////////////////////
ModulePtr Module::loadModuleByName( const std::string &moduleName )
{
ModuleList::iterator it;
for ( it = m_moduleList.begin(); it != m_moduleList.end(); ++it )
{
if ( (*it)->m_name == moduleName )
return *it;
}
ModulePtr modPtr = ModulePtr( new Module( moduleName ) );
m_moduleList.push_back( modPtr );
return modPtr;
};
ModulePtr Module::loadModuleByOffset( ULONG64 offset ) {
return ModulePtr( new Module( offset ) );
/////////////////////////////////////////////////////////////////////////////////////
ModulePtr Module::loadModuleByOffset( ULONG64 offset )
{
ModuleList::iterator it;
for ( it = m_moduleList.begin(); it != m_moduleList.end(); ++it )
{
if ( (*it)->m_base <= offset && offset < (*it)->m_base + (*it)->m_size )
return *it;
}
ModulePtr modPtr = ModulePtr( new Module( offset ) );
m_moduleList.push_back( modPtr );
return modPtr;
}
/////////////////////////////////////////////////////////////////////////////////////
void Module::onUnloadModule( ULONG64 offset )
{
ModuleList::iterator it;
for ( it = m_moduleList.begin(); it != m_moduleList.end(); ++it )
{
if ( (*it)->m_base == offset )
{
m_moduleList.erase( it );
return;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////

View File

@ -24,6 +24,14 @@ public:
static
ModulePtr loadModuleByOffset( ULONG64 offset );
static
void onUnloadModule( ULONG64 offset );
private:
typedef std::list<ModulePtr> ModuleList;
static ModuleList m_moduleList;
public:
Module(const std::string &name );