[llvm-bugs] [Bug 34312] New: Clang's source locations are too detailed for Visual Studio, breaking "step into specific"

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 24 09:02:32 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=34312

            Bug ID: 34312
           Summary: Clang's source locations are too detailed for Visual
                    Studio, breaking "step into specific"
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: llvm-bugs at lists.llvm.org
            Blocks: 28154

Discovered by a Chromium developer: http://crbug.com/756175

The summary is that MSVC emits statement line information, not expression line
information. Consider this example:

/*  1 */ int g(int a, int b, int c, int d, int e, int f) {
/*  2 */   return a + b + c + d + e + f;
/*  3 */ }
/*  4 */ int x() { return 1; }
/*  5 */ int main() {
/*  6 */   return g(
/*  7 */       x(),
/*  8 */       x(),
/*  9 */       x(),
/* 10 */       x(),
/* 11 */       x(),
/* 12 */       x()
/* 13 */       );
/* 14 */ }


When compiled by clang (clang-cl -Z7 step.c), MS debuggers step through this
program by stopping at line 5, 12, 11, 10, 9, 8, 7, 6, and 14. When compiled
with MSVC, windbg and VS will stop on lines 5, 6, and 14.

In fact, you cannot break on lines 7-12 when debugging an MSVC binary. It will
only stop at the beginning of the statement. Perhaps to work around that
limitation, VS has a feature called "step into specific"
(https://msdn.microsoft.com/en-us/library/7ad07721(v=vs.100).aspx): 

"""
To step into a specific function

1. Advance the execution point to the function call you want to step into. You
might use a breakpoint, Step Into, Step Over, or Run To Cursor.

2. Right-click the source window.

3. Click Step Into Specific and choose the function you want.
The debugger executes the function call and breaks at the beginning of the
selected function. The Step Into Specific command appears only if the execution
point is located on a line of code that contains a nested function.
"""

This feature only works when the function call you want to step into is within
the same line table entry, so all expressions within the same statement must
have the same location information in order for it to work.

The downside of implementing this is that it will reduce the accuracy of line
info in stack traces. Clang's line tables in my example will be able to
distinguish which call to x is on the stack, while MSVC's will not. We already
have -gcolumn-info, which essentially improves stack trace quality at the cost
of more confusing stepping behavior in the debugger, so I think we should make
this new behavior conditional on -gcodeview && !-gcolumn-info.

I suspect we can add the check to disable location information inside
`ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E)`, and then we can
modify CGStmt.cpp to apply debug locations when emitting statements.


Referenced Bugs:

https://bugs.llvm.org/show_bug.cgi?id=28154
[Bug 28154] [meta] Add support for CodeView, the MSVC-compatible debug
information format
-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170824/8d70a670/attachment.html>


More information about the llvm-bugs mailing list