通过gdb观看stl向量的内容

发布于 2024-09-10 05:03:41 字数 237 浏览 1 评论 0原文

我有一个在全局命名空间中定义的自定义类对象的 stl 向量(是的,邪恶的,我知道)。 现在我想在 gdb 中设置一个观察点来监视该向量的某个元素的(公共)成员变量中可能发生的变化。类似于:

watch custom_namespace::vec[123].aVariable

如果我这样做,那么 gdb(Ubuntu Lucid 上的版本 7.1)会出现段错误。 有没有替代方法。这有可能吗?

I've got a stl vector of custom class objects defined in a global namespace (yeah, evil, I know).
Now I would like to set a watchpoint in gdb to monitor possible changes in a (public) member variable for a certain element of this vector. Something like:

watch custom_namespace::vec[123].aVariable

If I do this, then gdb (Version 7.1 on Ubuntu Lucid) segfaults.
Are there alternative ways. Is this possible at all?

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

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

发布评论

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

评论(1

你怎么敢 2024-09-17 05:03:41

看看这是否适用于您的情况(来自 gdb 手册) :

有时,gdb 无法设置硬件观察点,因为监视表达式的数据类型比目标计算机上的硬件观察点可以处理的数据类型更宽。例如,某些系统只能监视最大 4 字节宽的区域;在此类系统上,您无法为生成双精度浮点数(通常为 8 字节宽)的表达式设置硬件观察点。作为一种解决方法,可以将大区域分成一系列较小的区域,并使用单独的观察点来观察它们。

尝试将地址转换为 (int*)。仍然存在段错误吗?

另外,如果 STL vector 需要扩展内部缓冲区,它也会移动其内容,因此您的对象可能只是从观察点下“被盗”。

See if this applies to your case (from gdb manual):

Sometimes, gdb cannot set a hardware watchpoint because the data type of the watched expression is wider than what a hardware watchpoint on the target machine can handle. For example, some systems can only watch regions that are up to 4 bytes wide; on such systems you cannot set hardware watchpoints for an expression that yields a double-precision floating-point number (which is typically 8 bytes wide). As a work-around, it might be possible to break the large region into a series of smaller ones and watch them with separate watchpoints.

Try casting the address to (int*). Does it still segfault?

Also STL vector will move its content if it needs to extend the internal buffer, so your object might just be "stolen" from under the watchpoint.

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