From 251a01d7e8fbe83e0e0cd0e95ca29191f9e512ea Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Tue, 27 Dec 2011 21:58:41 +0000 Subject: [PATCH] [0.1.x] + getNumberProcessors() + getPageSize() git-svn-id: https://pykd.svn.codeplex.com/svn@72721 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.h | 35 ++++++++++++++++++++++++++++++++++- pykd/dbgext.cpp | 10 +++++++++- test/scripts/clienttest.py | 12 ++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index 37dbdfc..bc1ecc7 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -30,6 +30,23 @@ typedef boost::shared_ptr DebugClientPtr; class DebugClient : private DbgObject { +private: + // simple IDebugControl4 call wrapper + template + T getDbgControlT( + HRESULT (STDMETHODCALLTYPE IDebugControl4::*method)(T *), + const char *methodName + ) + { + T retValue; + HRESULT hres = (m_control->*method)(&retValue); + if (S_OK != hres) + throw DbgException( buildExceptDesc(methodName, hres) ); + return retValue; + } + #define getDbgControl(method) \ + getDbgControlT( &IDebugControl4::##method, "IDebugControl4::" #method ) + public: virtual ~DebugClient() {} @@ -208,6 +225,13 @@ public: void waitForEvent(); + ULONG getNumberProcessors() { + return getDbgControl(GetNumberProcessors); + } + + ULONG getPageSize() { + return getDbgControl(GetPageSize); + } public: @@ -266,7 +290,6 @@ public: } private: - template python::list loadArray( ULONG64 offset, ULONG count, bool phyAddr ); @@ -356,6 +379,16 @@ inline ULONG delSyntheticSymbolsMask( ///////////////////////////////////////////////////////////////////////////////// +inline ULONG getNumberProcessors() { + return g_dbgClient->getNumberProcessors(); +} + +inline ULONG getPageSize() { + return g_dbgClient->getPageSize(); +} + +///////////////////////////////////////////////////////////////////////////////// + template void DebugClient::changeDebuggerStatus() { diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index e575140..7e7f9a9 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -279,6 +279,10 @@ BOOST_PYTHON_MODULE( pykd ) "Wait for events that breaks into the debugger" ) .def( "wrmsr", &DebugClient::setMSR, "Set MSR value" ) + .def( "getNumberProcessors", &DebugClient::getNumberProcessors, + "Get the number of actual processors in the machine" ) + .def( "getPageSize", &DebugClient::getPageSize, + "Get the page size for the currently executing processor context" ) .def( "addSynSymbol", &DebugClient::addSyntheticSymbol, "Add new synthetic symbol for virtual address" ) .def( "delAllSynSymbols", &DebugClient::delAllSyntheticSymbols, @@ -446,7 +450,11 @@ BOOST_PYTHON_MODULE( pykd ) "Change debugger status to DEBUG_STATUS_STEP_INTO" ); python::def( "waitForEvent", &waitForEvent, "Wait for events that breaks into the debugger" ); - + python::def( "getNumberProcessors", &getNumberProcessors, + "Get the number of actual processors in the machine" ); + python::def( "getPageSize", &getPageSize, + "Get the page size for the currently executing processor context" ); + python::class_, boost::noncopyable >("typeInfo", "Class representing typeInfo", python::no_init ) .def( "name", &TypeInfo::getName ) .def( "size", &TypeInfo::getSize ) diff --git a/test/scripts/clienttest.py b/test/scripts/clienttest.py index 2d4c501..62f6010 100644 --- a/test/scripts/clienttest.py +++ b/test/scripts/clienttest.py @@ -9,10 +9,18 @@ class DbgClientTest( unittest.TestCase ): c, q = pykd.getDebuggeeType() self.assertEqual( c, pykd.DEBUG_CLASS_USER_WINDOWS ) self.assertEqual( q, pykd.DEBUG_USER_WINDOWS_PROCESS ) - + def testIsKernelDebugging( self ): self.assertFalse( pykd.isKernelDebugging() ) - + + def testNumberProcessors( self ): + """Number of processors mus be >= 0""" + self.assertNotEqual( 0, pykd.getNumberProcessors() ) + + def testPageSize( self ): + """Size of memory page mus be >= 4kb""" + self.assertTrue( pykd.getPageSize() >= 4*1024 ) + def testIsDumpAnalyzing( self ): self.assertFalse( pykd.isDumpAnalyzing() )