Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb: exit program without exiting gdb

Tags:

c

gdb

I am debugging a program using gdb. First I load my executable, then I continue to run the program. I sometimes want to interrupt execution of my program, so I do Ctrl + C.

My problem is that this closes both my program and gdb. How can I exit my program without exiting gdb?

like image 651
Randomblue Avatar asked Mar 12 '12 14:03

Randomblue


People also ask

How do I close a running 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 command do you use to quit the debugging environment?

The QUIT command ends a z/OS® Debugger session and, if an expression is specified, sets the return code. In full-screen mode, it also displays a prompt panel that asks if you really want to quit the debug session. In line, batch, and remote debug mode, the QUIT command ends the session without prompting.

How do you stop an infinite loop in GDB?

Like you can cancel a program on the command line, GDB lets you use ctrl-c to stop a program wherever it currently is. Hit ctrl-c now to break the infinite loop.

What is batch mode in GDB?

According to GDB documentation : Batch mode disables pagination, sets unlimited terminal width and height see Screen Size, and acts as if set confirm off were in effect (see Messages/Warnings).


3 Answers

Have you tried to use kill from inside gdb?

like image 130
Manlio Avatar answered Oct 23 '22 13:10

Manlio


Use ctrl-c to interrupt the application. Then run "signal SIGINT" from the GDB prompt, which will send this signal to your application, causing it to do the same things it would normally have done when you do ctrl-c from the command line.

like image 25
David Martens Avatar answered Oct 23 '22 13:10

David Martens


Looks like under Windows, you have to use Ctrl-Break not Ctrl-C. See this page.

Excerpt:

MS-Windows programs that call SetConsoleMode to switch off the special meaning of the `Ctrl-C' keystroke cannot be interrupted by typing C-c. For this reason, gdb on MS-Windows supports C- as an alternative interrupt key sequence, which can be used to interrupt the debuggee even if it ignores C-c.

like image 21
trojanfoe Avatar answered Oct 23 '22 13:10

trojanfoe