diff --git a/IDEHelper/Backend/BeIRCodeGen.cpp b/IDEHelper/Backend/BeIRCodeGen.cpp index d0f8edc6..796131ec 100644 --- a/IDEHelper/Backend/BeIRCodeGen.cpp +++ b/IDEHelper/Backend/BeIRCodeGen.cpp @@ -241,6 +241,12 @@ BeIRCodeGen::~BeIRCodeGen() void BeIRCodeGen::Hash(BeHashContext& hashCtx) { +// if (mBeModule->mModuleName == "IDE_IDEApp") +// { +// hashCtx.mDbgViz = true; +// NOP; +// } + hashCtx.Mixin(mPtrSize); hashCtx.Mixin(mIsOptimized); if (mBeModule != NULL) @@ -2782,6 +2788,7 @@ void BeIRCodeGen::HandleNextCmd() if (dbgFunc->mValue != NULL) dbgFunc->mValue->mDbgFunction = dbgFunc; + dbgFunc->mIdx = (int)mBeModule->mDbgModule->mFuncs.size(); mBeModule->mDbgModule->mFuncs.push_back(dbgFunc); SetResult(curId, dbgFunc); @@ -2823,6 +2830,7 @@ void BeIRCodeGen::HandleNextCmd() }*/ if (dbgFunc->mValue != NULL) dbgFunc->mValue->mDbgFunction = dbgFunc; + dbgFunc->mIdx = (int)mBeModule->mDbgModule->mFuncs.size(); mBeModule->mDbgModule->mFuncs.push_back(dbgFunc); SetResult(curId, dbgFunc); diff --git a/IDEHelper/Backend/BeModule.cpp b/IDEHelper/Backend/BeModule.cpp index c4d8f962..437ea285 100644 --- a/IDEHelper/Backend/BeModule.cpp +++ b/IDEHelper/Backend/BeModule.cpp @@ -3264,9 +3264,89 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx) hashCtx.MixinStr(mDirectory); hashCtx.MixinStr(mProducer); - for (auto dbgFunc : mFuncs) - dbgFunc->HashReference(hashCtx); + BeDumpContext dc; + dc.mModule = mBeModule; + String lhsName; + String rhsName; - for (auto globalVar : mGlobalVariables) - globalVar->HashReference(hashCtx); + if (!mFuncs.IsEmpty()) + { + auto _GetName = [&](BeDbgFunction* func, String& str) + { + if (!func->mLinkageName.IsEmpty()) + str.Append(func->mLinkageName); + else + dc.ToString(str, func); + }; + + Array unrefFuncs; + for (auto dbgFunc : mFuncs) + { + if ((!dbgFunc->mIncludedAsMember) && (dbgFunc->mHashId == -1)) + unrefFuncs.Add(dbgFunc); + } + + std::sort(unrefFuncs.begin(), unrefFuncs.end(), [&](BeDbgFunction* lhs, BeDbgFunction* rhs) + { + lhsName.Clear(); + _GetName(lhs, lhsName); + + rhsName.Clear(); + _GetName(rhs, rhsName); + + int cmp = String::Compare(lhsName, rhsName, false); + if (cmp != 0) + return cmp < 0; + + if (lhs->mFile != rhs->mFile) + { + lhsName.Clear(); + rhsName.Clear(); + if (lhs->mFile != NULL) + lhs->mFile->ToString(lhsName); + if (rhs->mFile != NULL) + rhs->mFile->ToString(rhsName); + cmp = String::Compare(lhsName, rhsName, false); + if (cmp != 0) + return cmp < 0; + } + + if (lhs->mLine != rhs->mLine) + return lhs->mLine < rhs->mLine; + + return lhs->mIdx < rhs->mIdx; + }); + + hashCtx.Mixin(unrefFuncs.size()); + for (auto dbgFunc : unrefFuncs) + { + if (dbgFunc->mHashId == -1) + dbgFunc->HashReference(hashCtx); + } + } + + if (!mGlobalVariables.IsEmpty()) + { + auto _GetName = [&](BeDbgGlobalVariable* func, String& str) + { + if (!func->mLinkageName.IsEmpty()) + str.Append(func->mLinkageName); + else + dc.ToString(str, func); + }; + + std::sort(mGlobalVariables.begin(), mGlobalVariables.end(), [&](BeDbgGlobalVariable* lhs, BeDbgGlobalVariable* rhs) + { + lhsName.Clear(); + _GetName(lhs, lhsName); + + rhsName.Clear(); + _GetName(rhs, rhsName); + + return (lhsName < rhsName); + }); + + for (auto globalVar : mGlobalVariables) + globalVar->HashReference(hashCtx); + } } diff --git a/IDEHelper/Backend/BeModule.h b/IDEHelper/Backend/BeModule.h index b7e3b4be..7638c2e4 100644 --- a/IDEHelper/Backend/BeModule.h +++ b/IDEHelper/Backend/BeModule.h @@ -1764,6 +1764,8 @@ public: BE_VALUE_TYPE(BeDbgFunction, BeMDNode); public: + int mIdx; + BeMDNode* mScope; BeDbgFile* mFile; int mLine; @@ -1793,6 +1795,7 @@ public: public: BeDbgFunction() { + mIdx = -1; mScope = NULL; mFile = NULL; mLine = -1; @@ -2009,8 +2012,8 @@ public: virtual void HashContent(BeHashContext& hashCtx) override { hashCtx.Mixin(TypeId); - hashCtx.Mixin(mName); - hashCtx.Mixin(mLinkageName); + hashCtx.MixinStr(mName); + hashCtx.MixinStr(mLinkageName); if (mFile != NULL) mFile->HashReference(hashCtx); hashCtx.Mixin(mLineNum);