gdb:如何在循环执行期间暂停?

发布于 2024-12-24 02:50:36 字数 584 浏览 4 评论 0原文

我正在 Windows 7 中的 mingw32 下用 g++ 编写一个软件渲染器,使用 NetBeans 7 作为我的 IDE。

我最近一直需要对其进行概要分析,既然我已经完成了结构的制定,这种需求已经达到了临界点。我环顾四周,对我来说这个答案显示了同时跨平台和保持简单的最大希望。

该方法的要点是,可能最基本(并且在许多方面,最准确)的分析/优化方法是通过停止执行来时不时地直接对堆栈进行采样...不幸的是,NetBeans 赢了不要暂停。所以我试图找出如何直接使用 gdb 进行采样。

我对gdb了解不多。不过,我从手册页可以看出,您在运行可执行文件之前设置了断点。那对我没有帮助。

有谁知道让 gdb (或其他 gnu 工具)执行以下任一操作的简单方法:

  1. 当我这么说时对堆栈进行采样(首选)
  2. 在给定时间段内以随机间隔获取一大堆样本

。 ..给出我所说的配置?

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:

  1. Sample the stack when I say so (preferable)
  2. Take a whole bunch of samples at random intervals over a given period

...give my stated configuration?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷…雨湿花 2024-12-31 02:50:37

您是否尝试过在 gdb 中简单地运行可执行文件,然后在想要中断它时只需按 ^C (Ctrl+C) ?这应该会让您进入 gdb 的提示符,您可以在其中简单地运行 where 命令来查看您所在的位置,然后使用 continue 继续执行。

如果您发现自己处于不相关的线程(例如循环 UI 线程)中,请使用 threadinfothreadsthreadn 转到正确的线程一,然后执行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 with 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文