gdb:如何在循环执行期间暂停?
我正在 Windows 7 中的 mingw32 下用 g++ 编写一个软件渲染器,使用 NetBeans 7 作为我的 IDE。
我最近一直需要对其进行概要分析,既然我已经完成了结构的制定,这种需求已经达到了临界点。我环顾四周,对我来说这个答案显示了同时跨平台和保持简单的最大希望。
该方法的要点是,可能最基本(并且在许多方面,最准确)的分析/优化方法是通过停止执行来时不时地直接对堆栈进行采样...不幸的是,NetBeans 赢了不要暂停。所以我试图找出如何直接使用 gdb 进行采样。
我对gdb了解不多。不过,我从手册页可以看出,您在运行可执行文件之前设置了断点。那对我没有帮助。
有谁知道让 gdb (或其他 gnu 工具)执行以下任一操作的简单方法:
- 当我这么说时对堆栈进行采样(首选)
- 在给定时间段内以随机间隔获取一大堆样本
。 ..给出我所说的配置?
I'm writing a software renderer in g++ under mingw32 in Windows 7, using NetBeans 7 as my 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 answer shows 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't pause. So I'm trying to find out how to do this sampling with gdb directly.
I don't know a great deal about gdb. What I can tell from the man pages though, is that you set breakpoints before running your executable. That doesn't help me.
Does anyone know of a simple approach to getting gdb (or other gnu tools) to either:
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过在 gdb 中简单地运行可执行文件,然后在想要中断它时只需按 ^C (Ctrl+C) ?这应该会让您进入 gdb 的提示符,您可以在其中简单地运行
where
命令来查看您所在的位置,然后使用continue
继续执行。如果您发现自己处于不相关的线程(例如循环 UI 线程)中,请使用
thread
、infothreads
和threadn
转到正确的线程一,然后执行where
。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 withcontinue
.If you find yourself in a irrelevant thread (e.g. a looping UI thread), use
thread
,info threads
andthread n
to go to the correct one, then executewhere
.