From b91bb8ca383ef653a3c0fd8ca9666839b512d04d Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996> Date: Thu, 16 Aug 2012 15:59:02 +0000 Subject: [PATCH] [0.2.x] added : getProcessorMode routine git-svn-id: https://pykd.svn.codeplex.com/svn@78889 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/cpureg.h | 4 ++++ pykd/pymod.cpp | 5 +++++ pykd/win/dbgeng.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/pykd/cpureg.h b/pykd/cpureg.h index f0f9c33..fa62bfb 100644 --- a/pykd/cpureg.h +++ b/pykd/cpureg.h @@ -42,6 +42,10 @@ ULONG64 loadMSR( ULONG msr ); void setMSR( ULONG msr, ULONG64 value); +std::string getProcessorMode(); + +std::string getProcessorType(); + /////////////////////////////////////////////////////////////////////////////////// }; // end pykd namespace diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index af57a49..6e10138 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -192,6 +192,11 @@ BOOST_PYTHON_MODULE( pykd ) "Return MSR value" ); python::def( "wrmsr", &setMSR, "Set MSR value" ); + 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" ); + // stack and local variables python::def( "getCurrentStack", &getCurrentStack, diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp index 623237b..6de7deb 100644 --- a/pykd/win/dbgeng.cpp +++ b/pykd/win/dbgeng.cpp @@ -645,6 +645,60 @@ void getStackTrace( STACK_FRAME_DESC* frames, ULONG frameCount, ULONG* frameRetu /////////////////////////////////////////////////////////////////////////////// +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 getProcessorMode() +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG processorMode; + + hres = g_dbgEng->control->GetEffectiveProcessorType( &processorMode ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" ); + + return processorToStr(processorMode); +} + +/////////////////////////////////////////////////////////////////////////////// + +std::string getProcessorType() +{ + PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); + + HRESULT hres; + ULONG processorMode; + + hres = g_dbgEng->control->GetActualProcessorType( &processorMode ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::GetActualProcessorType failed" ); + + return processorToStr(processorMode); +} + +/////////////////////////////////////////////////////////////////////////////// + } // end pykd namespace