From 0eeb81b022eece82455760df01284f8ff209233f Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Wed, 24 Jul 2013 12:22:19 +0000 Subject: [PATCH] [0.3.x] updated: typeInfo for function prototype( args-type and calling convention) git-svn-id: https://pykd.svn.codeplex.com/svn@84449 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/pymod.cpp | 49 +++++++++++++++++++++++++++++++++++++++- test/scripts/typeinfo.py | 37 ++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 1a27cb4..d31f013 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -444,7 +444,7 @@ BOOST_PYTHON_MODULE( pykd ) .def( "field", TypeInfoAdapter::getElementByName, "Return field's type" ) .def( "fieldName", &kdlib::TypeInfo::getElementName, - "Return name of struct field by index" ) + "Return name of struct field by index" ) //.def( "asMap", &kdlib::TypeInfo::asMap, // "Return type as python dict ( for enum types )" ) .def( "deref", &kdlib::TypeInfo::deref, @@ -455,6 +455,26 @@ BOOST_PYTHON_MODULE( pykd ) "Return pointer to the type" ) .def( "arrayOf", &kdlib::TypeInfo::arrayOf, "Return array of the type" ) + .def( "isArray", &kdlib::TypeInfo::isArray, + "Return flag: type is array" ) + .def( "isPointer", &kdlib::TypeInfo::isPointer, + "Return flag: type is pointer" ) + .def( "isVoid", &kdlib::TypeInfo::isVoid, + "Return flag: type is void" ) + .def( "isBase", &kdlib::TypeInfo::isBase, + "Return flag: type is base" ) + .def( "isUserDefined", &kdlib::TypeInfo::isUserDefined, + "Return flag: type is UDT" ) + .def( "isEnum", &kdlib::TypeInfo::isEnum, + "Return flag: type is enum" ) + .def( "isBitField", &kdlib::TypeInfo::isBitField, + "Return flag: type is bit field" ) + .def( "isFunction", &kdlib::TypeInfo::isFunction, + "Return flag: type is function" ) + .def( "isConstant", &kdlib::TypeInfo::isConstant, + "Return flag: type is constant" ) + .def( "getCallingConvention", &kdlib::TypeInfo::getCallingConvention, + "Returns an indicator of a methods calling convention: callingConvention" ) .def( "__str__", &kdlib::TypeInfo::str, "Return type as a printable string" ) .def( "__getattr__", TypeInfoAdapter::getElementByName ) @@ -659,6 +679,33 @@ BOOST_PYTHON_MODULE( pykd ) .value("NoDebuggee", kdlib::DebugStatusNoDebuggee ) .export_values(); + python::enum_("callingConvention", "Calling convention for a function") + .value("NearC", kdlib::CallConv_NearC ) + .value("FarC", kdlib::CallConv_FarC ) + .value("NearPascal", kdlib::CallConv_NearPascal ) + .value("FarPascal", kdlib::CallConv_FarPascal ) + .value("NearFast", kdlib::CallConv_NearFast ) + .value("FarFast", kdlib::CallConv_FarFast ) + .value("Skipped", kdlib::CallConv_Skipped ) + .value("NearStd", kdlib::CallConv_NearStd ) + .value("FarStd0", kdlib::CallConv_FarStd ) + .value("NearSys", kdlib::CallConv_NearSys ) + .value("FarSys", kdlib::CallConv_FarSys ) + .value("ThisCall", kdlib::CallConv_ThisCall ) + .value("MipsCall", kdlib::CallConv_MipsCall ) + .value("Generic", kdlib::CallConv_Generic ) + .value("AlphaCall ", kdlib::CallConv_AlphaCall ) + .value("PpcCall", kdlib::CallConv_PpcCall ) + .value("ShCall", kdlib::CallConv_ShCall ) + .value("ArmCall", kdlib::CallConv_ArmCall ) + .value("Am33Call", kdlib::CallConv_Am33Call ) + .value("TriCall", kdlib::CallConv_TriCall ) + .value("Sh5Call", kdlib::CallConv_Sh5Call ) + .value("M32RCall", kdlib::CallConv_M32RCall ) + .value("ClrCall", kdlib::CallConv_ClrCall ) + .value("Inline", kdlib::CallConv_Inline ) + .export_values(); + python::class_( "eventHandler", "Base class for overriding and handling debug notifications" ) .def( "onBreakpoint", &EventHandler::onBreakpoint, diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index 8e8fee5..89bd693 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -201,7 +201,7 @@ class TypeInfoTest( unittest.TestCase ): # self.assertTrue( str(target.module.type( "g_voidPtr" ) ) ) # self.assertTrue( str(target.module.type( "g_arrOfPtrToFunc" ) ) ) # self.assertTrue( str(target.module.type( "g_unTypedPtrToFunction" ) ) ) - + def testTypedef(self): self.assertEqual( "structTest", pykd.typeInfo( "g_structTypeDef" ).name() ) self.assertEqual( "structTest", pykd.typeInfo( "structTestTypeDef" ).name() ) @@ -216,27 +216,46 @@ class TypeInfoTest( unittest.TestCase ): def testVfnTable(self): ti = pykd.typeInfo( "g_classChild" ) self.assertTrue( hasattr( ti, "__VFN_table" ) ) - + def testUdtSubscribe(self): ti = pykd.typeInfo( "g_virtChild" ) self.assertEqual( 6, len(ti) ) for field in ti: str( field ) - + def testStructNullSize(self): ti = target.module.type("structNullSize") self.assertEqual( 0, len(ti) ) - + def testDerefName(self): entry = pykd.typedVar("g_listHead").flink self.assertEqual( "listEntry*", entry.type().name() ) - - def testPtrTo(self): + + def testPtrTo(self): ti = pykd.typeInfo("UInt8B").ptrTo() self.assertTrue( "UInt8B*", ti.name() ) self.assertNotEqual( 0, ti.size() ) - + def testArrayOf(self): ti = pykd.typeInfo("UInt8B").arrayOf(10) - self.assertTrue( "UInt8B[10]", ti.name() ) - + self.assertTrue( "UInt8B[10]", ti.name() ) + + def testFunction(self): + functype = target.module.typedVar( "CdeclFuncPtr" ).type().deref() + self.assertTrue( functype.isFunction() ) + + def testFunctionArgs(self): + functype = target.module.typedVar( "CdeclFuncPtr" ).type().deref() + self.assertEqual( [ arg.name() for arg in functype ], ["Int4B", "Float"] ) + + def testFunctionCallConv(self): + functype = target.module.typedVar( "CdeclFuncPtr" ).type().deref() + self.assertEqual( functype.getCallingConvention(), pykd.callingConvention.NearC ) + + def testFunctionThis(self): + functype = target.module.typedVar( "MethodPtr" ).type().deref() + self.assertEqual( [ arg.name() for arg in functype ], ["FuncTestClass*"] ) + + functype = target.module.typedVar( "CdeclStaticMethodPtr" ).type().deref() + self.assertEqual( [ arg.name() for arg in functype ], [] ) +