From 7ed95d1577558f95db6b03968b561b17bbb0fec3 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Sun, 16 Jan 2022 12:44:52 -0800 Subject: [debug-info] Add support for llvm.dbg.addr in DIBuilder. I based this off of the API already create for llvm.dbg.value since both intrinsics have the same arguments at the API level. I added some tests exercising the API a little as well as an additional small test that shows how one can use llvm.dbg.addr to limit the PC range where an address value is available in the debugger. This is done by calling llvm.dbg.value with undef and the same metadata info as one used to create the llvm.dbg.addr. rdar://83957028 Reviewed By: aprantl Differential Revision: https://reviews.llvm.org/D117442 --- llvm/lib/IR/DIBuilder.cpp | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'llvm/lib/IR/DIBuilder.cpp') diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 16429e0..5712f4e 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -33,7 +33,7 @@ static cl::opt DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU) : M(m), VMContext(M.getContext()), CUNode(CU), DeclareFn(nullptr), - ValueFn(nullptr), LabelFn(nullptr), + ValueFn(nullptr), LabelFn(nullptr), AddrFn(nullptr), AllowUnresolvedNodes(AllowUnresolvedNodes) { if (CUNode) { if (const auto &ETs = CUNode->getEnumTypes()) @@ -974,6 +974,24 @@ Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr); } +Instruction *DIBuilder::insertDbgAddrIntrinsic(Value *V, + DILocalVariable *VarInfo, + DIExpression *Expr, + const DILocation *DL, + Instruction *InsertBefore) { + return insertDbgAddrIntrinsic( + V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr, + InsertBefore); +} + +Instruction *DIBuilder::insertDbgAddrIntrinsic(Value *V, + DILocalVariable *VarInfo, + DIExpression *Expr, + const DILocation *DL, + BasicBlock *InsertAtEnd) { + return insertDbgAddrIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr); +} + /// Initialize IRBuilder for inserting dbg.declare and dbg.value intrinsics. /// This abstracts over the various ways to specify an insert position. static void initIRBuilder(IRBuilder<> &Builder, const DILocation *DL, @@ -1018,17 +1036,20 @@ Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, return B.CreateCall(DeclareFn, Args); } -Instruction *DIBuilder::insertDbgValueIntrinsic( - Value *V, DILocalVariable *VarInfo, DIExpression *Expr, - const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) { - assert(V && "no value passed to dbg.value"); - assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value"); +Instruction *DIBuilder::insertDbgIntrinsic(llvm::Function *IntrinsicFn, + Value *V, DILocalVariable *VarInfo, + DIExpression *Expr, + const DILocation *DL, + BasicBlock *InsertBB, + Instruction *InsertBefore) { + assert(IntrinsicFn && "must pass a non-null intrinsic function"); + assert(V && "must pass a value to a dbg intrinsic"); + assert(VarInfo && + "empty or invalid DILocalVariable* passed to debug intrinsic"); assert(DL && "Expected debug loc"); assert(DL->getScope()->getSubprogram() == VarInfo->getScope()->getSubprogram() && "Expected matching subprograms"); - if (!ValueFn) - ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); trackIfUnresolved(VarInfo); trackIfUnresolved(Expr); @@ -1038,7 +1059,7 @@ Instruction *DIBuilder::insertDbgValueIntrinsic( IRBuilder<> B(DL->getContext()); initIRBuilder(B, DL, InsertBB, InsertBefore); - return B.CreateCall(ValueFn, Args); + return B.CreateCall(IntrinsicFn, Args); } Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, -- cgit v1.1