diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index ab42514856bafcbbe6f9d1dd532634f158dbac64..36e1224eb81af1d0973aefe247be5e54ba0d1179 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -609,6 +609,7 @@ class DebugInfo { funcScopeHighs(std::less(), m->GetMPAllocator().Adapter()), funcScopeIdStatus(std::less(), m->GetMPAllocator().Adapter()), typedefStrIdxDieIdMap(std::less(), m->GetMPAllocator().Adapter()), + typedefStrIdxTyIdxMap(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); @@ -762,10 +763,12 @@ class DebugInfo { DBGDie *GetOrCreateFuncDeclDie(MIRFunction *func); DBGDie *GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum); DBGDie *GetOrCreatePrimTypeDie(MIRType *ty); + DBGDie *GetOrCreateTypeDie(TyIdx tyidx); DBGDie *GetOrCreateTypeDie(MIRType *type); DBGDie *GetOrCreatePointTypeDie(const MIRPtrType *ptrType); DBGDie *GetOrCreateArrayTypeDie(const MIRArrayType *arrayType); DBGDie *GetOrCreateStructTypeDie(const MIRType *type); + DBGDie *GetOrCreateTypedefDie(GStrIdx stridx, TyIdx tyidx); void AddAliasDies(MapleMap &aliasMap); void AddScopeDie(MIRScope *scope); @@ -804,8 +807,10 @@ class DebugInfo { return true; } - // src code type name stridx and aliased maple var - DBGDie *GetOrCreateTypeDefDie(GStrIdx stridx, const MIRSymbol *var); + void AddTypedefMap(GStrIdx stridx, TyIdx tyidx) { + typedefStrIdxTyIdxMap[stridx.GetIdx()] = tyidx.GetIdx(); + } + void DumpTypedefMap(); private: MIRModule *module; @@ -845,6 +850,7 @@ class DebugInfo { /* alias type */ MapleMap typedefStrIdxDieIdMap; + MapleMap typedefStrIdxTyIdxMap; MapleSet strps; std::string varPtrPrefix; diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 0cfa53aaaf30d6653dd34e55a77137a25a2a9cd3..52c11cf3aac45476d071240f11a062daa2a9b440 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -319,15 +319,12 @@ 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 src code type name for type if provided + if (i.second.srcTypeStrIdx.GetIdx()) { + DBGDie *typedefDie = GetOrCreateTypedefDie(i.second.srcTypeStrIdx, var->GetTyIdx()); // use negtive number to indicate DIE id instead of tyidx in normal cases (void)(vdie->SetAttr(DW_AT_type, -typedefDie->GetId())); } @@ -426,6 +423,7 @@ void DebugInfo::BuildDebugInfo() { } } + // setup debug info for global symbols for (size_t i = 0; i < GlobalTables::GetGsymTable().GetSymbolTableSize(); ++i) { MIRSymbol *mirSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(static_cast(i)); if (mirSymbol == nullptr || mirSymbol->IsDeleted() || mirSymbol->GetStorageClass() == kScUnused || @@ -438,6 +436,13 @@ void DebugInfo::BuildDebugInfo() { } } + // setup debug info for typedef types + for (auto it : typedefStrIdxTyIdxMap) { + (void) GetOrCreateTypeDie(TyIdx(it.second)); + DBGDie *die = GetOrCreateTypedefDie(GStrIdx(it.first), TyIdx(it.second)); + compUnit->AddSubVec(die); + } + // setup debug info for functions for (auto func : GlobalTables::GetFunctionTable().GetFuncTable()) { // the first one in funcTable is nullptr @@ -792,6 +797,11 @@ DBGDie *DebugInfo::CreatePointedFuncTypeDie(MIRFuncType *fType) { return die; } +DBGDie *DebugInfo::GetOrCreateTypeDie(TyIdx tyidx) { + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyidx); + return GetOrCreateTypeDie(type); +} + DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { if (type == nullptr) { return nullptr; @@ -853,7 +863,7 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { return die; } -DBGDie *DebugInfo::GetOrCreateTypeDefDie(GStrIdx stridx, const MIRSymbol *var) { +DBGDie *DebugInfo::GetOrCreateTypedefDie(GStrIdx stridx, TyIdx tyidx) { uint32 sid = stridx.GetIdx(); auto it = typedefStrIdxDieIdMap.find(sid); if (it != typedefStrIdxDieIdMap.end()) { @@ -863,14 +873,12 @@ DBGDie *DebugInfo::GetOrCreateTypeDefDie(GStrIdx stridx, const MIRSymbol *var) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_typedef); compUnit->AddSubVec(die); - (void)(die->AddAttr(DW_AT_name, DW_FORM_strp, sid)); - (void)(die->AddAttr(DW_AT_decl_file, DW_FORM_data1, var->GetSrcPosition().FileNum())); - (void)(die->AddAttr(DW_AT_decl_line, DW_FORM_data1, var->GetSrcPosition().LineNum())); - (void)(die->AddAttr(DW_AT_decl_column, DW_FORM_data1, var->GetSrcPosition().Column())); - - MIRType *type = var->GetType(); - DBGDie *tdie = GetOrCreateTypeDie(type); + die->AddAttr(DW_AT_name, DW_FORM_strp, sid); + die->AddAttr(DW_AT_decl_file, DW_FORM_data1, 0); + die->AddAttr(DW_AT_decl_line, DW_FORM_data1, 0); + die->AddAttr(DW_AT_decl_column, DW_FORM_data1, 0); + DBGDie *tdie = GetOrCreateTypeDie(tyidx); // use negative vaule of Die id (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId())); @@ -1277,7 +1285,7 @@ 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 + // handle typedef where die id is already used but with negative value if (static_cast(tid) < 0) { at->SetId(-static_cast(tid)); break; @@ -1458,6 +1466,15 @@ void DebugInfo::Dump(int indent) { return; } +void DebugInfo::DumpTypedefMap() const { + for (auto it : typedefStrIdxTyIdxMap) { + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(it.second)); + LogInfo::MapleLogger() << " " << + GlobalTables::GetStrTable().GetStringFromStrIdx(it.first).c_str() << " " << + type->GetName() << "\n"; + } +} + void DBGExprLoc::Dump() const { LogInfo::MapleLogger() << " " << HEX(GetOp()); for (auto it : simpLoc->GetOpnd()) { diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index 32970e9839a82d328561bf370e8da792926d85bf..088ab648583c4fcdaf58c81abdc206f47e337daf 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -1636,17 +1636,23 @@ bool MIRParser::ParseTypedef() { } // for class/interface types, prev_tyidx could also be set during processing // so we check again right before SetGStrIdxToTyIdx + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); if (isLocal) { prevTyIdx = mod.CurFunction()->GetTyIdxFromGStrIdx(strIdx); mod.CurFunction()->SetGStrIdxToTyIdx(strIdx, tyIdx); ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); - if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->GetNameStrIdx() == 0u) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->SetNameIsLocal(true); + if (type->GetNameStrIdx() == 0u) { + type->SetNameIsLocal(true); } } else { prevTyIdx = mod.GetTypeNameTab()->GetTyIdxFromGStrIdx(strIdx); mod.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); mod.PushbackTypeDefOrder(strIdx); + + // debuginfo for typedef + if (mod.IsWithDbgInfo() && strIdx != type->GetNameStrIdx()) { + mod.GetDbgInfo()->AddTypedefMap(strIdx, tyIdx); + } } if (prevTyIdx != TyIdx(0) && prevTyIdx != tyIdx) { @@ -1658,7 +1664,6 @@ bool MIRParser::ParseTypedef() { // Merge class or interface type at the cross-module level ASSERT(GlobalTables::GetTypeTable().GetTypeTable().empty() == false, "container check"); - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); if (!isLocal && (type->GetKind() == kTypeClass || type->GetKind() == kTypeClassIncomplete || type->GetKind() == kTypeInterface || type->GetKind() == kTypeInterfaceIncomplete)) { prevTyIdx = GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(strIdx); @@ -2529,17 +2534,16 @@ bool MIRParser::ParseOneAlias(GStrIdx &strIdx, MIRAliasVars &aliasVar) { lexer.NextToken(); TokenKind tk = lexer.GetTokenKind(); TyIdx tyIdx(0); - if (ParseType(tyIdx)) { - aliasVar.tyIdx = tyIdx; - aliasVar.srcTypeStrIdx = GStrIdx(0); - } else if (tk == TK_string) { - /* it is original type name from source code */ + if (tk == TK_string || tk == TK_gname) { + // 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 if (ParseType(tyIdx)) { + aliasVar.tyIdx = tyIdx; + aliasVar.srcTypeStrIdx = GStrIdx(0); } else { Error("parseType failed when parsing ALIAS "); return false;