From 5a1b8de013c6ae96585277946f3924751e9bd577 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Thu, 4 Aug 2022 10:15:38 -0700 Subject: [PATCH] refine alias handling --- src/mapleall/maple_ir/src/debug_info.cpp | 33 ++++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 004cf96ff5..3198f88da3 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -333,27 +333,26 @@ void DebugInfo::AddScopeDie(MIRScope *scope, bool isLocal) { void DebugInfo::AddAliasDies(MapleMap &aliasMap, bool isLocal) { MIRFunction *func = GetCurFunction(); for (auto &i : aliasMap) { - // maple var - MIRSymbol *var = nullptr; + // maple var and die + MIRSymbol *mvar = nullptr; + DBGDie *mDie = nullptr; GStrIdx mplIdx = i.second.mplStrIdx; if (i.second.isLocal) { - var = func->GetSymTab()->GetSymbolFromStrIdx(mplIdx); + mvar = func->GetSymTab()->GetSymbolFromStrIdx(mplIdx); + mDie = GetLocalDie(mplIdx); } else { - var = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(mplIdx); - } - if (var == nullptr) { - continue; - } - // maple var die - DBGDie *mDie = (var->IsGlobal()) ? GetGlobalDie(mplIdx) : GetLocalDie(mplIdx); - // some global scope var are introduced by system, skip them - if (mDie == nullptr) { - continue; + mvar = GlobalTables::GetGsymTable().GetSymbolFromStrIdx(mplIdx); + mDie = GetGlobalDie(mplIdx); + // some global vars are introduced by system, skip them + if (mvar == nullptr || mDie == nullptr) { + continue; + } } // for local scope, create alias die using maple var except name and type // for global scope, update type only if needed - DBGDie *vdie = isLocal ? CreateVarDie(var, i.first) : GetGlobalDie(mplIdx); + bool updateOnly = (isLocal == i.second.isLocal && i.first == mplIdx); + DBGDie *vdie = updateOnly ? mDie : CreateVarDie(mvar, i.first); // get type from alias uint32 index = i.second.index; @@ -366,7 +365,7 @@ void DebugInfo::AddAliasDies(MapleMap &aliasMap, bool isL } case kATKString: { // use src code type - DBGDie *typeDie = GetOrCreateTypedefDie(GStrIdx(index), var->GetTyIdx()); + DBGDie *typeDie = GetOrCreateTypedefDie(GStrIdx(index), mvar->GetTyIdx()); DBGDie *newDie = GetOrCreateTypeDie(i.second.attrs, typeDie); // use negtive number to indicate DIE id instead of tyidx in normal cases (void)(vdie->SetAttr(DW_AT_type, -newDie->GetId())); @@ -385,8 +384,8 @@ void DebugInfo::AddAliasDies(MapleMap &aliasMap, bool isL break; } - // for local scope - if (isLocal) { + // for new var + if (!updateOnly) { // link vdie's ExprLoc to mDie's vdie->LinkExprLoc(mDie); -- Gitee