mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 11:53:23 +08:00
[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:
parent
b8811c8554
commit
1e4f7166b8
@ -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
|
||||
|
||||
|
||||
|
@ -134,8 +134,6 @@ 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;
|
||||
|
130
pykd/module.cpp
130
pykd/module.cpp
@ -8,58 +8,20 @@ namespace pykd {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Module::ModuleList Module::m_moduleList;
|
||||
Module::SymbolSessionCache Module::m_symSessionCache;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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;
|
||||
return ModulePtr( new Module( moduleName ) );
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
return ModulePtr( new Module( offset ) );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -93,39 +55,93 @@ SymbolSessionPtr& Module::getSymSession()
|
||||
if (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
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_symSessionCache.insert( std::make_pair( cacheKey, 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;
|
||||
if (m_symfile.empty())
|
||||
throw SymbolException( "failed to find symbol file" );
|
||||
|
||||
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" );
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// 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()
|
||||
|
@ -24,13 +24,33 @@ public:
|
||||
static
|
||||
ModulePtr loadModuleByOffset( ULONG64 offset );
|
||||
|
||||
static
|
||||
void onUnloadModule( ULONG64 offset );
|
||||
|
||||
private:
|
||||
|
||||
typedef std::list<ModulePtr> ModuleList;
|
||||
static ModuleList m_moduleList;
|
||||
struct SymbolMapKey{
|
||||
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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user