From 689ce0ae42a09d6ce8ee937e033eb289e8bc3ec9 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Fri, 23 Nov 2012 09:45:21 +0000 Subject: [PATCH] [0.2.x] ~ ptrTo is method of typeInfo git-svn-id: https://pykd.svn.codeplex.com/svn@81387 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/customtypes.cpp | 26 +++++++++++++++----------- pykd/customtypes.h | 19 +++++++++---------- pykd/pymod.cpp | 15 +++++++-------- pykd/typeinfo.cpp | 7 +++++++ pykd/typeinfo.h | 2 ++ test/scripts/typedvar.py | 25 ++++++++++++++----------- 6 files changed, 54 insertions(+), 40 deletions(-) diff --git a/pykd/customtypes.cpp b/pykd/customtypes.cpp index 86ebd3a..7a61ca1 100644 --- a/pykd/customtypes.cpp +++ b/pykd/customtypes.cpp @@ -8,6 +8,14 @@ namespace pykd { //////////////////////////////////////////////////////////////////////////////// +CustomTypeBase::CustomTypeBase(const std::string &name, ULONG pointerSize) + : UdtFieldColl(name) +{ + m_ptrSize = pointerSize ? pointerSize : ptrSize(); +} + +//////////////////////////////////////////////////////////////////////////////// + void CustomTypeBase::throwIfFiledExist(const std::string &fieldName) { bool fieldExist = false; @@ -61,9 +69,12 @@ void CustomTypeBase::throwIfTypeRecursiveImpl(TypeInfoPtr type) //////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr CustomStruct::create(const std::string &name, ULONG alignReq /*= 0*/) +TypeInfoPtr CustomStruct::create( + const std::string &name, + ULONG alignReq /*= 0*/, + ULONG pointerSize /*= 0*/) { - return TypeInfoPtr( new CustomStruct(name, alignReq) ); + return TypeInfoPtr( new CustomStruct(name, alignReq, pointerSize) ); } //////////////////////////////////////////////////////////////////////////////// @@ -93,9 +104,9 @@ void CustomStruct::appendField(const std::string &fieldName, TypeInfoPtr fieldTy //////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr CustomUnion::create(const std::string &name) +TypeInfoPtr CustomUnion::create(const std::string &name, ULONG pointerSize /*= 0*/) { - return TypeInfoPtr( new CustomUnion(name) ); + return TypeInfoPtr( new CustomUnion(name, pointerSize) ); } //////////////////////////////////////////////////////////////////////////////// @@ -133,13 +144,6 @@ TypeInfoPtr PtrToVoid() //////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr PtrTo(TypeInfoPtr type) -{ - return TypeInfoPtr( new PointerTypeInfo(type, ptrSize()) ); -} - -//////////////////////////////////////////////////////////////////////////////// - } // namespace pykd //////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/customtypes.h b/pykd/customtypes.h index b217e9e..2b1e8eb 100644 --- a/pykd/customtypes.h +++ b/pykd/customtypes.h @@ -16,7 +16,7 @@ class CustomTypeBase : public UdtFieldColl { typedef UdtFieldColl Base; protected: - CustomTypeBase(const std::string &name) : UdtFieldColl(name) {} + CustomTypeBase(const std::string &name, ULONG pointerSize); void throwIfFiledExist(const std::string &fieldName); void throwIfTypeRecursive(TypeInfoPtr type); @@ -31,11 +31,11 @@ class CustomStruct : public CustomTypeBase { typedef CustomTypeBase Base; public: - static TypeInfoPtr create(const std::string &name, ULONG align = 0); + static TypeInfoPtr create(const std::string &name, ULONG align = 0, ULONG pointerSize = 0); protected: - CustomStruct(const std::string &name, ULONG align) - : Base(name), m_name(name), m_align(align) + CustomStruct(const std::string &name, ULONG align, ULONG pointerSize) + : Base(name, pointerSize), m_name(name), m_align(align) { } @@ -62,10 +62,13 @@ class CustomUnion : public CustomTypeBase { typedef CustomTypeBase Base; public: - static TypeInfoPtr create(const std::string &name); + static TypeInfoPtr create(const std::string &name, ULONG pointerSize = 0); protected: - CustomUnion(const std::string &name) : Base(name) {} + CustomUnion(const std::string &name, ULONG pointerSize) + : Base(name, pointerSize) + { + } virtual ULONG getSize() override; @@ -85,10 +88,6 @@ TypeInfoPtr PtrToVoid(); //////////////////////////////////////////////////////////////////////////////// -TypeInfoPtr PtrTo(TypeInfoPtr type); - -//////////////////////////////////////////////////////////////////////////////// - } // namespace pykd //////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 678cc8f..fbadff0 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -60,7 +60,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceFile_, getSourceFile, 0, 1 ); BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBp_, setSoftwareBp, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 ); -BOOST_PYTHON_FUNCTION_OVERLOADS( CustomStruct_create, CustomStruct::create, 1, 2 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( CustomStruct_create, CustomStruct::create, 1, 3 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( CustomUnion_create, CustomUnion::create, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( findSymbol_, TypeInfo::findSymbol, 1, 2 ); @@ -274,14 +275,11 @@ BOOST_PYTHON_MODULE( pykd ) python::def( "appendSymbolPath", &appendSymbolPath, "Append current symbol path"); // custom types - python::def( "createStruct", &CustomStruct::create, CustomStruct_create( python::args( "name", "align" ), + python::def( "createStruct", &CustomStruct::create, CustomStruct_create( python::args( "name", "align", "ptrSize" ), "Create empty structure. Use append() method for building" ) ); - python::def( "createUnion", &CustomUnion::create, - "Create empty union. Use append() method for building" ); - python::def( "pVoid", &PtrToVoid, - "Create \"Void *\" type" ); - python::def( "ptrTo", &PtrTo, - "Create pointer to target type" ); + python::def( "createUnion", &CustomUnion::create, CustomUnion_create( python::args( "name", "ptrSize" ), + "Create empty union. Use append() method for building" ) ); + python::def( "pVoid", &PtrToVoid, "Create \"Void*\" type" ); python::class_( "intBase", "intBase", python::no_init ) .def( python::init() ) @@ -391,6 +389,7 @@ BOOST_PYTHON_MODULE( pykd ) .def( "asMap", &TypeInfo::asMap ) .def( "deref", &TypeInfo::deref ) .def( "append", &TypeInfo::appendField ) + .def( "ptrTo", &TypeInfo::ptrTo ) .def( "__str__", &TypeInfo::print ) .def( "__getattr__", &TypeInfo::getField ) .def("__len__", &TypeInfo::getElementCount ) diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index 3eb4886..b2f287b 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -602,6 +602,13 @@ TypeInfoPtr TypeInfo::getRecurciveComplexType( TypeInfoPtr &lowestType, std::str ///////////////////////////////////////////////////////////////////////////////////// +TypeInfoPtr TypeInfo::ptrTo() +{ + return TypeInfoPtr( new PointerTypeInfo(shared_from_this(), m_ptrSize) ); +} + +///////////////////////////////////////////////////////////////////////////////////// + ULONG64 TypeInfo::getStaticOffset() { if ( !m_staticMember ) diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index c5a0c56..34fb5f3 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -162,6 +162,8 @@ public: throw TypeException( getName(), "type is not is not extensible" ); } + TypeInfoPtr ptrTo(); + virtual ULONG getAlignReq() { return 1; } diff --git a/test/scripts/typedvar.py b/test/scripts/typedvar.py index 3236c63..632097c 100644 --- a/test/scripts/typedvar.py +++ b/test/scripts/typedvar.py @@ -32,18 +32,21 @@ class TypedVarTest( unittest.TestCase ): self.assertEqual( -8, target.module.typedVar( "g_longlongValue" ) ) def testPtrTo(self): - tv1 = target.module.typedVar( "g_ulonglongValue" ) - tv2 = pykd.typedVar( pykd.ptrTo(tv1.type()), - target.module.offset("g_pUlonglongValue") ) - self.assertEqual( tv1, tv2.deref() ) + tvBaseType = pykd.typedVar( pykd.typeInfo("UInt8B").ptrTo(), + target.module.offset("g_pUlonglongValue") ) + self.assertEqual( target.module.typedVar( "g_ulonglongValue" ), + tvBaseType.deref() ) - tv3 = pykd.typedVar( pykd.ptrTo( target.module.type("structTest") ).deref(), - target.module.offset("g_structTest") ) - self.assertEqual( 500, tv3.m_field1 ) + tvDiaStruct = pykd.typedVar( target.module.type("structTest").ptrTo(), + target.module.offset("g_structTestPtr") ) + self.assertEqual( 500, tvDiaStruct.deref().m_field1 ) - tv4 = pykd.typedVar( pykd.ptrTo( target.module.type("structTest") ), - target.module.offset("g_structTestPtr") ) - self.assertEqual( 500, tv4.deref().m_field1 ) + customStructTest = pykd.createStruct("customStructTest") + customStructTest.append("m_field0", pykd.typeInfo("UInt4B")) + customStructTest.append("m_field1", pykd.typeInfo("UInt8B")) + tvCustomStruct = pykd.typedVar( customStructTest.ptrTo(), + target.module.offset("g_structTestPtr") ) + self.assertEqual( 500, tvCustomStruct.deref().m_field1 ) def testConst(self): self.assertEqual( True, target.module.typedVar( "g_constBoolValue" ) ) @@ -64,7 +67,7 @@ class TypedVarTest( unittest.TestCase ): self.assertEqual( pykd.sizeof("g_structTest"), tv1.sizeof() ) self.assertEqual( pykd.sizeof("g_testArray"), tv2.sizeof() ) - self.assertEqual( pykd.sizeof("g_ucharValue"), 1 ) + self.assertEqual( pykd.sizeof("g_ucharValue"), 1 ) def testByAddress( self ): tv1 = target.module.typedVar( "structTest", target.module.g_structTest )