diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index e8c594c..d0aa827 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -203,7 +203,7 @@ public: throw PyException( PyExc_TypeError, "object has no len()" ); } - virtual python::tuple getElementByIndex( ULONG index ) { + virtual python::object getElementByIndex( ULONG index ) { throw PyException( PyExc_TypeError, "object is unsubscriptable"); } @@ -400,7 +400,7 @@ protected: return getFieldCount(); } - virtual python::tuple getElementByIndex( ULONG index ) { + virtual python::object getElementByIndex( ULONG index ) { return python::make_tuple( getFieldNameByIndex(index), getFieldByIndex(index) ); } @@ -542,6 +542,14 @@ protected: return getSize(); } + virtual ULONG getElementCount() { + return getFieldCount(); + } + + virtual python::object getElementByIndex( ULONG index ) { + return python::make_tuple( getFieldNameByIndex(index), getFieldByIndex(index) ); + } + SymbolPtr m_dia; }; @@ -630,6 +638,16 @@ public: return m_count; } + virtual ULONG getElementCount() { + return getCount(); + } + + virtual python::object getElementByIndex( ULONG index ) { + if( index < m_count ) + return python::object( m_derefType ); + throw PyException( PyExc_IndexError, "index out of range" ); + } + virtual TypeInfoPtr getElementType() { return m_derefType; } diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index a03fabb..de75fde 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -213,6 +213,19 @@ class TypeInfoTest( unittest.TestCase ): self.assertEqual( 5, len(ti) ) for field in ti: str( field ) + + def testArraySubscribe(self): + ti = pykd.typeInfo("g_testArray") + self.assertEqual(2, len(ti) ) + for field in ti: + str( field ) + + def testEnumSubscribe(self): + ti = pykd.typeInfo("enumType") + self.assertEqual(3, len(ti) ) + self.assertEqual( ( "TWO", 2 ), ti[1] ) + for field in ti: + str( field ) def testStructNullSize(self): ti = target.module.type("structNullSize")