added TypeInfo.isStaticField method ( return True if a field is a static field )
This commit is contained in:
parent
0450a3abdf
commit
7d9b0faffa
2
kdlibcpp
2
kdlibcpp
@ -1 +1 @@
|
|||||||
Subproject commit deda36a086494be526a5d62bf1b104cb780d7a07
|
Subproject commit 58bd65641b0a351204b60f0697d4868241eae198
|
@ -913,6 +913,10 @@ void pykd_init()
|
|||||||
"Return offset of the nonstatic field")
|
"Return offset of the nonstatic field")
|
||||||
.def("fieldOffset", TypeInfoAdapter::getElementOffsetByIndex,
|
.def("fieldOffset", TypeInfoAdapter::getElementOffsetByIndex,
|
||||||
"Return offset of the nonstatic field by index")
|
"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,
|
.def("bitOffset", TypeInfoAdapter::getBitOffset,
|
||||||
"Return bit field's offset")
|
"Return bit field's offset")
|
||||||
.def("bitWidth", TypeInfoAdapter::getBitWidth,
|
.def("bitWidth", TypeInfoAdapter::getBitWidth,
|
||||||
@ -929,6 +933,8 @@ void pykd_init()
|
|||||||
"Return name of struct field by index" )
|
"Return name of struct field by index" )
|
||||||
.def( "fields", TypeInfoAdapter::getFields,
|
.def( "fields", TypeInfoAdapter::getFields,
|
||||||
"Return list of tuple ( filedName, fieldType )" )
|
"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,
|
.def( "getNumberMethods", TypeInfoAdapter::getMethodsCount,
|
||||||
"Return number of methods" )
|
"Return number of methods" )
|
||||||
.def( "method", TypeInfoAdapter::getMethodByName,
|
.def( "method", TypeInfoAdapter::getMethodByName,
|
||||||
@ -1049,6 +1055,8 @@ void pykd_init()
|
|||||||
"Check if a typedVar object has the specified field")
|
"Check if a typedVar object has the specified field")
|
||||||
.def( "fields", TypedVarAdapter::getFields,
|
.def( "fields", TypedVarAdapter::getFields,
|
||||||
"Return list of tuple ( filedName, fieldOffset, fieldValue )" )
|
"Return list of tuple ( filedName, fieldOffset, fieldValue )" )
|
||||||
|
.def ("members", TypedVarAdapter::getMembers,
|
||||||
|
"Return list of tuple ( filedName, fieldOffset, fieldValue )")
|
||||||
.def( "fieldName", TypedVarAdapter::getElementName,
|
.def( "fieldName", TypedVarAdapter::getElementName,
|
||||||
"Return name of struct field by index" )
|
"Return name of struct field by index" )
|
||||||
.def("method", TypedVarAdapter::getMethodByName, ( python::arg("name"), python::arg("prototype") = "" ),
|
.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;
|
typedef boost::tuple<std::wstring,kdlib::TypeInfoPtr> FieldTuple;
|
||||||
|
|
||||||
@ -85,10 +85,10 @@ python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
|
|||||||
|
|
||||||
AutoRestorePyState pystate;
|
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);
|
std::wstring name = typeInfo->getElementName(i);
|
||||||
kdlib::TypeInfoPtr val = typeInfo.getElement(i);
|
kdlib::TypeInfoPtr val = typeInfo->getElement(i);
|
||||||
|
|
||||||
lst.push_back( FieldTuple( name, val ) );
|
lst.push_back( FieldTuple( name, val ) );
|
||||||
}
|
}
|
||||||
@ -103,6 +103,35 @@ python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
|
|||||||
return pylst;
|
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)
|
bool TypeInfoAdapter::hasFieldOrMethod(kdlib::TypeInfoPtr& typeInfo, const std::wstring& fieldName)
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
AutoRestorePyState pystate;
|
||||||
|
@ -143,6 +143,17 @@ struct TypeInfoAdapter : public kdlib::TypeInfo {
|
|||||||
return typeInfo.getElementVa( name );
|
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 )
|
static kdlib::TypeInfoPtr getElementByName( kdlib::TypeInfo &typeInfo, const std::wstring &name )
|
||||||
{
|
{
|
||||||
@ -332,7 +343,9 @@ struct TypeInfoAdapter : public kdlib::TypeInfo {
|
|||||||
return typeInfo.str();
|
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);
|
static python::list getMethods(kdlib::TypeInfo &typeInfo);
|
||||||
|
|
||||||
|
@ -371,3 +371,13 @@ class TypeInfoTest( unittest.TestCase ):
|
|||||||
self.assertTrue(ti.isTemplate)
|
self.assertTrue(ti.isTemplate)
|
||||||
self.assertEqual(['int', 'TestClassTemplate<int>'], ti.getTemplateArgs() )
|
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"))
|
Loading…
Reference in New Issue
Block a user