C语言 我如何停止 GDB 中的继续

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3483163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:11:14  来源:igfitidea点击:

How do I halt the continuing in GDB

cgdb

提问by Jas

I'm pretty much using GDB for the first time. I run

我几乎是第一次使用 GDB。我跑

$ gdb

then I'm running

然后我跑

attach <mypid>

then I see that my process is stuck (which is probably ok). Now I want it to continue running, so I run

然后我看到我的进程卡住了(这可能没问题)。现在我想让它继续运行,所以我运行

continue

and my process continues running but from here I'm stuck if I want again to watch my current stack trace etc. I couldn't get out of continuing... I tried Ctrl-Detc. but nothing worked for me... (was just a guess).

我的过程中继续运行,但在这里我坚持,如果我想再次观看我目前的堆栈跟踪等我找不到继续的了...我想Ctrl-D等,但没有什么工作对我来说...(为只是猜测)。

采纳答案by Lopje

You should interrupt the process that is attached by gdb. Do not interrupt gdb itself. Interrupt the process by either ctrl-c in the terminal in which the process was started or send the process the SIGINT by kill -2 procid. With procid the id of the process being attached.

您应该中断由 gdb 附加的进程。不要中断 gdb 本身。在启动进程的终端中通过 ctrl-c 中断进程,或者通过 kill -2 procid 向进程发送 SIGINT。使用 procid 附加进程的 ID。

回答by Tyler McHenry

Control+C in the gdb process should bring you back to the command prompt.

gdb 进程中的 Control+C 应该会将您带回命令提示符。

回答by Nikolai Fetissov

Here's a short GDB tutorial, and here's a full GDB manual.

这里有一个简短的GDB 教程,这里有一个完整的 GDB 手册

The point of debugging is to inspect interesting/suspicious parts of the program. Breakpointsallow you to stop execution at some source location, and watchpointsallow you to stop when interesting data changes.

调试的目的是检查程序中有趣/可疑的部分。断点允许您在某个源位置停止执行,而观察点允许您在感兴趣的数据更改时停止。

Simple examples:

简单的例子:

(gdb) break my_function
(gdb) cont

This will insert a breakpoint at the beginning of my_function, so when execution of the program enters the function the program will be suspended and you get GDB prompt back, and be able to inspect program's state. Or you can stepthrough the code.

这会在开头插入一个断点my_function,所以当程序执行进入函数时,程序将被挂起并返回 GDB 提示,并可以检查程序的状态。或者您可以单执行代码。

(gdb) watch my_var
(gdb) cont

Same, but now the program will be stopped at whatever location that modifies the value of my_var.

相同,但现在程序将在修改 值的任何位置停止my_var

Shameless plug - here's a link to my GDB presentationat NYC BSD User Group. Hope this helps.

无耻的插件 - 这是我在纽约 BSD 用户组的GDB 演示的链接。希望这可以帮助。