-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[DebugInfo] Prevent salvaged debug vars from being marked artificial #38942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
@@ -2542,6 +2542,17 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic( | |||
!llvm::FindDbgDeclareUses(Storage).empty()) | |||
return; | |||
|
|||
// Fragment DIExpression cannot cover the whole variable | |||
// or going out-of-bound. | |||
if (auto Fragment = Expr->getFragmentInfo()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we understand why we generate a fragment that covers the entire variable? Does this happen because we SROA a struct with a single member? Could we catch that case in IRGenDebugInfoImpl::emitVariableDeclaration()
and not emit a DW_OP_LLVM_fragment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this only happens when the struct only has one member. Originally I was going to solve this by preserving the bail out logic here and avoid emitting DW_OP_LLVM_fragment some place earlier as suggested. But then I found that it will be easier to just drop the fragment part here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works!
We were using compiler-generated source location (i.e. line number 0) on `debug_value` instructions were emitted by salvage debug info. But it turned out that IRGen will attach DW_AT_artificial on the associated debug variables, which are hidden in debugger by default. This patch prevent this issue by using the source location from the just-deleted instruction for these `debug_value` instructions. This indirectly triggered another bug where some of the LLVM !DIExpression-s we generated are actually invalid -- more specifically, the fragment inside is covering the whole debug variable. The reason it was not previously caught is because LLVM verifier skips any debug variable that is marked artificial, and all debug variables that have illegal fragment are falling under this category. Thus, this patch also fixes this issue by not generating the DW_OP_LLVM_fragment part if it's illegal.
7b2b13e
to
da5ef90
Compare
@swift-ci please test |
@@ -2542,6 +2542,17 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic( | |||
!llvm::FindDbgDeclareUses(Storage).empty()) | |||
return; | |||
|
|||
// Fragment DIExpression cannot cover the whole variable | |||
// or going out-of-bound. | |||
if (auto Fragment = Expr->getFragmentInfo()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works!
@swift-ci please test |
@swift-ci test windows |
We were using compiler-generated source location (i.e. line number
0) on
debug_value
instructions that were emitted by salvage debug info.But it turned out that IRGen will attach DW_AT_artificial on the
associated debug variables, which are hidden in debugger by default.
This patch prevent this issue by using the source location from the
just-deleted instruction for these
debug_value
instructions.This indirectly triggered another bug where some of the LLVM
!DIExpression-s we generated were actually invalid -- more specifically,
the enclosed fragment is covering the whole debug variable. The reason it was
not previously caught is because LLVM verifier skips any debug variable
that is marked artificial, and all debug variables that have illegal fragment
are falling under this category. This patch fixes this issue
by not generating any
llvm.dbg.value
with illegal fragment.