[0.2.x] updated : change module caching into symbol file caching

git-svn-id: https://pykd.svn.codeplex.com/svn@81521 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-11-27 11:52:50 +00:00 committed by Mikhail I. Izmestev
parent b8811c8554
commit 1e4f7166b8
4 changed files with 98 additions and 73 deletions

View File

@ -58,15 +58,6 @@ 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 }; // namespace pykd

View File

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

View File

@ -8,58 +8,20 @@ namespace pykd {
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
Module::ModuleList Module::m_moduleList; Module::SymbolSessionCache Module::m_symSessionCache;
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
ModulePtr Module::loadModuleByName( const std::string &moduleName ) ModulePtr Module::loadModuleByName( const std::string &moduleName )
{ {
return ModulePtr( new Module( 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 ) ModulePtr Module::loadModuleByOffset( ULONG64 offset )
{ {
ModuleList::iterator it; return ModulePtr( new Module( offset ) );
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;
}
}
} }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
@ -93,39 +55,93 @@ SymbolSessionPtr& Module::getSymSession()
if (m_symSession) if (m_symSession)
return m_symSession; return m_symSession;
SymbolMapKey cacheKey = { m_size, m_timeDataStamp, m_checkSum };
SymbolSessionCache::iterator found = m_symSessionCache.find( cacheKey );
if ( found != m_symSessionCache.end() )
{
m_symSession = found->second;
return m_symSession;
}
try try
{ {
m_symSession = loadSymbolFile(m_base, m_imageName, m_symfile); m_symSession = loadSymbolFile( m_base, m_imageName, m_symfile);
} }
catch(const SymbolException &e) catch(const SymbolException &)
{ {
DBG_UNREFERENCED_LOCAL_VARIABLE(e);
} }
if (m_symSession) if (m_symSession)
{
m_symSessionCache.insert( std::make_pair( cacheKey, m_symSession ) );
return m_symSession; return m_symSession;
}
// TODO: read image file path and load using IDiaReadExeAtOffsetCallback // TODO: read image file path and load using IDiaReadExeAtOffsetCallback
m_symfile = getModuleSymbolFileName(m_base); m_symfile = getModuleSymbolFileName(m_base);
if (!m_symfile.empty()) if (m_symfile.empty())
{ throw SymbolException( "failed to find symbol file" );
try
{
m_symSession = loadSymbolFile(m_symfile, m_base);
}
catch(const SymbolException &e)
{
DBG_UNREFERENCED_LOCAL_VARIABLE(e);
}
if (m_symSession)
return m_symSession;
m_symfile.clear(); try
{
m_symSession = loadSymbolFile(m_symfile, m_base);
} }
catch(const SymbolException&)
{
}
if (m_symSession)
{
m_symSessionCache.insert( std::make_pair( cacheKey, m_symSession ) );
return m_symSession;
}
m_symfile.clear();
throw SymbolException( "failed to load symbol file" ); throw SymbolException( "failed to load symbol file" );
} }
/////////////////////////////////////////////////////////////////////////////////////
// std::string m_symfile;
//ULONG64 m_base;
//ULONG m_size;
//ULONG m_timeDataStamp;
//ULONG m_checkSum;
//try
//{
// m_symSession = loadSymbolFile(m_base, m_imageName, m_symfile);
//}
//catch(const SymbolException &e)
//{
// DBG_UNREFERENCED_LOCAL_VARIABLE(e);
//}
//if (m_symSession)
// return m_symSession;
//// TODO: read image file path and load using IDiaReadExeAtOffsetCallback
//m_symfile = getModuleSymbolFileName(m_base);
//if (!m_symfile.empty())
//{
// try
// {
// m_symSession = loadSymbolFile(m_symfile, m_base);
// }
// catch(const SymbolException &e)
// {
// DBG_UNREFERENCED_LOCAL_VARIABLE(e);
// }
// if (m_symSession)
// return m_symSession;
// m_symfile.clear();
//}
//throw SymbolException( "failed to load symbol file" );
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
SymbolPtr& Module::getSymScope() SymbolPtr& Module::getSymScope()

View File

@ -24,13 +24,33 @@ public:
static static
ModulePtr loadModuleByOffset( ULONG64 offset ); ModulePtr loadModuleByOffset( ULONG64 offset );
static
void onUnloadModule( ULONG64 offset );
private: private:
typedef std::list<ModulePtr> ModuleList; struct SymbolMapKey{
static ModuleList m_moduleList; ULONG size;
ULONG timeStamp;
ULONG checkSum;
bool operator < ( const SymbolMapKey& key ) const
{
if ( size < key.size )
return true;
if ( size > key.size )
return false;
if ( timeStamp < key.timeStamp )
return true;
if ( timeStamp > key.timeStamp )
return false;
return checkSum < key.checkSum;
}
};
typedef std::map<SymbolMapKey,SymbolSessionPtr> SymbolSessionCache;
static SymbolSessionCache m_symSessionCache;
SymbolSessionPtr getFromCache();
public: public: