diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 24f6b1f..d7e6947 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -104,6 +104,8 @@ BOOST_PYTHON_MODULE( pykd ) "Return pointer size ( in bytes )" ); boost::python::def( "reg", &loadRegister, "Return CPU's register value" ); + boost::python::def( "rdmsr", &loadMSR, + "Return MSR value" ); boost::python::def( "typedVarList", &loadTypedVarList, "Return list of typedVarClass instances. Each item represents one item of the linked list in the target memory" ); boost::python::def( "typedVarArray", &loadTypedVarArray, diff --git a/pykd/dbgreg.cpp b/pykd/dbgreg.cpp index af92131..4a39b75 100644 --- a/pykd/dbgreg.cpp +++ b/pykd/dbgreg.cpp @@ -12,49 +12,53 @@ boost::python::object loadRegister( const std::string ®isterName ) { HRESULT hres; - - try { - ULONG registerIndex = 0; - - hres = dbgExt->registers->GetIndexByName( registerName.c_str(), ®isterIndex ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugRegister::GetIndexByName failed" ); - - DEBUG_VALUE debugValue; - hres = dbgExt->registers->GetValue( registerIndex, &debugValue ); - if ( FAILED( hres ) ) - throw DbgException( "IDebugRegister::GetValue failed" ); - - switch( debugValue.Type ) - { - case DEBUG_VALUE_INT8: - return boost::python::long_( debugValue.I8 ); - break; - - case DEBUG_VALUE_INT16: - return boost::python::long_( debugValue.I16 ); - break; - - case DEBUG_VALUE_INT32: - return boost::python::long_( debugValue.I32 ); - break; - - case DEBUG_VALUE_INT64: - return boost::python::long_(debugValue.I64 ); - break; - } - } - catch( std::exception &e ) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() ); - } - catch(...) - { - dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); - } - - return boost::python::str( "REG_ERR" ); + ULONG registerIndex = 0; + + hres = dbgExt->registers->GetIndexByName( registerName.c_str(), ®isterIndex ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugRegister::GetIndexByName failed" ); + + DEBUG_VALUE debugValue; + hres = dbgExt->registers->GetValue( registerIndex, &debugValue ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugRegister::GetValue failed" ); + + switch( debugValue.Type ) + { + case DEBUG_VALUE_INT8: + return boost::python::long_( debugValue.I8 ); + break; + + case DEBUG_VALUE_INT16: + return boost::python::long_( debugValue.I16 ); + break; + + case DEBUG_VALUE_INT32: + return boost::python::long_( debugValue.I32 ); + break; + + case DEBUG_VALUE_INT64: + return boost::python::long_(debugValue.I64 ); + break; + } + + throw DbgException( "Invalid register value" ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +ULONG64 +loadMSR( ULONG msr ) +{ + HRESULT hres; + ULONG64 value; + + hres = dbgExt->dataSpaces->ReadMsr( msr, &value ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugDataSpaces::ReadMsr failed" ); + + return value; } /////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgreg.h b/pykd/dbgreg.h index 3f24cda..b915b7c 100644 --- a/pykd/dbgreg.h +++ b/pykd/dbgreg.h @@ -7,4 +7,7 @@ boost::python::object loadRegister( const std::string ®isterName ); +ULONG64 +loadMSR( ULONG msr ); + ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file