vsk created this revision. Instead of only setting a non-zero debug location on the return instruction in *_helper_block functions, set a proper location on all instructions within these functions. Pick the start location of the block literal expr for maximum clarity.
The debugger does not step into *_helper_block functions during normal single-stepping because we mark their parameters as artificial. This is what we want (the functions are implicitly generated and uninteresting to most users). The stepping behavior is unchanged by this patch. rdar://32907581 https://reviews.llvm.org/D39310 Files: lib/CodeGen/CGBlocks.cpp test/CodeGenObjC/debug-info-blocks.m Index: test/CodeGenObjC/debug-info-blocks.m =================================================================== --- test/CodeGenObjC/debug-info-blocks.m +++ test/CodeGenObjC/debug-info-blocks.m @@ -10,9 +10,10 @@ // CHECK-NEXT: call void @llvm.dbg.declare(metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}}) // CHECK-NEXT: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D:[0-9]+]], metadata !{{.*}}) -// rdar://problem/14386148 -// Test that we don't emit bogus line numbers for the helper functions. -// Test that we do emit scope info for the helper functions. +// rdar://problem/32907581 +// Test that we do emit scope info for the helper functions, and that the +// parameters to these functions are marked as artificial (so the debugger +// doesn't accidentally step into the function). // CHECK: define {{.*}} @__copy_helper_block_{{.*}}(i8*, i8*) // CHECK-NOT: ret // CHECK: call {{.*}}, !dbg ![[DBG_LINE:[0-9]+]] @@ -23,10 +24,13 @@ // CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]] // CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]]) -// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]]) +// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 67, scope: ![[COPY_SP:[0-9]+]]) // CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_" -// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]]) +// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 67, scope: ![[DESTROY_SP:[0-9]+]]) // CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_" +// CHECK-DAG: !DILocalVariable(arg: 1, scope: ![[COPY_SP]], {{.*}}, flags: DIFlagArtificial) +// CHECK-DAG: !DILocalVariable(arg: 2, scope: ![[COPY_SP]], {{.*}}, flags: DIFlagArtificial) +// CHECK-DAG: !DILocalVariable(arg: 1, scope: ![[DESTROY_SP]], {{.*}}, flags: DIFlagArtificial) typedef unsigned int NSUInteger; @protocol NSObject Index: lib/CodeGen/CGBlocks.cpp =================================================================== --- lib/CodeGen/CGBlocks.cpp +++ lib/CodeGen/CGBlocks.cpp @@ -1647,10 +1647,8 @@ CGM.SetInternalFunctionAttributes(nullptr, Fn, FI); - auto NL = ApplyDebugLocation::CreateEmpty(*this); StartFunction(FD, C.VoidTy, Fn, FI, args); - // Create a scope with an artificial location for the body of this function. - auto AL = ApplyDebugLocation::CreateArtificial(*this); + ApplyDebugLocation NL{*this, blockInfo.getBlockExpr()->getLocStart()}; llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo(); Address src = GetAddrOfLocalVar(&SrcDecl); @@ -1819,10 +1817,8 @@ CGM.SetInternalFunctionAttributes(nullptr, Fn, FI); - // Create a scope with an artificial location for the body of this function. - auto NL = ApplyDebugLocation::CreateEmpty(*this); StartFunction(FD, C.VoidTy, Fn, FI, args); - auto AL = ApplyDebugLocation::CreateArtificial(*this); + ApplyDebugLocation NL{*this, blockInfo.getBlockExpr()->getLocStart()}; llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
Index: test/CodeGenObjC/debug-info-blocks.m =================================================================== --- test/CodeGenObjC/debug-info-blocks.m +++ test/CodeGenObjC/debug-info-blocks.m @@ -10,9 +10,10 @@ // CHECK-NEXT: call void @llvm.dbg.declare(metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}}) // CHECK-NEXT: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D:[0-9]+]], metadata !{{.*}}) -// rdar://problem/14386148 -// Test that we don't emit bogus line numbers for the helper functions. -// Test that we do emit scope info for the helper functions. +// rdar://problem/32907581 +// Test that we do emit scope info for the helper functions, and that the +// parameters to these functions are marked as artificial (so the debugger +// doesn't accidentally step into the function). // CHECK: define {{.*}} @__copy_helper_block_{{.*}}(i8*, i8*) // CHECK-NOT: ret // CHECK: call {{.*}}, !dbg ![[DBG_LINE:[0-9]+]] @@ -23,10 +24,13 @@ // CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]] // CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]]) -// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]]) +// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 67, scope: ![[COPY_SP:[0-9]+]]) // CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_" -// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]]) +// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 67, scope: ![[DESTROY_SP:[0-9]+]]) // CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_" +// CHECK-DAG: !DILocalVariable(arg: 1, scope: ![[COPY_SP]], {{.*}}, flags: DIFlagArtificial) +// CHECK-DAG: !DILocalVariable(arg: 2, scope: ![[COPY_SP]], {{.*}}, flags: DIFlagArtificial) +// CHECK-DAG: !DILocalVariable(arg: 1, scope: ![[DESTROY_SP]], {{.*}}, flags: DIFlagArtificial) typedef unsigned int NSUInteger; @protocol NSObject Index: lib/CodeGen/CGBlocks.cpp =================================================================== --- lib/CodeGen/CGBlocks.cpp +++ lib/CodeGen/CGBlocks.cpp @@ -1647,10 +1647,8 @@ CGM.SetInternalFunctionAttributes(nullptr, Fn, FI); - auto NL = ApplyDebugLocation::CreateEmpty(*this); StartFunction(FD, C.VoidTy, Fn, FI, args); - // Create a scope with an artificial location for the body of this function. - auto AL = ApplyDebugLocation::CreateArtificial(*this); + ApplyDebugLocation NL{*this, blockInfo.getBlockExpr()->getLocStart()}; llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo(); Address src = GetAddrOfLocalVar(&SrcDecl); @@ -1819,10 +1817,8 @@ CGM.SetInternalFunctionAttributes(nullptr, Fn, FI); - // Create a scope with an artificial location for the body of this function. - auto NL = ApplyDebugLocation::CreateEmpty(*this); StartFunction(FD, C.VoidTy, Fn, FI, args); - auto AL = ApplyDebugLocation::CreateArtificial(*this); + ApplyDebugLocation NL{*this, blockInfo.getBlockExpr()->getLocStart()}; llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits