c++ - 通过 gdb 查看 STL vector 的内容

标签 c++ stl gdb

我有一个在全局命名空间中定义的自定义类对象的 STL vector (是的,邪恶的,我知道)。 现在我想在 gdb 中设置一个观察点,以监视此 vector 的某个元素的(公共(public))成员变量中可能发生的变化。像这样的东西:

watch custom_namespace::vec[123].aVariable

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

最佳答案

看看这是否适用于您的情况(来自 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 <b>double-precision floating-point number</b> (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.


尝试将地址转换为 (int*) .它仍然是段错误吗?

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

关于c++ - 通过 gdb 查看 STL vector 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3256256/

相关文章:

c++ - 无法使 decltype 说明符在 lambda 函数内正常工作

c++ - 在 dll 边界上公开 std::vector - 编译器独立性的最佳实践

c++ - 访问另一个类包含的 std::vector

c - 使用gdb--仍然找不到malloc错误

gdb - mingw gdb 64 位构建

c++ - 我如何#include 一个名称由宏构建的文件?

c++ - 如何在图像中绘制一个矩形,只有当鼠标移动到opencv中的特定位置时才会显示?

c++ - 原始类型的 emplace_back 与 push_back

c++ - 是否有像管道一样工作的 C++ STL 类?

linux - 利用导致程序在 GDB 中以不同的值退出?