To my knowledge I'm initializing a string a fairly normal way and when I debug, the variables window in my IDE (CLion) shows its value as <incomplete type>
. I have some simple code that results in the issue for the string variable Bob
.
#include <iostream>
int main() {
std::string Bob = "this doesn't show up in the variables window";
std::cout << Bob << std::endl;
return 0;
}
I don't know what impact it has but I'll include the CMakeLists file that appears to be the simplest that I can use.
cmake_minimum_required(VERSION 3.8)
project(testing123)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11"}
set(SOURCE_FILES main.cpp)
add_executable(testing123 ${SOURCE_FILES})
set(CMAKE_CXX_COMPILER "/cygdrive/c/cygwin64/bin/clang++")
set(CMAKE_C_COMPILER "/cygdrive/c/cygwin64/bin/clang++")
I looked at the other questions and they all had to do with classes and pointers which I can't see to be directly related, so if they are to blame for this, I'd appreciate an explanation as to how that would be.
On Linux, a less intrusive way than to recompile your whole source code with _GLIBCXX_DEBUG
is to define
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6
for your debugger or IDE. You may have to install it via
sudo apt install libstdc++6-8-dbg
first. On Ubuntu, where I get CLion via Snap, I then replaced the symlink at /snap/bin/clion
with a file that contains
#!/bin/bash
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6 /usr/bin/snap run clion "$@"
Now I can see the contents of strings, at least in LLDB (I didn't try GDB).
For GDB, a very quick workaround without any preparation is to cast a string to char*
:
(gdb) p (char*) my_string
$13 = 0x2058970 "These are the contents"
This also works in CLion out of the box.
You might need to set debug mode using _GLIBCXX_DEBUG
macro.
You can do this in a CMakeLists.txt file with the following line:
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With