[[0.1.x] updated : module class integrated with Dia

git-svn-id: https://pykd.svn.codeplex.com/svn@70036 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-09-26 08:46:32 +00:00 committed by Mikhail I. Izmestev
parent c6a92278cf
commit dbb9782404
5 changed files with 107 additions and 34 deletions

View File

@ -124,10 +124,15 @@ BOOST_PYTHON_MODULE( pykd )
"Return size of the module" ) "Return size of the module" )
.def("name", &pykd::Module::getName, .def("name", &pykd::Module::getName,
"Return name of the module" ) "Return name of the module" )
.def("image", &pykd::Module::getImageName,
"Return name of the image of the module" )
.def("pdb", &pykd::Module::getPdbName, .def("pdb", &pykd::Module::getPdbName,
"Return the full path to the module's pdb file ( symbol information )" ) "Return the full path to the module's pdb file ( symbol information )" )
.def("reload", &pykd::Module::reloadSymbols, .def("reload", &pykd::Module::reloadSymbols,
"(Re)load symbols for the module" ); "(Re)load symbols for the module" )
.def("symbols", &pykd::Module::getSymbols,
"Return list of all symbols of the module" );
python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb, python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb,
"Open pdb file for quering debug symbols. Return DiaSymbol of global scope"); "Open pdb file for quering debug symbols. Return DiaSymbol of global scope");

View File

@ -36,6 +36,21 @@ Module::Module( IDebugClient5 *client, const std::string& moduleName ) : DbgObje
throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); throw DbgException( "IDebugSymbol::GetModuleParameters failed" );
m_size = moduleParam.Size; m_size = moduleParam.Size;
char imageName[0x100];
hres = m_symbols->GetModuleNameString(
DEBUG_MODNAME_IMAGE,
DEBUG_ANY_ID,
m_base,
imageName,
sizeof( imageName ),
NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::GetModuleNameString failed" );
m_imageName = std::string( imageName );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -66,6 +81,21 @@ Module::Module( IDebugClient5 *client, ULONG64 offset ) : DbgObject( client )
m_name = std::string( moduleName ); m_name = std::string( moduleName );
char imageName[0x100];
hres = m_symbols->GetModuleNameString(
DEBUG_MODNAME_IMAGE,
DEBUG_ANY_ID,
m_base,
imageName,
sizeof( imageName ),
NULL );
if ( FAILED( hres ) )
throw DbgException( "IDebugSymbol::GetModuleNameString failed" );
m_imageName = std::string( imageName );
DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; DEBUG_MODULE_PARAMETERS moduleParam = { 0 };
hres = m_symbols->GetModuleParameters( 1, &m_base, 0, &moduleParam ); hres = m_symbols->GetModuleParameters( 1, &m_base, 0, &moduleParam );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
@ -76,7 +106,7 @@ Module::Module( IDebugClient5 *client, ULONG64 offset ) : DbgObject( client )
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
std::wstring std::string
Module::getPdbName() Module::getPdbName()
{ {
HRESULT hres; HRESULT hres;
@ -97,7 +127,10 @@ Module::getPdbName()
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException( "IDebugAdvanced2::GetSymbolInformation failed" ); throw DbgException( "IDebugAdvanced2::GetSymbolInformation failed" );
return std::wstring( moduleInfo.LoadedPdbName ); char pdbName[ 256 ];
WideCharToMultiByte( CP_ACP, 0, moduleInfo.LoadedPdbName, 256, pdbName, 256, NULL, NULL );
return std::string( pdbName );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -107,10 +140,14 @@ Module::reloadSymbols()
{ {
HRESULT hres; HRESULT hres;
hres = m_symbols->Reload( "/f" ); std::string param = "/f ";
param += m_imageName;
hres = m_symbols->Reload( param.c_str() );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException("IDebugSymbols::Reload failed" ); throw DbgException("IDebugSymbols::Reload failed" );
m_dia = pyDia::GlobalScope::loadPdb( getPdbName() );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -3,6 +3,7 @@
#include <string> #include <string>
#include "dbgobj.h" #include "dbgobj.h"
#include "diawrapper.h"
namespace pykd { namespace pykd {
@ -20,6 +21,10 @@ public:
return m_name; return m_name;
} }
std::string getImageName() {
return m_imageName;
}
ULONG64 getBase() { ULONG64 getBase() {
return m_base; return m_base;
} }
@ -32,17 +37,28 @@ public:
return m_size; return m_size;
} }
std::wstring std::string
getPdbName(); getPdbName();
void void
reloadSymbols(); reloadSymbols();
python::list
getSymbols() {
if ( !m_dia )
m_dia = pyDia::GlobalScope::loadPdb( getPdbName() );
return m_dia->findChildrenEx( SymTagNull, "*", nsRegularExpression );
}
private: private:
std::string m_name; std::string m_name;
std::string m_imageName;
ULONG64 m_base; ULONG64 m_base;
ULONG m_size; ULONG m_size;
pyDia::GlobalScopePtr m_dia;
}; };

View File

@ -7,6 +7,12 @@ import target
import pykd import pykd
class DiaTest( unittest.TestCase ): class DiaTest( unittest.TestCase ):
def testCtor(self):
""" DiaSymbol can not be created direct """
try: pykd.DiaSymbol()
except RuntimeError: pass
def testFind(self): def testFind(self):
try: try:
gScope = pykd.diaLoadPdb( str(target.module.pdb()) ) gScope = pykd.diaLoadPdb( str(target.module.pdb()) )

View File

@ -9,7 +9,9 @@ import pykd
class ModuleTest( unittest.TestCase ): class ModuleTest( unittest.TestCase ):
def testCtor( self ): def testCtor( self ):
self.assertRaises( RuntimeError, pykd.module ) " module class can not be created direct """
try: pykd.module()
except RuntimeError: pass
def testName( self ): def testName( self ):
self.assertEqual( target.moduleName, target.module.name() ) self.assertEqual( target.moduleName, target.module.name() )
@ -24,7 +26,10 @@ class ModuleTest( unittest.TestCase ):
self.assertEqual( target.module.size(), target.module.end() - target.module.begin() ) self.assertEqual( target.module.size(), target.module.end() - target.module.begin() )
def testPdb( self ): def testPdb( self ):
self.assertNotEqual( "", target.module.pdb() ); self.assertNotEqual( "", target.module.pdb() )
def testImage( self ):
self.assertEqual( target.module.name() + ".exe", target.module.image() )
def testFindModule( self ): def testFindModule( self ):
@ -40,3 +45,7 @@ class ModuleTest( unittest.TestCase ):
try: pykd.findModule( target.module.end() + 0x10) try: pykd.findModule( target.module.end() + 0x10)
except pykd.BaseException: pass except pykd.BaseException: pass
def testSymbols( self ):
syms = target.module.symbols()
self.assertNotEqual( 0, len( syms ) )