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