From bb282f64539417c78596bae98251c99a20ea2404 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Fri, 12 Aug 2022 10:11:46 -0700 Subject: [PATCH 1/2] consolidate to only use DIE id for DW_AT_type --- src/mapleall/maple_ir/include/debug_info.h | 4 - src/mapleall/maple_ir/src/debug_info.cpp | 166 +++++++-------------- 2 files changed, 51 insertions(+), 119 deletions(-) diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index 9606cc24ef..3112c218a0 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -658,9 +658,6 @@ class DebugInfo { // also insert DW_AT_sibling attributes when needed void BuildDieTree(); - // replace type idx with die id in DW_AT_type attributes - void FillTypeAttrWithDieId(); - void BuildAbbrev(); uint32 GetAbbrevId(DBGAbbrevEntryVec *vec, DBGAbbrevEntry *entry) const; @@ -814,7 +811,6 @@ class DebugInfo { typedefStrIdxTyIdxMap[stridx.GetIdx()] = tyidx.GetIdx(); } void DumpTypedefMap() const; - void SetDieTypeAttribute(DBGDie &die, const MIRType &type, const DBGDie &typeDie); private: MIRModule *module; diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 6ff29826f7..c0bb634952 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -65,7 +65,7 @@ void DBGDie::ResetParentDie() const { } DBGDieAttr *DBGDie::AddAttr(DwAt at, DwForm form, uint64 val, bool keepFlag) { - auto *attr = AddAttr(at, form, val); + DBGDieAttr *attr = AddAttr(at, form, val); attr->SetKeep(keepFlag); return attr; } @@ -357,34 +357,26 @@ void DebugInfo::AddAliasDies(MapleMap &aliasMap, bool isL // get type from alias uint32 index = i.second.index; + DBGDie *typeDie = nullptr; switch (i.second.atk) { - case kATKType: { - DBGDie *typeDie = GetOrCreateTypeDie(TyIdx(index)); - DBGDie *newDie = GetOrCreateTypeDie(i.second.attrs, typeDie); - (void)(vdie->SetAttr(DW_AT_type, -newDie->GetId())); + case kATKType: + typeDie = GetOrCreateTypeDie(TyIdx(index)); break; - } - case kATKString: { - // use src code type - DBGDie *typeDie = GetOrCreateTypedefDie(GStrIdx(index), mplVar->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())); + case kATKString: + typeDie = GetOrCreateTypedefDie(GStrIdx(index), mplVar->GetTyIdx()); break; - } - case kATKEnum: { - // use src code enum type - DBGDie *typeDie = GetOrCreateEnumTypeDie(index); - 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())); + case kATKEnum: + typeDie = GetOrCreateEnumTypeDie(index); break; - } default: ASSERT(false, "unknown alias type kind"); break; } + ASSERT(typeDie, "null typeDie"); + DBGDie *newDie = GetOrCreateTypeDie(i.second.attrs, typeDie); + (void)(vdie->SetAttr(DW_AT_type, newDie->GetId())); + // for new var if (!updateOnly) { // link vdie's ExprLoc to mplDie's @@ -445,7 +437,6 @@ void DebugInfo::GetCrossScopeId(MIRFunction *func, void DebugInfo::Finish() { SetupCU(); - FillTypeAttrWithDieId(); // build tree from root DIE compUnit BuildDieTree(); BuildAbbrev(); @@ -470,14 +461,11 @@ void DebugInfo::BuildDebugInfo() { case kTypeInterfaceIncomplete: case kTypeStruct: case kTypeStructIncomplete: - case kTypeUnion: - { + case kTypeUnion: { (void) GetOrCreateStructTypeDie(type); break; } default: - LogInfo::MapleLogger() << "named type " << GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx).c_str() - << "\n"; break; } } @@ -602,8 +590,8 @@ LabelIdx DebugInfo::GetLabelIdx(GStrIdx strIdx) { DBGDie *DebugInfo::CreateFormalParaDie(MIRFunction *func, MIRType *type, MIRSymbol *sym) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_formal_parameter); - (void)GetOrCreateTypeDie(type); - die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx()); + DBGDie *tdie = GetOrCreateTypeDie(type); + die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); /* var Name */ if (sym) { @@ -712,8 +700,7 @@ DBGDie *DebugInfo::CreateVarDie(MIRSymbol *sym, GStrIdx strIdx) { MIRType *type = sym->GetType(); DBGDie *typeDie = GetOrCreateTypeDie(type); DBGDie *newDie = GetOrCreateTypeDie(sym->GetAttrs(), typeDie); - int index = (newDie == typeDie ? type->GetTypeIndex().GetIdx() : -newDie->GetId()); - die->AddAttr(DW_AT_type, DW_FORM_ref4, index); + die->AddAttr(DW_AT_type, DW_FORM_ref4, newDie->GetId()); return die; } @@ -793,8 +780,8 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func, uint32 lnum) { if (!func->IsReturnVoid()) { auto returnType = func->GetReturnType(); - (void)GetOrCreateTypeDie(returnType); - die->AddAttr(DW_AT_type, DW_FORM_ref4, returnType->GetTypeIndex().GetIdx()); + DBGDie *tdie = GetOrCreateTypeDie(returnType); + die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); } die->AddAttr(DW_AT_low_pc, DW_FORM_addr, kDbgDefaultVal); @@ -874,29 +861,21 @@ DBGDie *DebugInfo::GetOrCreatePrimTypeDie(MIRType *ty) { return die; } -void DebugInfo::SetDieTypeAttribute(DBGDie &die, const MIRType &type, const DBGDie &typeDie) { - if (type.GetKind() == kTypeByName) { - (void)die.AddAttr(DW_AT_type, DW_FORM_ref4, -typeDie.GetId()); - } else { - die.AddAttr(DW_AT_type, DW_FORM_ref4, type.GetTypeIndex().GetIdx()); - } -} - DBGDie *DebugInfo::CreatePointedFuncTypeDie(MIRFuncType *fType) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_subroutine_type); die->AddAttr(DW_AT_prototyped, DW_FORM_data4, static_cast(fType->GetParamTypeList().size() > 0)); MIRType *rtype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fType->GetRetTyIdx()); - auto *rtypeDie = GetOrCreateTypeDie(rtype); - SetDieTypeAttribute(*die, *rtype, *rtypeDie); + DBGDie *rtypeDie = GetOrCreateTypeDie(rtype); + die->AddAttr(DW_AT_type, DW_FORM_ref4, rtypeDie->GetId()); compUnit->AddSubVec(die); for (uint32 i = 0; i < fType->GetParamTypeList().size(); i++) { DBGDie *paramDie = module->GetMemPool()->New(module, DW_TAG_formal_parameter); MIRType *ptype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fType->GetNthParamType(i)); - auto *ptypeDie = GetOrCreateTypeDie(ptype); - SetDieTypeAttribute(*paramDie, *ptype, *ptypeDie); + DBGDie *ptypeDie = GetOrCreateTypeDie(ptype); + paramDie->AddAttr(DW_AT_type, DW_FORM_ref4, ptypeDie->GetId()); die->AddSubVec(paramDie); } @@ -915,7 +894,7 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(AttrKind attr, DBGDie *typeDie) { die = idDieMap[newId]; } else { die = module->GetMemPool()->New(module, DW_TAG_const_type); - (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, -dieId)); + (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, dieId)); compUnit->AddSubVec(die); newId = die->GetId(); constTypeDieMap[dieId] = newId; @@ -927,7 +906,7 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(AttrKind attr, DBGDie *typeDie) { die = idDieMap[newId]; } else { die = module->GetMemPool()->New(module, DW_TAG_volatile_type); - (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, -dieId)); + (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, dieId)); compUnit->AddSubVec(die); newId = die->GetId(); volatileTypeDieMap[dieId] = newId; @@ -978,23 +957,17 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { DBGDie *die = nullptr; switch (type->GetKind()) { - case kTypePointer: { - MIRPtrType *pType = static_cast(type); - die = GetOrCreatePointTypeDie(pType); + case kTypePointer: + die = GetOrCreatePointTypeDie(static_cast(type)); break; - } - case kTypeFunction: { - MIRFuncType *fType = static_cast(type); - die = CreatePointedFuncTypeDie(fType); + case kTypeFunction: + die = CreatePointedFuncTypeDie(static_cast(type)); break; - } case kTypeArray: case kTypeFArray: - case kTypeJArray: { - MIRArrayType *aType = static_cast(type); - die = GetOrCreateArrayTypeDie(aType); + case kTypeJArray: + die = GetOrCreateArrayTypeDie(static_cast(type)); break; - } case kTypeUnion: case kTypeStruct: case kTypeStructIncomplete: @@ -1034,8 +1007,7 @@ DBGDie *DebugInfo::GetOrCreateTypedefDie(GStrIdx stridx, TyIdx tyidx) { (void)(die->AddAttr(DW_AT_decl_column, DW_FORM_data1, 0)); DBGDie *typeDie = GetOrCreateTypeDie(tyidx); - // use negative vaule of Die id - (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, -typeDie->GetId())); + (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, typeDie->GetId())); typedefStrIdxDieIdMap[sid] = die->GetId(); return die; @@ -1060,8 +1032,8 @@ DBGDie *DebugInfo::GetOrCreateEnumTypeDie(unsigned idx) { (void)(die->AddAttr(DW_AT_encoding, DW_FORM_data4, GetAteFromPTY(pty))); (void)(die->AddAttr(DW_AT_byte_size, DW_FORM_data1, GetPrimTypeSize(pty))); MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pty); - (void) GetOrCreateTypeDie(type); - (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx())); + DBGDie *tdie = GetOrCreateTypeDie(type); + (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId())); (void)(die->AddAttr(DW_AT_decl_file, DW_FORM_data1, 0)); (void)(die->AddAttr(DW_AT_decl_line, DW_FORM_data1, 0)); (void)(die->AddAttr(DW_AT_decl_column, DW_FORM_data1, 0)); @@ -1098,7 +1070,7 @@ DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrType) { die = module->GetMemPool()->New(module, DW_TAG_pointer_type); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, k8BitSize); } - die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); + die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); tyIdxDieIdMap[ptrType->GetTypeIndex().GetIdx()] = die->GetId(); compUnit->AddSubVec(die); return die; @@ -1130,7 +1102,7 @@ DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrType) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_pointer_type); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, k8BitSize); - die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); + die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); tyIdxDieIdMap[ptrType->GetTypeIndex().GetIdx()] = die->GetId(); compUnit->AddSubVec(die); @@ -1150,7 +1122,7 @@ DBGDie *DebugInfo::GetOrCreateArrayTypeDie(const MIRArrayType *arrayType) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_array_type); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, k8BitSize); - die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); + die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); tyIdxDieIdMap[arrayType->GetTypeIndex().GetIdx()] = die->GetId(); compUnit->AddSubVec(die); @@ -1164,7 +1136,8 @@ DBGDie *DebugInfo::GetOrCreateArrayTypeDie(const MIRArrayType *arrayType) { for (auto i = 0; i < dim; ++i) { DBGDie *rangeDie = module->GetMemPool()->New(module, DW_TAG_subrange_type); (void)GetOrCreatePrimTypeDie(GlobalTables::GetTypeTable().GetUInt32()); - rangeDie->AddAttr(DW_AT_type, DW_FORM_ref4, PTY_u32); + DBGDie *tdie = GetOrCreateTypeDie(TyIdx(PTY_u32)); + rangeDie->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); // The default lower bound value for C, C++, or Java is 0 (void)rangeDie->AddAttr(DW_AT_upper_bound, DW_FORM_data4, arrayType->GetSizeArrayItem(i) - 1); die->AddSubVec(rangeDie); @@ -1186,7 +1159,7 @@ DBGDie *DebugInfo::CreateFieldDie(maple::FieldPair pair, uint32 lnum) { MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pair.second.first); DBGDie *tdie = GetOrCreateTypeDie(type); - die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); + die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); die->AddAttr(DW_AT_data_member_location, DW_FORM_data4, kDbgDefaultVal); @@ -1202,7 +1175,7 @@ DBGDie *DebugInfo::CreateBitfieldDie(const MIRBitFieldType *type, GStrIdx sidx, MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(type->GetPrimType()); DBGDie *tdie = GetOrCreateTypeDie(ty); - die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); + die->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, GetPrimTypeSize(type->GetPrimType())); die->AddAttr(DW_AT_bit_size, DW_FORM_data4, type->GetFieldSize()); @@ -1229,26 +1202,17 @@ DBGDie *DebugInfo::GetOrCreateStructTypeDie(const MIRType *type) { switch (type->GetKind()) { case kTypeClass: case kTypeClassIncomplete: - { - const MIRClassType *classType = static_cast(type); - die = CreateClassTypeDie(strIdx, classType); - break; - } + die = CreateClassTypeDie(strIdx, static_cast(type)); + break; case kTypeInterface: case kTypeInterfaceIncomplete: - { - const MIRInterfaceType *interfaceType = static_cast(type); - die = CreateInterfaceTypeDie(strIdx, interfaceType); - break; - } + die = CreateInterfaceTypeDie(strIdx, static_cast(type)); + break; case kTypeStruct: case kTypeStructIncomplete: case kTypeUnion: - { - const MIRStructType *stype = static_cast(type); - die = CreateStructTypeDie(strIdx, stype, false); - break; - } + die = CreateStructTypeDie(strIdx, static_cast(type), false); + break; default: LogInfo::MapleLogger() << "named type " << GlobalTables::GetStrTable().GetStringFromStrIdx(strIdx).c_str() << "\n"; @@ -1356,7 +1320,8 @@ DBGDie *DebugInfo::CreateClassTypeDie(GStrIdx strIdx, const MIRClassType *classT if (parentDie) { parentDie = module->GetMemPool()->New(module, DW_TAG_inheritance); parentDie->AddAttr(DW_AT_name, DW_FORM_strp, parenttype->GetNameStrIdx().GetIdx()); - parentDie->AddAttr(DW_AT_type, DW_FORM_ref4, ptid); + DBGDie *tdie = GetOrCreateStructTypeDie(classType); + parentDie->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); // set to DW_ACCESS_public for now parentDie->AddAttr(DW_AT_accessibility, DW_FORM_data4, DW_ACCESS_public); @@ -1388,7 +1353,8 @@ DBGDie *DebugInfo::CreateInterfaceTypeDie(GStrIdx strIdx, const MIRInterfaceType } parentDie = module->GetMemPool()->New(module, DW_TAG_inheritance); parentDie->AddAttr(DW_AT_name, DW_FORM_strp, type->GetNameStrIdx().GetIdx()); - parentDie->AddAttr(DW_AT_type, DW_FORM_ref4, it.GetIdx()); + DBGDie *tdie = GetOrCreateStructTypeDie(interfaceType); + parentDie->AddAttr(DW_AT_type, DW_FORM_ref4, tdie->GetId()); parentDie->AddAttr(DW_AT_data_member_location, DW_FORM_data4, kDbgDefaultVal); // set to DW_ACCESS_public for now @@ -1468,35 +1434,6 @@ void DebugInfo::BuildDieTree() { } } -void DebugInfo::FillTypeAttrWithDieId() { - for (auto it : idDieMap) { - DBGDie *die = it.second; - 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 negative value - if (static_cast(tid) < 0) { - at->SetId(-static_cast(tid)); - break; - } - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(tid)); - if (type) { - uint32 dieid = tyIdxDieIdMap[tid]; - if (dieid != 0) { - at->SetId(dieid); - } else { - LogInfo::MapleLogger() << "dieid not found, typeKind = " << type->GetKind() << " primType = " - << type->GetPrimType() << " nameStrIdx = " << type->GetNameStrIdx().GetIdx() << std::endl; - } - } else { - LogInfo::MapleLogger() << "type not found, tid = " << tid << std::endl; - } - break; - } - } - } -} - DBGDie *DebugInfo::GetDie(const MIRFunction *func) { uint32 id = stridxDieIdMap[func->GetNameStrIdx().GetIdx()]; if (id != 0) { @@ -1561,9 +1498,8 @@ size_t DBGDieAttr::SizeOf(DBGDieAttr *attr) const { } } default: - CHECK_FATAL(maple::GetDwFormName(form) != nullptr, - "GetDwFormName return null in DebugInfo::FillTypeAttrWithDieId"); LogInfo::MapleLogger() << "unhandled SizeOf: " << maple::GetDwFormName(form) << std::endl; + CHECK_FATAL(maple::GetDwFormName(form) != nullptr, "null GetDwFormName(form)"); return 0; } } -- Gitee From 9275f7c09a9792791d3be946dfea95c29fe8c548 Mon Sep 17 00:00:00 2001 From: Wen HU Date: Fri, 12 Aug 2022 10:58:21 -0700 Subject: [PATCH 2/2] consolidate typedefStrIdxDieIdMap with stridxDieIdMap --- src/mapleall/maple_ir/include/debug_info.h | 2 -- src/mapleall/maple_ir/src/debug_info.cpp | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index 3112c218a0..19dc4a133b 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -607,7 +607,6 @@ 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()), typedefStrIdxTyIdxMap(std::less(), m->GetMPAllocator().Adapter()), constTypeDieMap(std::less(), m->GetMPAllocator().Adapter()), volatileTypeDieMap(std::less(), m->GetMPAllocator().Adapter()), @@ -848,7 +847,6 @@ class DebugInfo { MapleMap> funcScopeIdStatus; /* alias type */ - MapleMap typedefStrIdxDieIdMap; MapleMap typedefStrIdxTyIdxMap; MapleMap constTypeDieMap; MapleMap volatileTypeDieMap; diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index c0bb634952..3af1bb9fa7 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -993,8 +993,8 @@ DBGDie *DebugInfo::GetOrCreateTypeDie(MIRType *type) { DBGDie *DebugInfo::GetOrCreateTypedefDie(GStrIdx stridx, TyIdx tyidx) { uint32 sid = stridx.GetIdx(); - auto it = typedefStrIdxDieIdMap.find(sid); - if (it != typedefStrIdxDieIdMap.end()) { + auto it = stridxDieIdMap.find(sid); + if (it != stridxDieIdMap.end()) { return idDieMap[it->second]; } @@ -1009,7 +1009,7 @@ DBGDie *DebugInfo::GetOrCreateTypedefDie(GStrIdx stridx, TyIdx tyidx) { DBGDie *typeDie = GetOrCreateTypeDie(tyidx); (void)(die->AddAttr(DW_AT_type, DW_FORM_ref4, typeDie->GetId())); - typedefStrIdxDieIdMap[sid] = die->GetId(); + stridxDieIdMap[sid] = die->GetId(); return die; } -- Gitee