Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 876
Logan Avatar asked Oct 17 '17 04:10

Logan


2 Answers

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.

like image 164
Felix Dombek Avatar answered Sep 21 '22 16:09

Felix Dombek


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

like image 34
emersonwood Avatar answered Sep 21 '22 16:09

emersonwood