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?!
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?!
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
andstd::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