mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[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:
parent
11960b2181
commit
4398021988
@ -469,7 +469,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
.def( "bitWidth", &TypeInfo::getBitWidth )
|
||||
.def( "field", &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",
|
||||
"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" )
|
||||
.def("offset", &TypedVar::getOffset,
|
||||
"Return offset to parent" )
|
||||
.def("field", &TypedVar::getField,
|
||||
.def("field", &TypedVar::getField,
|
||||
"Return field of structure as an object attribute" )
|
||||
.def("deref", &TypedVar::deref,
|
||||
"Return value by pointer" )
|
||||
.def("__getattr__", &TypedVar::getField,
|
||||
"Return field of structure as an object attribute" )
|
||||
.def( "__str__", &TypedVar::print )
|
||||
|
@ -180,9 +180,22 @@ Module::getTypedVarByType( const TypeInfoPtr &typeInfo, ULONG64 addr )
|
||||
TypedVarPtr
|
||||
Module::getTypedVarByName( const std::string &symName )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -53,8 +53,8 @@ END
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 0,1,0,4
|
||||
PRODUCTVERSION 0,1,0,4
|
||||
FILEVERSION 0,1,0,5
|
||||
PRODUCTVERSION 0,1,0,5
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -70,11 +70,11 @@ BEGIN
|
||||
BLOCK "041904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "pykd - python extension for windbg"
|
||||
VALUE "FileVersion", "0, 1, 0, 4"
|
||||
VALUE "FileVersion", "0, 1, 0, 5"
|
||||
VALUE "InternalName", "pykd"
|
||||
VALUE "OriginalFilename", "pykd.dll"
|
||||
VALUE "ProductName", "pykd - python extension for windbg"
|
||||
VALUE "ProductVersion", "0, 1, 0, 4"
|
||||
VALUE "ProductVersion", "0, 1, 0, 5"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
@ -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
|
||||
UdtTypedVar::getField( const std::string &fieldName )
|
||||
{
|
||||
|
@ -37,7 +37,11 @@ public:
|
||||
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");
|
||||
}
|
||||
|
||||
@ -106,7 +110,9 @@ public:
|
||||
return "PtrTypedVar";
|
||||
}
|
||||
|
||||
virtual BaseTypeVariant getValue();
|
||||
virtual TypedVarPtr deref();
|
||||
|
||||
virtual BaseTypeVariant getValue();
|
||||
|
||||
};
|
||||
|
||||
|
@ -86,6 +86,10 @@ public:
|
||||
throw DbgException( "there is no fields" );
|
||||
}
|
||||
|
||||
virtual TypeInfoPtr deref() {
|
||||
throw DbgException( "type is not a pointer" );
|
||||
}
|
||||
|
||||
ULONG getOffset() {
|
||||
return m_offset;
|
||||
}
|
||||
@ -282,6 +286,10 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual TypeInfoPtr deref() {
|
||||
return m_derefType;
|
||||
}
|
||||
|
||||
TypeInfoPtr getDerefType() {
|
||||
return m_derefType;
|
||||
}
|
||||
|
@ -128,7 +128,6 @@ class TypedVarTest( unittest.TestCase ):
|
||||
self.assertEqual( target.module.type("enumType").THREE, tv.m_enumField )
|
||||
|
||||
def testIndex(self):
|
||||
|
||||
ind = target.module.typedVar( "g_ucharValue" )
|
||||
self.assertEqual( 5, [0,5,10][ind] )
|
||||
|
||||
@ -142,5 +141,15 @@ class TypedVarTest( unittest.TestCase ):
|
||||
self.assertTrue( ind in { 1 : "1", 4 : "2" } )
|
||||
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
|
||||
|
@ -105,3 +105,20 @@ class TypeInfoTest( unittest.TestCase ):
|
||||
def testAsMap(self):
|
||||
ti = target.module.type("enumType")
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user