Normally when you run a program through GDB you can press Ctrl+C to interrupt it, e.g. if it gets stuck in an infinite loop and you want to get a backtrace.
I'm debugging a program (xmms2d as it happens) but in this program only, when I press Ctrl+C it gets treated as if GDB was not running - the program shuts down cleanly and then GDB tells me the program exited normally.
How do I get the usual GDB behaviour back, where Ctrl+C interrupts the program? Or is there another way to produce the same reaction in GDB as a Ctrl+C normally does?
Normally when you run a program through GDB you can press Ctrl+C to interrupt it, e.g. if it gets stuck in an infinite loop and you want to get a backtrace.
To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program. To specify other places where gdb should stop, see the section on breakpoints below.
From the (gdb) prompt, type signal SIGINT . This will send (surprize) SIGINT to the program being debugged. Alternatively, handle SIGINT nostop print pass will make GDB pass the signal straight to the inferior (being debugged) process. Ctrl-Z works in GDB: it suspends the process and gets you to that (gdb) prompt.
GDB does software watchpointing by single-stepping your program and testing the variable's value each time, which is hundreds of times slower than normal execution. (But this may still be worth it, to catch errors where you have no clue what part of your program is the culprit.)
You should interrupt the process that is attached by gdb. Do not interrupt gdb itself. Interrupt the process by either ctrl-c in the terminal in which the process was started or send the process the SIGINT by kill -2 procid. With procid the id of the process being attached.
GDB does not currently define a BREAK mechanism for any of the network interfaces except for TCP, in which case GDB sends the telnet BREAK sequence. ‘ Ctrl-C ’, on the other hand, is defined and implemented for all transport mechanisms.
Next: Notification Packets, Previous: Host I/O Packets, Up: Remote Protocol [ Contents ] [ Index] In all-stop mode, when a program on the remote target is running, GDB may attempt to interrupt it by sending a ‘ Ctrl-C ’, BREAK or a BREAK followed by g, control of which is specified via GDB ’s ‘ interrupt-sequence ’.
Control+C in the gdb process should bring you back to the command prompt. Show activity on this post. Here's a short GDB tutorial, and here's a full GDB manual.
I'll bet that xmms2d is using sigwait() to handle signals, which breaks gdb's ability to catch CTRL-C. See https://bugzilla.kernel.org/show_bug.cgi?id=9039
I got an idea for a workaround by reading Continue to debug after failed assertion on Linux? -- when I'm ready to break in gdb, I run "kill -TRAP <pid>" from another terminal window.
In the gdb prompt you can do "handle SIGINT stop" so that gdb catches CTRL-C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With