当前位置: 首页 > 面试题库 >

用于调试stdlib变量的Python漂亮打印机无法正常工作

穆歌者
2023-03-14
问题内容

我按照这篇文章很好地调试了变量。eclipse mars
CDT中没有出现字符串的值

但是我最终收到如下错误消息:

 File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'

我该如何解决这个问题?


问题答案:

.gdbinit的内容似乎不正确,或者没有运行。

确保添加的路径对于您的机器是正确的,并且gdbinit文件正在运行。

由于您遇到了该错误,因此只需要向python添加正确的路径即可。

这是一个示例跟踪,它首先不起作用,然后在更正路径后才起作用:

$ cat hello.cc 
#include <string>
using namespace std;

int main() {
    string mystring = "my string here";
    return 0;
}

$ g++ hello.cc -g -o hello.elf

$ gdb hello.elf --quiet

Reading symbols from hello.elf...done.
(gdb) b hello.cc:6
Breakpoint 1 at 0x400863: file hello.cc, line 6.
(gdb) r
Starting program: /tmp/x/hello.elf 
Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'

Breakpoint 1, main () at hello.cc:6
6       return 0;
(gdb) p mystring
$1 = {static npos = <optimised out>, _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, 
    _M_p = 0x602028 "my string here"}}
(gdb) python
>import sys
>sys.path.insert(0, '/usr/share/gcc-4.8/python/')
>end
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /tmp/x/hello.elf

Breakpoint 1, main () at hello.cc:6
6       return 0;
(gdb) p mystring
$2 = "my string here"
(gdb)

以上示例的版本信息:

$ g++ --version
g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gdb --version
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

使用Eclipse CDT时

使用Eclipse CDT时,您需要手动指定gdbinit文件。Eclipse CDT使用该--nx标志启动GDB
,这将阻止GDB.gdbinit自动拾取任何文件。您应该在启动配置中指定CDT合适的初始化文件:

cdt中的gdbinit

此外,您可以在“首选项”中为新的启动配置更改默认的启动gdbinit,如下图所示:

默认的gdb初始化



 类似资料:
  • 问题内容: Go中有类似Ruby的东西吗? 例如,在Ruby中,您可以编写: 输出将是: 我能找到的最接近的东西是 问题答案: 如果您的目标是避免导入第三方软件包,则另一个选择是使用json.MarshalIndent: 输出: 工作示例:http : //play.golang.org/p/SNdn7DsBjy

  • 问题内容: 如果有人对JSON的打印非常了解,那么我将不胜感激! 我正在使用以下功能将JSON字符串移动到文件中,以将复杂的python字符串转换为JSON格式: 问题是我遇到了方括号的语法错误,因为这对我来说是个新话题,我不知道该如何解决。我需要的JSON格式如下: 我正在使用Google Visualization API,您可能对此比较熟悉,但是我需要动态图。上面的代码是API创建图形所需的

  • 问题内容: 在使用“难看的” XML读取现有文件并进行一些修改后,漂亮的打印不起作用。我试过了。 我有以下XML: 我这样使用它: 问题答案: 对我来说,这个问题直到我在这里注意到这个小窍门才得以解决: http://lxml.de/FAQ.html#why-doesn-t-the-pretty-print-option-reformat-my-xml- output 简洁版本: 使用以下命令读入

  • 问题内容: 是否有一种简单的内置方法将2D Python列表打印为2D矩阵? 所以这: 会变成像 我找到了pprint模块,但是它似乎并没有实现我想要的功能。 问题答案: 为了使事情变得有趣,让我们尝试使用更大的矩阵: 输出: UPD:对于多行单元格,应如下所示: 然后应用上面的代码。 另请参见http://pypi.python.org/pypi/texttable

  • 问题内容: 我正在构建一个PHP脚本,该脚本将JSON数据提供给另一个脚本。我的脚本将数据构建到一个大的关联数组中,然后使用来输出数据。这是一个示例脚本: 上面的代码产生以下输出: 如果您的数据量很少,那就太好了,但是我希望遵循以下几点: 有没有办法在PHP中做到这一点而又没有丑陋的破解?似乎有人在Facebook上找到了答案。 问题答案: PHP 5.4提供了用于调用的选项。 http://ph

  • 问题内容: 我正在创建一个JSON文件的脚本。现在,我只是使用(PHP 5.2.x)将数组编码为JSON输出。然后,我将返回值打印到文件中并保存。问题是客户端希望能够打开这些JSON文件以提高可读性,因此我想在其中添加换行符并“漂亮打印” JSON输出。有关如何执行此操作的任何想法?我唯一可以看到的替代方法是完全不使用,而只是手动写入文件内容,并为每行添加自己的换行符。 这是我得到的: 这就是我想