3

Why does the value of strings in Eclipse Mars CDT not appear in the expression or variables windows? It appears {...} but i want to see the value itself under the value tab.

How can i do this?

greg-449
  • 109,219
  • 232
  • 102
  • 145
user1673892
  • 409
  • 2
  • 5
  • 17
  • it's probably truncated, see http://stackoverflow.com/questions/2873949/viewing-complete-strings-while-debugging-in-eclipse – flafoux Sep 05 '15 at 11:13
  • i cant see the max length or the change value options when i right click on the value section. – user1673892 Sep 06 '15 at 16:10

1 Answers1

6

What is going on here is CDT is showing the information that GDB is providing to it.

For a trivial program, with the debugger stopped on the line with return 0;

#include <string>
using namespace std;

int main() {
    string mystring = "my string here";
    return 0;
}

this is what I see in the CDT variable view:

cdt view of variable

which matches what I see in GDB:

(gdb) p mystring 
$1 = {static npos = <optimised out>, 
  _M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>}, 
    _M_p = 0x602028 "my string here"}}

Pretty Printing C++

However, what I suspect you want is the pretty printers for libstdc++ which makes the variables view look like this:

string pretty printed

Create a ~/.gdbinit file with the following contents (updating the path for your machine)

python
import sys
sys.path.insert(0, '/usr/share/gcc-4.8/python/')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end

Then point your launch configuration at that gdbinit file and start debugging.

Jonah Graham
  • 7,890
  • 23
  • 55
  • how to make this work with Eclipse CDT running in Windows? (compiler is mingw) – thinlizzy Mar 11 '17 at 15:29
  • @jose.diego It should work the same as in Windows, assuming that you are using a gdb with python enabled (afaik mingw and msys2 both enable by default), you may have to update the path to the correct path. If that does not work, please post a new answer showing the error you get with the eclipse-cdt tag and we can work on it there. – Jonah Graham Mar 11 '17 at 18:56
  • it looks like I have to do this, instead: https://www.eclipse.org/forums/index.php?t=msg&th=1083556&goto=1751218& there are no python binaries in my mingw distro, so I gonna try to use one of my standalone python versions I have here, instead – thinlizzy Mar 12 '17 at 17:10