From 0df705a6e716174444e1c6fb08f9face91f5407d Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 9 Aug 2022 10:34:16 -0700 Subject: [PATCH 1/2] fix parser for irbuild to handles output from hir2mpl -g --- src/mapleall/maple_ir/src/parser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mapleall/maple_ir/src/parser.cpp b/src/mapleall/maple_ir/src/parser.cpp index d3e23cd3ba..9591537863 100644 --- a/src/mapleall/maple_ir/src/parser.cpp +++ b/src/mapleall/maple_ir/src/parser.cpp @@ -2851,6 +2851,10 @@ bool MIRParser::ParseMIR(uint32 fileIdx, uint32 option, bool isIPA, bool isComb) MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(it->second); CHECK_FATAL(type != nullptr, "type is null"); if (type->GetKind() == kTypeByName) { + TyIdx tyIdx = GlobalTables::GetTypedefTable().GetTyIdxFromMap(it->first); + if (tyIdx.GetIdx() != 0) { + continue; + } std::string strStream; const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(it->first); strStream += "type $"; -- Gitee From 7537fbdb5996d4bfafedff8990f74be0e2369cad Mon Sep 17 00:00:00 2001 From: Wen HU Date: Tue, 9 Aug 2022 12:56:08 -0700 Subject: [PATCH 2/2] update dwarf for typedef --- src/mapleall/maple_ir/src/debug_info.cpp | 30 ++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index ceafa40d05..916f38cbd2 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -1081,25 +1081,25 @@ DBGDie *DebugInfo::GetOrCreatePointTypeDie(const MIRPtrType *ptrType) { } MIRType *type = ptrType->GetPointedType(); + DBGDie *tdie = GetOrCreateTypeDie(type); // for <* void> and if ((type != nullptr) && (type->GetPrimType() == PTY_void || type->GetKind() == kTypeFunction)) { DBGDie *die = nullptr; if (type->GetKind() == kTypeFunction) { // for maple's function pointer type, function type should be used in dwarf - die = GetOrCreateTypeDie(type); - die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx()); + die = tdie; tyIdxDieIdMap[type->GetTypeIndex().GetIdx()] = die->GetId(); } else { 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()); tyIdxDieIdMap[ptrType->GetTypeIndex().GetIdx()] = die->GetId(); compUnit->AddSubVec(die); return die; } - (void)GetOrCreateTypeDie(type); if (typeDefTyIdxMap.find(type->GetTypeIndex().GetIdx()) != typeDefTyIdxMap.end()) { uint32 tyIdx = typeDefTyIdxMap[type->GetTypeIndex().GetIdx()]; if (pointedPointerMap.find(tyIdx) != pointedPointerMap.end()) { @@ -1126,9 +1126,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); - // fill with type idx instead of typedie->id to avoid nullptr typedie of - // forward reference of class types - die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx()); + die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); tyIdxDieIdMap[ptrType->GetTypeIndex().GetIdx()] = die->GetId(); compUnit->AddSubVec(die); @@ -1144,17 +1142,11 @@ DBGDie *DebugInfo::GetOrCreateArrayTypeDie(const MIRArrayType *arrayType) { } MIRType *type = arrayType->GetElemType(); - auto *typedie = GetOrCreateTypeDie(type); + DBGDie *tdie = GetOrCreateTypeDie(type); DBGDie *die = module->GetMemPool()->New(module, DW_TAG_array_type); die->AddAttr(DW_AT_byte_size, DW_FORM_data4, k8BitSize); - // fill with type idx instead of typedie->id to avoid nullptr typedie of - // forward reference of class types - if (type->GetKind() == kTypeByName) { - die->AddAttr(DW_AT_type, DW_FORM_ref4, -typedie->GetId()); - } else { - die->AddAttr(DW_AT_type, DW_FORM_ref4, type->GetTypeIndex().GetIdx()); - } + die->AddAttr(DW_AT_type, DW_FORM_ref4, -tdie->GetId()); tyIdxDieIdMap[arrayType->GetTypeIndex().GetIdx()] = die->GetId(); compUnit->AddSubVec(die); @@ -1189,10 +1181,8 @@ DBGDie *DebugInfo::CreateFieldDie(maple::FieldPair pair, uint32 lnum) { die->AddAttr(DW_AT_decl_line, DW_FORM_data4, lnum, keep); MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pair.second.first); - (void)GetOrCreateTypeDie(type); - // fill with type idx instead of typedie->id to avoid nullptr typedie of - // forward reference of class types - 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()); die->AddAttr(DW_AT_data_member_location, DW_FORM_data4, kDbgDefaultVal); @@ -1207,8 +1197,8 @@ DBGDie *DebugInfo::CreateBitfieldDie(const MIRBitFieldType *type, GStrIdx sidx, die->AddAttr(DW_AT_decl_line, DW_FORM_data4, 0); MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(type->GetPrimType()); - (void)GetOrCreateTypeDie(ty); - die->AddAttr(DW_AT_type, DW_FORM_ref4, ty->GetTypeIndex().GetIdx()); + DBGDie *tdie = GetOrCreateTypeDie(ty); + 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()); -- Gitee