[0.1.x] added : method deref for typeInfo class

[0.1.x] added : method deref for typedVar class

git-svn-id: https://pykd.svn.codeplex.com/svn@73050 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-01-10 06:54:25 +00:00 committed by Mikhail I. Izmestev
parent 11960b2181
commit 4398021988
8 changed files with 82 additions and 12 deletions

View File

@ -469,7 +469,8 @@ BOOST_PYTHON_MODULE( pykd )
.def( "bitWidth", &TypeInfo::getBitWidth ) .def( "bitWidth", &TypeInfo::getBitWidth )
.def( "field", &TypeInfo::getField ) .def( "field", &TypeInfo::getField )
.def( "__getattr__", &TypeInfo::getField ) .def( "__getattr__", &TypeInfo::getField )
.def( "asMap", &TypeInfo::asMap ); .def( "asMap", &TypeInfo::asMap )
.def( "deref", &TypeInfo::deref );
python::class_<TypedVar, TypedVarPtr, python::bases<intBase>, boost::noncopyable >("typedVar", python::class_<TypedVar, TypedVarPtr, python::bases<intBase>, boost::noncopyable >("typedVar",
"Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance",
@ -480,8 +481,10 @@ BOOST_PYTHON_MODULE( pykd )
"Return size of a variable in the target memory" ) "Return size of a variable in the target memory" )
.def("offset", &TypedVar::getOffset, .def("offset", &TypedVar::getOffset,
"Return offset to parent" ) "Return offset to parent" )
.def("field", &TypedVar::getField, .def("field", &TypedVar::getField,
"Return field of structure as an object attribute" ) "Return field of structure as an object attribute" )
.def("deref", &TypedVar::deref,
"Return value by pointer" )
.def("__getattr__", &TypedVar::getField, .def("__getattr__", &TypedVar::getField,
"Return field of structure as an object attribute" ) "Return field of structure as an object attribute" )
.def( "__str__", &TypedVar::print ) .def( "__str__", &TypedVar::print )

View File

@ -180,9 +180,22 @@ Module::getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr )
TypedVarPtr TypedVarPtr
Module::getTypedVarByName( const std::string &symName ) Module::getTypedVarByName( const std::string &symName )
{ {
HRESULT hres;
pyDia::SymbolPtr typeSym = getDia()->getChildByName( symName ); pyDia::SymbolPtr typeSym = getDia()->getChildByName( symName );
return TypedVar::getTypedVar( m_client, TypeInfo::getTypeInfo( typeSym->getType() ), typeSym->getRva() + m_base ); std::string fullName = m_name;
fullName += '!';
fullName += symName;
ULONG64 offset;
hres = m_symbols->GetOffsetByName( fullName.c_str(), &offset );
if ( FAILED( hres ) )
throw DbgException("IDebugSymbols::GetOffsetByName failed" );
return TypedVar::getTypedVar( m_client, TypeInfo::getTypeInfo( typeSym->getType() ), offset );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -53,8 +53,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,0,4 FILEVERSION 0,1,0,5
PRODUCTVERSION 0,1,0,4 PRODUCTVERSION 0,1,0,5
FILEFLAGSMASK 0x17L FILEFLAGSMASK 0x17L
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -70,11 +70,11 @@ BEGIN
BLOCK "041904b0" BLOCK "041904b0"
BEGIN BEGIN
VALUE "FileDescription", "pykd - python extension for windbg" VALUE "FileDescription", "pykd - python extension for windbg"
VALUE "FileVersion", "0, 1, 0, 4" VALUE "FileVersion", "0, 1, 0, 5"
VALUE "InternalName", "pykd" VALUE "InternalName", "pykd"
VALUE "OriginalFilename", "pykd.dll" VALUE "OriginalFilename", "pykd.dll"
VALUE "ProductName", "pykd - python extension for windbg" VALUE "ProductName", "pykd - python extension for windbg"
VALUE "ProductVersion", "0, 1, 0, 4" VALUE "ProductVersion", "0, 1, 0, 5"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -131,6 +131,20 @@ BaseTypeVariant PtrTypedVar::getValue()
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
TypedVarPtr PtrTypedVar::deref()
{
HRESULT hres;
ULONG64 val = 0;
hres = m_dataSpaces->ReadPointersVirtual( 1, m_offset, &val );
if ( FAILED( hres ) )
throw MemoryException( m_offset, false );
return TypedVar::getTypedVar( m_client, m_typeInfo->deref(), val );
}
///////////////////////////////////////////////////////////////////////////////////
TypedVarPtr TypedVarPtr
UdtTypedVar::getField( const std::string &fieldName ) UdtTypedVar::getField( const std::string &fieldName )
{ {

View File

@ -37,7 +37,11 @@ public:
return m_typeInfo; return m_typeInfo;
} }
virtual TypedVarPtr getField( const std::string &fieldName ) { virtual TypedVarPtr deref() {
throw DbgException("object can not be derefernced" );
}
virtual TypedVarPtr getField( const std::string &fieldName ) {
throw DbgException("no fields"); throw DbgException("no fields");
} }
@ -106,7 +110,9 @@ public:
return "PtrTypedVar"; return "PtrTypedVar";
} }
virtual BaseTypeVariant getValue(); virtual TypedVarPtr deref();
virtual BaseTypeVariant getValue();
}; };

View File

@ -86,6 +86,10 @@ public:
throw DbgException( "there is no fields" ); throw DbgException( "there is no fields" );
} }
virtual TypeInfoPtr deref() {
throw DbgException( "type is not a pointer" );
}
ULONG getOffset() { ULONG getOffset() {
return m_offset; return m_offset;
} }
@ -282,6 +286,10 @@ public:
return true; return true;
} }
virtual TypeInfoPtr deref() {
return m_derefType;
}
TypeInfoPtr getDerefType() { TypeInfoPtr getDerefType() {
return m_derefType; return m_derefType;
} }

View File

@ -128,7 +128,6 @@ class TypedVarTest( unittest.TestCase ):
self.assertEqual( target.module.type("enumType").THREE, tv.m_enumField ) self.assertEqual( target.module.type("enumType").THREE, tv.m_enumField )
def testIndex(self): def testIndex(self):
ind = target.module.typedVar( "g_ucharValue" ) ind = target.module.typedVar( "g_ucharValue" )
self.assertEqual( 5, [0,5,10][ind] ) self.assertEqual( 5, [0,5,10][ind] )
@ -142,5 +141,15 @@ class TypedVarTest( unittest.TestCase ):
self.assertTrue( ind in { 1 : "1", 4 : "2" } ) self.assertTrue( ind in { 1 : "1", 4 : "2" } )
self.assertEqual( "2", { 1 : "1", 4 : "2" }[ind] ) self.assertEqual( "2", { 1 : "1", 4 : "2" }[ind] )
def testDeref(self):
tv = target.module.typedVar( "g_structTest1" )
self.assertEqual( target.module.g_structTest, tv.m_field4.deref().getAddress() )
tv = target.module.typedVar( "g_structTest" )
self.assertEqual( 0, tv.m_field4.deref().getAddress() )
try:
tv.m_field1.deref()
self.assertTrue(False)
except pykd.BaseException:
pass

View File

@ -105,3 +105,20 @@ class TypeInfoTest( unittest.TestCase ):
def testAsMap(self): def testAsMap(self):
ti = target.module.type("enumType") ti = target.module.type("enumType")
self.assertEqual( { 1 : "ONE", 2 : "TWO", 3 : "THREE" }, ti.asMap() ) self.assertEqual( { 1 : "ONE", 2 : "TWO", 3 : "THREE" }, ti.asMap() )
def testDeref(self):
ti = target.module.type("listStruct1")
self.assertEqual( "listStruct1", ti.next.deref().name() )
ti = target.module.type("listStruct1*")
self.assertEqual( "listStruct1", ti.deref().name() )
ti = target.module.type("classChild")
try:
ti.deref()
self.assertTrue(False)
except pykd.BaseException:
pass