c++debugginggdb

How to find where an application freezes?


I have a large C++ application that reproducibly freezes at a certain point. It does not crash, no segfault. I have access to the source code, but I'm not the author. Thus I can't make an educated guess about what is going on.

I tried to use gdb to debug it. The problem is however, that when I hit a breakpoint, the application freezes. When I'm stepping through, the application also appears frozen. Thus I can't really distinguish, whether or not I have found a problem, or if the application simply appears frozen because execution is paused in the debugger.

I fear that my best bet would be to go back to good old cout debugging. Are there any other options?


Solution

  • Possible it is "frozen" because you have called a function that is waiting for input. If you step-over such a function, the debugger will not halt until the function returns (by providing the requisite input perhaps).

    Alternatively you have stepped over a non-returning function because the function itself is incorrect or was provided incorrect parameters.

    Either way, the appropriate strategy is to run the program until it appears to be "frozen", then halt the program to determine where it is stuck. Likely this is in some library code with no source code available. In that case you should inspect the call stack to determine how it got to where it is, and in particular traceback to the call that was recognisably your code.

    In gdb ctrl+c will halt the running process. The where command will output the call stack.