var-create 无法创建变量对象

var-create unable to create variable object

当我调试 c++(在 clion 中)时,我看不到 全局字符串。我尝试检查其他类型,但效果很好。

还有,我试了本地字符串,我也能看吗?!

以防万一,问题现在被跟踪为 CPP-8693

根本原因在某种程度上与 libstdc++ dual ABI 有关。 std::string 类型的全局符号被不同地破坏,这反过来又混淆了 GDB。

In the GCC 5.1 release libstdc++ introduced a new library ABI that includes new implementations of std::string and std::list. These changes were necessary to conform to the 2011 C++ standard which forbids Copy-On-Write strings and requires lists to keep track of their size.

给定以下代码:

std::string global_var = "Hi there!";
static std::string static_var = "Hello";

这是相关的 nm 输出:

0000000000602240 B _Z10global_varB5cxx11
0000000000602280 b _ZL10static_var

可能的解决方法 是禁用 C++11 ABI。在 CMakeLists.txt 中,在 set(CMAKE_CXX_STANDARD 11) 行之后添加以下行(如果有的话):

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

这使得符号名称以不同的方式被破坏,在某种程度上 GDB 再次高兴:

0000000000602238 B global_var
0000000000602248 b _ZL10static_var