From 60918684783ab73eb85e920b1b75f9cf6e10dc5c Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Thu, 22 Sep 2011 11:20:31 +0000 Subject: [PATCH] [+] pyDia: offset, indexId, udtKind + tests git-svn-id: https://pykd.svn.codeplex.com/svn@69951 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 14 +++++++++++++- pykd/diawrapper.cpp | 30 +++++++++++++++++++++++++++++ pykd/diawrapper.h | 11 +++++++++++ test/scripts/diatest.py | 25 ++++++++++++++++++++++++ test/targetapp/targetapp.cpp | 37 ++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 1 deletion(-) diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 072caed..763c2eb 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -144,13 +144,15 @@ BOOST_PYTHON_MODULE( pykd ) .def( "type", &pyDia::Symbol::getType, "Retrieves the symbol that represents the type for this symbol" ) .def( "indexType", &pyDia::Symbol::getIndexType, - "Retrieves the symbol interface of the array index type of the symbol" ) + "Retrieves a reference to the class parent of the symbol" ) .def( "rva", &pyDia::Symbol::getRva, "Retrieves the relative virtual address (RVA) of the location") .def( "symTag", &pyDia::Symbol::getSymTag, "Retrieves the symbol type classifier: SymTagXxx" ) .def( "locType", &pyDia::Symbol::getLocType, "Retrieves the location type of a data symbol: LocIsXxx" ) + .def( "offset", &pyDia::Symbol::getOffset, + "Retrieves the offset of the symbol location" ) .def( "value", &pyDia::Symbol::getValue, "Retrieves the value of a constant") .def( "isBasic", &pyDia::Symbol::isBasicType, @@ -159,6 +161,10 @@ BOOST_PYTHON_MODULE( pykd ) "Retrieves the base type for this symbol") .def( "bitPos", &pyDia::Symbol::getBitPosition, "Retrieves the base type for this symbol") + .def( "indexId", &pyDia::Symbol::getIndexId, + "Retrieves the unique symbol identifier") + .def( "udtKind", &pyDia::Symbol::getUdtKind, + "Retrieves the variety of a user-defined type") .def( "__str__", &pyDia::Symbol::print) .def("__getitem__", &pyDia::Symbol::getChildByName) .def("__len__", &pyDia::Symbol::getChildCount ) @@ -249,6 +255,12 @@ BOOST_PYTHON_MODULE( pykd ) python::scope().attr("diaBasicType") = genDict(pyDia::Symbol::basicTypeName, pyDia::Symbol::cntBasicTypeName); + DEF_PY_CONST_ULONG(UdtStruct); + DEF_PY_CONST_ULONG(UdtClass); + DEF_PY_CONST_ULONG(UdtUnion); + python::scope().attr("diaUdtKind") = + genDict(pyDia::Symbol::udtKindName, pyDia::Symbol::cntUdtKindName); + // exception: // base exception diff --git a/pykd/diawrapper.cpp b/pykd/diawrapper.cpp index 8ebfb7e..fce4706 100644 --- a/pykd/diawrapper.cpp +++ b/pykd/diawrapper.cpp @@ -91,6 +91,15 @@ const Symbol::ValueNameEntry Symbol::basicTypeName[] = { const size_t Symbol::cntBasicTypeName = _countof(Symbol::basicTypeName); +#define _DEF_UDT_KIND(x) Symbol::ValueNameEntry(Udt##x, #x) +const Symbol::ValueNameEntry Symbol::udtKindName[] = { + _DEF_UDT_KIND(Struct), + _DEF_UDT_KIND(Class), + _DEF_UDT_KIND(Union) +}; +#undef _DEF_UDT_KIND +const size_t Symbol::cntUdtKindName = _countof(udtKindName); + //////////////////////////////////////////////////////////////////////////////// #define callSymbol(method) \ @@ -216,6 +225,13 @@ ULONG Symbol::getLocType() return callSymbol(get_locationType); } +//////////////////////////////////////////////////////////////////////////////// + +ULONG Symbol::getOffset() +{ + return callSymbol(get_offset); +} + //////////////////////////////////////////////////////////////////////////////// void Symbol::getValueImpl(VARIANT &vtValue) { @@ -298,6 +314,20 @@ ULONG Symbol::getBitPosition() //////////////////////////////////////////////////////////////////////////////// +ULONG Symbol::getIndexId() +{ + return callSymbol(get_symIndexId); +} + +//////////////////////////////////////////////////////////////////////////////// + +ULONG Symbol::getUdtKind() +{ + return callSymbol(get_udtKind); +} + +//////////////////////////////////////////////////////////////////////////////// + Symbol Symbol::getChildByName(const std::string &_name) { throwIfNull(__FUNCTION__); diff --git a/pykd/diawrapper.h b/pykd/diawrapper.h index efaa856..aadfcf4 100644 --- a/pykd/diawrapper.h +++ b/pykd/diawrapper.h @@ -94,6 +94,8 @@ public: ULONG getLocType(); + ULONG getOffset(); + void getValueImpl(VARIANT &vtValue); python::object getValue(); @@ -103,6 +105,10 @@ public: ULONG getBitPosition(); + ULONG getIndexId(); + + ULONG getUdtKind(); + Symbol getChildByName(const std::string &_name); ULONG getChildCount(); Symbol getChildByIndex(ULONG _index); @@ -113,10 +119,15 @@ public: typedef std::pair ValueNameEntry; static const ValueNameEntry symTagName[SymTagMax]; + static const ValueNameEntry locTypeName[LocTypeMax]; + static const ValueNameEntry basicTypeName[]; static const size_t cntBasicTypeName; + static const ValueNameEntry udtKindName[]; + static const size_t cntUdtKindName; + protected: template diff --git a/test/scripts/diatest.py b/test/scripts/diatest.py index b997ed7..075d76a 100644 --- a/test/scripts/diatest.py +++ b/test/scripts/diatest.py @@ -74,3 +74,28 @@ class DiaTest( unittest.TestCase ): self.assertEqual(pykd.LocIsBitField, bitField.locType()) self.assertEqual(6, bitField.bitPos()) self.assertEqual(2, bitField.size()) + + def testIndexId(self): + globalScope = pykd.diaOpenPdb( str(target.module.pdb()) ) + self.assertNotEqual( globalScope["classChild"].indexId(), + globalScope["classBase"].indexId() ) + self.assertNotEqual( globalScope["FuncWithName0"].indexId(), + globalScope["FuncWithName1"].indexId() ) + + def testUdtKind(self): + globalScope = pykd.diaOpenPdb( str(target.module.pdb()) ) + self.assertEqual(pykd.UdtStruct, globalScope["structWithBits"].udtKind()) + self.assertEqual(pykd.UdtUnion, globalScope["unionTest"].udtKind()) + self.assertEqual(pykd.UdtClass, globalScope["classBase"].udtKind()) + + def testOffset(self): + globalScope = pykd.diaOpenPdb( str(target.module.pdb()) ) + structTest = globalScope["structTest"] + self.assertEqual( 0, structTest["m_field0"].offset() ) + self.assertTrue( structTest["m_field0"].offset() < + structTest["m_field1"].offset() ) + self.assertTrue( structTest["m_field1"].offset() < + structTest["m_field2"].offset() ) + self.assertTrue( structTest["m_field2"].offset() < + structTest["m_field3"].offset() ) + self.assertTrue(structTest["m_field3"].offset() < structTest.size()) diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index 8a74f17..6188d33 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -24,12 +24,49 @@ struct structWithBits { }; structWithBits g_structWithBits = {0}; +union unionTest { + ULONG m_value; + structWithBits m_bits; +}; + +class classBase { +public: + int m_baseField; + void baseMethod() const {} + virtual void virtFunc() = 0; + virtual void virtFunc2() = 0; +}; + +struct structTest { + ULONG m_field0; + ULONGLONG m_field1; + bool m_field2; + USHORT m_field3; +}; + +class classChild : public classBase { +public: + int m_childField; + int m_childField2; + void childMethod() const {} + virtual void virtFunc() {} + virtual void virtFunc2() {} +}; + void FuncWithName0() { + classChild _classChild; + _classChild.baseMethod(); + + reinterpret_cast(&_classChild)->virtFunc2(); } void FuncWithName1() { + unionTest _unionTest; + _unionTest.m_value = 0; + structTest _structTest; + _structTest.m_field1 = 1; } int _tmain(int argc, _TCHAR* argv[])