diff --git a/src/coreclr/debug/di/process.cpp b/src/coreclr/debug/di/process.cpp index 59a6b98c1c9bc3..7c87c6cd1d82d7 100644 --- a/src/coreclr/debug/di/process.cpp +++ b/src/coreclr/debug/di/process.cpp @@ -13317,7 +13317,11 @@ void CordbProcess::HandleDebugEventForInteropDebugging(const DEBUG_EVENT * pEven { LOG((LF_CORDB, LL_INFO100000, "W32ET::W32EL: hijack complete will restore context...\n")); DT_CONTEXT tempContext = { 0 }; +#if defined(DT_CONTEXT_EXTENDED_REGISTERS) + tempContext.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS; +#else tempContext.ContextFlags = DT_CONTEXT_FULL; +#endif HRESULT hr = pUnmanagedThread->GetThreadContext(&tempContext); _ASSERTE(SUCCEEDED(hr)); diff --git a/src/coreclr/debug/di/rsthread.cpp b/src/coreclr/debug/di/rsthread.cpp index cc0656b5bd1948..f501c6837a6496 100644 --- a/src/coreclr/debug/di/rsthread.cpp +++ b/src/coreclr/debug/di/rsthread.cpp @@ -3721,9 +3721,14 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync() LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: hijackCtx started as:\n")); LogContext(GetHijackCtx()); - // Save the thread's full context. + // Save the thread's full context + DT_CONTEXT_EXTENDED_REGISTERS + // to avoid getting incomplete information and corrupt the thread context DT_CONTEXT context; +#if defined(DT_CONTEXT_EXTENDED_REGISTERS) + context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS; +#else context.ContextFlags = DT_CONTEXT_FULL; +#endif BOOL succ = DbiGetThreadContext(m_handle, &context); _ASSERTE(succ); // for debugging when GetThreadContext fails @@ -3732,8 +3737,11 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync() DWORD error = GetLastError(); LOG((LF_CORDB, LL_ERROR, "CUT::SFCHFS: DbiGetThreadContext error=0x%x\n", error)); } - +#if defined(DT_CONTEXT_EXTENDED_REGISTERS) + GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS; +#else GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL; +#endif CORDbgCopyThreadContext(GetHijackCtx(), &context); LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: thread=0x%x Hijacking for sync. Original context is:\n", this)); LogContext(GetHijackCtx());