mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[0.1.x] fixed : typedVar can nor be used as a index
git-svn-id: https://pykd.svn.codeplex.com/svn@72759 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
dd66507b4b
commit
2d141abec2
@ -132,7 +132,8 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def( "__str__", &intBase::str )
|
.def( "__str__", &intBase::str )
|
||||||
.def( "__hex__", &intBase::hex )
|
.def( "__hex__", &intBase::hex )
|
||||||
.def( "__long__", &intBase::long_ )
|
.def( "__long__", &intBase::long_ )
|
||||||
.def( "__int__", &intBase::int_ );
|
.def( "__int__", &intBase::int_ )
|
||||||
|
.def( "__index__", &intBase::long_ );
|
||||||
|
|
||||||
python::class_<DebugClient, DebugClientPtr>("dbgClient", "Class representing a debugging session", python::no_init )
|
python::class_<DebugClient, DebugClientPtr>("dbgClient", "Class representing a debugging session", python::no_init )
|
||||||
.def( "addr64", &DebugClient::addr64,
|
.def( "addr64", &DebugClient::addr64,
|
||||||
@ -483,7 +484,8 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Return field of structure as an object attribute" )
|
"Return field of structure as an object attribute" )
|
||||||
.def( "__str__", &TypedVar::print )
|
.def( "__str__", &TypedVar::print )
|
||||||
.def("__len__", &TypedVar::getElementCount )
|
.def("__len__", &TypedVar::getElementCount )
|
||||||
.def("__getitem__", &TypedVar::getElementByIndex );
|
.def("__getitem__", &TypedVar::getElementByIndex )
|
||||||
|
.def("__getitem__", &TypedVar::getElementByIndexPtr );
|
||||||
|
|
||||||
python::class_<Module, python::bases<intBase> >("module", "Class representing executable module", python::no_init )
|
python::class_<Module, python::bases<intBase> >("module", "Class representing executable module", python::no_init )
|
||||||
.def("begin", &Module::getBase,
|
.def("begin", &Module::getBase,
|
||||||
|
@ -26,8 +26,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VariantToPyobj : public boost::static_visitor<python::object>
|
class VariantToPyobj : public boost::static_visitor<python::object>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -46,6 +44,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class VariantToULong : public boost::static_visitor<ULONG>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
ULONG operator()(T i ) const {
|
||||||
|
return static_cast<ULONG>( i );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class intBase {
|
class intBase {
|
||||||
|
@ -53,6 +53,10 @@ public:
|
|||||||
throw PyException( PyExc_TypeError, "object is unsubscriptable");
|
throw PyException( PyExc_TypeError, "object is unsubscriptable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual TypedVarPtr getElementByIndexPtr( const TypedVarPtr& tv ) {
|
||||||
|
return getElementByIndex( boost::apply_visitor( VariantToULong(), tv->getValue() ) );
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset );
|
TypedVar ( IDebugClient4 *client, const TypeInfoPtr& typeInfo, ULONG64 offset );
|
||||||
@ -118,9 +122,9 @@ public:
|
|||||||
return m_typeInfo->getCount();
|
return m_typeInfo->getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TypedVarPtr getElementByIndex( ULONG index ) {
|
virtual TypedVarPtr getElementByIndex( ULONG index )
|
||||||
|
{
|
||||||
if ( index > m_typeInfo->getCount() )
|
if ( index >= m_typeInfo->getCount() )
|
||||||
{
|
{
|
||||||
throw PyException( PyExc_IndexError, "Index out of range" );
|
throw PyException( PyExc_IndexError, "Index out of range" );
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,11 @@ class TypedVarTest( unittest.TestCase ):
|
|||||||
self.assertEqual( 3, tv.m_noArrayField )
|
self.assertEqual( 3, tv.m_noArrayField )
|
||||||
self.assertNotEqual( -1, tv.m_arrayField[0] )
|
self.assertNotEqual( -1, tv.m_arrayField[0] )
|
||||||
self.assertNotEqual( 0, tv.m_noArrayField )
|
self.assertNotEqual( 0, tv.m_noArrayField )
|
||||||
|
try:
|
||||||
|
tv.m_arrayField[len(tv.m_arrayField)]
|
||||||
|
self.assertTrue(False)
|
||||||
|
except IndexError:
|
||||||
|
self.assertTrue(True)
|
||||||
|
|
||||||
def testGlobalVar(self):
|
def testGlobalVar(self):
|
||||||
self.assertEqual( 4, target.module.typedVar( "g_ulongValue" ) )
|
self.assertEqual( 4, target.module.typedVar( "g_ulongValue" ) )
|
||||||
@ -121,4 +126,10 @@ class TypedVarTest( unittest.TestCase ):
|
|||||||
self.assertEqual( 3, tv.m_enumField )
|
self.assertEqual( 3, tv.m_enumField )
|
||||||
self.assertEqual( target.module.type("enumType").THREE, tv.m_enumField )
|
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] )
|
||||||
|
|
||||||
|
tv = target.module.typedVar( "g_struct3" )
|
||||||
|
self.assertEqual( 2, tv.m_arrayField[ind] )
|
||||||
|
Loading…
Reference in New Issue
Block a user