1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12: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) void WinDebugger::SetBreakpoint(addr_target address, bool fromRehup)
{ {
int* countPtr = NULL; int* countPtr = NULL;
if (mBreakpointAddrMap.TryAdd(address, NULL, &countPtr)) if (mPhysBreakpointAddrMap.TryAdd(address, NULL, &countPtr))
{ {
BfLogDbg("SetBreakpoint %p\n", address); BfLogDbg("SetBreakpoint %p\n", address);
*countPtr = 1; *countPtr = 1;
@ -752,7 +752,7 @@ void WinDebugger::PhysRemoveBreakpoint(addr_target address)
void WinDebugger::RemoveBreakpoint(addr_target address) void WinDebugger::RemoveBreakpoint(addr_target address)
{ {
int* countPtr = NULL; int* countPtr = NULL;
mBreakpointAddrMap.TryGetValue(address, &countPtr); mPhysBreakpointAddrMap.TryGetValue(address, &countPtr);
// This can happen when we shutdown and we're continuing from a breakpoint // This can happen when we shutdown and we're continuing from a breakpoint
//BF_ASSERT(*countPtr != NULL); //BF_ASSERT(*countPtr != NULL);
@ -768,7 +768,7 @@ void WinDebugger::RemoveBreakpoint(addr_target address)
(*countPtr)--; (*countPtr)--;
return; return;
} }
mBreakpointAddrMap.Remove(address); mPhysBreakpointAddrMap.Remove(address);
PhysRemoveBreakpoint(address); PhysRemoveBreakpoint(address);
} }
@ -842,25 +842,47 @@ bool WinDebugger::ContinueFromBreakpoint()
return true; return true;
} }
Breakpoint* WinDebugger::FindBreakpointAt(intptr addressIn) void WinDebugger::ValidateBreakpoints()
{ {
addr_target address = addressIn; HashSet<addr_target> usedBreakpoints;
WdBreakpoint* found = NULL; std::function<void(WdBreakpoint*)> _AddBreakpoint = [&](WdBreakpoint* breakpoint)
for (auto breakpoint : mBreakpoints)
{ {
if (breakpoint->mAddr == address) if (breakpoint->mAddr != 0)
found = breakpoint; {
usedBreakpoints.Add(breakpoint->mAddr);
WdBreakpoint* foundBreakpoint = NULL;
mBreakpointAddrMap.TryGetValue(breakpoint->mAddr, &foundBreakpoint);
BF_ASSERT(breakpoint == foundBreakpoint);
}
auto checkSibling = (WdBreakpoint*)breakpoint->mLinkedSibling; auto checkSibling = (WdBreakpoint*)breakpoint->mLinkedSibling;
while (checkSibling != NULL) while (checkSibling != NULL)
{ {
if (checkSibling->mAddr == address) _AddBreakpoint(checkSibling);
found = checkSibling;
checkSibling = (WdBreakpoint*)checkSibling->mLinkedSibling; 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() Breakpoint* WinDebugger::GetActiveBreakpoint()
@ -899,6 +921,10 @@ void WinDebugger::DebugThreadProc()
for (int i = 0; i < (int) mBreakpoints.size(); i++) for (int i = 0; i < (int) mBreakpoints.size(); i++)
{ {
WdBreakpoint* wdBreakpoint = mBreakpoints[i]; WdBreakpoint* wdBreakpoint = mBreakpoints[i];
if (wdBreakpoint->mAddr != 0)
mBreakpointAddrMap.Remove(wdBreakpoint->mAddr, wdBreakpoint);
wdBreakpoint->mAddr = 0; wdBreakpoint->mAddr = 0;
wdBreakpoint->mLineData = DbgLineDataEx(); wdBreakpoint->mLineData = DbgLineDataEx();
wdBreakpoint->mSrcFile = NULL; wdBreakpoint->mSrcFile = NULL;
@ -1351,6 +1377,7 @@ void WinDebugger::Detach()
mGotStartupEvent = false; mGotStartupEvent = false;
mIsDebuggerWaiting = false; mIsDebuggerWaiting = false;
mPhysBreakpointAddrMap.Clear();
mBreakpointAddrMap.Clear(); mBreakpointAddrMap.Clear();
gDebugUpdateCnt = 0; 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()); 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); SetBreakpoint(address);
foundInSequence = true; foundInSequence = true;
@ -3239,6 +3267,7 @@ void WinDebugger::CheckBreakpoint(WdBreakpoint* wdBreakpoint)
{ {
wdBreakpoint->mAddr = targetAddr; wdBreakpoint->mAddr = targetAddr;
wdBreakpoint->mBreakpointType = BreakpointType_User; wdBreakpoint->mBreakpointType = BreakpointType_User;
mBreakpointAddrMap.ForceAdd(wdBreakpoint->mAddr, wdBreakpoint);
SetBreakpoint(wdBreakpoint->mAddr); SetBreakpoint(wdBreakpoint->mAddr);
} }
else else
@ -3385,6 +3414,7 @@ Breakpoint* WinDebugger::CreateAddressBreakpoint(intptr inAddress)
addr_target address = (addr_target)inAddress; addr_target address = (addr_target)inAddress;
WdBreakpoint* wdBreakpoint = new WdBreakpoint(); WdBreakpoint* wdBreakpoint = new WdBreakpoint();
wdBreakpoint->mAddr = address; wdBreakpoint->mAddr = address;
mBreakpointAddrMap.ForceAdd(wdBreakpoint->mAddr, wdBreakpoint);
SetBreakpoint(address); SetBreakpoint(address);
if ((mDebuggerWaitingThread != NULL) && (mDebuggerWaitingThread->mStoppedAtAddress == address)) if ((mDebuggerWaitingThread != NULL) && (mDebuggerWaitingThread->mStoppedAtAddress == address))
@ -3431,6 +3461,7 @@ void WinDebugger::DeleteBreakpoint(Breakpoint* breakpoint)
if (wdBreakpoint->mAddr != 0) if (wdBreakpoint->mAddr != 0)
{ {
mBreakpointAddrMap.Remove(wdBreakpoint->mAddr, wdBreakpoint);
RemoveBreakpoint(wdBreakpoint->mAddr); RemoveBreakpoint(wdBreakpoint->mAddr);
for (auto thread : mThreadList) for (auto thread : mThreadList)
@ -3463,6 +3494,7 @@ void WinDebugger::DetachBreakpoint(Breakpoint* breakpoint)
if (wdBreakpoint->mAddr != 0) if (wdBreakpoint->mAddr != 0)
{ {
mBreakpointAddrMap.Remove(wdBreakpoint->mAddr, wdBreakpoint);
RemoveBreakpoint(wdBreakpoint->mAddr); RemoveBreakpoint(wdBreakpoint->mAddr);
if ((mDebuggerWaitingThread != NULL) && (mDebuggerWaitingThread->mIsAtBreakpointAddress == wdBreakpoint->mAddr)) if ((mDebuggerWaitingThread != NULL) && (mDebuggerWaitingThread->mIsAtBreakpointAddress == wdBreakpoint->mAddr))
mDebuggerWaitingThread->mIsAtBreakpointAddress = NULL; mDebuggerWaitingThread->mIsAtBreakpointAddress = NULL;
@ -5056,7 +5088,7 @@ bool WinDebugger::SetHotJump(DbgSubprogram* oldSubprogram, addr_target newTarget
{ {
for (addr_target addr = jmpInstStart; addr < jmpInstEnd; addr++) for (addr_target addr = jmpInstStart; addr < jmpInstEnd; addr++)
{ {
if (mBreakpointAddrMap.ContainsKey(addr)) if (mPhysBreakpointAddrMap.ContainsKey(addr))
{ {
removedBreakpoint = true; removedBreakpoint = true;
RemoveBreakpoint(addr); RemoveBreakpoint(addr);

View file

@ -421,8 +421,9 @@ public:
DWORD mDebuggerThreadId; DWORD mDebuggerThreadId;
WdMemoryBreakpointBind mMemoryBreakpoints[4]; 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; Array<WdBreakpoint*> mBreakpoints;
Dictionary<addr_target, WdBreakpoint*> mBreakpointAddrMap;
Array<int> mFreeMemoryBreakIndices; Array<int> mFreeMemoryBreakIndices;
Array<WdStackFrame*> mCallStack; Array<WdStackFrame*> mCallStack;
bool mIsPartialCallStack; bool mIsPartialCallStack;
@ -477,6 +478,7 @@ public:
void ThreadRestoreUnpause(); void ThreadRestoreUnpause();
void UpdateThreadDebugRegisters(WdThreadInfo* threadInfo); void UpdateThreadDebugRegisters(WdThreadInfo* threadInfo);
void UpdateThreadDebugRegisters(); void UpdateThreadDebugRegisters();
void ValidateBreakpoints();
void PhysSetBreakpoint(addr_target address); void PhysSetBreakpoint(addr_target address);
void SetBreakpoint(addr_target address, bool fromRehup = false); void SetBreakpoint(addr_target address, bool fromRehup = false);
void SetTempBreakpoint(addr_target address); void SetTempBreakpoint(addr_target address);