C++ Debug Window showing "<incomplete type> for string variable
Asked Answered
S

2

14

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.

Sound answered 17/10, 2017 at 4:13 Comment(4)
We cannot try compiling the above, because (for starters) we do not have the various #include files. Please post a minimal, complete, and verifiable program.stackoverflow.com/help/mcveSinfonia
I've posted something that replicates the problem without the excess.Sound
#include <string> ?Kolnos
Unfortunately #include <string> appears to have no effect, MattSound
C
24

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")

Culpable answered 31/10, 2017 at 22:33 Comment(0)
D
3

Using a standard library with debug symbols

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).

Hack

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.

Downhill answered 22/10, 2021 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.