aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2019-10-10 01:06:01 +0000
committerReid Kleckner <rnk@google.com>2019-10-10 01:06:01 +0000
commit9d8f0b3519c4e9e4e2a3d3b19ea0caf9ef3f85ce (patch)
treef671bdfb4eed447c69b00403a42b568d45ced981 /llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
parentf6777964bde28c349d3e289ea37ecf5f5eeedbc4 (diff)
downloadllvm-9d8f0b3519c4e9e4e2a3d3b19ea0caf9ef3f85ce.zip
llvm-9d8f0b3519c4e9e4e2a3d3b19ea0caf9ef3f85ce.tar.gz
llvm-9d8f0b3519c4e9e4e2a3d3b19ea0caf9ef3f85ce.tar.bz2
[codeview] Try to avoid emitting .cv_loc with line zero
Summary: Visual Studio doesn't like it while stepping. It kicks you out of the source view of the file being stepped through and tries to fall back to the disassembly view. Fixes PR43530 The fix is incomplete, because it's possible to have a basic block with no source locations at all. In this case, we don't emit a .cv_loc, but that will result in wrong stepping behavior in the debugger if the layout predecessor of the location-less BB has an unrelated source location. We could try harder to find a valid location that dominates or post-dominates the current BB, but in general it's a dataflow problem, and one still might not exist. I left a FIXME about this. As an alternative, we might want to consider having the middle-end check if its emitting codeview and get it to stop using line zero. Reviewers: akhuang Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68747 llvm-svn: 374267
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 616b136..012da94 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -2858,6 +2858,14 @@ void CodeViewDebug::endFunctionImpl(const MachineFunction *MF) {
CurFn = nullptr;
}
+// Usable locations are valid with non-zero line numbers. A line number of zero
+// corresponds to optimized code that doesn't have a distinct source location.
+// In this case, we try to use the previous or next source location depending on
+// the context.
+static bool isUsableDebugLoc(DebugLoc DL) {
+ return DL && DL.getLine() != 0;
+}
+
void CodeViewDebug::beginInstruction(const MachineInstr *MI) {
DebugHandlerBase::beginInstruction(MI);
@@ -2869,19 +2877,21 @@ void CodeViewDebug::beginInstruction(const MachineInstr *MI) {
// If the first instruction of a new MBB has no location, find the first
// instruction with a location and use that.
DebugLoc DL = MI->getDebugLoc();
- if (!DL && MI->getParent() != PrevInstBB) {
+ if (!isUsableDebugLoc(DL) && MI->getParent() != PrevInstBB) {
for (const auto &NextMI : *MI->getParent()) {
if (NextMI.isDebugInstr())
continue;
DL = NextMI.getDebugLoc();
- if (DL)
+ if (isUsableDebugLoc(DL))
break;
}
+ // FIXME: Handle the case where the BB has no valid locations. This would
+ // probably require doing a real dataflow analysis.
}
PrevInstBB = MI->getParent();
// If we still don't have a debug location, don't record a location.
- if (!DL)
+ if (!isUsableDebugLoc(DL))
return;
maybeRecordLocation(DL, Asm->MF);