From 25d2e5ef590748a63db9b27f20a77e988973e6fe Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 16 Mar 2012 06:40:15 +0000 Subject: [PATCH] [0.1.x] fixed : issue #10338 ( print typeInfo raises TypeException ) git-svn-id: https://pykd.svn.codeplex.com/svn@74920 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 7 ++++--- pykd/typeinfo.h | 7 +++++++ test/scripts/typeinfo.py | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 36fb439..e75644a 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -513,10 +513,11 @@ BOOST_PYTHON_MODULE( pykd ) .def( "bitOffset", &TypeInfo::getBitOffset ) .def( "bitWidth", &TypeInfo::getBitWidth ) .def( "field", &TypeInfo::getField ) - .def( "__getattr__", &TypeInfo::getField ) .def( "asMap", &TypeInfo::asMap ) - .def( "deref", &TypeInfo::deref ); - + .def( "deref", &TypeInfo::deref ) + .def( "__str__", &TypeInfo::print ) + .def( "__getattr__", &TypeInfo::getField ); + python::class_, boost::noncopyable >("typedVar", "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", python::no_init ) diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index d4cc505..a1e10b4 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -35,6 +35,13 @@ public: public: + virtual std::string print() { + std::stringstream sstr; + sstr << "Type name: " << getName(); + sstr << " Size: 0x" << std::hex << getSize() << " (" << std::dec << getSize() << ")"; + return sstr.str(); + } + virtual std::string getName() = 0; virtual ULONG getSize() = 0; diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index c74f741..f3472be 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -147,3 +147,25 @@ class TypeInfoTest( unittest.TestCase ): ti = target.module.type("StructWithNested::Nested") self.assertTrue( hasattr( ti, "m_nestedFiled" ) ) + + def testPrint(self): + self.assertTrue( str(target.module.type( "g_ucharValue" ) ) ) + self.assertTrue( str(target.module.type( "g_ushortValue" ) ) ) + self.assertTrue( str(target.module.type( "g_ulongValue" ) ) ) + self.assertTrue( str(target.module.type( "g_ulonglongValue" ) ) ) + self.assertTrue( str(target.module.type( "g_structWithBits" ) ) ) + self.assertTrue( str(target.module.type( "g_structTest" ) ) ) + self.assertTrue( str(target.module.type( "g_structTest1" ) ) ) + self.assertTrue( str(target.module.type( "g_testArray" ) ) ) + self.assertTrue( str(target.module.type( "g_structTestPtr" ) ) ) + self.assertTrue( str(target.module.type( "g_structTestPtrPtr" ) ) ) + self.assertTrue( str(target.module.type( "longlongArray" ) ) ) + self.assertTrue( str(target.module.type( "intMatrix4" ) ) ) + self.assertTrue( str(target.module.type( "ptrIntMatrix" ) ) ) + self.assertTrue( str(target.module.type( "g_classChild" ) ) ) + self.assertTrue( str(target.module.type( "g_struct3" ) ) ) + self.assertTrue( str(target.module.type( "g_listHead" ) ) ) + self.assertTrue( str(target.module.type( "g_voidPtr" ) ) ) + self.assertTrue( str(target.module.type( "g_arrOfPtrToFunc" ) ) ) + self.assertTrue( str(target.module.type( "g_unTypedPtrToFunction" ) ) ) +