使用GDB进行漂亮的Python打印不支持map的索引操作符[] [英] Python pretty printing with GDB does not support map's indexing operator []

查看:199
本文介绍了使用GDB进行漂亮的Python打印不支持map的索引操作符[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用GDB检查std :: map类型变量时遇到了麻烦。在GDB中,我通常在libstd-c ++存储库中使用漂亮的打印机( https://sourceware.org/gdb / wiki / STLSupport )在STL容器中打印项目。漂亮的打印机可以很好地处理像矢量这样的简单容器,但它似乎不能完全支持地图。



要在map中查找具有给定键的项目,我尝试使用operator [],但是GDB报告了以下错误消息:Could not find operator [] 。

是否由于漂亮打印机缺乏对地图的支持?或者我错过了什么?



感谢

解决方案

打印机只是一个显示功能。它们不影响评估。这可能会让你感到困惑,正如你发现的那样。

在你的情况中,gdb试图调用正确的运算符[] 。然而,你的编译器已经优化了它 - 这在C ++程序中非常常见。



一个选项可以用 -fkeep-inline -functions 。这将导致排出的副本被发射。但是,这并不总是可取的。

另一种方法可能是使用gdb相对较新的 xmethod 特性(< a href =https://sourceware.org/gdb/current/onlinedocs/gdb/Xmethods-In-Python.html =nofollow>查看相关的手册页面)编写自己的。 libstdc ++的一些xmethods已经进入GCC树,所以你的答案可能和升级GCC一样简单。


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

解决方案

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.

这篇关于使用GDB进行漂亮的Python打印不支持map的索引操作符[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆