visual-studiodebuggingbreakpointspause

Does Visual Studio have "break where you are" functionality?


We have started encountering endless loops in our engine recently and I have no idea how to effectively fight them. The app simply freezes for eternity.

I am unable to stop it's execution to understand what is going on. Placing normal breakpoint in major places (update loop) does nothing. I am almost certain that the problem is in a continuously running loop somwhere, but due to the code's size I cannot even start guessing where to look for it.

So, my question is:
How do you break an app's execution in Visual Studio at some arbitrary place in the code where the app happens to be at that time?

Something akin to "break where you are".
Is it even theoretically possible?


Solution

  • Sure, use Debug + Break All.

    This of course doesn't necessarily break your program at a nice address that happens to match one of the statements in your program. Pretty likely if setting breakpoints didn't invoke a break. You are likely to see a notification from the debugger that it cannot display source code. Or for that matter, it might not have selected the correct thread.

    So first thing you want to do is use Debug + Windows + Threads and make sure that the correct thread is selected. Double-click the one you want to debug. Next thing you want to do is look at the Debug + WIndows + Call Stack window. It should at least display some of your methods, giving you a hint how it ended up in never-never land.

    And it isn't unlikely that it got deadlocked on native code or an operating system call. To see that, you'll need to enable unmanaged debugging. Project + Properties, Debugging, tick the "Enable native code debugging". And make sure you've got the symbol server enabled so you'll get debugging info for the operating system DLLs. Tools + Options, Debugging, Symbols.