Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminate program hitting CTRL+C within GDB

Tags:

mingw

gdb

My program is determined to stop its execution by hitting CTRL+C in command window. By now, I have a critical error right in this stopping phase, so i want to debug with gdb.

Problem is, gdb redefines CTRL+C as its own interrupt and pauses the execution when hitted. How can I handle it that CTRL+C powers my programm off and gdb can catch the stack trace?

like image 705
Benjamin Avatar asked Oct 17 '11 13:10

Benjamin


People also ask

How do I stop a program 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.

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

How do I restart GDB?

When you're doing a usual gdb session on an executable file on the same computer, you can give the run command and it will start the program over again.


1 Answers

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.

like image 108
Employed Russian Avatar answered Sep 17 '22 18:09

Employed Russian