43

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?

2
  • 5
    That isn't supposed to happen; Ctrl-C is just supposed to interrupt (not terminate) your program, and it's definitely not supposed to terminate gdb. What environment are you using? Commented Mar 12, 2012 at 14:37
  • 2
    I'm using Cygwin. Weird. Commented Mar 12, 2012 at 14:39

5 Answers 5

44

Have you tried to use kill from inside gdb?

Sign up to request clarification or add additional context in comments.

3 Comments

Yes. But after continue I do not running to the gdb command prompt, so nothing happens.
How @trojanfoe said, Ctrl-C should just interrupt your program, so that you'll have again the gdb console. However, try to use start to start your program. The execution should stop at the beginning of main function. Then use kill to kill your program.
When I try start I get "No symbol table loaded. Use the "file" command."
20

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.

Comments

9

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.

3 Comments

Thanks. This still quits GDB. Now when it quits it writes "Quit (core dumped)"
@Randomblue Oh blimey - doesn't seem very happy does it. I don't know what to suggest, other than switching to Microsoft compilers perhaps (they are free with the Windows SDK).
@Randomblue do you run the stuff from cmd or sh console? Is the debugged program Cygwin or Win32 native? (for the record: is gdb Cygwin or Win32? ;) )
4

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.

1 Comment

My program is running on a remote host. (An ARM chip.)
4

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.