Python pretty printing with GDB does not support m

2019-07-11 20:58发布

I have in trouble in inspecting std::map type variable with GDB. In GDB, I usually use the pretty-printer in libstd-c++ repository (https://sourceware.org/gdb/wiki/STLSupport) to print items in STL containers. The pretty-printer works fine with simple containers like vector, but it does not seem to fully support map.

To find an item with a given key in map, I tried to use operator[], but GDB reported the following error message, "Could not find operator[]".

Is it due to the pretty-printer's lack of support of map? or am I missing something?

Thanks

标签: c++ gdb
1条回答
Deceive 欺骗
2楼-- · 2019-07-11 21:50

The pretty-printers are just a display feature. They don't affect evaluation. This can be confusing at times, as you've found.

In your case, gdb is trying to invoke the correct operator[]. However, your compiler has optimized it away -- this is very common in C++ programs.

One option might be to compile with -fkeep-inline-functions. This will cause an out-of-line copy to be emitted. But, this isn't always desirable.

Another method might be to use gdb's relatively new xmethod feature (see the relevant manual page) to write your own. Some xmethods for libstdc++ already went into the GCC tree, so your answer might be as simple as upgrading GCC.

查看更多
登录 后发表回答