From 1e4f7166b8186666c15b78911de47fecbaf229a5 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Tue, 27 Nov 2012 11:52:50 +0000 Subject: [PATCH] [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 --- pykd/eventhandler.cpp | 9 --- pykd/eventhandler.h | 2 - pykd/module.cpp | 130 ++++++++++++++++++++++++------------------ pykd/module.h | 30 ++++++++-- 4 files changed, 98 insertions(+), 73 deletions(-) diff --git a/pykd/eventhandler.cpp b/pykd/eventhandler.cpp index 9c7af3c..784545c 100644 --- a/pykd/eventhandler.cpp +++ b/pykd/eventhandler.cpp @@ -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 diff --git a/pykd/eventhandler.h b/pykd/eventhandler.h index 990e396..4ee4a17 100644 --- a/pykd/eventhandler.h +++ b/pykd/eventhandler.h @@ -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 BpMap; diff --git a/pykd/module.cpp b/pykd/module.cpp index d5f0af4..61c0659 100644 --- a/pykd/module.cpp +++ b/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() diff --git a/pykd/module.h b/pykd/module.h index 46c5b4e..946774a 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -24,13 +24,33 @@ public: static ModulePtr loadModuleByOffset( ULONG64 offset ); - static - void onUnloadModule( ULONG64 offset ); - private: - typedef std::list 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 SymbolSessionCache; + static SymbolSessionCache m_symSessionCache; + + SymbolSessionPtr getFromCache(); public: