diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index c3ddd506883b2c0fadfd3c0430bb5b0dfc68ef07..b888a430fdf1f7ae02957a77d9e92903989d7ffe 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -3553,14 +3553,13 @@ void Emitter::FillInClassByteSize(DBGDie *die, DBGDieAttr *byteSizeAttr) const { "Unknown FORM value for DW_AT_byte_size"); if (static_cast(byteSizeAttr->GetI()) == kDbgDefaultVal) { /* get class size */ - DBGDieAttr *nameAttr = LFindDieAttr(die, DW_AT_name); - CHECK_FATAL(nameAttr != nullptr, "name_attr is nullptr in Emitter::FillInClassByteSize"); - /* hope this is a global string index as it is a type name */ - TyIdx tyIdx = - GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(GStrIdx(nameAttr->GetId())); - CHECK_FATAL(tyIdx.GetIdx() < Globals::GetInstance()->GetBECommon()->GetSizeOfTypeSizeTable(), + DBGDieAttr *typeAttr = LFindDieAttr(die, DW_AT_type); + CHECK_FATAL(typeAttr != nullptr, "at_type is nullptr in Emitter::FillInClassByteSize"); + /* hope this is a global type */ + uint32 tid = typeAttr->GetId(); + CHECK_FATAL(tid < Globals::GetInstance()->GetBECommon()->GetSizeOfTypeSizeTable(), "index out of range in Emitter::FillInClassByteSize"); - int64_t byteSize = static_cast(Globals::GetInstance()->GetBECommon()->GetTypeSize(tyIdx.GetIdx())); + int64_t byteSize = static_cast(Globals::GetInstance()->GetBECommon()->GetTypeSize(tid)); LUpdateAttrValue(byteSizeAttr, byteSize); } } @@ -3595,12 +3594,11 @@ void Emitter::SetupDBGInfo(DebugInfo *mirdi) { if (byteSizeAttr) { emitter->FillInClassByteSize(die, byteSizeAttr); } - /* get the name */ - DBGDieAttr *atName = LFindDieAttr(die, DW_AT_name); - CHECK_FATAL(atName != nullptr, "at_name is null in Emitter::SetupDBGInfo"); - /* get the type from string name */ - TyIdx ctyIdx = GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(GStrIdx(atName->GetId())); - MIRType *mty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(ctyIdx); + /* get the type from tid instead of name as it could be changed by type alias */ + DBGDieAttr *typeAttr = LFindDieAttr(die, DW_AT_type); + CHECK_FATAL(typeAttr != nullptr, "at_type is null in Emitter::SetupDBGInfo"); + uint32 tid = typeAttr->GetId(); + MIRType *mty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tid); MIRStructType *sty = static_cast(mty); CHECK_FATAL(sty != nullptr, "pointer cast failed"); CHECK_FATAL(sty->GetTypeIndex().GetIdx() < diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index 33357359bd43bc7954c7bc0fd1280798161aa4a6..9b84182fb3d3db55b8f62d1045f06d38376aa8e4 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -841,7 +841,8 @@ class DebugInfo { void AddScopeDie(MIRScope *scope, bool isLocal); DBGDie *GetAliasVarTypeDie(const MIRAliasVars &aliasVar, TyIdx tyidx); - void AddAliasDies(MapleMap &aliasMap, bool isLocal); + void HandleTypeAlias(MIRScope *scope, bool isLocal); + void AddAliasDies(MIRScope *scope, bool isLocal); void CollectScopePos(MIRFunction *func, MIRScope *scope); // Functions for calculating the size and offset of each DW_TAG_xxx and DW_AT_xxx diff --git a/src/mapleall/maple_ir/include/mir_scope.h b/src/mapleall/maple_ir/include/mir_scope.h index d9908823ce10ddd06842ce4c55e0328303066cc4..307558dd326e267c901abff26f20f3b7216e541b 100644 --- a/src/mapleall/maple_ir/include/mir_scope.h +++ b/src/mapleall/maple_ir/include/mir_scope.h @@ -170,7 +170,7 @@ class MIRScope { typeAlias->SetTypeAliasMap(gStrIdx, tyIdx); } - const MIRTypeAliasTable *GetTypAliasTable() const { + const MIRTypeAliasTable *GetTypeAliasTable() const { return typeAlias; } diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index c17457f1a5db3d5ec39c6b8c4d38496ad07aa819..ec6c562b682202958ebf605bb50d5073b07d76e0 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -308,8 +308,11 @@ void DebugInfo::AddScopeDie(MIRScope *scope, bool isLocal) { PushParentDie(die); } - // process aliasVarMap - AddAliasDies(scope->GetAliasVarMap(), isLocal); + // process type alias + HandleTypeAlias(scope, isLocal); + + // process alias + AddAliasDies(scope, isLocal); if (scope->GetSubScopes().size() > 0) { // process subScopes @@ -345,9 +348,26 @@ DBGDie *DebugInfo::GetAliasVarTypeDie(const MIRAliasVars &aliasVar, TyIdx tyidx) return GetOrCreateTypeDieWithAttr(aliasVar.attrs, typeDie); } -void DebugInfo::AddAliasDies(MapleMap &aliasMap, bool isLocal) { +void DebugInfo::HandleTypeAlias(MIRScope *scope, bool isLocal) { + const MIRTypeAliasTable *table = scope->GetTypeAliasTable(); + if (table) { + for (auto &i : table->GetTypeAliasMap()) { + uint32 tid = i.second.GetIdx(); + if (tyIdxDieIdMap.find(tid) == tyIdxDieIdMap.end()) { + ASSERT(false, "type alias type not in tyIdxDieIdMap"); + continue; + } + uint32 id = tyIdxDieIdMap[tid]; + DBGDie *die = idDieMap[id]; + die->SetAttr(DW_AT_name, i.first.GetIdx()); + AddStrps(i.first.GetIdx()); + } + } +} + +void DebugInfo::AddAliasDies(MIRScope *scope, bool isLocal) { MIRFunction *func = GetCurFunction(); - for (auto &i : aliasMap) { + for (auto &i : scope->GetAliasVarMap()) { // maple var and die MIRSymbol *mplVar = nullptr; DBGDie *mplDie = nullptr; @@ -457,6 +477,13 @@ void DebugInfo::BuildDebugInfoTypedefs() { (void)GetOrCreateTypeDie(TyIdx(it.second)); DBGDie *die = GetOrCreateTypedefDie(GStrIdx(it.first), TyIdx(it.second)); compUnit->AddSubVec(die); + // associate typedef's type with die + for (auto i : module->GetTypeNameTab()->GetGStrIdxToTyIdxMap()) { + if (i.first.GetIdx() == it.first) { + tyIdxDieIdMap[i.second.GetIdx()] = die->GetId(); + break; + } + } } } @@ -1032,6 +1059,10 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { break; } + if (die) { + tyIdxDieIdMap[tid] = die->GetId(); + } + return die; } @@ -1238,8 +1269,9 @@ DBGDie *DebugInfo::GetOrCreateStructTypeDie(const MIRType *type) { GStrIdx strIdx = type->GetNameStrIdx(); ASSERT(strIdx.GetIdx(), "struture type missing name"); - if (tyIdxDieIdMap.find(type->GetTypeIndex().GetIdx()) != tyIdxDieIdMap.end()) { - uint32 id = tyIdxDieIdMap[type->GetTypeIndex().GetIdx()]; + uint32 tid = type->GetTypeIndex().GetIdx(); + if (tyIdxDieIdMap.find(tid) != tyIdxDieIdMap.end()) { + uint32 id = tyIdxDieIdMap[tid]; return idDieMap[id]; } @@ -1269,6 +1301,9 @@ DBGDie *DebugInfo::GetOrCreateStructTypeDie(const MIRType *type) { GlobalTables::GetTypeNameTable().SetGStrIdxToTyIdx(strIdx, type->GetTypeIndex()); + if (die) { + tyIdxDieIdMap[type->GetTypeIndex().GetIdx()] = die->GetId(); + } return die; } @@ -1336,15 +1371,17 @@ void DebugInfo::CreateStructTypeMethodsDies(const MIRStructType *structType, DBG // shared between struct and union, also used as part by class and interface DBGDie *DebugInfo::CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *structType, bool update) { DBGDie *die = nullptr; + uint32 tid = structType->GetTypeIndex().GetIdx(); if (update) { - uint32 id = tyIdxDieIdMap[structType->GetTypeIndex().GetIdx()]; + ASSERT(tyIdxDieIdMap.find(tid) != tyIdxDieIdMap.end(), "update type die not exist"); + uint32 id = tyIdxDieIdMap[tid]; die = idDieMap[id]; ASSERT(die, "update type die not exist"); } else { DwTag tag = structType->GetKind() == kTypeStruct ? DW_TAG_structure_type : DW_TAG_union_type; die = module->GetMemPool()->New(module, tag); - tyIdxDieIdMap[structType->GetTypeIndex().GetIdx()] = die->GetId(); + tyIdxDieIdMap[tid] = die->GetId(); } die = GetOrCreateTypeDieWithAttr(structType->GetTypeAttrs(), die); @@ -1361,6 +1398,8 @@ DBGDie *DebugInfo::CreateStructTypeDie(GStrIdx strIdx, const MIRStructType *stru die->AddAttr(DW_AT_name, DW_FORM_strp, strIdx.GetIdx(), keep); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, kDbgDefaultVal); die->AddAttr(DW_AT_decl_file, DW_FORM_data4, mplSrcIdx.GetIdx()); + // store tid for cg emitter + die->AddAttr(DW_AT_type, DW_FORM_data4, tid, false); PushParentDie(die);