GDB pretty printing importorror:没有名为“printers”的模块

2024-05-14 03:27:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Ubuntu 14.04上的GDB中添加STL的pretty printing。有关工具的一些详细信息:

操作系统:Ubuntu 14.04

gdb版本:7.7

python版本:2.7.6

python3版本:3.4.0

但在我完全按照指令设置之后。我仍然有以下错误:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6/__init__.py", line 19, in <module>
    from printers import register_libstdcxx_printers
ImportError: No module named 'printers'
/home/jerry/.gdbinit:6: Error in sourced command file:
Error while executing Python code.
Reading symbols from main...done.

然后我重新检查了我漂亮的打印安装目录。在目录/home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6/下,我可以清楚地看到printers.py文件。我还查看printers.py的内容,我确信它也有register_libstdcxx_printers类。为什么python解释器仍然抱怨缺少printers模块?这对我来说真的很奇怪。


Tags: inpy版本supporthomeubuntulinefile
1条回答
网友
1楼 · 发布于 2024-05-14 03:27:17

我自己也试过,幸运的是,现在成功了。至少它可以按预期打印出地图和矢量内容。以下是我所做的:

因为它抱怨找不到printer.py模块,所以我想应该告诉python解释器这个文件的位置。所以我首先在我的~/.gdbinit中添加了这一行: sys.path.append("/home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6")

(在第sys.path.insert(0, '/home/jerry/myLib/gdb_stl_support/python')行之后)

然后再次运行gdb,我得到以下错误:

Traceback (most recent call last):
  File "<string>", line 5, in <module>
  File "/home/jerry/myLib/gdb_stl_support/python/libstdcxx/v6/printers.py", line 1247, in register_libstdcxx_printers
    gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
  File "/usr/share/gdb/python/gdb/printing.py", line 146, in register_pretty_printer
    printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6
/home/jerry/.gdbinit:7: Error in sourced command file:
Error while executing Python code.

给定错误信息,我编辑了~/.gdbinit文件并对register_libstdcxx_printers (None)行进行了注释。

然后在运行gdb之后,它就工作了。

但我仍然想知道sys.path中的目录是否递归搜索?我的意思是,在我看来,python解释器应该这样工作:一旦您向sys.path添加了一个目录,那么该目录下的子目录也将被搜索到模块文件。

相关问题 更多 >