Skip to content

Commit ef7ee5d

Browse files
authored
[debugger] Fix debugging a x86 app in mixed mode (#114075)
* Fixing get incomplete context information and assigning invalid information to the context later.
1 parent bbc50e5 commit ef7ee5d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/coreclr/debug/di/process.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13317,7 +13317,11 @@ void CordbProcess::HandleDebugEventForInteropDebugging(const DEBUG_EVENT * pEven
1331713317
{
1331813318
LOG((LF_CORDB, LL_INFO100000, "W32ET::W32EL: hijack complete will restore context...\n"));
1331913319
DT_CONTEXT tempContext = { 0 };
13320+
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
13321+
tempContext.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
13322+
#else
1332013323
tempContext.ContextFlags = DT_CONTEXT_FULL;
13324+
#endif
1332113325
HRESULT hr = pUnmanagedThread->GetThreadContext(&tempContext);
1332213326
_ASSERTE(SUCCEEDED(hr));
1332313327

src/coreclr/debug/di/rsthread.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3721,9 +3721,14 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
37213721
LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: hijackCtx started as:\n"));
37223722
LogContext(GetHijackCtx());
37233723

3724-
// Save the thread's full context.
3724+
// Save the thread's full context + DT_CONTEXT_EXTENDED_REGISTERS
3725+
// to avoid getting incomplete information and corrupt the thread context
37253726
DT_CONTEXT context;
3727+
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
3728+
context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
3729+
#else
37263730
context.ContextFlags = DT_CONTEXT_FULL;
3731+
#endif
37273732
BOOL succ = DbiGetThreadContext(m_handle, &context);
37283733
_ASSERTE(succ);
37293734
// for debugging when GetThreadContext fails
@@ -3732,8 +3737,11 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync()
37323737
DWORD error = GetLastError();
37333738
LOG((LF_CORDB, LL_ERROR, "CUT::SFCHFS: DbiGetThreadContext error=0x%x\n", error));
37343739
}
3735-
3740+
#if defined(DT_CONTEXT_EXTENDED_REGISTERS)
3741+
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS;
3742+
#else
37363743
GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL;
3744+
#endif
37373745
CORDbgCopyThreadContext(GetHijackCtx(), &context);
37383746
LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: thread=0x%x Hijacking for sync. Original context is:\n", this));
37393747
LogContext(GetHijackCtx());

0 commit comments

Comments
 (0)