I have a MFC dialog application that occasionally will freeze on exit. I can set a breakpoint at CWinApp::ExitInstance and it will get there but on continuing will hang.
I don't seem to have the option in Visual Studio to break the program either, only "Stop Debugging".
The only thing special about the app is it does most of its work (file processing) in a separate thread while the UI just shows a progress bar.
It's been a while since I have done any C++ or MFC coding so am a bit rusty how to debug such a problem. So I am looking for some ideas how to debug this or what is most likely the cause?
Memory leak?
Thread deadlock?
Thread not exiting?
Related
I have a C++ application that suddenly stops working when I do a certain action (clicking at a button in gtk). I tried debugging it, creating Signal Handlers for SIGTERM, SIGABORT, SIGILL, etc to write a backtrace with the gcc functions, tried to attach a debugger, etc. Nothing. I just do not get any output from anything, the program just vanishes from the memory.
Are there any techniques I have not tried yet? I dont know how to debug this problem.
I forgot to mention: This happens on a Linux system (tried debian and ubuntu). Both with X11 (not wayland)
It could be:
A signal. By default, gdb stops on error signals, so no custom handler is needed.
exit() function and any other function from exit family (like _exit, _Exit , etc.). Use b exit to set a breakpoint.
Since it's c++, and exception could be thrown. Use catch throw to stop when an exception is thrown.
The last thread exit. b pthread_exit.
Thread cancellation. b pthread_cancel.
main function normally reached its end. Use disassembly to set a breakpoint on address.
If all of this doesn't help, attach to your application before the button is pressed, pause it with Ctrl+c in gdb. Then, press the button (while the window is unresponsive). A gtk application should normally dispatch the event from X11 queue even if it was paused. Do step by step assembly debugging with ni and si.
I'm debugging C++ program compiled with MSVC under Windows.
I want to investigate issue linked with multi threading. So I put ASSERT in my code and when program reaches ASSERT it displays window about ASSERT (Standart [Abort], [Retry], [Ignore] window) with proposal to pause program in debugger. I press [Retry] button and program pauses. BUT while I was pressing the button other threads continue to execute.
So the question is how to immediately stop the program when it reaches some point to see what other threads was doing at that time?
You might want to set a conditional breakpoint instead of using an assert:
In case you want to do it programmatically, use DebugBreak. (C# has an equivalent api System.Diagnostics.Debugger.Break)
In case you want to do it from ide, from the msdn page you can put a breakpoint (or break all the application, ctrl+alt+B) from visual studio and then control the thread execution using "freeze" and "thaw" in the thread window.
I have just got this problem for a few days. Before, I've always thought that letting the program exit by returning from main and clicking close the console window is the same way to end the program.
However, I've found that they are different. Since my program opens a camera which is an object. And closing the console windows does not destroy or clean up the object. So the next time I have error to open the camera again
I just need a confirm if this is true?
Then why only until now I can see the problem?
Closing a console window in Windows, kills the running program (or stack of running programs). Unless it has registered a handler for this event, it gets no chance to clean up. If you want solution, register a handler.
Hm, consulting the documentation, wait a few secs…
OK, look up SetConsoleCtrlHandler.
Closing a running console application will kill the process, not giving you the chance for any clean up code. I guess you could hook a windows message loop to trap the WM_CLOSE message and do proper cleanup, but at the end of the day, you just shouldn't kill the process.
I have an SDI in which there is a:
AfxGetMainWnd()->PostMessageW(WM_CLOSE);
in the OnInitialUpdate() in the *View class.
The application closes and a few seconds later a
"MFC Application has stopped working"
window appears with the option to
(a) Check online for a solution and close the program
(b) Close the program
(c) Debug the program
Can someone please tell me what I can do to get rid of this problem?
Get rid of the AfxGetMainWnd()->PostMessageW(WM_CLOSE). It's retarded.
Basically, it's closing the windows application immediately. It makes no sense to spin up an SDI MFC application that is going to do that. You might as well write a console application.
And yes, you need to learn how to use the debugger. I'm sure it is telling you exactly what is wrong.
I have a Qt program that is using the QtConcurrent API to spawn worker threads. The problem I am having is that the worker threads keep going even if I exit the Qt application.
I have an actionExit in my menu, which is what i am using to close the app, or the "X" in the window corner. Is there any way to make these kill off all threads related to this app?
Thanks
Are you sure that the UI application really closes? You might be missing:
qApp->setQuitOnLastWindowClosed(true);
Otherwise QT only hides your window. To debug put a breakpoint behind your
mainWindow->exec(); and see whether it is really reached.
If you confirm that exec() returns and QTConcurrent really hangs (it might be possible: http://lists.trolltech.com/qt-interest/2008-06/thread00414-0.html), then do:
exit(0);