我在名为 ExecState 的类中有一个 std::map 数据成员:
class ExecState { // ...
std::map<int,ref<Expr> > ab_size;
// ...
};
当我从 gdb 打印它时,我看到了预期值:
(gdb) print state.ab_size
$1 = std::map with 1 elements = {[1] = {ptr = 0x2a221d0}}
但是,当我尝试访问元素本身时,gdb 失败:
(gdb) print state.ab_size[1]
Attempt to take address of value not located in memory.
我在这里做错了什么?谢谢!
最佳答案
When I print it from gdb I see the expected values:
您看到这个是因为 magic of pretty-printers 。要查看变量的实际内容,请尝试print/r state.ab_size
。
However, when I try to access the element itself, gdb fails:
GDB 并没有失败,但是 pretty-print 还没有神奇到足以实现你的愿望。您必须使用实际数据元素来“找出”该值,而不是 pretty-print 创建的幻象(这很困难)。
关于c++ - Gdb 打印 std::map 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47765421/