[pykd] added: TypedVar instantiation by symbol name or by address

[test] added : testTypedVarByAddress and testTypedVarBySymbolName for above-mentioned functionality. 

git-svn-id: https://pykd.svn.codeplex.com/svn@69328 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\air_max_cp 2011-08-25 23:30:53 +00:00
parent eeac3d5a80
commit f443f0cbe2
4 changed files with 59 additions and 0 deletions

View File

@ -260,6 +260,10 @@ BOOST_PYTHON_MODULE( pykd )
"constructor" ) )
.def(boost::python::init<std::string,std::string,ULONG64>(boost::python::args("moduleName", "typeName", "address"),
"constructor" ) )
.def(boost::python::init<ULONG64>(boost::python::args("address"),
"constructor" ) )
.def(boost::python::init<std::string>(boost::python::args("symbolName"),
"constructor" ) )
.def("getAddress", &TypedVar::getAddress,
"Return virtual address" )
.def("sizeof", &TypedVar::getSize,

View File

@ -807,6 +807,49 @@ TypeInfo::printField( size_t index, void* buffer, size_t bufferLength ) const
///////////////////////////////////////////////////////////////////////////////////
TypedVar::TypedVar( ULONG64 targetOffset ) :
m_targetOffset( addr64(targetOffset) )
{
HRESULT hres;
ULONG typeId;
ULONG64 module;
hres = dbgExt->symbols->GetOffsetTypeId( m_targetOffset, &typeId, &module );
if ( FAILED( hres ) )
throw TypeException();
char moduleName[0x100];
hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, DEBUG_ANY_ID, module,
moduleName, sizeof( moduleName ), NULL );
if ( FAILED( hres ) )
throw TypeException();
m_typeInfo = TypeInfo( moduleName , addr64(module), typeId );
}
///////////////////////////////////////////////////////////////////////////////////
TypedVar::TypedVar( const std::string &symbolName )
{
HRESULT hres;
ULONG typeId;
ULONG64 module;
hres = dbgExt->symbols->GetSymbolTypeId( symbolName.c_str(), &typeId, &module );
if ( FAILED( hres ) )
throw TypeException();
char moduleName[0x100];
hres = dbgExt->symbols2->GetModuleNameString( DEBUG_MODNAME_MODULE, DEBUG_ANY_ID, module,
moduleName, sizeof( moduleName ), NULL );
if ( FAILED( hres ) )
throw TypeException();
m_typeInfo = TypeInfo( moduleName , addr64(module), typeId );
}
///////////////////////////////////////////////////////////////////////////////////
TypedVar::TypedVar( const TypeInfo &typeInfo, ULONG64 targetOffset, char* buffer, size_t bufferLength ) :
m_typeInfo( typeInfo ),
m_targetOffset( addr64(targetOffset) )

View File

@ -218,6 +218,10 @@ public:
m_targetOffset( addr64(targetOffset) )
{}
TypedVar( ULONG64 targetOffset );
TypedVar( const std::string &symbolName );
ULONG64
getAddress() const {
return m_targetOffset;

View File

@ -69,3 +69,11 @@ class TypeInfoTest( unittest.TestCase ):
self.assertEqual( v7.field1[5].field2, 20 )
self.assertEqual( v7.field2[1][0].field1, 10 )
self.assertEqual( v7.field2[0][1].field2, 20 )
def testTypedVarByAddress(self):
var5 = pykd.typedVar( pykd.getOffset( target.moduleName, "Namespace3::var5" ) )
self.assertEqual( var5.m_field1, 5 )
def testTypedVarBySymbolName(self):
var5 = pykd.typedVar( "Namespace3::var5" )
self.assertEqual( var5.m_field1, 5 )