Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB: Ctrl+C doesn't interrupt process as it usually does but rather terminates the program

Tags:

signals

gdb

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?

like image 564
Malvineous Avatar asked May 02 '11 12:05

Malvineous


People also ask

What does Ctrl C do in GDB?

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.

How do I stop a program from running in GDB?

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.

How do I send Sigint in GDB?

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.

Does GDB slow down?

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.)

How do I interrupt a GDB session?

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.

What is the break mechanism in gdb?

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.

What is GDB’s ‘All-Stop mode’?

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 ’.

How do I get back to the command prompt after GDB?

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.


2 Answers

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.

like image 144
Jared Robinson Avatar answered Oct 10 '22 02:10

Jared Robinson


In the gdb prompt you can do "handle SIGINT stop" so that gdb catches CTRL-C

like image 36
sunil Avatar answered Oct 10 '22 02:10

sunil