diff --git a/IDEHelper/COFF.cpp b/IDEHelper/COFF.cpp index c6736c55..5952a7f9 100644 --- a/IDEHelper/COFF.cpp +++ b/IDEHelper/COFF.cpp @@ -727,7 +727,7 @@ DbgSubprogram* COFF::CvParseMethod(DbgType* parentType, const char* methodName, } - if ((parentType != NULL) && (!mIsHotObjectFile)) + if ((parentType != NULL) && (!IsObjectFile())) { subprogram->mCompileUnit = parentType->mCompileUnit; parentType->mMethodList.PushBack(subprogram); @@ -1025,7 +1025,7 @@ void COFF::CvParseMembers(DbgType* parentType, int tagIdx, bool ipi) } } - if ((isStatic) && (!isConst) && (mIsHotObjectFile)) + if ((isStatic) && (!isConst) && (IsObjectFile())) { // Already has statics filled in break; @@ -2219,7 +2219,7 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD uint8* dataEnd = data + symLen; GET_INTO(uint16, symType); - if (!mIsHotObjectFile) + if (!IsObjectFile()) BF_ASSERT(symLen % 4 == 2); bool newLocalVarHasLocData = false; @@ -2320,7 +2320,7 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD case S_GDATA32: case S_LDATA32: // In PDB reads we get this from the symbol stream - if ((mIsHotObjectFile) || (curSubprogram != NULL)) + if ((IsObjectFile()) || (curSubprogram != NULL)) { auto linkedModule = GetLinkedModule(); DATASYM32& dataSym = *(DATASYM32*)dataStart; @@ -2362,7 +2362,7 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD if (curSubprogram != NULL) { - if (!mIsHotObjectFile) + if (!IsObjectFile()) { // Copy this, we free the source data variable->mName = DbgDupString(name, "DbgDupString.S_GDATA32"); @@ -2387,7 +2387,7 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD case S_GTHREAD32: case S_LTHREAD32: { - if ((mIsHotObjectFile) || (curSubprogram != NULL)) + if ((IsObjectFile()) || (curSubprogram != NULL)) { auto linkedModule = GetLinkedModule(); THREADSYM32& dataSym = *(THREADSYM32*)dataStart; @@ -2429,7 +2429,7 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD if (curSubprogram != NULL) { - if (!mIsHotObjectFile) + if (!IsObjectFile()) { // Copy this, we free the source data variable->mName = DbgDupString(name, "DbgDupString.S_GTHREAD32"); @@ -2474,7 +2474,7 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD else { bool ipi = false; - if ((!mIsHotObjectFile) && + if ((!IsObjectFile()) && ((symType == S_GPROC32_ID) || (symType == S_LPROC32_ID))) { if (!mCvIPIReader.IsSetup()) @@ -2961,7 +2961,7 @@ void COFF::ParseCompileUnit_Symbols(DbgCompileUnit* compileUnit, uint8* sectionD DbgSubprogram* inlineParent = curSubprogram; DbgSubprogram* subprogram = NULL; - if (mIsHotObjectFile) + if (IsObjectFile()) { subprogram = CvParseMethod(NULL, NULL, inlinee, false); subprogram->mCompileUnit = compileUnit; @@ -3990,7 +3990,7 @@ DbgType* COFF::CvGetTypeOrNamespace(char* name, DbgLanguage language) void COFF::MapCompileUnitMethods(DbgCompileUnit* compileUnit) { - bool addHotTypes = (mIsHotObjectFile) && (mHotPrimaryTypes.size() == 0); + bool addHotTypes = (IsObjectFile()) && (mHotPrimaryTypes.size() == 0); DbgSubprogram* prevDbgMethod = NULL; DbgSubprogram* dbgMethod = compileUnit->mOrphanMethods.mHead; @@ -4467,7 +4467,7 @@ void COFF::FixTypes(int startingIdx) if (dbgType->mIsDeclaration) continue; - if (mIsHotObjectFile) + if (IsObjectFile()) { auto entry = linkedModule->mTypeMap.Find(dbgType->mName, dbgType->mLanguage); if (entry != NULL) @@ -5184,7 +5184,7 @@ const char* COFF::CvParseSymbol(int offset, CvSymStreamType symStreamType, addr_ // Push front so we will find before the original static declaration (that has no memory associated with it) mGlobalsTargetType->mMemberList.PushFront(variable); - if (mIsHotObjectFile) + if (IsObjectFile()) { if ((variable->mIsExtern) && (variable->mLinkName != NULL)) mStaticVariables.push_back(variable); @@ -6406,7 +6406,7 @@ bool COFF::LoadModuleImage(const StringImpl& imagePath) if (mappedFile != NULL) { MemStream memStream(mappedFile->mData, mappedFile->mFileSize, false); - ReadCOFF(&memStream, false); + ReadCOFF(&memStream, DbgModuleKind_Module); mOrigImageData = new DbgModuleMemoryCache(mImageBase, mImageSize); } @@ -6512,7 +6512,7 @@ bool COFF::WantsAutoLoadDebugInfo() bool COFF::DbgIsStrMutable(const char* str) { - if (mIsHotObjectFile) + if (IsObjectFile()) { return GetLinkedModule()->DbgIsStrMutable(str); } @@ -6678,7 +6678,7 @@ addr_target COFF::LocateSymbol(const StringImpl& name) DbgModule* dbgModule = new COFF(mDebugger->mDebugTarget); dbgModule->mHotIdx = mDebugger->mActiveHotIdx; dbgModule->mFilePath = libEntry->mName + "@" + libEntry->mLibFile->mFilePath; - bool success = dbgModule->ReadCOFF(&fileStream, true); + bool success = dbgModule->ReadCOFF(&fileStream, DbgModuleKind_FromLocateSymbol); fileStream.mFP = NULL; // Mark as loaded diff --git a/IDEHelper/DbgExprEvaluator.cpp b/IDEHelper/DbgExprEvaluator.cpp index e259ffd1..e3e41498 100644 --- a/IDEHelper/DbgExprEvaluator.cpp +++ b/IDEHelper/DbgExprEvaluator.cpp @@ -597,7 +597,7 @@ bool DwMethodMatcher::CheckType(DbgType* typeInstance, bool isFailurePass) if ((methodNameEntry->mCompileUnitId != -1) && (methodNameEntry->mName == mMethodName)) { // If we hot-replaced this type then we replaced and parsed all the methods too - if (!curType->mCompileUnit->mDbgModule->mIsHotObjectFile) + if (!curType->mCompileUnit->mDbgModule->IsObjectFile()) curType->mCompileUnit->mDbgModule->MapCompileUnitMethods(methodNameEntry->mCompileUnitId); methodNameEntry->mCompileUnitId = -1; } diff --git a/IDEHelper/DbgModule.cpp b/IDEHelper/DbgModule.cpp index 7e8f0d57..bc2b6d50 100644 --- a/IDEHelper/DbgModule.cpp +++ b/IDEHelper/DbgModule.cpp @@ -1982,7 +1982,7 @@ DbgModule::DbgModule(DebugTarget* debugTarget) : mDefaultCompileUnit(this) mSymbolData = NULL; mCheckedBfObject = false; mBfObjectHasFlags = false; - mIsHotObjectFile = false; + mModuleKind = DbgModuleKind_Module; mStartTypeIdx = 0; mEndTypeIdx = 0; mHotIdx = 0; @@ -2042,7 +2042,7 @@ DbgModule::~DbgModule() delete mOrigImageData; - if ((mIsHotObjectFile) && (mImageBase != 0)) + if ((IsObjectFile()) && (mImageBase != 0)) { mDebugger->ReleaseHotTargetMemory((addr_target)mImageBase, (int)mImageSize); } @@ -2064,7 +2064,7 @@ DbgSubprogram* DbgModule::FindSubprogram(DbgType* dbgType, const char * methodNa if ((methodNameEntry->mCompileUnitId != -1) && (strcmp(methodNameEntry->mName, methodName) == 0)) { // If we hot-replaced this type then we replaced and parsed all the methods too - if (!dbgType->mCompileUnit->mDbgModule->mIsHotObjectFile) + if (!dbgType->mCompileUnit->mDbgModule->IsObjectFile()) dbgType->mCompileUnit->mDbgModule->MapCompileUnitMethods(methodNameEntry->mCompileUnitId); methodNameEntry->mCompileUnitId = -1; } @@ -2108,14 +2108,14 @@ char* DbgModule::DbgDupString(const char* str, const char* allocName) DbgModule* DbgModule::GetLinkedModule() { - if (mIsHotObjectFile) + if (IsObjectFile()) return mDebugTarget->mTargetBinary; return this; } addr_target DbgModule::GetTargetImageBase() { - if (mIsHotObjectFile) + if (IsObjectFile()) return (addr_target)mDebugTarget->mTargetBinary->mImageBase; return (addr_target)mImageBase; } @@ -2577,7 +2577,7 @@ void DbgModule::MapTypes(int startingTypeIdx) if (dbgType->mCompileUnit->mDbgModule != prevType->mCompileUnit->mDbgModule) { // Don't replace original types with hot types -- those need to be inserted in the the hot alternates list - BF_ASSERT(dbgType->mCompileUnit->mDbgModule->mIsHotObjectFile); + BF_ASSERT(dbgType->mCompileUnit->mDbgModule->IsObjectFile()); prevType->mHotNewType = dbgType; continue; } @@ -5297,7 +5297,7 @@ bool DbgModule::CanRead(DataStream* stream, DebuggerResult* outResult) return true; } -bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) +bool DbgModule::ReadCOFF(DataStream* stream, DbgModuleKind moduleKind) { BP_ZONE("DbgModule::ReadCOFF"); @@ -5323,10 +5323,13 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) miniDumpDebugger = (MiniDumpDebugger*)mDebugger; } - mIsHotObjectFile = isHotObjectFile; + mModuleKind = moduleKind; + bool isHotSwap = mModuleKind == DbgModuleKind_HotObject; + bool isObjectFile = mModuleKind != DbgModuleKind_Module; + auto linkedModule = GetLinkedModule(); - if (mIsHotObjectFile) + if (isObjectFile) linkedModule->PopulateStaticVariableMap(); mStartTypeIdx = (int)linkedModule->mTypes.size(); @@ -5339,7 +5342,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) PE_NTHeaders ntHdr; memset(&ntHdr, 0, sizeof(ntHdr)); - if (!mIsHotObjectFile) + if (!isObjectFile) { stream->Read(&hdr, sizeof(PEHeader)); stream->SetPos(hdr.e_lfanew); @@ -5484,7 +5487,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) sectionNames[sectNum] = name; DbgHotTargetSection* targetSection = NULL; - if (mIsHotObjectFile) + if (IsObjectFile()) { targetSection = new DbgHotTargetSection(); targetSection->mDataSize = sectHdr.mSizeOfRawData; @@ -5509,7 +5512,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) if (strcmp(name, ".tls") == 0) mTLSAddr = (addr_target)(sectHdr.mVirtualAddress + mImageBase); - if ((mIsHotObjectFile) && (strcmp(name, ".tls$") == 0)) + if ((IsObjectFile()) && (strcmp(name, ".tls$") == 0)) { tlsSection = sectNum; mTLSSize = sectHdr.mSizeOfRawData; @@ -5518,7 +5521,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) bool isExportDataDir = ((exportDataDir->mVirtualAddress != 0) && (exportDataDir->mVirtualAddress >= sectHdr.mVirtualAddress) && (exportDataDir->mVirtualAddress < sectHdr.mVirtualAddress + sectHdr.mSizeOfRawData)); - if ((!mIsHotObjectFile) && (!isExportDataDir)) + if ((!IsObjectFile()) && (!isExportDataDir)) { if (((strcmp(name, ".text")) == 0) || ((strcmp(name, ".textbss")) == 0) || @@ -5545,7 +5548,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) memset(data + sectHdr.mSizeOfRawData, 0, 8); - if (mIsHotObjectFile) + if (IsObjectFile()) targetSection->mData = data; addr_target addrOffset = sectHdr.mVirtualAddress; @@ -5594,7 +5597,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) } } - if ((mIsHotObjectFile) && (sectHdr.mNumberOfRelocations > 0)) + if ((IsObjectFile()) && (sectHdr.mNumberOfRelocations > 0)) { //mDebugger->AllocTargetMemory(sectHdr.mSizeOfRawData, true, true); @@ -5602,7 +5605,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) if (strcmp(name, ".text") == 0) { - if (!mIsHotObjectFile) + if (!IsObjectFile()) mCodeAddress = ntHdr.mOptionalHeader.mImageBase + sectHdr.mVirtualAddress; } @@ -5795,7 +5798,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) { if (mExceptionData != NULL) { - if (mIsHotObjectFile) + if (IsObjectFile()) { mOwnedSectionData.push_back(mExceptionData); } @@ -5863,7 +5866,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) if (!usedData) { - if (mIsHotObjectFile) + if (IsObjectFile()) { mOwnedSectionData.push_back(data); } @@ -5878,7 +5881,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) } int needHotTargetMemory = 0; - if (mIsHotObjectFile) + if (isObjectFile) { for (int sectNum = 0; sectNum < ntHdr.mFileHeader.mNumberOfSections; sectNum++) { @@ -5894,7 +5897,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) } int numSections = ntHdr.mFileHeader.mNumberOfSections; - if (mIsHotObjectFile) + if (isObjectFile) { addr_target* resolvedSymbolAddrs = new addr_target[ntHdr.mFileHeader.mNumberOfSymbols]; memset(resolvedSymbolAddrs, 0, ntHdr.mFileHeader.mNumberOfSymbols * sizeof(addr_target)); @@ -5973,7 +5976,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) { bool isTLS = false; addr_target targetAddr = 0; - if (mIsHotObjectFile) + if (isObjectFile) { if (symInfo->mSectionNum - 1 == tlsSection) { @@ -6007,7 +6010,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) if ((isStaticSymbol) && (IsHotSwapPreserve(symbolName))) isStaticSymbol = false; - if ((mIsHotObjectFile) && (!isStaticSymbol)) + if ((isObjectFile) && (!isStaticSymbol)) { DbgSymbol* dwSymbol = NULL; @@ -6109,10 +6112,10 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) dwSymbol->mName = symbolName; dwSymbol->mAddress = targetAddr; - if (!mIsHotObjectFile) + if (!IsObjectFile()) dwSymbol->mAddress += (addr_target)mImageBase; - if (mIsHotObjectFile) + if (IsObjectFile()) BF_ASSERT((dwSymbol->mAddress >= mImageBase) && (dwSymbol->mAddress < mImageBase + mImageSize)); mDebugTarget->mSymbolMap.Insert(dwSymbol); @@ -6178,7 +6181,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) } } - if (!mIsHotObjectFile) + if (!isObjectFile) { mImageSize = ntHdr.mOptionalHeader.mSizeOfImage; mEntryPoint = ntHdr.mOptionalHeader.mAddressOfEntryPoint; @@ -6187,7 +6190,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) /*OutputDebugStrF("%s:\n CompileUnits:%d DebugLines: %d Types: %d (%d in map) SubPrograms: %d (%dk) AllocSize:%dk\n", mFilePath.c_str(), mCompileUnits.size(), lineDataCount, mEndTypeIdx - mStartTypeIdx, (int)linkedModule->mTypes.size() - mStartTypeIdx, mEndSubprogramIdx - mStartSubprogramIdx, subProgramSizes / 1024, mAlloc.GetAllocSize() / 1024);*/ - if (mIsHotObjectFile) + if (isHotSwap) { // In COFF, we don't necessarily add an actual primary type during MapCompileUnitMethods, so this fixes that while (true) @@ -6293,7 +6296,7 @@ bool DbgModule::ReadCOFF(DataStream* stream, bool isHotObjectFile) void DbgModule::FinishHotSwap() { - BF_ASSERT(mIsHotObjectFile); + BF_ASSERT(IsObjectFile()); auto linkedModule = GetLinkedModule(); auto mainModule = mDebugTarget->mTargetBinary; diff --git a/IDEHelper/DbgModule.h b/IDEHelper/DbgModule.h index 8e650851..ba1b41da 100644 --- a/IDEHelper/DbgModule.h +++ b/IDEHelper/DbgModule.h @@ -120,6 +120,13 @@ enum DbgFileExistKind : uint8 DbgFileExistKind_Found }; +enum DbgModuleKind : uint8 +{ + DbgModuleKind_Module, + DbgModuleKind_HotObject, + DbgModuleKind_FromLocateSymbol +}; + class DbgCompileUnit; struct DbgSectionData @@ -1159,7 +1166,7 @@ public: Array mSecRelEncodingVec; bool mCheckedBfObject; bool mBfObjectHasFlags; - bool mIsHotObjectFile; + DbgModuleKind mModuleKind; bool mIsDwarf64; HashSet mSrcFileDeferredRefs; @@ -1237,6 +1244,8 @@ public: void FixupInnerTypes(int startingTypeIdx); void MapTypes(int startingTypeIdx); void CreateNamespaces(); + bool IsObjectFile() { return mModuleKind != DbgModuleKind_Module; } + bool IsHotSwapObjectFile() { return mModuleKind == DbgModuleKind_HotObject; } bool IsHotSwapPreserve(const String& name); addr_target GetHotTargetAddress(DbgHotTargetSection* hotTargetSection); uint8* GetHotTargetData(addr_target address); @@ -1268,7 +1277,7 @@ public: static bool CanRead(DataStream* stream, DebuggerResult* outResult); - bool ReadCOFF(DataStream* stream, bool isHotObjectFile); + bool ReadCOFF(DataStream* stream, DbgModuleKind dbgModuleKind); void RemoveTargetData(); virtual void ReportMemory(MemReporter* memReporter); diff --git a/IDEHelper/DebugTarget.cpp b/IDEHelper/DebugTarget.cpp index 1ace19aa..c450c08f 100644 --- a/IDEHelper/DebugTarget.cpp +++ b/IDEHelper/DebugTarget.cpp @@ -153,7 +153,7 @@ DbgModule* DebugTarget::Init(const StringImpl& launchPath, const StringImpl& tar dwarf->mDisplayName = GetFileName(launchPath); dwarf->mFilePath = launchPath; dwarf->mImageBase = (intptr)imageBase; - if (!dwarf->ReadCOFF(&fileStream, false)) + if (!dwarf->ReadCOFF(&fileStream, DbgModuleKind_Module)) { mDebugger->OutputMessage(StrFormat("Debugger failed to read binary: %s\n", launchPath.c_str())); delete dwarf; @@ -191,7 +191,7 @@ DbgModule* DebugTarget::HotLoad(const StringImpl& fileName, int hotIdx) dwarf->mHotIdx = hotIdx; dwarf->mDisplayName = GetFileName(fileName); dwarf->mFilePath = fileName; - if (!dwarf->ReadCOFF(&fileStream, true)) + if (!dwarf->ReadCOFF(&fileStream, DbgModuleKind_HotObject)) { mDebugger->OutputMessage(StrFormat("Debugger failed to read binary: %s\n", fileName.c_str())); delete dwarf; @@ -210,7 +210,7 @@ DbgModule* DebugTarget::SetupDyn(const StringImpl& filePath, DataStream* stream, DbgModule* dwarf = new COFF(this); dwarf->mFilePath = filePath; dwarf->mImageBase = (intptr)imageBase; - if (!dwarf->ReadCOFF(stream, false)) + if (!dwarf->ReadCOFF(stream, DbgModuleKind_Module)) { //mDebugger->OutputMessage(StrFormat("Debugger failed to read binary: %s", fileName.c_str())); delete dwarf; @@ -270,7 +270,7 @@ void DebugTarget::CleanupHotHeap() for (int dwarfIdx = 0; dwarfIdx < (int)mDbgModules.size(); dwarfIdx++) { DbgModule* dbgModule = mDbgModules[dwarfIdx]; - if (dbgModule->mIsHotObjectFile) + if (dbgModule->IsObjectFile()) { if (!mHotHeap->IsReferenced(dbgModule->mImageBase, dbgModule->mImageSize)) { @@ -919,7 +919,7 @@ bool DebugTarget::RollBackStackFrame_ExceptionDirectory(addr_target findPC, CPUR //const uint8* data = dbgModule->mExceptionData + exceptionDirectoryEntry->mExceptionPos; uint32 exceptionPos = exceptionDirectoryEntry->mExceptionPos; - if (dbgModule->mIsHotObjectFile) + if (dbgModule->IsObjectFile()) { exceptionPos -= dbgModule->mImageBase - dbgModule->GetLinkedModule()->mImageBase; } diff --git a/IDEHelper/WinDebugger.cpp b/IDEHelper/WinDebugger.cpp index 2bfcd205..c2e15ff7 100644 --- a/IDEHelper/WinDebugger.cpp +++ b/IDEHelper/WinDebugger.cpp @@ -1062,7 +1062,7 @@ void WinDebugger::HotLoad(const Array& objectFiles, int hotIdx) for (int moduleIdx = startingModuleIdx; moduleIdx < (int)mDebugTarget->mDbgModules.size(); moduleIdx++) { auto dbgModule = mDebugTarget->mDbgModules[moduleIdx]; - BF_ASSERT(dbgModule->mIsHotObjectFile); + BF_ASSERT(dbgModule->IsObjectFile()); BF_ASSERT(dbgModule->mHotIdx == hotIdx); dbgModule->FinishHotSwap(); }