【问题标题】:"Python Exception <class 'gdb.error'> There is no member named _M_dataplus." when trying to print string“Python 异常 <class 'gdb.error'> 没有名为 _M_dataplus 的成员。”尝试打印字符串时
【发布时间】:2020-02-09 20:59:31
【问题描述】:

我正在尝试调试作业程序中的段错误,我发现我的 GDB 甚至无法再打印 std::strings。我该如何解决?

我使用的是 Ubuntu 18.04 LTS。

CLang++ 版本:

$ clang++ --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

GDB 版本:

$ gdb --version
GNU gdb (Ubuntu 8.1-0ubuntu3.1) 8.1.0.20180409-git
Copyright (C) 2018 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".

我编写了一个名为 gdbbroke.cpp 的小测试程序:

#include <string>

int main()
{
    std::string test = "sanity check";
    return 0;
}
gdbbroke$ clang++ -o gdbbroke gdbbroke.cpp  -std=c++11 -Wall -Wextra -Wpedantic -Wconversion -Wnon-virtual-d
tor -ggdb
gdbbroke$ gdb ./gdbbroke
[...]
Reading symbols from ./gdbbroke...done.
(gdb) break main()
Breakpoint 1 at 0x4007a3: file gdbbroke.cpp, line 5.
(gdb) run
Starting program: gdbbroke/gdbbroke
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main () at gdbbroke.cpp:5
5           std::string test = "sanity check";
(gdb) print test
$1 = Python Exception <class 'gdb.error'> There is no member named _M_dataplus.:

(gdb)

我希望print test 输出:

(gdb) print test
$1 = "sanity check"

但是它只是抛出了上面的 Python 错误。

【问题讨论】:

标签: c++ linux debugging gdb clang


【解决方案1】:

使用 Clang,要打印字符串,您需要安装 libstdc++ 的调试符号。 请参阅此 Clang 错误已解决为 INVALID https://bugs.llvm.org/show_bug.cgi?id=24202

如果您安装了 libstdc++ 调试符号,则应该打印该字符串。另一方面,您可以简单地使用 GCC 而不是 Clang。在这种情况下,您不需要安装 libstdc++ 调试符号,因为 GCC 已经发出它们。 Clang 不会发出它们,因为它会调试信息优化,而 GCC 不会这样做。另见相关问题Cannot view std::string when compiled with clang

【讨论】:

  • 我在 Ubuntu 16.04 的 g++ 5.4 中看到了同样的错误。但是,上面最小化的测试用例不是。
猜你喜欢
  • 1970-01-01
  • 2020-11-14
  • 2021-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-08
  • 2021-02-20
  • 1970-01-01
相关资源
最近更新 更多