Commit 7d9b0faf authored by ussrhero's avatar ussrhero
Browse files

added TypeInfo.isStaticField method ( return True if a field is a static field )

parent 0450a3ab
Subproject commit deda36a086494be526a5d62bf1b104cb780d7a07
Subproject commit 58bd65641b0a351204b60f0697d4868241eae198
......@@ -913,6 +913,10 @@ void pykd_init()
"Return offset of the nonstatic field")
.def("fieldOffset", TypeInfoAdapter::getElementOffsetByIndex,
"Return offset of the nonstatic field by index")
.def("isStaticField", TypeInfoAdapter::isStaticField,
"Return True if a field is a static field by field name")
.def("isStaticField", TypeInfoAdapter::isStaticFieldByIndex,
"Return True if a field is a static field by field name")
.def("bitOffset", TypeInfoAdapter::getBitOffset,
"Return bit field's offset")
.def("bitWidth", TypeInfoAdapter::getBitWidth,
......@@ -929,6 +933,8 @@ void pykd_init()
"Return name of struct field by index" )
.def( "fields", TypeInfoAdapter::getFields,
"Return list of tuple ( filedName, fieldType )" )
.def( "members", TypeInfoAdapter::getMembers,
"Return list of tuple ( memberName, fieldType ). Only defined member, not inherited from base class")
.def( "getNumberMethods", TypeInfoAdapter::getMethodsCount,
"Return number of methods" )
.def( "method", TypeInfoAdapter::getMethodByName,
......@@ -1049,6 +1055,8 @@ void pykd_init()
"Check if a typedVar object has the specified field")
.def( "fields", TypedVarAdapter::getFields,
"Return list of tuple ( filedName, fieldOffset, fieldValue )" )
.def ("members", TypedVarAdapter::getMembers,
"Return list of tuple ( filedName, fieldOffset, fieldValue )")
.def( "fieldName", TypedVarAdapter::getElementName,
"Return name of struct field by index" )
.def("method", TypedVarAdapter::getMethodByName, ( python::arg("name"), python::arg("prototype") = "" ),
......
......@@ -75,7 +75,7 @@ python::tuple findSymbolAndDisp( ULONG64 offset )
///////////////////////////////////////////////////////////////////////////////
python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
python::list TypeInfoAdapter::getFields( const kdlib::TypeInfoPtr &typeInfo )
{
typedef boost::tuple<std::wstring,kdlib::TypeInfoPtr> FieldTuple;
......@@ -85,10 +85,10 @@ python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
AutoRestorePyState pystate;
for ( size_t i = 0; i < typeInfo.getElementCount(); ++i )
for ( size_t i = 0; i < typeInfo->getElementCount(); ++i )
{
std::wstring name = typeInfo.getElementName(i);
kdlib::TypeInfoPtr val = typeInfo.getElement(i);
std::wstring name = typeInfo->getElementName(i);
kdlib::TypeInfoPtr val = typeInfo->getElement(i);
lst.push_back( FieldTuple( name, val ) );
}
......@@ -103,6 +103,35 @@ python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
return pylst;
}
python::list TypeInfoAdapter::getMembers(const kdlib::TypeInfoPtr &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);
if (!typeInfo->isInheritedMember(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;
}
bool TypeInfoAdapter::hasFieldOrMethod(kdlib::TypeInfoPtr& typeInfo, const std::wstring& fieldName)
{
AutoRestorePyState pystate;
......
......@@ -143,6 +143,17 @@ struct TypeInfoAdapter : public kdlib::TypeInfo {
return typeInfo.getElementVa( name );
}
static bool isStaticField(const kdlib::TypeInfoPtr &typeInfo, const std::wstring &name)
{
AutoRestorePyState pystate;
return typeInfo->isStaticMember(name);
}
static bool isStaticFieldByIndex(const kdlib::TypeInfoPtr &typeInfo, size_t index)
{
AutoRestorePyState pystate;
return typeInfo->isStaticMember(index);
}
static kdlib::TypeInfoPtr getElementByName( kdlib::TypeInfo &typeInfo, const std::wstring &name )
{
......@@ -332,7 +343,9 @@ struct TypeInfoAdapter : public kdlib::TypeInfo {
return typeInfo.str();
}
static python::list getFields( kdlib::TypeInfo &typeInfo );
static python::list getFields( const kdlib::TypeInfoPtr &typeInfo );
static python::list getMembers(const kdlib::TypeInfoPtr &typeInfo);
static python::list getMethods(kdlib::TypeInfo &typeInfo);
......
......@@ -371,3 +371,13 @@ class TypeInfoTest( unittest.TestCase ):
self.assertTrue(ti.isTemplate)
self.assertEqual(['int', 'TestClassTemplate<int>'], ti.getTemplateArgs() )
def testMembers(self):
self.assertEqual(
['__VFN_table', '__VFN_table', 'm_staticConst', 'm_staticField', 'm_childField',
'm_childField2', 'm_childField3', 'm_enumField'],
[ member[0] for member in pykd.typeInfo( "classChild" ).members() ])
def testIsStaticField(self):
ti = pykd.typeInfo("classChild")
self.assertTrue(ti.isStaticField("m_staticField"))
self.assertFalse(ti.isStaticField("m_baseField"))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment