track deleted breakpoints to handle stale events safely

This commit is contained in:
AzuLX 2026-01-09 19:08:26 +00:00
parent 552aa92637
commit 1533cc3e84
No known key found for this signature in database
GPG Key ID: BED7E7DC23A637BC
4 changed files with 18 additions and 8 deletions

View File

@ -21,17 +21,14 @@ namespace GleeBug
}
else
{
//check if this was a deleted breakpoint
//if the byte at the exception address is not 0xCC, our breakpoint was deleted
//and we should set IP back and continue execution
uint8 currentByte = 0xCC;
if(mThread && mProcess->MemReadUnsafe(exceptionAddress, &currentByte, 1) && currentByte != 0xCC)
//check if this address had a breakpoint that was recently deleted
auto& deletedBps = mProcess->recentlyDeletedSwbp;
auto foundIt = std::find(deletedBps.begin(), deletedBps.end(), exceptionAddress);
if(foundIt != deletedBps.end() && mThread)
{
//this was our deleted breakpoint, set IP back and continue
Registers(mThread->hThread, CONTEXT_CONTROL).Gip = exceptionAddress;
mContinueStatus = DBG_CONTINUE;
}
//else: byte is 0xCC, this is a real int3 in original code, let debuggee handle it
}
return;
}

View File

@ -40,6 +40,8 @@ namespace GleeBug
IsDbgReplyLaterSupported = mSafeStep;
}
uint32 consecutiveTimeouts = 0;
while(!mBreakDebugger)
{
//wait for a debug event
@ -65,11 +67,18 @@ namespace GleeBug
#endif
else
{
// Regular timeout, wait again
//after 2 consecutive timeouts, clear recently deleted breakpoints
//any stale events would have been delivered by now
consecutiveTimeouts++;
if(consecutiveTimeouts >= 2 && mProcess)
mProcess->recentlyDeletedSwbp.clear();
continue;
}
}
//event received, reset timeout counter
consecutiveTimeouts = 0;
// Handle safe stepping
if(IsDbgReplyLaterSupported)
{

View File

@ -68,6 +68,8 @@ namespace GleeBug
return false;
FlushInstructionCache(hProcess, nullptr, 0);
recentlyDeletedSwbp.push_back(address);
//remove the breakpoint from the maps
softwareBreakpointReferences.erase(info.address);
breakpoints.erase(found);

View File

@ -32,6 +32,8 @@ namespace GleeBug
MemoryBreakpointSet memoryBreakpointRanges;
MemoryBreakpointMap memoryBreakpointPages;
std::vector<ptr> recentlyDeletedSwbp;
/**
\brief Constructor.
\param hProcess Process handle.