From 8b43bd9e8e5aad14cd6318636dbb203cdb3ea473 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Thu, 15 Dec 2011 06:28:13 +0000 Subject: [PATCH] [0.1.x] added : getProcessorMode routine [0.1.x] added : getProcessorType routine git-svn-id: https://pykd.svn.codeplex.com/svn@72357 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.h | 4 +++ pykd/dbgext.cpp | 8 +++++ pykd/process.cpp | 60 ++++++++++++++++++++++++++++++++++++++ pykd/process.h | 4 +++ test/scripts/clienttest.py | 10 +++---- 5 files changed, 80 insertions(+), 6 deletions(-) diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index c03c010..0e8fa85 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -97,6 +97,10 @@ public: std::string getPdbFile( ULONG64 moduleBase ); + std::string getProcessorMode(); + + std::string getProcessorType(); + template void changeDebuggerStatus(); diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index e6f7191..a23d8c9 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -166,6 +166,10 @@ BOOST_PYTHON_MODULE( pykd ) "Return traget virtual address for specified symbol" ) .def( "getPdbFile", &DebugClient::getPdbFile, "Return full path to PDB (Program DataBase, debug information) file" ) + .def( "getProcessorMode", &DebugClient::getProcessorMode, + "Return current processor mode as string: X86, ARM, IA64 or X64" ) + .def( "getProcessorType", &DebugClient::getProcessorType, + "Return type of physical processor: X86, ARM, IA64 or X64" ) .def( "go", &DebugClient::changeDebuggerStatus, "Change debugger status to DEBUG_STATUS_GO" ) .def( "is64bitSystem", &DebugClient::is64bitSystem, @@ -293,6 +297,10 @@ BOOST_PYTHON_MODULE( pykd ) "Return full path to PDB (Program DataBase, debug information) file" ); python::def( "go", &changeDebuggerStatus, "Change debugger status to DEBUG_STATUS_GO" ); + python::def( "getProcessorMode", &getProcessorMode, + "Return current processor mode as string: X86, ARM, IA64 or X64" ); + python::def( "getProcessorType", &getProcessorType, + "Return type of physical processor: X86, ARM, IA64 or X64" ); python::def( "is64bitSystem", &is64bitSystem, "Check if target system has 64 address space" ); python::def( "isDumpAnalyzing", &isDumpAnalyzing, diff --git a/pykd/process.cpp b/pykd/process.cpp index 22d0b56..2efe157 100644 --- a/pykd/process.cpp +++ b/pykd/process.cpp @@ -78,4 +78,64 @@ getCurrentStack() /////////////////////////////////////////////////////////////////////////////////// +static std::string processorToStr(ULONG processorMode) +{ + switch( processorMode ) + { + case IMAGE_FILE_MACHINE_I386: + return "X86"; + + case IMAGE_FILE_MACHINE_ARM: + return "ARM"; + + case IMAGE_FILE_MACHINE_IA64: + return "IA64"; + + case IMAGE_FILE_MACHINE_AMD64: + return "X64"; + } + + throw DbgException( "Unknown CPU type" ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +std::string DebugClient::getProcessorMode() +{ + HRESULT hres; + ULONG processorMode; + + hres = m_control->GetEffectiveProcessorType( &processorMode ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" ); + + return processorToStr(processorMode); +} + +std::string getProcessorMode() +{ + return g_dbgClient->getProcessorMode(); +} + +/////////////////////////////////////////////////////////////////////////////////// + +std::string DebugClient::getProcessorType() +{ + HRESULT hres; + ULONG processorMode; + + hres = m_control->GetActualProcessorType( &processorMode ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetActualProcessorType failed" ); + + return processorToStr(processorMode); +} + +std::string getProcessorType() +{ + return g_dbgClient->getProcessorType(); +} + +/////////////////////////////////////////////////////////////////////////////////// + } \ No newline at end of file diff --git a/pykd/process.h b/pykd/process.h index 823d739..fc4215e 100644 --- a/pykd/process.h +++ b/pykd/process.h @@ -10,6 +10,10 @@ ULONG64 getImplicitThread(); python::list getCurrentStack(); +std::string getProcessorMode(); + +std::string getProcessorType(); + /////////////////////////////////////////////////////////////////////////////////// } diff --git a/test/scripts/clienttest.py b/test/scripts/clienttest.py index 14e3bd0..145fff0 100644 --- a/test/scripts/clienttest.py +++ b/test/scripts/clienttest.py @@ -24,9 +24,7 @@ class DbgClientTest( unittest.TestCase ): def testPdbFile( self ): self.assertNotEqual( '', target.module ) - - - - - - + + def testProcessorMode( self ): + self.assertNotEqual( '', pykd.getProcessorMode() ) + self.assertNotEqual( '', pykd.getProcessorType() )