From bac46ef6e9ccccecdcf04c8562c199e18615b685 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Fri, 27 Sep 2019 13:05:39 -0700 Subject: [PATCH] Changes to improve IDE Module Panel, allowing loading image and pdb --- IDE/src/Debugger/DebugManager.bf | 8 ++++ IDEHelper/COFF.cpp | 59 ++++++++++++++++---------- IDEHelper/COFF.h | 4 ++ IDEHelper/Compiler/BfExprEvaluator.cpp | 20 +++++---- IDEHelper/Compiler/BfIRBuilder.cpp | 2 +- IDEHelper/DbgSymSrv.cpp | 7 +-- IDEHelper/DebugManager.cpp | 5 +++ IDEHelper/Debugger.h | 1 + IDEHelper/WinDebugger.cpp | 50 ++++++++++++++++++++-- IDEHelper/WinDebugger.h | 9 ++-- 10 files changed, 124 insertions(+), 41 deletions(-) diff --git a/IDE/src/Debugger/DebugManager.bf b/IDE/src/Debugger/DebugManager.bf index 426d1f3a..8979d0a1 100644 --- a/IDE/src/Debugger/DebugManager.bf +++ b/IDE/src/Debugger/DebugManager.bf @@ -328,6 +328,9 @@ namespace IDE.Debugger [StdCall,CLink] static extern bool Debugger_HasPendingDebugLoads(); + [StdCall,CLink] + static extern int32 Debugger_LoadImageForModuleWith(char8* moduleName, char8* imageFileName); + [StdCall,CLink] static extern int32 Debugger_LoadDebugInfoForModule(char8* moduleName); @@ -1089,6 +1092,11 @@ namespace IDE.Debugger return Debugger_LoadDebugInfoForModule(moduleName); } + public int32 LoadImageForModule(String moduleName, String debugFileName) + { + return Debugger_LoadImageForModuleWith(moduleName, debugFileName); + } + public int32 LoadDebugInfoForModule(String moduleName, String debugFileName) { return Debugger_LoadDebugInfoForModuleWith(moduleName, debugFileName); diff --git a/IDEHelper/COFF.cpp b/IDEHelper/COFF.cpp index 94fb695c..314407a9 100644 --- a/IDEHelper/COFF.cpp +++ b/IDEHelper/COFF.cpp @@ -223,7 +223,9 @@ uint8* CvStreamReader::GetPermanentPtr(int offset, int size, bool* madeCopy) COFF::COFF(DebugTarget* debugTarget) : DbgModule(debugTarget) { mParseKind = ParseKind_Full; - memset(mPDBGuid, 0, 16); + memset(mWantPDBGuid, 0, 16); + memset(mPDBGuid, 0, 16); + mWantAge = -1; mDebugAge = -1; mFileAge = -1; mCvMinTag = -1; @@ -5824,6 +5826,9 @@ bool COFF::LoadPDB(const String& pdbPath, uint8 wantGuid[16], int32 wantAge) mDebugTarget->mWasLocallyBuilt = FileExists(pdbPath); } + memcpy(mWantPDBGuid, wantGuid, 16); + mWantAge = wantAge; + mDbgSymRequest = mDebugger->mDbgSymSrv.CreateRequest(mFilePath, pdbPath, wantGuid, wantAge); mDbgSymRequest->SearchLocal(); @@ -6424,6 +6429,36 @@ void COFF::PreCacheDebugInfo() } } +bool COFF::LoadModuleImage(const StringImpl& imagePath) +{ + if (!mDebugger->IsMiniDumpDebugger()) + return false; + + auto miniDumpDebugger = (MiniDumpDebugger*)mDebugger; + + if (!imagePath.IsEmpty()) + { + MappedFile* mappedFile = miniDumpDebugger->MapModule(this, imagePath); + mMappedImageFile = mappedFile; + + if (mappedFile != NULL) + { + MemStream memStream(mappedFile->mData, mappedFile->mFileSize, false); + ReadCOFF(&memStream, false); + + mOrigImageData = new DbgModuleMemoryCache(mImageBase, mImageSize); + } + } + + if (mOrigImageData == NULL) // Failed? + { + mLoadState = DbgModuleLoadState_Failed; + return false; + } + + return true; +} + bool COFF::RequestImage() { if (!mDebugger->IsMiniDumpDebugger()) @@ -6455,27 +6490,7 @@ bool COFF::RequestImage() mDebugger->mRunState = prevRunState; - if (!imagePath.IsEmpty()) - { - MappedFile* mappedFile = miniDumpDebugger->MapModule(this, imagePath); - mMappedImageFile = mappedFile; - - if (mappedFile != NULL) - { - MemStream memStream(mappedFile->mData, mappedFile->mFileSize, false); - ReadCOFF(&memStream, false); - - mOrigImageData = new DbgModuleMemoryCache(mImageBase, mImageSize); - } - } - - if (mOrigImageData == NULL) // Failed? - { - mLoadState = DbgModuleLoadState_NotLoaded; - return false; - } - - return true; + return LoadModuleImage(imagePath); } else { diff --git a/IDEHelper/COFF.h b/IDEHelper/COFF.h index fc544521..58ce9292 100644 --- a/IDEHelper/COFF.h +++ b/IDEHelper/COFF.h @@ -214,6 +214,9 @@ public: }; public: + uint8 mWantPDBGuid[16]; + int mWantAge; + uint8 mPDBGuid[16]; int mFileAge; int mDebugAge; @@ -321,6 +324,7 @@ public: virtual addr_target LocateSymbol(const StringImpl& name) override; virtual void ParseFrameDescriptors() override; + bool LoadModuleImage(const StringImpl& imagePath); void FixConstant(DbgVariable* variable); void MapRanges(DbgVariable* variable, CV_LVAR_ADDR_RANGE* range, CV_LVAR_ADDR_GAP* gaps); void MakeThis(DbgSubprogram* curSubprogram, DbgVariable*& curParam); diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 56aa00ef..5172c176 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -9756,22 +9756,26 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam auto voidType = mModule->GetPrimitiveType(BfTypeCode_None); auto dtorFuncType = mModule->mBfIRBuilder->CreateFunctionType(mModule->mBfIRBuilder->MapType(voidType), newTypes, false); - String dtorMangledName = "~" + closureFuncName; - dtorFunc = mModule->mBfIRBuilder->CreateFunction(dtorFuncType, BfIRLinkageType_External, dtorMangledName); - BfMethodDef* dtorMethodDef = new BfMethodDef(); dtorMethodDef->mDeclaringType = mModule->mCurMethodInstance->mMethodDef->mDeclaringType; - dtorMethodDef->mName = "~this"; + dtorMethodDef->mName = "~this$"; + dtorMethodDef->mName += methodDef->mName; + dtorMethodDef->mMethodType = BfMethodType_Normal; dtorMethodDef->mBody = lambdaBindExpr->mDtor; dtorMethodDef->mIdx = mModule->mCurMethodInstance->mMethodDef->mIdx; - BfMethodInstance* dtorMethodInstance = new BfMethodInstance(); - //dtorMethodInstance->mMethodInstanceGroup = &methodInstanceGroup; - dtorMethodInstance->mIRFunction = dtorFunc; + BfMethodInstance* dtorMethodInstance = new BfMethodInstance(); dtorMethodInstance->mMethodDef = dtorMethodDef; dtorMethodInstance->mReturnType = mModule->GetPrimitiveType(BfTypeCode_None); dtorMethodInstance->mMethodInstanceGroup = &methodInstanceGroup; + + StringT<128> dtorMangledName; + BfMangler::Mangle(dtorMangledName, mModule->mCompiler->GetMangleKind(), dtorMethodInstance); + dtorFunc = mModule->mBfIRBuilder->CreateFunction(dtorFuncType, BfIRLinkageType_External, dtorMangledName); + mModule->SetupIRMethod(NULL, dtorFunc, false); + dtorMethodInstance->mIRFunction = dtorFunc; + mModule->mIncompleteMethodCount++; mModule->mBfIRBuilder->SaveDebugLocation(); // @@ -9784,7 +9788,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam mModule->mBfIRBuilder->RestoreDebugLocation(); if (mModule->mCompiler->IsSkippingExtraResolveChecks()) dtorFunc = BfIRFunction(); - + if (dtorMethodInstance->mIsReified) mModule->CheckHotMethod(dtorMethodInstance, dtorMangledName); if ((dtorMethodInstance->mHotMethod != NULL) && (mModule->mCurMethodState->mHotDataReferenceBuilder)) diff --git a/IDEHelper/Compiler/BfIRBuilder.cpp b/IDEHelper/Compiler/BfIRBuilder.cpp index 7840546d..c1024230 100644 --- a/IDEHelper/Compiler/BfIRBuilder.cpp +++ b/IDEHelper/Compiler/BfIRBuilder.cpp @@ -4668,7 +4668,7 @@ BfIRMDNode BfIRBuilder::DbgCreateMethod(BfIRMDNode context, const StringImpl& na { BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateMethod, context, name, linkageName, file, lineNum, type, isLocalToUnit, isDefinition, vk, vIndex, vTableHolder, flags, isOptimized, fn, genericArgs, genericConstValueArgs); NEW_CMD_INSERTED_IRMD; - + // if (mDbgVerifyCodeGen && gDebugDbgLoc) // { // OutputDebugStrF("DbgCreateFunction Context:%d name:%s = %d\n", context.mId, name.c_str(), retVal.mId); diff --git a/IDEHelper/DbgSymSrv.cpp b/IDEHelper/DbgSymSrv.cpp index 712f6ba4..f15a0104 100644 --- a/IDEHelper/DbgSymSrv.cpp +++ b/IDEHelper/DbgSymSrv.cpp @@ -494,10 +494,11 @@ String DbgSymRequest::SearchForImage(const String& filePath, uint32 fileTime, in } } - if ((!mIsPreCache) && (!mDbgSymSrv->mDebugger->mHadImageFindError)) + if (!mIsPreCache) { - mDbgSymSrv->mDebugger->mHadImageFindError = true; - mDbgSymSrv->mDebugger->OutputMessage(StrFormat("ERROR: Unable to locate image '%s'. If this file is located on a symbol server, configure the symbol server location in File\\Preferences\\Settings under Debugger\\Symbol File Locations.\n", GetFileName(filePath).c_str())); + mDbgSymSrv->mDebugger->mHadImageFindError = true; + mDbgSymSrv->mDebugger->OutputMessage(StrFormat("ERROR: Unable to locate image '%s' (%08X%x). If this file is located on a symbol server, configure the symbol server location in File\\Preferences\\Settings under Debugger\\Symbol File Locations.\n", + GetFileName(filePath).c_str(), fileTime, size)); } mFailed = true; diff --git a/IDEHelper/DebugManager.cpp b/IDEHelper/DebugManager.cpp index 583fd67c..a352287b 100644 --- a/IDEHelper/DebugManager.cpp +++ b/IDEHelper/DebugManager.cpp @@ -1532,6 +1532,11 @@ BF_EXPORT void BF_CALLTYPE Debugger_CancelSymSrv() gDebugger->CancelSymSrv(); } +BF_EXPORT int BF_CALLTYPE Debugger_LoadImageForModuleWith(const char* moduleName, const char* debugFilePath) // 0 = No Change, 1 = Loaded, 2 = Loading in background +{ + return gDebugger->LoadImageForModule(moduleName, debugFilePath); +} + BF_EXPORT int BF_CALLTYPE Debugger_LoadDebugInfoForModule(const char* moduleName) // 0 = No Change, 1 = Loaded, 2 = Loading in background { return gDebugger->LoadDebugInfoForModule(moduleName); diff --git a/IDEHelper/Debugger.h b/IDEHelper/Debugger.h index a496ab43..694e74d3 100644 --- a/IDEHelper/Debugger.h +++ b/IDEHelper/Debugger.h @@ -304,6 +304,7 @@ public: virtual void SetAliasPath(const StringImpl& origPath, const StringImpl& localPath) = 0; virtual void CancelSymSrv() = 0; virtual bool HasPendingDebugLoads() = 0; + virtual int LoadImageForModule(const StringImpl& moduleName, const StringImpl& debugFileName) = 0; virtual int LoadDebugInfoForModule(const StringImpl& moduleName) = 0; virtual int LoadDebugInfoForModule(const StringImpl& moduleName, const StringImpl& debugFileName) = 0; virtual void StopDebugging() = 0; diff --git a/IDEHelper/WinDebugger.cpp b/IDEHelper/WinDebugger.cpp index c54cadb6..7d7c79da 100644 --- a/IDEHelper/WinDebugger.cpp +++ b/IDEHelper/WinDebugger.cpp @@ -11920,7 +11920,28 @@ String WinDebugger::GetModulesInfo() str += module->mDisplayName; str += "\t"; - str += module->mFilePath; + if (module->mLoadState == DbgModuleLoadState_Loaded) + { + str += module->mFilePath; + } + else if (module->mLoadState == DbgModuleLoadState_NotLoaded) + { + str += module->mFilePath; + str += " (Loading...)"; + } + else if (module->mLoadState == DbgModuleLoadState_Failed) + { + str += "!"; + str += module->mFilePath; + } + + if (module->mMappedImageFile != NULL) + { + str += " ("; + str += module->mMappedImageFile->mFileName; + str += ")"; + } + str += "\t"; str += coff->mPDBPath; str += "\t"; @@ -11957,6 +11978,29 @@ bool WinDebugger::HasPendingDebugLoads() return (!mPendingImageLoad.IsEmpty()) || (!mPendingDebugInfoLoad.IsEmpty()); } +int WinDebugger::LoadImageForModule(const StringImpl &modulePath, const StringImpl& imagePath) +{ + AutoCrit autoCrit(mDebugManager->mCritSect); + + for (auto dbgModule : mDebugTarget->mDbgModules) + { + if (modulePath.Equals(dbgModule->mFilePath, StringImpl::CompareKind_OrdinalIgnoreCase)) + { + auto coff = (COFF*)dbgModule; + + if (!coff->LoadModuleImage(imagePath)) + { + mDebugManager->mOutMessages.push_back("error Failed to load image " + imagePath); + } + ModuleChanged(dbgModule); + + return 0; + } + } + + return 0; +} + int WinDebugger::LoadDebugInfoForModule(DbgModule* dbgModule) { if (!dbgModule->HasPendingDebugInfo()) @@ -12007,10 +12051,10 @@ int WinDebugger::LoadDebugInfoForModule(const StringImpl& modulePath, const Stri auto coff = (COFF*)dbgModule; String err; - if (coff->mDbgSymRequest != NULL) + if (!coff->mPDBLoaded) { dbgModule->mFailMsgPtr = &err; - if (coff->TryLoadPDB(debugFileName, coff->mDbgSymRequest->mWantGuid, coff->mDbgSymRequest->mWantAge)) + if (coff->TryLoadPDB(debugFileName, coff->mWantPDBGuid, coff->mWantAge)) { ModuleChanged(dbgModule); } diff --git a/IDEHelper/WinDebugger.h b/IDEHelper/WinDebugger.h index 766d838c..376ba40b 100644 --- a/IDEHelper/WinDebugger.h +++ b/IDEHelper/WinDebugger.h @@ -558,10 +558,9 @@ public: String GetAutocompleteOutput(DwAutoComplete& autoComplete); bool CheckConditionalBreakpoint(WdBreakpoint* breakpoint, DbgSubprogram* dbgSubprogram, addr_target pcAddress); void CleanupDebugEval(bool restoreRegisters = true); - bool FixCallStackIdx(int& callStackIdx); - - virtual int LoadDebugInfoForModule(DbgModule* dbgModule); - virtual int LoadDebugInfoForModule(const StringImpl& moduleName, const StringImpl& debugFileName); + bool FixCallStackIdx(int& callStackIdx); + + int LoadDebugInfoForModule(DbgModule* dbgModule); public: WinDebugger(DebugManager* debugManager); @@ -643,6 +642,8 @@ public: virtual String GetModulesInfo() override; virtual void CancelSymSrv() override; virtual bool HasPendingDebugLoads() override; + virtual int LoadImageForModule(const StringImpl& moduleName, const StringImpl& debugFileName) override; + virtual int LoadDebugInfoForModule(const StringImpl& moduleName, const StringImpl& debugFileName) override; virtual int LoadDebugInfoForModule(const StringImpl& moduleName) override; virtual void StopDebugging() override; virtual void Terminate() override;