Break point in release mode

前端 未结 4 1425
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-04 12:18

I am using (C++) Visual Studio 2010.

I have to trace the control flow of my Application. To do so, I have put a break point in the source code.

While running

相关标签:
4条回答
  • 2021-01-04 12:27

    In release mode your code is optimized and that can change the flow of your program. For example, if a function is simple and only called once, the compiler can inline the function in release mode.

    Debug mode doesn't have these kind of optimization and is designed for debugging your code.

    0 讨论(0)
  • 2021-01-04 12:36

    Release mode breakpoints are handy to get working. The simplest way to get it working is to make a call to a function called release_mode_breakpoint() in your code. Then define that function like this:

    #pragma optimize("", off)
    void release_mode_breakpoint()
    {
        int put_breakpoint_here = 1;
    }
    #pragma optimize("", on)
    

    You can then put a breakpoint on that int declaration line, and it'll be hit, even in release mode. Then just step up the stack in the debugger back to the function you actually wanted a breakpoint in.

    Don't actually leave that code in your final production release though, as the unoptimized line may prevent the compiler from optimizing the calling code properly.

    0 讨论(0)
  • 2021-01-04 12:42

    I'm using VS2015. after lots of failed solutions I found one that worked for me. Just uncheck "Enable Just My Code" under Menu->Debug->Options->Debugging->General. See attached image: enable debug in release mode-VS2015

    I really hope this will solve the problem to you :)

    0 讨论(0)
  • 2021-01-04 12:46

    You can use the __debugbreak() intrinisic. This is also very handy if you want to break on a specific condition. For example:

    if (var > LIMIT)
      __debugbreak();
    
    0 讨论(0)
提交回复
热议问题