Values of std::vector not showing up in debug window

zb4ng zb4ng at arcor.de
Thu Nov 22 09:19:48 GMT 2018


On 11/21/18 5:37 PM, Kevin Funk wrote:
> On Wednesday, 7 November 2018 17:09:01 CET zb4ng wrote:
>> Hi,
>>
>> I am sitting on a small C++ project using the standard library
>> "vector"-container and can't see the entries in a "std::vector<long>" in
>> the "Variables" window while debugging.
>> Even after I had installed the "DEBUG-INFO" packages (see below), they
>> were missing.
>> I don't know, if I've done sth wrong or if this is a known issue.
>> As an alternative, it would be possible to use the "print" command in
>> GDB, but it's a little too cumbersome.
>>
>>
>> Distro: openSuSE Leap 15.0
>> KDE: KDE Frameworks 5.45.0,
>> Qt 5.9.4 (built against 5.9.4)
>> KDevelop: 5.1.2
>>
>> "DEBUG-INFO" packages:
>> gcc7-debugsource
>> libstdc++6-debuginfo
>> libstdc++6-32bit-debuginfo
> 
> Heya,
> 
> what you will definitely need are the STL GDB pretty printers (a file called
> libstdcxx/v6/printers.py)
> 
> On Ubuntu they are in this package:
>    libstdc++6:amd64: /usr/share/gcc-8/python/libstdcxx/v6/printers.py
> 
> 
> # Solution A
> 
> You'll also need to load them in KDevelop, for this, edit the gdbinit file
> installed by KDevelop (for your probably somewhere in /usr/.../kdevgdb/
> printers/gdbinit) and add this between "python & "end":
> 
> ```
> sys.path.insert(0, '/usr/share/gcc-8/python/')
> from libstdcxx.v6.printers import register_libstdcxx_printers
> register_libstdcxx_printers (None)
> ```
> 
> 
> # Solution B
> 
> Since some version GDB also supports auto-loading them (this is what happens
> here on my Ubuntu system), cf.:
>    https://stackoverflow.com/a/42896336
> 
> This file here causes gdb to auto-load the pretty printers:
>    libstdc++6:amd64: /usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc+
> +.so.6.0.25-gdb.py
> 
> To check whether pretty-printing STL types works at all, probably try to debug
> a simple test program creating a std::vector<> and debug it with command-line
> GDB and print the vector.
> 
> 
> Hope that helps.
> 
> Regards,
> Kevin
> 
> 
>> I checked the release notes of later versions, but didn't find sth there
>> either.
>>
>> Thanks,
>> zb4bg
> 
> 

Hi,

thanks for your answer!
Well, as mentioned, I actually wanted to avoid the GDB-console
and would rather use the "Variables"-window on the left hand side.


I tried your suggestion (via Solution A), but there still seems to
be a problem:
--------------------
set print pretty on
disp v
--------------------
leads to "std::vector of length 0, capacity 10" and no elements are
displayed.


But this is OK for me now, since I found that I can - as a workaround -
switch to std::array for debugging, so I'm fine for now.
(Only problem: arrays can't handle as many elements as vectors)

Thank you once more and best regards,
zb4bg




More information about the KDevelop mailing list