[0.3.x] added : typeInfo.fields methos ( return list of tuple ( filedName, fieldType ) )

git-svn-id: https://pykd.svn.codeplex.com/svn@87546 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2014-03-12 17:07:56 +00:00 committed by Mikhail I. Izmestev
parent 33761324e3
commit fb823ae164
4 changed files with 41 additions and 5 deletions

View File

@ -528,6 +528,8 @@ BOOST_PYTHON_MODULE( pykd )
"Return field's type" )
.def( "fieldName", TypeInfoAdapter::getElementName,
"Return name of struct field by index" )
.def( "fields", TypeInfoAdapter::getFields,
"Return list of tuple ( filedName, fieldType )" )
.def( "deref", TypeInfoAdapter::deref,
"Return type of pointer" )
.def( "append", TypeInfoAdapter::appendField,
@ -580,7 +582,7 @@ BOOST_PYTHON_MODULE( pykd )
"Return field of structure as an object attribute" )
.def("field", TypedVarAdapter::getElementByIndex,
"Return field of structure as an object attribute" )
.add_property( "fields", TypedVarAdapter::getFields,
.def( "fields", TypedVarAdapter::getFields,
"Return list of tuple ( filedName, fieldOffset, fieldValue )" )
.def( "fieldName", TypedVarAdapter::getElementName,
"Return name of struct field by index" )

View File

@ -72,4 +72,34 @@ python::tuple findSymbolAndDisp( ULONG64 offset )
///////////////////////////////////////////////////////////////////////////////
python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
{
typedef boost::tuple<std::wstring,kdlib::TypeInfoPtr> FieldTuple;
std::list<FieldTuple> lst;
do {
AutoRestorePyState pystate;
for ( size_t i = 0; i < typeInfo.getElementCount(); ++i )
{
std::wstring name = typeInfo.getElementName(i);
kdlib::TypeInfoPtr val = typeInfo.getElement(i);
lst.push_back( FieldTuple( name, val ) );
}
} while(false);
python::list pylst;
for ( std::list<FieldTuple>::const_iterator it = lst.begin(); it != lst.end(); ++it)
pylst.append( python::make_tuple( it->get<0>(), it->get<1>() ) );
return pylst;
}
///////////////////////////////////////////////////////////////////////////////
} // pykd namespace

View File

@ -206,6 +206,8 @@ struct TypeInfoAdapter : public kdlib::TypeInfo {
return typeInfo.str();
}
static python::list getFields( kdlib::TypeInfo &typeInfo );
};
struct BaseTypesEnum {

View File

@ -154,10 +154,6 @@ class TypeInfoTest( unittest.TestCase ):
self.assertEqual( 0, ti.fieldOffset("m_structValue") )
self.assertEqual( ti.size(), ti.m_structValue.size() )
def testAsMap(self):
ti = target.module.type("enumType")
self.assertEqual( { 1 : "ONE", 2 : "TWO", 3 : "THREE" }, ti.asMap() )
def testDeref(self):
ti = pykd.typeInfo("Int1B*")
self.assertEqual( "Int1B", ti.deref().name() )
@ -223,6 +219,12 @@ class TypeInfoTest( unittest.TestCase ):
for field in ti:
str( field )
def testEnumSubscribe(self):
ti = pykd.typeInfo( "enumType" )
self.assertEqual( 3, len(ti) )
self.assertEqual( [ 1, 2, 3], [ long(field) for field in ti ] )
self.assertEqual( [ ( "ONE", 1), ("TWO", 2), ("THREE", 3) ], ti.fields() )
def testStructNullSize(self):
ti = target.module.type("structNullSize")
self.assertEqual( 0, len(ti) )