Can't debug inline functions? (VC++ 2019)

ET3D 1 Reputation point
2021-01-21T16:42:19.81+00:00

I thought of moving things to inline function to organise code without making it slower, but when running in debug that makes it impossible to break in that code or enter that function in any way.

That's true of even basic examples, like

`
inline void Function(int* a, int b, int c)
{
for (int i = 0; i < 100; i++)
c[i] = a[i] + b[i];
}

int main()
{
int a[100], b[100], c[100];
for (int i = 0; i < 100; i++)
a[i] = b[i] = 5;

Function(a, b, c);
}
`

(And what's the deal with the code showing here as one line?)

Microsoft Learn talk about the /Zo switch, how it's enabled by default, and that it allows debugging inlines, but that doesn't seem to be the case. (I tried setting it manually, it didn't help.)

Is this functionality available, and if not, can anything be done?

I tried this with the Visual Studio 2019 and 2017 (fully updated).

Developer technologies Visual Studio Debugging
Developer technologies C++
{count} votes

3 answers

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,426 Reputation points
    2021-01-22T06:02:21.947+00:00

    Hi ET3D,

    Please try to set "Remove unreferenced code and data" to "No" in Configuration Properties > C/C++ > Language 59454-image.png Best Regards, Dylan

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our * *documentation* to enable e-mail notifications if you want to receive the related email notification for this thread.**


  2. Maybecompletelyw_0 281 Reputation points
    2021-01-23T23:47:55.833+00:00

    Do not know your exact compiler/linker flags. But obviously debugger has some difficulties with your code sample Release / Inline and the generated symbols.
    Here is a picture of Windbg Preview - which has a more talkative Symbol Engine - trying to reach a breakpoint in Inline Function.
    Interesting the ambigous symbol and no locals. There seems to be some (flaky) line info available :
    59871-inlinewindbg.jpg


  3. Maybecompletelyw_0 281 Reputation points
    2021-01-25T01:13:16.673+00:00

    Here are some internals about debugging optimized code and inlining:
    https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugging-optimized-code-and-inline-functions-external
    Please bear in mind that "Windows debugger" refers to the debuggers of "Debugging Tools for Windows"(legacy windbg, cdb, kd) or "WinDbg Preview".

    VS debuggers used to support only a subset of dbgcmds - no joy with context-operator or "x" in VS 2015 in Immediate window.
    https://learn.microsoft.com/en-us/visualstudio/debugger/context-operator-cpp?view=vs-2019
    In VS would try to set breakpoint on source line
    Function(a, b, c);
    then change to Disassembly and "Step Into" (F11)
    or set bp in in Disassembly window (there 'Show Source Code' enabled).
    59837-inline.jpg

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.