In java debugging a hung application is easy. You can take the memory dump of the application and use and use eclipse jvm dump analyser to see the status of the threads and where each threads were blocked?
Does something like this exists for C++?
In java debugging a hung application is easy. You can take the memory dump of the application and use and use eclipse jvm dump analyser to see the status of the threads and where each threads were blocked?
Does something like this exists for C++?
I have not done this, but I think you can use gdb to generate core of your application at the moment it is hung.
You can try debugging this core using the gdb itself and see for yourself what threads are blocked where?
The above is possible in linux platforms. Not sure, if cygwin on windows can be used for the same purpose.
Of course, strategically placed cout
statements (or other output alternatives) are always an option but often far from ideal.
If compiling with g++, compile with -g
and use gdb. You can attach to a running process (and the source code) or simply run the program in the debugger to start with. Then look at the stack.
In Windows, just pause execution of your program and look at the stack.
You can do the exact same thing with C++; force a core dump and look into it after.
Or, if you're using MSVC, you can simply attach the debugger to the application while it's running. Hit "break all" and poke around through the threads.
The magic invocation in gdb is:
thread all apply bt
That runs the bt (backtrace) command for all threads. Unless you have completely stripped your program, you should be able to see the names of each function.
This works both for live and post-mortem (i.e. running gdb against a core) debugging.