C++ gdb:如何在循环执行期间暂停?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8702658/
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
gdb: How do I pause during loop execution?
提问by Engineer
I'm writing a software renderer in g++ under mingw32 in Windows 7, using NetBeans 7 as my IDE.
我正在 Windows 7 中的 mingw32 下用 g++ 编写软件渲染器,使用 NetBeans 7 作为我的 IDE。
I've been needing to profile it of late, and this need has reached critical mass now that I'm past laying down the structure. I looked around, and to me this answershows the most promise in being simultaneously cross-platform and keeping things simple.
我最近一直需要对它进行概要分析,现在我已经完成了结构的铺设,这种需求已经达到了临界点。我环顾四周,对我来说,这个答案显示了同时跨平台和保持简单的最大希望。
The gist of that approach is that possibly the most basic (and in many ways, the most accurate) way to profile/optimise is to simply sample the stack directly every now and then by halting execution... Unfortunately, NetBeans won'tpause. So I'm trying to find out how to do this sampling with gdb directly.
该方法的要点可能是,配置/优化的最基本(在许多方面也是最准确的)方法是不时通过暂停执行来简单地直接对堆栈进行采样......不幸的是,NetBeans不会暂停. 所以我试图找出如何直接使用 gdb 进行采样。
I don't know a great deal about gdb. What I can tell from the man pages though, is that you set breakpoints beforerunning your executable. That doesn't help me.
我对gdb了解不多。不过,我从手册页中可以看出,您在运行可执行文件之前设置了断点。那对我没有帮助。
Does anyone know of a simple approach to getting gdb (or other gnu tools) to either:
有谁知道让 gdb(或其他 gnu 工具)达到以下任一目的的简单方法:
- Sample the stack when I say so(preferable)
- Take a whole bunch of samples at random intervals over a given period
- 当我这么说时对堆栈进行采样(最好)
- 在给定时间段内以随机间隔采集一大堆样本
...give my stated configuration?
...给我陈述的配置?
回答by unwind
Have you tried simply running your executable in gdb, and then just hitting ^C (Ctrl+C) when you want to interrupt it? That should drop you to gdb's prompt, where you can simply run the where
command to see where you are, and then carry on execution with continue
.
你有没有试过简单地在 gdb 中运行你的可执行文件,然后Ctrl+C在你想中断它时点击 ^C ( ) ?这应该会让您进入 gdb 的提示符,您可以在其中简单地运行where
命令以查看您所在的位置,然后使用continue
.
If you find yourself in a irrelevant thread (e.g. a looping UI thread), use thread
, info threads
and thread n
to go to the correct one, then execute where
.
如果你在一个不相关的线程(如循环UI线程)发现自己使用thread
,info threads
并thread n
去正确的,然后执行where
。