[英]GDB printing STL data
After following the instructions given on this site: https://sourceware.org/gdb/wiki/STLSupport GDB is still unable to print the contents of stl containers like vectors, other than printing out a huge amount of useless information. 按照本网站上给出的说明进行操作后: https ://sourceware.org/gdb/wiki/STLSupport除了打印出大量无用的信息外,GDB仍然无法打印诸如矢量之类的stl容器的内容。 When GDB loads, I also get the following errors, which I think are related to the Python that I put into
~/.gdbinit
加载GDB时,我还会收到以下错误,我认为这与我放入
~/.gdbinit
的Python有关
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "/Users/mayankp/gdb_printers/python/libstdcxx/v6/printers.py", line 1247, in register_libstdcxx_printers
gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
File "/usr/local/share/gdb/python/gdb/printing.py", line 146, in register_pretty_printer
printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6
/Users/mayankp/.gdbinit:6: Error in sourced command file:
Error while executing Python code.
When GDB loads, I also get the following errors...
加载GDB时,我还会收到以下错误...
It looks like instructions you followed on https://sourceware.org/gdb/wiki/STLSupport are invalid now. 您在https://sourceware.org/gdb/wiki/STLSupport上遵循的说明似乎无效。 If you look at
svn log
you will see that registering of pretty printers was added in __init__.py
recently: 如果查看
svn log
您会发现最近在__init__.py
中添加了漂亮打印机的注册:
------------------------------------------------------------------------
r215726 | redi | 2014-09-30 18:33:27 +0300 (Вт., 30 сент. 2014) | 4 lines
2014-09-30 Siva Chandra Reddy <sivachandra@google.com>
* python/hook.in: Only import libstdcxx.v6.
* python/libstdcxx/v6/__init__.py: Load printers and xmethods.
------------------------------------------------------------------------
And therefore second registration throws error. 因此,第二次注册会引发错误。 You can remove it or comment out:
您可以将其删除或注释掉:
#register_libstdcxx_printers (None)
GDB is still unable to print the contents of stl containers
GDB仍然无法打印stl容器的内容
You have probably mismatched pretty printers with your gcc. 您可能没有将漂亮的打印机与gcc匹配。 See https://stackoverflow.com/a/9108404/72178 for details.
有关详细信息,请参见https://stackoverflow.com/a/9108404/72178 。
From your traceback it seems that the register_libstdcxx_printers()
call is failing because there already is such a pretty printer registered. 从您的追溯看来,
register_libstdcxx_printers()
调用似乎失败了,因为已经注册了一个漂亮的打印机。 To avoid that, you can wrap it in a try..except
to make sure instructions in .gdbinit
don't interfere with the launch of GDB if they fail: 为了避免这种情况,您可以将其包装在
try..except
,以确保.gdbinit
指令在.gdbinit
时不会干扰GDB的启动:
python
import sys
sys.path.insert(0, '/home/user/gdb_printers/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
try:
register_libstdcxx_printers(None)
except:
pass
end
( Note : You should usually never use a bare except
statement without qualifying the type of exceptions you want to catch. This is a special case though, in startup configuration files like .gdbinit
, .pdbrc
or your PYTHONSTARTUP
file you'll probably want to write defensive code like that). ( 注意 :通常,在不限定要捕获的异常类型的情况下, 切勿使用裸
except
语句 。这是一种特殊情况,在启动配置文件(如.gdbinit
, .pdbrc
或PYTHONSTARTUP
文件中)编写类似的防御性代码)。
But chances are this will only get rid of the ugly traceback for you, and printing of STL vectors still wont work. 但是,这可能只会为您消除丑陋的追溯,并且STL向量的打印仍然无法进行。 Because it seems there is already a pretty printer registered from somewhere else.
因为似乎已经有其他地方注册了漂亮的打印机。
Make sure the path /home/user/gdb_printers/python
actually matches the path where you checked out the module mentioned in the STLSupport docs . 确保路径
/home/user/gdb_printers/python
确实与您签出STLSupport文档中提到的模块的路径匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.