var-create unable to create variable object

时间秒杀一切 提交于 2019-12-04 06:46:23

问题


When I debug c++ (in clion), I can't watch global strings. I tried to check other types but it worked well.

Also, I tried local string and I can watch it too?!


回答1:


Just in case, the issue is now tracked as CPP-8693.

The root cause is somehow related to libstdc++ dual ABI. Global symbols of std::string types are mangled differently, which in turn confuses 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.

Given the following code:

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

Here's the related nm output:

0000000000602240 B _Z10global_varB5cxx11
0000000000602280 b _ZL10static_var

A possible workaround is to disable C++11 ABI. In CMakeLists.txt, add the following line, right after the set(CMAKE_CXX_STANDARD 11) line, if any:

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

This makes symbol names to be mangled differently, in a way GDB is happy again:

0000000000602238 B global_var
0000000000602248 b _ZL10static_var


来源:https://stackoverflow.com/questions/41854840/var-create-unable-to-create-variable-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!