Randomblue
Randomblue

Reputation: 116383

gdb: exit program without exiting 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?

Upvotes: 43

Views: 44537

Answers (5)

dko
dko

Reputation: 361

Like Manlio said, what you want in this case is kill, which will prompt you with a message that reads:

Kill the program being debugged? (y or n)

If you type help running you will see all the important commands you will need to know to do common things, such as stopping the execution of a current program. These should be all commands for the program you are running and not gdb.

shell

Upvotes: 4

trojanfoe
trojanfoe

Reputation: 122449

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.

Upvotes: 9

David Martens
David Martens

Reputation: 201

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.

Upvotes: 20

Manlio
Manlio

Reputation: 10864

Have you tried to use kill from inside gdb?

Upvotes: 44

swingbit
swingbit

Reputation: 2745

First run the program (not from inside gdb), then find its pid.

In another shell, run gdb --pid=<your program's pid>. This attaches gdb to a running program. It stops the program's execution, so issue c to continue.

Now quit your program, your gdb session will stay there.

Upvotes: 4

Related Questions