diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index e11b3c59dc8eefa0e27d3de94f2a3bd3e2dbad13..bd1eb3acc24f44a6839fc7098899908f0416fd2a 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -608,6 +608,7 @@ class DebugInfo { funcScopeLows(std::less(), m->GetMPAllocator().Adapter()), funcScopeHighs(std::less(), m->GetMPAllocator().Adapter()), funcScopeIdStatus(std::less(), m->GetMPAllocator().Adapter()), + typedefStrIdxDieIdMap(std::less(), m->GetMPAllocator().Adapter()), strps(std::less(), m->GetMPAllocator().Adapter()) { /* valid entry starting from index 1 as abbrevid starting from 1 as well */ abbrevVec.push_back(nullptr); @@ -803,6 +804,9 @@ class DebugInfo { return true; } + // src code type name stridx and aliased maple var + DBGDie *GetOrCreateTypeDefDie(GStrIdx stridx, MIRSymbol *var); + private: MIRModule *module; DBGDie *compUnit; // root die: compilation unit @@ -839,6 +843,9 @@ class DebugInfo { /* save functions's scope id that has been emited */ MapleMap> funcScopeIdStatus; + /* alias type */ + MapleMap typedefStrIdxDieIdMap; + MapleSet strps; std::string varPtrPrefix; }; diff --git a/src/mapleall/maple_ir/include/mir_scope.h b/src/mapleall/maple_ir/include/mir_scope.h index dca207e013d747b3b98dbc89ca01bd453402b9f1..38a6f5cc1f59df29ac889096ae89e5adcadc76e0 100644 --- a/src/mapleall/maple_ir/include/mir_scope.h +++ b/src/mapleall/maple_ir/include/mir_scope.h @@ -22,8 +22,9 @@ namespace maple { // mapping src variable to mpl variables to display debug info struct MIRAliasVars { - GStrIdx mplStrIdx; // maple varialbe name + GStrIdx mplStrIdx; // maple varialbe name TyIdx tyIdx; + GStrIdx srcTypeStrIdx; // src type name bool isLocal; GStrIdx sigStrIdx; }; diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index c47baa1a8a8b6d7a3f1256258fae55ee4dfb171c..6a33cd7138e9dea9190fb398b45ef0476aa3cd45 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -319,8 +319,18 @@ void DebugInfo::AddAliasDies(MapleMap &aliasMap) { continue; } + // use src code type name if provided + DBGDie *typedefDie = nullptr; + if (i.second.srcTypeStrIdx.GetIdx()) { + typedefDie = GetOrCreateTypeDefDie(i.second.srcTypeStrIdx, var); + } + // create alias die using maple var except name DBGDie *vdie = CreateVarDie(var, i.first); + if (typedefDie) { + // use negtive number to indicate DIE id instead of tyidx in normal cases + vdie->SetAttr(DW_AT_type, -typedefDie->GetId()); + } // link vdie's ExprLoc to mdie's vdie->LinkExprLoc(mdie); @@ -843,6 +853,31 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { return die; } +DBGDie *DebugInfo::GetOrCreateTypeDefDie(GStrIdx stridx, MIRSymbol *var) { + uint32 sid = stridx.GetIdx(); + if (typedefStrIdxDieIdMap.find(sid) != typedefStrIdxDieIdMap.end()) { + uint32 id = typedefStrIdxDieIdMap[sid]; + return idDieMap[id]; + } + + DBGDie *die = module->GetMemPool()->New(module, DW_TAG_typedef); + compUnit->AddSubVec(die); + + die->AddAttr(DW_AT_name, DW_FORM_strp, sid); + die->AddAttr(DW_AT_decl_file, DW_FORM_data1, var->GetSrcPosition().FileNum()); + die->AddAttr(DW_AT_decl_line, DW_FORM_data1, var->GetSrcPosition().LineNum()); + die->AddAttr(DW_AT_decl_column, DW_FORM_data1, var->GetSrcPosition().Column()); + + MIRType *type = var->GetType(); + DBGDie *tdie = GetOrCreateTypeDie(type); + + // use negative vaule of Die id + die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); + + typedefStrIdxDieIdMap[sid] = die->GetId(); + return die; +} + DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrType) { uint32 tid = ptrType->GetTypeIndex().GetIdx(); if (tyIdxDieIdMap.find(tid) != tyIdxDieIdMap.end()) { @@ -1242,6 +1277,11 @@ void DebugInfo::FillTypeAttrWithDieId() { for (auto at : die->GetAttrVec()) { if (at->GetDwAt() == DW_AT_type) { uint32 tid = at->GetId(); + // handle typedef where die id is already used but with nagetive value + if ((int)tid < 0) { + at->SetId(-(int)tid); + break; + } MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(tid)); if (type) { uint32 dieid = tyIdxDieIdMap[tid]; diff --git a/src/mapleall/maple_ir/src/mir_scope.cpp b/src/mapleall/maple_ir/src/mir_scope.cpp index d675529a6125e73248a13377ed7537c902e240ad..9f0e3e41a60bf53d1851dda4853936bdc02c85ed 100644 --- a/src/mapleall/maple_ir/src/mir_scope.cpp +++ b/src/mapleall/maple_ir/src/mir_scope.cpp @@ -124,7 +124,11 @@ void MIRScope::Dump(int32 indent) const { LogInfo::MapleLogger() << "ALIAS %" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.first) << ((it.second.isLocal) ? " %" : " $") << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.mplStrIdx) << " "; - GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second.tyIdx)->Dump(0); + if (it.second.tyIdx) { + GlobalTables::GetTypeTable().GetTypeFromTyIdx(it.second.tyIdx)->Dump(0); + } else { + LogInfo::MapleLogger() << "\"" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.srcTypeStrIdx) << "\""; + } if (it.second.sigStrIdx) { LogInfo::MapleLogger() << " \"" << GlobalTables::GetStrTable().GetStringFromStrIdx(it.second.sigStrIdx) << "\""; } diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index d4e3d2828aad047224b716b790cd52fe4098c748..7bf9003ae4bf0cf737ab2a9d975e69fc702c1e0a 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2526,9 +2526,23 @@ bool MIRParser::ParseOneAlias(GStrIdx &strIdx, MIRAliasVars &aliasVar) { return false; } GStrIdx mplStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); + aliasVar.mplStrIdx = mplStrIdx; + aliasVar.isLocal = isLocal; lexer.NextToken(); + TokenKind tk = lexer.GetTokenKind(); TyIdx tyIdx(0); - if (!ParseType(tyIdx)) { + if (ParseType(tyIdx)) { + aliasVar.tyIdx = tyIdx; + aliasVar.srcTypeStrIdx = GStrIdx(0); + } else if (tk == TK_string) { + /* it is original type name from source code */ + std::string typeName = lexer.GetName(); + GStrIdx srcTypeStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(typeName); + + aliasVar.tyIdx = TyIdx(0); + aliasVar.srcTypeStrIdx = srcTypeStrIdx; + lexer.NextToken(); + } else { Error("parseType failed when parsing ALIAS "); return false; } @@ -2537,9 +2551,6 @@ bool MIRParser::ParseOneAlias(GStrIdx &strIdx, MIRAliasVars &aliasVar) { signStrIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(lexer.GetName()); lexer.NextToken(); } - aliasVar.mplStrIdx = mplStrIdx; - aliasVar.tyIdx = tyIdx; - aliasVar.isLocal = isLocal; aliasVar.sigStrIdx = signStrIdx; return true; }