Skip to content

[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

Merged
merged 1 commit into from
Aug 20, 2021

Conversation

mshockwave
Copy link
Contributor

@mshockwave mshockwave commented Aug 18, 2021

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.

@mshockwave
Copy link
Contributor Author

@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())
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.
@mshockwave mshockwave force-pushed the dev-dbg-var-artificial branch from 7b2b13e to da5ef90 Compare August 19, 2021 20:23
@mshockwave
Copy link
Contributor Author

@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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works!

@mshockwave
Copy link
Contributor Author

@swift-ci please test

@mshockwave
Copy link
Contributor Author

@swift-ci test windows

@mshockwave mshockwave merged commit 4361da6 into swiftlang:main Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants