[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
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user