mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Improved hot compilation handling of DLLs
This commit is contained in:
parent
990b509111
commit
c7ae0988dc
9 changed files with 84 additions and 9 deletions
|
@ -1108,6 +1108,14 @@ BF_EXPORT int BF_CALLTYPE Debugger_GetRunState()
|
|||
return gDebugger->mRunState;
|
||||
}
|
||||
|
||||
BF_EXPORT bool Debugger_HasLoadedTargetBinary()
|
||||
{
|
||||
AutoCrit autoCrit(gDebugManager->mCritSect);
|
||||
if (gDebugger == NULL)
|
||||
return false;
|
||||
return gDebugger->HasLoadedTargetBinary();
|
||||
}
|
||||
|
||||
BF_EXPORT bool BF_CALLTYPE Debugger_HasPendingDebugLoads()
|
||||
{
|
||||
if (gDebugger == NULL)
|
||||
|
|
|
@ -30,6 +30,8 @@ DebugTarget::DebugTarget(WinDebugger* debugger)
|
|||
mCapturedNamesPtr = NULL;
|
||||
mCapturedTypesPtr = NULL;
|
||||
mHotHeap = NULL;
|
||||
mHotHeapAddr = 0;
|
||||
mHotHeapReserveSize = 0;
|
||||
mLastHotHeapCleanIdx = 0;
|
||||
mIsEmpty = false;
|
||||
mWasLocallyBuilt = false;
|
||||
|
@ -107,12 +109,18 @@ void DebugTarget::SetupTargetBinary()
|
|||
{
|
||||
reservedPtr = (addr_target)VirtualAllocEx(mDebugger->mProcessInfo.hProcess, (void*)(intptr)checkHotReserveAddr, reserveSize, MEM_RESERVE, PAGE_EXECUTE_READWRITE);
|
||||
if (reservedPtr != NULL)
|
||||
{
|
||||
mHotHeapAddr = reservedPtr;
|
||||
mHotHeapReserveSize = reserveSize;
|
||||
BfLogDbg("VirtualAllocEx %p %d. ImageBase: %p\n", mHotHeapAddr, mHotHeapReserveSize, mTargetBinary->mImageBase);
|
||||
break;
|
||||
}
|
||||
checkHotReserveAddr += 4 * mb;
|
||||
}
|
||||
|
||||
if (reservedPtr == 0)
|
||||
{
|
||||
BfLogDbg("VirtualAllocEx failed. ImageBase: %p\n", mTargetBinary->mImageBase);
|
||||
mDebugger->Fail("Failed to reserve memory for hot swapping");
|
||||
}
|
||||
else
|
||||
|
@ -207,7 +215,7 @@ DbgModule* DebugTarget::SetupDyn(const StringImpl& filePath, DataStream* stream,
|
|||
{
|
||||
BP_ZONE("DebugTarget::SetupDyn");
|
||||
|
||||
AutoDbgTime dbgTime("DebugTarget::SetupDyn " + filePath);
|
||||
//AutoDbgTime dbgTime("DebugTarget::SetupDyn " + filePath);
|
||||
|
||||
DbgModule* dwarf = new COFF(this);
|
||||
dwarf->mFilePath = filePath;
|
||||
|
@ -239,7 +247,7 @@ String DebugTarget::UnloadDyn(addr_target imageBase)
|
|||
{
|
||||
String filePath;
|
||||
|
||||
AutoDbgTime dbgTime("DebugTarget::UnloadDyn");
|
||||
//AutoDbgTime dbgTime("DebugTarget::UnloadDyn");
|
||||
|
||||
for (int i = 0; i < (int)mDbgModules.size(); i++)
|
||||
{
|
||||
|
@ -252,7 +260,18 @@ String DebugTarget::UnloadDyn(addr_target imageBase)
|
|||
filePath = dwarf->mFilePath;
|
||||
|
||||
if (mTargetBinary == dwarf)
|
||||
{
|
||||
mTargetBinary = NULL;
|
||||
delete mHotHeap;
|
||||
mHotHeap = NULL;
|
||||
|
||||
if (mHotHeapAddr != 0)
|
||||
{
|
||||
BfLogDbg("VirtualFreeEx %p %d\n", mHotHeapAddr, mHotHeapReserveSize);
|
||||
::VirtualFreeEx(mDebugger->mProcessInfo.hProcess, (void*)(intptr)mHotHeapAddr, 0, MEM_RELEASE);
|
||||
mHotHeapAddr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
mDbgModules.RemoveAt(i);
|
||||
bool success = mDbgModuleMap.Remove(dwarf->mId);
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
Array<DbgType*>* mCapturedTypesPtr;
|
||||
|
||||
HotHeap* mHotHeap;
|
||||
addr_target mHotHeapAddr;
|
||||
int64 mHotHeapReserveSize;
|
||||
int mLastHotHeapCleanIdx;
|
||||
String mTargetPath;
|
||||
DbgModule* mLaunchBinary;
|
||||
|
|
|
@ -159,7 +159,8 @@ enum RunState
|
|||
RunState_Terminating,
|
||||
RunState_Terminated,
|
||||
RunState_SearchingSymSrv,
|
||||
RunState_HotResolve
|
||||
RunState_HotResolve,
|
||||
RunState_TargetUnloaded
|
||||
};
|
||||
|
||||
enum DebuggerResult
|
||||
|
@ -268,6 +269,7 @@ public:
|
|||
virtual void OpenFile(const StringImpl& launchPath, const StringImpl& targetPath, const StringImpl& args, const StringImpl& workingDir, const Array<uint8>& envBlock, bool hotSwapEnabled) = 0;
|
||||
virtual bool Attach(int processId, BfDbgAttachFlags attachFlags) = 0;
|
||||
virtual void Run() = 0;
|
||||
virtual bool HasLoadedTargetBinary() { return true; }
|
||||
virtual void HotLoad(const Array<String>& objectFiles, int hotIdx) = 0;
|
||||
virtual void InitiateHotResolve(DbgHotResolveFlags flags) = 0;
|
||||
virtual intptr GetDbgAllocHeapSize() = 0;
|
||||
|
|
|
@ -1067,6 +1067,13 @@ void WinDebugger::Run()
|
|||
CloseHandle(hThread);
|
||||
}
|
||||
|
||||
bool WinDebugger::HasLoadedTargetBinary()
|
||||
{
|
||||
if (mDebugTarget == NULL)
|
||||
return false;
|
||||
return mDebugTarget->mTargetBinary != NULL;
|
||||
}
|
||||
|
||||
void WinDebugger::HotLoad(const Array<String>& objectFiles, int hotIdx)
|
||||
{
|
||||
AutoCrit autoCrit(mDebugManager->mCritSect);
|
||||
|
@ -1891,10 +1898,16 @@ bool WinDebugger::DoUpdate()
|
|||
}
|
||||
}
|
||||
|
||||
bool hadTarget = mDebugTarget->mTargetBinary != NULL;
|
||||
mDebugTarget->UnloadDyn(dbgModule->mImageBase);
|
||||
if (needsBreakpointRehup)
|
||||
RehupBreakpoints(true);
|
||||
|
||||
if ((mDebugTarget->mTargetBinary == NULL) && (hadTarget))
|
||||
{
|
||||
mRunState = RunState_TargetUnloaded;
|
||||
}
|
||||
|
||||
mPendingDebugInfoLoad.Remove(dbgModule);
|
||||
mPendingDebugInfoRequests.Remove(dbgModule);
|
||||
mDebugManager->mOutMessages.push_back("modulesChanged");
|
||||
|
@ -2880,7 +2893,7 @@ void WinDebugger::ContinueDebugEvent()
|
|||
}
|
||||
}
|
||||
|
||||
if ((mRunState == RunState_Breakpoint) || (mRunState == RunState_Paused))
|
||||
if ((mRunState == RunState_Breakpoint) || (mRunState == RunState_Paused) || (mRunState == RunState_TargetUnloaded))
|
||||
{
|
||||
ClearCallStack();
|
||||
mRunState = RunState_Running;
|
||||
|
|
|
@ -584,6 +584,7 @@ public:
|
|||
virtual void OpenFile(const StringImpl& launchPath, const StringImpl& targetPath, const StringImpl& args, const StringImpl& workingDir, const Array<uint8>& envBlock, bool hotSwapEnabled) override;
|
||||
virtual bool Attach(int processId, BfDbgAttachFlags attachFlags) override;
|
||||
virtual void Run() override;
|
||||
virtual bool HasLoadedTargetBinary() override;
|
||||
virtual void HotLoad(const Array<String>& objectFiles, int hotIdx) override;
|
||||
virtual void InitiateHotResolve(DbgHotResolveFlags flags) override;
|
||||
virtual intptr GetDbgAllocHeapSize() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue