C++ single step in debugger throws an exception - c++

I have a C++ app that will throw an exception when I try to single step from a breakpoint. For example:
1) Start app from VS2010 0 debugger is attached.
2) Set a breakpoint. It doesn't seem to matter where.
3) Do something in the app so that it hits the break point.
** VS2010 hits the break point
4) Single step the debugger to the next line of code.
VS2010 pops up a message box with this exception:
"Unhandled exception at 0x087df66f in SimpleGraphSDI.exe: 0xC0000005: Access violation."
Note that if I set a breakpoint on two consecutive lines of code, and press run to advance from one line to another, the app "runs" to the next line of code with no issues. The access violation is only when I use the single step command from VS2010.
Some code in the app has been around since VC6 and maybe earlier. However do not know if this is relevant.
UPDATE: The exception when single stepping the debugger does not occur if I start the app, and then attach the debugger after the app has started.

I had this exact same issue. I was able to solve it by starting VS from the command line telling it to reset the UI to default (/ResetSettings) Details on the command line arguments are here
I did not need to reboot after resetting VS, but I did a full rebuild of the project after completing the reset of the environment.

A work around for this problem is to disable RPC debugging.
In the Visual Studio 2010, Visual Studio 2010 SP1 toolbar select below steps -
Tools->Options->Debugging->Native and deselect "Enable RPC debugging"

There maybe exist a thread that somehow detects that the code is being debugged step by step and pagefaults in response to prevent you from debugging. Try to locate that thread by suspending threads one by one.
Also, is address 0x087df66f always the same? If it is then you can set a breakpoint there and look around when the breakpoint is hit.

Related

Is it possible to continue debugging past an unhandled exception in Visual Studio?

A variety of other questions hint that it is possible to continue debugging past an "Exception Unhandled" popup like this:
This is the popup from Visual Studio 2019, but VS 2015 gives similar behaviour. In both cases, for all combos of Win32/x64 and Debug/Release I have tried, the debugger refuses to go past the point that throws the unhandled exception - the same popup pops up again on each attempt to continue. I would like to push past this point and continue into the code I have set up via SetUnhandledExceptionFilter(). Is that possible?
This strongly upvoted answer suggests that it might be, via an option under Tools -> Options then Debugging -> General regarding unwinding the stack... but a comment on the answer suggests the option may have disappeared from VS2017. I found the option in VS 2015, but it does not have the desired effect. Is the accepted answer to that question therefore correct despite fewer votes - that continuing to debug past an unhandled exception is not possible by design?
Yes - it's possible. If you get to that pop up repeatedly, and the exception settings are such that the exception is NOT intercepted by the debugger (and therefore passed to the application's own exception handling), then it could be that your "unhandled" exception handling has already run, or does not exist in the form you think it does. Double-check where you have set breakpoints and make sure they are ones that stand to be hit.
Note also that if you have something like this to catch SEH exceptions (such as integer divide by zero):
__try
{
// set up and run the application
}
__except( RecordUnhandledException( GetExceptionInfo() ) )
{
}
... then the debugger can hide RecordUnhandledException() from you. That is, if you set a breakpoint on the line where the exception is (deliberately) thrown, and try to step into it, the debugger may step straight back to that point by executing the handling code in a single step that makes it invisible to you. However, if it produces other output, you should be able to see that output. If not, it may take an explicit breakpoint within RecordUnhandledException() to reveal that it exists and step through its logic.

CLion LLDB doesn't break on uncaught exception

I making a WinAPI DLL using CLion and debugging via LLDB debugger (inside CLion). So breakpoints work fine, however, if there's uncaught exception in my DLL target process crashes and debugger doesn't break when it does. But if there's exception in the target process, debugger breaks fine. Is there any workaround?
Did you enable breaking on exception in Run menu - View breakpoints window?
this happens to me often and almost always the culpret is that the section marked Disable until hitting the following breakpoint: is set to Any Exception. simply change that value to None and the debugger will break when an exception is thrown.
i have no idea how or why this setting is changing itself to that value but, whenever it does, exception breakpoints stop working.

Step over JNI_CreateJavaVM crashes program under debug in VS2017

I am currently working on moving our multi-threaded server app fom VS2013 to VS2017. The port was straightforward enough however i have encountered a weird issue with our use of JNI.
We load the jvm.dll dynamically and then do a GetProcAddress for JNI_CreateJavaVM; this code has worked robustly in VS2013 however in VS2017 i am unable to step over the call to the create JVM function without it reporting a null ptr exception.
Whats wierd is that if i then hit continue to the next break point i find my call to create JVM has succeed and i can then go on to call JNI function to create classes etc.
Anyone got a remedy for this - is it a known issue ?
In VS2017 goto
Exception Settings - (Ctrl + Alt + E)
and in Win32 exceptions tick 0xc0000005 Access violation.
JVM generates the mentioned exception when it startups to check OS features. So you can ignore it and move forward.

Break in Visual Studio on process exit

I'm having some difficulties determining what is causing a process to exit. I have a breakpoint in some shutdown code that I'm debugging, but, after breaking in the debugger at the breakpoint and stepping once, the whole process exits immediately. Every thread reports an exit code of -1 in the output window. There are a large number of threads in the process at that time, and the code base is quite large, making searching for the culprit difficult.
I've tried installing a std::atexit function, but this doesn't get hit. I've also tried overriding SetUnhandledExceptionFilter, in case it is caused by a crash, and it also doesn't get hit. The project has exceptions disabled (#define _HAS_EXCEPTIONS=0), so I cannot call std::set_terminate or std::set_unexpected.
Is there some other way to determine what is causing the process to exit? Some option to break in the debugger when the process is about to terminate?
Run your app with debugger and read the debug output. If the app terminates because C++ exceptions, or SEH, you’ll read it in the output window.
If you’ll see nothing interesting there, it means your app called ExitProcess/ExitThread/exit, or worse, TerminateProcess/TerminateThread/_exit.
You can put breakpoints on these. Set a breakpoint at startup, launch debugger. Ensure you have debug symbols loaded for relevant DLLs, kernel32.dll for ExitProcess and friends, some other DLL for exit, e.g. ucrtbase.dll. Press “New / Function breakpoint” in the Breakpoints window, type e.g. “ExitProcess”, press OK.
You can also try using gflags tool from Windows SDK.
If you’ll find (by reading Windows Logs > Application) the reason was self exit, you can check “Enable dump collection” in gflags, then you’ll be able to load the dump in WinDBG and get the complete call stack telling you who called what.
Unfortunately, the latest version of the tool is broken beyond repair.
But you can install older Windows SDK. You only need “Debugging tools for Windows” from there, no need to install the complete SDK.

How to dump the whole procees, raise it and start debugging?

I have an application, which is running for a long time and then crash. I need to debug it several times to fix it and don't want to wait every time for an hour to reach the state, in which an error is occurred.
So, I want some tool to clone the whole process on a disk, then raise it, attach to it and debug.
I use Visual Studio 2012/2013 on (surprise) Windows.
For example:
for (int i = 0; i < 10000; ++i)
{
if (i == 9999)
throw MyExcept();
}
And I want to have a saved state of application (process) at 9998-th iteration to start debugging from it.
UPD 1: Visual Studio dump files are not admirable, because I can't get all functionality of debugger after opening it it VS. For example: I can't set breakpoints and even old ones don't work.
UPD 2: Also I need to have a possibility of duplicating this saves session of the app.
If I understood correctly, you want to accomplish two tasks:
1) Break the execution on a specific condition
You need to set a watchpoint with a condition to achieve this, or Data Breakpoint in Visual Studio terms. Have a look at this question: Can I set a breakpoint when variable is getting a specific value in .NET?
2) Dump a core file
Once you have set the watchpoint and your program reached that point, you can dump a core file. From that you can continue with the execution later on. There is an official FAQ entry entry on how to dump and load cores.
You need procdump from here
Register as the Just-in-Time (AeDebug) debugger.
Perhaps you should enable full local dumps.
Crash you program
Launch a process with procdump from full dump
But I think it is better to use DebugBreak API in your example without a crash.
Usually crash will not allow you to start further - only postmortem analysis.