简体   繁体   English

gdb:退出程序而不退出gdb

[英]gdb: exit program without exiting gdb

I am debugging a program using gdb. 我正在使用gdb调试程序。 First I load my executable, then I continue to run the program. 首先,我load我的可执行文件,然后continue运行该程序。 I sometimes want to interrupt execution of my program, so I do Ctrl + C . 我有时想要中断我的程序的执行,所以我做Ctrl + C

My problem is that this closes both my program and gdb. 我的问题是这关闭我的程序和gdb。 How can I exit my program without exiting gdb? 如何在不退出gdb的情况下退出程序?

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

Use ctrl-c to interrupt the application. 使用ctrl-c中断应用程序。 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. 然后从GDB提示符运行“signal SIGINT”,它会将此信号发送到您的应用程序,使其执行与从命令行执行ctrl-c时通常所做的相同的操作。

Looks like under Windows, you have to use Ctrl-Break not Ctrl-C . 看起来在Windows下,你必须使用Ctrl-Break而不是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. 调用SetConsoleMode以关闭“Ctrl-C”键击特殊含义的MS-Windows程序不能通过键入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. 因此,MS-Windows上的gdb支持C-作为备用中断键序列,即使它忽略了Cc,也可用于中断调试对象。

First run the program (not from inside gdb), then find its pid. 首先运行程序(不是从gdb内部),然后找到它的pid。

In another shell, run gdb --pid=<your program's pid> . 在另一个shell中,运行gdb --pid=<your program's pid> This attaches gdb to a running program. 这会将gdb附加到正在运行的程序中。 It stops the program's execution, so issue c to continue. 它会停止程序的执行,因此问题c继续。

Now quit your program, your gdb session will stay there. 现在退出你的程序,你的gdb会话将保持在那里。

Like Manlio said, what you want in this case is kill , which will prompt you with a message that reads: 就像Manlio说的那样,在这种情况下你想要的是kill ,它会提示你一条消息:

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. 如果键入help running您将看到执行常见操作时需要了解的所有重要命令,例如停止执行当前程序。 These should be all commands for the program you are running and not gdb. 这些应该是您正在运行的程序的所有命令,而不是gdb。

贝壳

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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