QtCreator debugger does not display std :: string values

I tried to debug my little lexer and ran into this problem: QtCreator-Debugger does not display the contents of my std :: string -variable. I tried debugging it in the console and got the same result, just structure information.

The version of QtCreator that I used a few days ago displayed the contents of the strings. All other STL elements, such as std :: vector, std :: map, std :: multimap, etc., display the correct data, this is just the std :: string class, which does not work correctly.

After hours of surfing the Internet, I found many web pages that describe the creation of cute printers; my truly Nubian approaches to fixing this did not help. Any ideas how I can get rid of this error?

Note. The "contents" of string variables will always be displayed as "unavailable." I am using QtCreator 2.6 (QT5) for 64bit Linux OS.

Edit (1): I reinstalled everything from the OS to compilers and the IDE ... It's strange when I build my project with optimization level 3 (-O3), QT can display std :: lines.

Command line: clang ++ -std = C ++ 11 -O3 -g -c foo.cpp

When I remove -O3 std :: string, <available>. Any ideas?

+6
source share
2 answers

Try it, it worked for me.
On the Qt Creator menu bar:

Tools -> Options -> Debugger Uncheck the option (Load system GDB pretty printers) 
+6
source

You can try to fix "/usr/share/qtcreator/debugger/stdtypes.py". Since they use the "assumption of hard code regarding member position", it seems that this does not work everywhere. In my case - Linux x64, gcc 9.1, it works exactly as you described: the line is not available

So find the function def qdumpHelper_std__string(d, value, charType, format):

And change (size, alloc, refcount) = d.split("ppp", data - 3 * d.ptrSize()) to (size, alloc, refcount) = d.split("ppp", value.address() + d.ptrSize())

Also comment on d.check(0 <= size and size <= alloc and alloc <= 100*1000*1000) or change it to something like

 if size > 1000: size = 1000 

On my system, std :: string has the following structure

 pointer 8 byte size 8 byte union 16 byte 

And this union field can change its value depending on the size of the string. Therefore, we need to comment on this size < alloc check. value.address() is the address of the string object, so value.address() + d.ptrSize() will indicate the size, and value.address() + 2 * d.ptrSize() indicate this union, which from time to time contain the value of alloc size .

Just look at the declaration of the std::string class to get the structure on your system. And after the fix: the debugger view is fixed

Both work - when the "system GDB beautiful printers" are checked and cleaned

+1
source

All Articles