There is no member named _M_dataplus."尝试打印字符串时-6ren"> There is no member named _M_dataplus."尝试打印字符串时-我正在尝试调试家庭作业程序中的段错误,我发现我的 GDB 甚至无法再打印 std::strings。我该如何解决? 我在 Ubuntu 18.04 LTS 上。 CLang++ 版本: $ clang-6ren">
gpt4 book ai didi

c++ - "Python Exception There is no member named _M_dataplus."尝试打印字符串时

转载 作者:太空宇宙 更新时间:2023-11-04 09:58:16 26 4
gpt4 key购买 nike

我正在尝试调试家庭作业程序中的段错误,我发现我的 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 错误。

最佳答案

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

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

关于c++ - "Python Exception <class ' gdb.error '> There is no member named _M_dataplus."尝试打印字符串时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58356385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com