简体   繁体   English

GDB打印std :: map元素

[英]Gdb printing std::map elements

I have a std::map data member inside a class called ExecState: 我在一个名为ExecState的类中有一个std :: map数据成员:

class ExecState { // ...
std::map<int,ref<Expr> > ab_size;
// ...
};

When I print it from gdb I see the expected values: 当我从gdb打印它时,我看到了预期的值:

(gdb) print state.ab_size
$1 = std::map with 1 elements = {[1] = {ptr = 0x2a221d0}}

However, when I try to access the element itself, gdb fails: 但是,当我尝试访问元素本身时,gdb失败:

(gdb) print state.ab_size[1]
Attempt to take address of value not located in memory.

What am I doing wrong here? 我在这里做错了什么? thanks! 谢谢!

When I print it from gdb I see the expected values: 当我从gdb打印它时,我看到了预期的值:

You see this because of the magic of pretty-printers . 您看到这是因为漂亮打印机魔力 To see the actual contents of the variable, try print/r state.ab_size . 要查看变量的实际内容,请尝试使用print/r state.ab_size

However, when I try to access the element itself, gdb fails: 但是,当我尝试访问元素本身时,gdb失败:

GDB didn't fail, but the pretty printers aren't magical enough to grant your wish. GDB并没有失败,但是漂亮的打印机不足以实现您的愿望。 You'll have to "fish out" the value by using the actual data elements, not the illusion that pretty printers create (and this is hard). 您必须通过使用实际的数据元素来“获取”值,而不是漂亮的打印机所产生的错觉(这很难)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM