gdb漂亮的打印不起作用

时间:2022-12-01 13:43:12

I am trying to view the contents of C++ STL Containers. I read here that the recent versions of gcc and gdb support pretty printing by default but when I tried to display a map I got the following:

我试图查看C ++ STL容器的内容。我在这里读到gcc和gdb的最新版本默认支持漂亮打印,但是当我尝试显示地图时,我得到以下内容:

gdb漂亮的打印不起作用

Then, I tried to set up pretty printing according to this answer but still it shows the same output. Can someone please help me out? Thanks.

然后,我尝试根据这个答案设置漂亮的打印,但它仍显示相同的输出。有人可以帮帮我吗?谢谢。

I am using Ubuntu 16.04, g++ 5.4.1, GDB 7.11.1 and python 2.7.12 (installed from their official sources).

我使用的是Ubuntu 16.04,g ++ 5.4.1,GDB 7.11.1和python 2.7.12(从官方来源安装)。

3 个解决方案

#1


3  

It was stated in the other thread you mentioned that some versions of GDB work with Python 3 only.

在你提到的另一个帖子中已经说过,某些版本的GDB仅适用于Python 3。

That can be ruled out as possible reasons since you don't receive any errors as far as your description says.

这可以排除为可能的原因,因为就您的描述而言,您没有收到任何错误。

Over at sourceware.org it is suggested that

在sourceware.org上建议

You can extend gdb using the Python programming language. This feature is available only if gdb was configured using --with-python.

您可以使用Python编程语言扩展gdb。仅当使用--with-python配置gdb时,此功能才可用。

Not sure if you did because the guides you used don't mention it directly.

不确定你是否这样做,因为你使用的指南没有直接提及它。

#2


2  

The gdb native to Ubuntu 16.04 should be able to pretty print a std::map; the python code which handles that is class StdMapPrinter in the following file from the libstdc++6 package:

原生于Ubuntu 16.04的gdb应该能够打印出一个std :: map;处理它的python代码是libstdc ++ 6包中的以下文件中的类StdMapPrinter:

/usr/share/gcc-5/python/libstdcxx/v6/printers.py

If your goal is to accomplish this with binaries you build from source, it might still be useful to get this working with the native Ubuntu packages first, as a basis for comparison. The likely reason pretty printers are not working in a gdb you built yourself is that libstdcxx/v6/printers.py (libstdcxx.v6.printers in the python namespace) is not where gdb expects to find it.

如果您的目标是使用从源代码构建的二进制文件来实现此目的,那么首先使用本机Ubuntu软件包作为比较的基础可能仍然有用。漂亮的打印机不能在你自己构建的gdb中工作的原因是libstdcxx / v6 / printers.py(python命名空间中的libstdcxx.v6.printers)不是gdb期望找到它的地方。

Also, the gdb native to Ubuntu 16.04 is linked against python3, not python2; one way to see that is in the output of

此外,Ubuntu 16.04本机的gdb链接到python3,而不是python2;一种看待它的方法是在输出中

ldd /usr/bin/gdb

It appears that the libstdcxx.v6.printers native to Ubuntu 16.04 is intended to work with either python2 or python3.

似乎Ubuntu 16.04原生的libstdcxx.v6.printers旨在与python2或python3一起使用。

If your native gdb binary is not already installed, you can use this:

如果尚未安装本机gdb二进制文件,则可以使用:

apt install gdb

#3


1  

Mark was correct. I built my own version of gdb 8.0 with --with-python option but still I was not able to see container contents. gdb was showing all complex structure. So I followed Mark's suggestion.

马克是对的。我使用--with-python选项构建了我自己的gdb 8.0版本,但我仍然无法看到容器内容。 gdb显示了所有复杂的结构。所以我遵循马克的建议。

You need to create a soft link (auto-load) in your gdb install directory. If your gdb install directory is $HOME/gdb_install then

您需要在gdb安装目录中创建一个软链接(自动加载)。如果你的gdb安装目录是$ HOME / gdb_install那么

cd $HOME/gdb_install/share/gdb

ln -s /usr/share/gdb/auto-load auto-load

/usr/share/gdb/auto-load already exists on my Ubuntu installation. It's the gdb version 7.11.1.

/ usr / share / gdb / auto-load已经存在于我的Ubuntu安装中。这是gdb版本7.11.1。

After that gdb is showing container contents. Thanks Mark.

之后,gdb显示容器内容。谢谢马克。

#1


3  

It was stated in the other thread you mentioned that some versions of GDB work with Python 3 only.

在你提到的另一个帖子中已经说过,某些版本的GDB仅适用于Python 3。

That can be ruled out as possible reasons since you don't receive any errors as far as your description says.

这可以排除为可能的原因,因为就您的描述而言,您没有收到任何错误。

Over at sourceware.org it is suggested that

在sourceware.org上建议

You can extend gdb using the Python programming language. This feature is available only if gdb was configured using --with-python.

您可以使用Python编程语言扩展gdb。仅当使用--with-python配置gdb时,此功能才可用。

Not sure if you did because the guides you used don't mention it directly.

不确定你是否这样做,因为你使用的指南没有直接提及它。

#2


2  

The gdb native to Ubuntu 16.04 should be able to pretty print a std::map; the python code which handles that is class StdMapPrinter in the following file from the libstdc++6 package:

原生于Ubuntu 16.04的gdb应该能够打印出一个std :: map;处理它的python代码是libstdc ++ 6包中的以下文件中的类StdMapPrinter:

/usr/share/gcc-5/python/libstdcxx/v6/printers.py

If your goal is to accomplish this with binaries you build from source, it might still be useful to get this working with the native Ubuntu packages first, as a basis for comparison. The likely reason pretty printers are not working in a gdb you built yourself is that libstdcxx/v6/printers.py (libstdcxx.v6.printers in the python namespace) is not where gdb expects to find it.

如果您的目标是使用从源代码构建的二进制文件来实现此目的,那么首先使用本机Ubuntu软件包作为比较的基础可能仍然有用。漂亮的打印机不能在你自己构建的gdb中工作的原因是libstdcxx / v6 / printers.py(python命名空间中的libstdcxx.v6.printers)不是gdb期望找到它的地方。

Also, the gdb native to Ubuntu 16.04 is linked against python3, not python2; one way to see that is in the output of

此外,Ubuntu 16.04本机的gdb链接到python3,而不是python2;一种看待它的方法是在输出中

ldd /usr/bin/gdb

It appears that the libstdcxx.v6.printers native to Ubuntu 16.04 is intended to work with either python2 or python3.

似乎Ubuntu 16.04原生的libstdcxx.v6.printers旨在与python2或python3一起使用。

If your native gdb binary is not already installed, you can use this:

如果尚未安装本机gdb二进制文件,则可以使用:

apt install gdb

#3


1  

Mark was correct. I built my own version of gdb 8.0 with --with-python option but still I was not able to see container contents. gdb was showing all complex structure. So I followed Mark's suggestion.

马克是对的。我使用--with-python选项构建了我自己的gdb 8.0版本,但我仍然无法看到容器内容。 gdb显示了所有复杂的结构。所以我遵循马克的建议。

You need to create a soft link (auto-load) in your gdb install directory. If your gdb install directory is $HOME/gdb_install then

您需要在gdb安装目录中创建一个软链接(自动加载)。如果你的gdb安装目录是$ HOME / gdb_install那么

cd $HOME/gdb_install/share/gdb

ln -s /usr/share/gdb/auto-load auto-load

/usr/share/gdb/auto-load already exists on my Ubuntu installation. It's the gdb version 7.11.1.

/ usr / share / gdb / auto-load已经存在于我的Ubuntu安装中。这是gdb版本7.11.1。

After that gdb is showing container contents. Thanks Mark.

之后,gdb显示容器内容。谢谢马克。