gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:00:21 28 4
gpt4 key购买 nike

我有一个在全局命名空间中定义的自定义类对象的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com