Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 299
MuertoExcobito Avatar asked Sep 14 '17 13:09

MuertoExcobito


People also ask

What is F11 in Visual Studio?

Step into codeTo stop on each statement when you're debugging, use Debug > Step Into, or select F11. The debugger steps through code statements, not physical lines. For example, an if clause can be written on one line: C#

What is break mode in Visual Studio?

Break mode in VBA is used for debugging and fixing errors. If we need to continue with execution, we should either click on the play button or press F5 or F8. Or we should just end the program's execution and start a fresh run of the code.


1 Answers

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.

like image 98
Soonts Avatar answered Sep 30 '22 00:09

Soonts