1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Switched to hashmap for FindBreakpointAt

This commit is contained in:
Brian Fiete 2020-03-14 16:15:38 -07:00
parent cf7914f71a
commit ecf812ee19
2 changed files with 56 additions and 22 deletions

View file

@ -700,7 +700,7 @@ void WinDebugger::PhysSetBreakpoint(addr_target address)
void WinDebugger::SetBreakpoint(addr_target address, bool fromRehup)
{
int* countPtr = NULL;
if (mBreakpointAddrMap.TryAdd(address, NULL, &countPtr))
if (mPhysBreakpointAddrMap.TryAdd(address, NULL, &countPtr))
{
BfLogDbg("SetBreakpoint %p\n", address);
*countPtr = 1;
@ -752,7 +752,7 @@ void WinDebugger::PhysRemoveBreakpoint(addr_target address)
void WinDebugger::RemoveBreakpoint(addr_target address)
{
int* countPtr = NULL;
mBreakpointAddrMap.TryGetValue(address, &countPtr);
mPhysBreakpointAddrMap.TryGetValue(address, &countPtr);
// This can happen when we shutdown and we're continuing from a breakpoint
//BF_ASSERT(*countPtr != NULL);
@ -768,7 +768,7 @@ void WinDebugger::RemoveBreakpoint(addr_target address)
(*countPtr)--;
return;
}
mBreakpointAddrMap.Remove(address);
mPhysBreakpointAddrMap.Remove(address);
PhysRemoveBreakpoint(address);
}
@ -842,25 +842,47 @@ bool WinDebugger::ContinueFromBreakpoint()
return true;
}
Breakpoint* WinDebugger::FindBreakpointAt(intptr addressIn)
void WinDebugger::ValidateBreakpoints()
{
addr_target address = addressIn;
HashSet<addr_target> usedBreakpoints;
WdBreakpoint* found = NULL;
for (auto breakpoint : mBreakpoints)
std::function<void(WdBreakpoint*)> _AddBreakpoint = [&](WdBreakpoint* breakpoint)
{
if (breakpoint->mAddr == address)
found = breakpoint;
if (breakpoint->mAddr != 0)
{
usedBreakpoints.Add(breakpoint->mAddr);
WdBreakpoint* foundBreakpoint = NULL;
mBreakpointAddrMap.TryGetValue(breakpoint->mAddr, &foundBreakpoint);
BF_ASSERT(breakpoint == foundBreakpoint);
}
auto checkSibling = (WdBreakpoint*)breakpoint->mLinkedSibling;
while (checkSibling != NULL)
{
if (checkSibling->mAddr == address)
found = checkSibling;
_AddBreakpoint(checkSibling);
checkSibling = (WdBreakpoint*)checkSibling->mLinkedSibling;
}
};
for (auto breakpoint : mBreakpoints)
_AddBreakpoint(breakpoint);
for (auto& entry : mBreakpointAddrMap)
{
BF_ASSERT(usedBreakpoints.Contains(entry.mKey));
}
return found;
}
Breakpoint* WinDebugger::FindBreakpointAt(intptr address)
{
#ifdef _DEBUG
ValidateBreakpoints();
#endif
WdBreakpoint* breakpoint = NULL;
mBreakpointAddrMap.TryGetValue(address, &breakpoint);
return breakpoint;
}
Breakpoint* WinDebugger::GetActiveBreakpoint()
@ -899,6 +921,10 @@ void WinDebugger::DebugThreadProc()
for (int i = 0; i < (int) mBreakpoints.size(); i++)
{
WdBreakpoint* wdBreakpoint = mBreakpoints[i];
if (wdBreakpoint->mAddr != 0)
mBreakpointAddrMap.Remove(wdBreakpoint->mAddr, wdBreakpoint);
wdBreakpoint->mAddr = 0;
wdBreakpoint->mLineData = DbgLineDataEx();
wdBreakpoint->mSrcFile = NULL;
@ -1351,6 +1377,7 @@ void WinDebugger::Detach()
mGotStartupEvent = false;
mIsDebuggerWaiting = false;
mPhysBreakpointAddrMap.Clear();
mBreakpointAddrMap.Clear();
gDebugUpdateCnt = 0;
@ -3049,6 +3076,7 @@ void WinDebugger::CheckBreakpoint(WdBreakpoint* wdBreakpoint, DbgSrcFile* srcFil
BfLogDbg("Breakpoint %p found at %s in %s\n", wdBreakpoint, subProgram->mName, GetFileName(subProgram->mCompileUnit->mDbgModule->mFilePath).c_str());
mBreakpointAddrMap.ForceAdd(address, wdBreakpoint);
SetBreakpoint(address);
foundInSequence = true;
@ -3239,6 +3267,7 @@ void WinDebugger::CheckBreakpoint(WdBreakpoint* wdBreakpoint)
{
wdBreakpoint->mAddr = targetAddr;
wdBreakpoint->mBreakpointType = BreakpointType_User;
mBreakpointAddrMap.ForceAdd(wdBreakpoint->mAddr, wdBreakpoint);
SetBreakpoint(wdBreakpoint->mAddr);
}
else
@ -3385,6 +3414,7 @@ Breakpoint* WinDebugger::CreateAddressBreakpoint(intptr inAddress)
addr_target address = (addr_target)inAddress;
WdBreakpoint* wdBreakpoint = new WdBreakpoint();
wdBreakpoint->mAddr = address;
mBreakpointAddrMap.ForceAdd(wdBreakpoint->mAddr, wdBreakpoint);
SetBreakpoint(address);
if ((mDebuggerWaitingThread != NULL) && (mDebuggerWaitingThread->mStoppedAtAddress == address))
@ -3431,6 +3461,7 @@ void WinDebugger::DeleteBreakpoint(Breakpoint* breakpoint)
if (wdBreakpoint->mAddr != 0)
{
mBreakpointAddrMap.Remove(wdBreakpoint->mAddr, wdBreakpoint);
RemoveBreakpoint(wdBreakpoint->mAddr);
for (auto thread : mThreadList)
@ -3463,6 +3494,7 @@ void WinDebugger::DetachBreakpoint(Breakpoint* breakpoint)
if (wdBreakpoint->mAddr != 0)
{
mBreakpointAddrMap.Remove(wdBreakpoint->mAddr, wdBreakpoint);
RemoveBreakpoint(wdBreakpoint->mAddr);
if ((mDebuggerWaitingThread != NULL) && (mDebuggerWaitingThread->mIsAtBreakpointAddress == wdBreakpoint->mAddr))
mDebuggerWaitingThread->mIsAtBreakpointAddress = NULL;
@ -5056,7 +5088,7 @@ bool WinDebugger::SetHotJump(DbgSubprogram* oldSubprogram, addr_target newTarget
{
for (addr_target addr = jmpInstStart; addr < jmpInstEnd; addr++)
{
if (mBreakpointAddrMap.ContainsKey(addr))
if (mPhysBreakpointAddrMap.ContainsKey(addr))
{
removedBreakpoint = true;
RemoveBreakpoint(addr);

View file

@ -421,8 +421,9 @@ public:
DWORD mDebuggerThreadId;
WdMemoryBreakpointBind mMemoryBreakpoints[4];
Dictionary<addr_target, int> mBreakpointAddrMap; // To make sure we don't create multiple physical breakpoints at the same addr
Dictionary<addr_target, int> mPhysBreakpointAddrMap; // To make sure we don't create multiple physical breakpoints at the same addr
Array<WdBreakpoint*> mBreakpoints;
Dictionary<addr_target, WdBreakpoint*> mBreakpointAddrMap;
Array<int> mFreeMemoryBreakIndices;
Array<WdStackFrame*> mCallStack;
bool mIsPartialCallStack;
@ -477,6 +478,7 @@ public:
void ThreadRestoreUnpause();
void UpdateThreadDebugRegisters(WdThreadInfo* threadInfo);
void UpdateThreadDebugRegisters();
void ValidateBreakpoints();
void PhysSetBreakpoint(addr_target address);
void SetBreakpoint(addr_target address, bool fromRehup = false);
void SetTempBreakpoint(addr_target address);