简体   繁体   中英

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?

你有没有试过在gdb里面使用kill

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.

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

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.

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.

贝壳

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM