通过gdb观看stl向量的内容

时间:2010-07-15 14:02:27

标签: c++ stl gdb

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

watch custom_namespace::vec[123].aVariable

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

1 个答案:

答案 0 :(得分:2)

看看这是否适用于您的情况(来自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.


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

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