diff --git a/TitanEngine/Global.Debugger.cpp b/TitanEngine/Global.Debugger.cpp index 4ccfa14..56655a3 100644 --- a/TitanEngine/Global.Debugger.cpp +++ b/TitanEngine/Global.Debugger.cpp @@ -42,6 +42,27 @@ bool DebugStepFinal = false; LPVOID StepOutCallBack = NULL; CRITICAL_SECTION engineStepActiveCr; +// Workaround for a bug in the kernel with x64 emulation on ARM +DWORD ContextControlFlags = [] +{ + DWORD flags = CONTEXT_CONTROL; + typedef BOOL(WINAPI *type_IsWow64Process2)(HANDLE, USHORT*, USHORT*); + auto p_IsWow64Process2 = (type_IsWow64Process2)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "IsWow64Process2"); + if (p_IsWow64Process2) + { + USHORT processMachine = 0; + USHORT nativeMachine = 0; + if (p_IsWow64Process2(GetCurrentProcess(), &processMachine, &nativeMachine)) + { + if (nativeMachine == IMAGE_FILE_MACHINE_ARM || nativeMachine == IMAGE_FILE_MACHINE_ARM64) + { + flags = CONTEXT_ALL; + } + } + } + return flags; +}(); + // Global.Debugger.functions: long DebugLoopInSecondThread(LPVOID InputParameter) { diff --git a/TitanEngine/Global.Debugger.h b/TitanEngine/Global.Debugger.h index 4e45b56..1861756 100644 --- a/TitanEngine/Global.Debugger.h +++ b/TitanEngine/Global.Debugger.h @@ -41,6 +41,7 @@ extern wchar_t szDebuggerName[512]; extern bool DebugStepFinal; extern LPVOID StepOutCallBack; extern CRITICAL_SECTION engineStepActiveCr; +extern DWORD ContextControlFlags; long DebugLoopInSecondThread(LPVOID InputParameter); void DebuggerReset(); diff --git a/TitanEngine/TitanEngine.Debugger.Control.cpp b/TitanEngine/TitanEngine.Debugger.Control.cpp index 6d75cdb..3ee04fa 100644 --- a/TitanEngine/TitanEngine.Debugger.Control.cpp +++ b/TitanEngine/TitanEngine.Debugger.Control.cpp @@ -55,7 +55,7 @@ __declspec(dllexport) void TITCALL StepInto(LPVOID StepCallBack) { CONTEXT myDBGContext; HANDLE hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); - myDBGContext.ContextFlags = CONTEXT_CONTROL; + myDBGContext.ContextFlags = ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); myDBGContext.EFlags |= UE_TRAP_FLAG; SetThreadContext(hActiveThread, &myDBGContext); diff --git a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp index d6d49f6..4199eaf 100644 --- a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp +++ b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp @@ -552,7 +552,7 @@ __declspec(dllexport) void TITCALL DebugLoop() FlushInstructionCache(dbgProcessInformation.hProcess, NULL, 0); DBGCode = DBG_CONTINUE; hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); - myDBGContext.ContextFlags = CONTEXT_CONTROL; + myDBGContext.ContextFlags = ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); if(FoundBreakPoint.BreakPointType != UE_SINGLESHOOT) myDBGContext.EFlags |= UE_TRAP_FLAG; @@ -674,7 +674,7 @@ __declspec(dllexport) void TITCALL DebugLoop() else { hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); - myDBGContext.ContextFlags = CONTEXT_CONTROL; + myDBGContext.ContextFlags = ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); myDBGContext.EFlags |= UE_TRAP_FLAG; SetThreadContext(hActiveThread, &myDBGContext); @@ -727,7 +727,7 @@ __declspec(dllexport) void TITCALL DebugLoop() { //handle hardware breakpoints hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); - myDBGContext.ContextFlags = CONTEXT_DEBUG_REGISTERS | CONTEXT_CONTROL; + myDBGContext.ContextFlags = CONTEXT_DEBUG_REGISTERS | ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); if((ULONG_PTR)DBGEvent.u.Exception.ExceptionRecord.ExceptionAddress == myDBGContext.Dr0 || (myDBGContext.Dr6 & 0x1)) { @@ -893,7 +893,7 @@ __declspec(dllexport) void TITCALL DebugLoop() if(bFoundBreakPoint) //found memory breakpoint { hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); - myDBGContext.ContextFlags = CONTEXT_CONTROL; + myDBGContext.ContextFlags = ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); DBGCode = DBG_CONTINUE; //debugger handled the exception MemoryBpxCallBack = FoundBreakPoint.ExecuteCallBack; @@ -1062,7 +1062,7 @@ __declspec(dllexport) void TITCALL DebugLoop() if(bFoundBreakPoint && engineMembpAlt) //found memory breakpoint { hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); - myDBGContext.ContextFlags = CONTEXT_CONTROL; + myDBGContext.ContextFlags = ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); DBGCode = DBG_CONTINUE; //debugger handled the exception MemoryBpxCallBack = FoundBreakPoint.ExecuteCallBack; @@ -1239,7 +1239,7 @@ __declspec(dllexport) void TITCALL DebugLoop() FlushInstructionCache(dbgProcessInformation.hProcess, NULL, 0); DBGCode = DBG_CONTINUE; hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); - myDBGContext.ContextFlags = CONTEXT_CONTROL; + myDBGContext.ContextFlags = ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); if(FoundBreakPoint.BreakPointType != UE_SINGLESHOOT) myDBGContext.EFlags |= UE_TRAP_FLAG; @@ -1400,7 +1400,7 @@ __declspec(dllexport) void TITCALL DebugLoop() { CONTEXT DbgCtx; - DbgCtx.ContextFlags = CONTEXT_CONTROL; + DbgCtx.ContextFlags = ContextControlFlags; hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, DBGEvent.dwThreadId); diff --git a/TitanEngine/TitanEngine.Debugger.cpp b/TitanEngine/TitanEngine.Debugger.cpp index 5828bfc..cd50070 100644 --- a/TitanEngine/TitanEngine.Debugger.cpp +++ b/TitanEngine/TitanEngine.Debugger.cpp @@ -620,7 +620,7 @@ __declspec(dllexport) bool TITCALL DetachDebuggerEx(DWORD ProcessId) { HANDLE hActiveThread = EngineOpenThread(THREAD_GETSETSUSPEND, false, hListThread.at(i).dwThreadId); CONTEXT myDBGContext; - myDBGContext.ContextFlags = CONTEXT_CONTROL; + myDBGContext.ContextFlags = ContextControlFlags; GetThreadContext(hActiveThread, &myDBGContext); myDBGContext.EFlags &= ~UE_TRAP_FLAG; myDBGContext.EFlags &= ~UE_RESUME_FLAG;