From 82cb469c285c83937d20b837eee0aa0419f04adc Mon Sep 17 00:00:00 2001 From: Wen HU Date: Wed, 14 Sep 2022 09:58:27 -0700 Subject: [PATCH] dwarf handle struct parameters size larger than 8 which are converted into pointers --- src/mapleall/maple_be/src/cg/emit.cpp | 18 +++++++ src/mapleall/maple_ir/include/debug_info.h | 4 +- src/mapleall/maple_ir/src/debug_info.cpp | 61 +++++++++++++++++----- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/src/mapleall/maple_be/src/cg/emit.cpp b/src/mapleall/maple_be/src/cg/emit.cpp index 00a60270cc..a78c0aa3ea 100644 --- a/src/mapleall/maple_be/src/cg/emit.cpp +++ b/src/mapleall/maple_be/src/cg/emit.cpp @@ -3337,6 +3337,24 @@ void Emitter::EmitDIAttrValue(DBGDie *die, DBGDieAttr *attr, DwAt attrName, DwTa EmitDecSigned(elp->GetFboffset()); (void)Emit(CMNT "fboffset"); break; + case DW_OP_breg0: + case DW_OP_breg1: + case DW_OP_breg2: + case DW_OP_breg3: + case DW_OP_breg4: + case DW_OP_breg5: + case DW_OP_breg6: + case DW_OP_breg7: + EmitHexUnsigned(2); + Emit(CMNT "size"); + Emit("\n\t.byte "); + EmitHexUnsigned(elp->GetOp()); + Emit(CMNT); + Emit(maple::GetDwOpName(elp->GetOp())); + Emit("\n\t.sleb128 "); + EmitDecSigned(0); + Emit(CMNT "offset"); + break; default: EmitHexUnsigned(uintptr_t(elp)); break; diff --git a/src/mapleall/maple_ir/include/debug_info.h b/src/mapleall/maple_ir/include/debug_info.h index bfa904ec6e..595274642b 100644 --- a/src/mapleall/maple_ir/include/debug_info.h +++ b/src/mapleall/maple_ir/include/debug_info.h @@ -342,7 +342,7 @@ class DBGDie { void AddSubVec(DBGDie *die); void AddAttr(DBGDieAttr *attr); void AddAttr(DwAt at, DwForm form, uint64 val, bool keep = true); - void AddSimpLocAttr(DwAt at, DwForm form, uint64 val); + void AddSimpLocAttr(DwAt at, DwForm form, DwOp op, uint64 val); void AddGlobalLocAttr(DwAt at, DwForm form, uint64 val); void AddFrmBaseAttr(DwAt at, DwForm form); DBGExprLoc *GetExprLoc(); @@ -814,7 +814,7 @@ class DebugInfo { DBGDie *CreateVarDie(MIRSymbol *sym); DBGDie *CreateVarDie(MIRSymbol *sym, const GStrIdx &strIdx); // use alt name - DBGDie *CreateFormalParaDie(MIRFunction *func, MIRType *type, MIRSymbol *sym); + DBGDie *CreateFormalParaDie(MIRFunction *func, uint32 idx, bool isDef); DBGDie *CreateFieldDie(maple::FieldPair pair); DBGDie *CreateBitfieldDie(const MIRBitFieldType *type, const GStrIdx &sidx, uint32 &prevBits); void CreateStructTypeFieldsDies(const MIRStructType *structType, DBGDie *die); diff --git a/src/mapleall/maple_ir/src/debug_info.cpp b/src/mapleall/maple_ir/src/debug_info.cpp index 1b938d2509..bce8933f9d 100644 --- a/src/mapleall/maple_ir/src/debug_info.cpp +++ b/src/mapleall/maple_ir/src/debug_info.cpp @@ -75,8 +75,8 @@ void DBGDie::AddAttr(DwAt at, DwForm form, uint64 val, bool keepFlag) { AddAttr(attr); } -void DBGDie::AddSimpLocAttr(DwAt at, DwForm form, uint64 val) { - DBGExprLoc *p = module->GetMemPool()->New(module, DW_OP_fbreg); +void DBGDie::AddSimpLocAttr(DwAt at, DwForm form, DwOp op, uint64 val) { + DBGExprLoc *p = module->GetMemPool()->New(module, op); if (val != kDbgDefaultVal) { p->AddSimpLocOpnd(val); } @@ -591,9 +591,10 @@ void DebugInfo::BuildDebugInfoFunctions() { } } // function def - if (funcDefStrIdxDieIdMap.find(func->GetNameStrIdx().GetIdx()) == funcDefStrIdxDieIdMap.end()) { + unsigned idx = func->GetNameStrIdx().GetIdx(); + if (func->GetBody() && funcDefStrIdxDieIdMap.find(idx) == funcDefStrIdxDieIdMap.end()) { DBGDie *funcDie = GetOrCreateFuncDefDie(func); - if (!func->GetClassTyIdx().GetIdx() && func->GetBody()) { + if (!func->GetClassTyIdx().GetIdx()) { compUnit->AddSubVec(funcDie); } } @@ -683,19 +684,46 @@ LabelIdx DebugInfo::GetLabelIdx(GStrIdx strIdx) { return labidx; } -DBGDie *DebugInfo::CreateFormalParaDie(MIRFunction *func, MIRType *type, MIRSymbol *sym) { +// passing pointer instead if strct size larger than this +#define STRUCT2PTRSIZE 8 + +static DwOp GetBreg(unsigned i) { + DwOp op = DW_OP_breg0; + switch (i) { + case 0: op = DW_OP_breg0; break; + case 1: op = DW_OP_breg1; break; + case 2: op = DW_OP_breg2; break; + case 3: op = DW_OP_breg3; break; + case 4: op = DW_OP_breg4; break; + case 5: op = DW_OP_breg5; break; + case 6: op = DW_OP_breg6; break; + case 7: op = DW_OP_breg7; break; + default: break; + } + return op; +} + +DBGDie *DebugInfo::CreateFormalParaDie(MIRFunction *func, uint32 idx, bool isDef) { DBGDie *die = module->GetMemPool()->New(module, DW_TAG_formal_parameter); + TyIdx tyIdx = func->GetFormalDefAt(idx).formalTyIdx; + MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); DBGDie *typeDie = GetOrCreateTypeDie(type); die->AddAttr(DW_AT_type, DW_FORM_ref4, typeDie->GetId()); - /* var Name */ - if (sym) { + /* var */ + MIRSymbol *sym = func->GetFormalDefAt(idx).formalSym; + if (isDef && sym) { die->AddAttr(DW_AT_name, DW_FORM_strp, sym->GetNameStrIdx().GetIdx()); die->AddAttr(DW_AT_decl_file, DW_FORM_data4, sym->GetSrcPosition().FileNum()); die->AddAttr(DW_AT_decl_line, DW_FORM_data4, sym->GetSrcPosition().LineNum()); die->AddAttr(DW_AT_decl_column, DW_FORM_data4, sym->GetSrcPosition().Column()); - die->AddSimpLocAttr(DW_AT_location, DW_FORM_exprloc, kDbgDefaultVal); + DwOp op = DW_OP_fbreg; + // struct parameters size larger than 8 are converted into pointers + if (type->IsStructType() && (static_cast(type)->GetSize() > STRUCT2PTRSIZE)) { + op = GetBreg(idx); + } + die->AddSimpLocAttr(DW_AT_location, DW_FORM_exprloc, op, kDbgDefaultVal); SetLocalDie(func, sym->GetNameStrIdx(), die); } return die; @@ -781,7 +809,7 @@ DBGDie *DebugInfo::CreateVarDie(MIRSymbol *sym, const GStrIdx &strIdx) { uint64 idx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(ptrName).GetIdx(); die->AddGlobalLocAttr(DW_AT_location, DW_FORM_exprloc, idx); } else { - die->AddSimpLocAttr(DW_AT_location, DW_FORM_exprloc, kDbgDefaultVal); + die->AddSimpLocAttr(DW_AT_location, DW_FORM_exprloc, DW_OP_fbreg, kDbgDefaultVal); } } else { // global var just use its name as address in .s @@ -840,8 +868,7 @@ DBGDie *DebugInfo::GetOrCreateFuncDeclDie(MIRFunction *func) { // formal parameter for (uint32 i = 0; i < func->GetFormalCount(); i++) { - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(func->GetFormalDefAt(i).formalTyIdx); - DBGDie *param = CreateFormalParaDie(func, type, nullptr); + DBGDie *param = CreateFormalParaDie(func, i, /* isDef */ false); die->AddSubVec(param); } @@ -911,8 +938,7 @@ DBGDie *DebugInfo::GetOrCreateFuncDefDie(MIRFunction *func) { // formal parameter for (uint32 i = 0; i < func->GetFormalCount(); i++) { - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(func->GetFormalDefAt(i).formalTyIdx); - DBGDie *pdie = CreateFormalParaDie(func, type, func->GetFormalDefAt(i).formalSym); + DBGDie *pdie = CreateFormalParaDie(func, i, /* isDef */ true); die->AddSubVec(pdie); } @@ -1654,6 +1680,15 @@ size_t DBGDieAttr::SizeOf(DBGDieAttr *attr) const { size_t size = 1 + namemangler::GetSleb128Size(ptr->GetFboffset()); return size + namemangler::GetUleb128Size(size); } + case DW_OP_breg0: + case DW_OP_breg1: + case DW_OP_breg2: + case DW_OP_breg3: + case DW_OP_breg4: + case DW_OP_breg5: + case DW_OP_breg6: + case DW_OP_breg7: + return k3BitSize; case DW_OP_addr: { return namemangler::GetUleb128Size(k9BitSize) + k9BitSize; } -- Gitee