From 92f5d48c85c86e77609938ac3518f2e0a05aca98 Mon Sep 17 00:00:00 2001 From: Herzeh Date: Fri, 11 Dec 2015 12:50:16 +0100 Subject: [PATCH] Hardware Breakpoint : Fixed a bug where when HW BP is hit and the user deletes the HW BP then resumes the execution, the Trap Flag is still set which make titanengine think the debuggee throwed a SINGLE_STEP Exception. BP : Fixed a bug where setting a HW BP and a SW BP (could be any combination e.g SW BP then a HW BP) on same address, then removing one of the two BP when program hits the BP will remove all BPs set on that address. --- .../TitanEngine.Debugger.DebugLoop.cpp | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp index 4792a7f..c694dcf 100644 --- a/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp +++ b/TitanEngine/TitanEngine.Debugger.DebugLoop.cpp @@ -594,7 +594,7 @@ __declspec(dllexport) void TITCALL DebugLoop() EngineCloseHandle(hActiveThread); } } - else if(ResetHwBPX) //restore hardware breakpoint + if(ResetHwBPX) //restore hardware breakpoint { ResetHwBPX = false; SetHardwareBreakPoint(DebugRegisterX.DrxBreakAddress, DebugRegisterXId, DebugRegisterX.DrxBreakPointType, DebugRegisterX.DrxBreakPointSize, (LPVOID)DebugRegisterX.DrxCallBack); @@ -613,7 +613,7 @@ __declspec(dllexport) void TITCALL DebugLoop() } } } - else if(ResetMemBPX) //restore memory breakpoint + if(ResetMemBPX) //restore memory breakpoint { ResetMemBPX = false; VirtualQueryEx(dbgProcessInformation.hProcess, (LPCVOID)ResetMemBPXAddress, &MemInfo, sizeof MEMORY_BASIC_INFORMATION); @@ -658,6 +658,12 @@ __declspec(dllexport) void TITCALL DebugLoop() DeleteHardwareBreakPoint(UE_DR0); ResetHwBPX = true; } + else + { + GetThreadContext(hActiveThread, &myDBGContext); + myDBGContext.EFlags &= ~(1 << 8); + SetThreadContext(hActiveThread, &myDBGContext); + } } else { @@ -680,6 +686,12 @@ __declspec(dllexport) void TITCALL DebugLoop() DeleteHardwareBreakPoint(UE_DR1); ResetHwBPX = true; } + else + { + GetThreadContext(hActiveThread, &myDBGContext); + myDBGContext.EFlags &= ~(1 << 8); + SetThreadContext(hActiveThread, &myDBGContext); + } } else { @@ -702,6 +714,12 @@ __declspec(dllexport) void TITCALL DebugLoop() DeleteHardwareBreakPoint(UE_DR2); ResetHwBPX = true; } + else + { + GetThreadContext(hActiveThread, &myDBGContext); + myDBGContext.EFlags &= ~(1 << 8); + SetThreadContext(hActiveThread, &myDBGContext); + } } else { @@ -724,6 +742,12 @@ __declspec(dllexport) void TITCALL DebugLoop() DeleteHardwareBreakPoint(UE_DR3); ResetHwBPX = true; } + else + { + GetThreadContext(hActiveThread, &myDBGContext); + myDBGContext.EFlags &= ~(1 << 8); + SetThreadContext(hActiveThread, &myDBGContext); + } } else {