How to quit an application running in gdb gracefully when the application isn't reponding.

8,160

You can use signals for this. Before you start your program, set up USR1 or USR2 to break gdb without affecting the program:

handle SIGUSR1 nopass

Then you can run your program, and when you need to stop it, run kill -USR1 from another shell with the appropriate (child) pid. gdb will pause the application, and you can then add breakpoints, examine state etc., and if you want to, continue the execution with cont.

Share:
8,160

Related videos on Youtube

shirish
Author by

shirish

A GNU/Linux and Debian user. Debian user for more than 5 years and yet still feel like a kid who has just started using the system yesterday.

Updated on September 18, 2022

Comments

  • shirish
    shirish over 1 year

    This is somewhat related to gdb set overwrite logging on should overwrite gdb.txt correct? .

    Let's say I'm running a session of some application. For example purposes, let me take the example of qbittorrent again.

    As shared before this is how a run happens -

    $ gdb qbittorrent 
    (gdb) set logging overwrite on 
    (gdb) set logging on 
    (gdb) set pagination 0
    (gdb) run
    

    one way I know is exiting the application gracefully but sometimes the application hangs/takes too much time or simply doesn't respond.

    Then the only option which remains with me is using CTRL+C which if I understand correctly kills the underlying application, in our example qbittorrent and then am able to quit gdb by means of

    (gdb) quit
    

    Is/would there be any other way of quitting the application and still let the gdb session keep running or the only way is the crude way I mentioned above.

    AFAI know killing an application process should be the last solution and not the first.

    • Ferenc Wágner
      Ferenc Wágner over 6 years
      When running under gdb under default settings, Ctrl-C does not kill the application, just breaks into the debugger, where you can decide what to do. Use cont to "swallow" the signal, and the application continues undisturbed. Or use signal 2 to pass the SIGINT (2) to the application. Or use kill to kill the application.