Quick Solution
To find out which version of libstdc++-dbg package will work: type apt-cache search libstdc++ | grep dbg
in the terminal. Find the latest version package, which is in the format libstdc++6-5-dbg
.
On one of my machines libstdc++6-5-dbg
works, while on the other one libstdc++6-8-dbg
does.
Installing libstdc++6-8-dbg
worked for me too. I have a 18.04 bionic beaver. Earlier I tried installing a dbg version that matched my libstdc++-dev version, but that did not work.
Thorough Solution:
- If you see
<incomplete type>
when trying to print a string inside gdb, then you need to install a packages similar to libstdc++6-8-dbg
available for your dist. Run ldd <executable>
. You will see an output like:
linux-vdso.so.1 => (0x00007ffe4cbea000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6 (0x00007f523eab1000)
libmpi.so.12 => /opt/mpich-3.2/lib/libmpi.so.12 (0x00007f523e36c000)
If you do not see a debug version in the libstdc++.so.6
link, then try to locate the corresponding library using locate libstdc++.so.6
. Include that debug directory with the -L
flag during linking stage of your executable. Also include the same directory in -rpath
to include it in the runtime library. Recompile your executable. Run again ldd <executable>
to verify if the debug directory is included or not. This takes care of the incomplete type.
- Now while trying to print a string if you see an output like this:
$1 = {static npos = 18446744073709551615,
_M_dataplus = {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
_M_p = 0x7fffffffda70 "dump-000"}, _M_string_length = 8, {_M_local_buf = "dump-000\000\000\000\000\000\000\000",
_M_allocated_capacity = 3472328284420535652}}
then your gdb version needs a pretty printer. First verify that the gdb is installed with python support, which can be found out by typing show configuration
in gdb:
(gdb) show configuration
This GDB was configured as follows:
configure --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
--with-auto-load-dir=$debugdir:$datadir/auto-load
--with-auto-load-safe-path=$debugdir:$datadir/auto-load
--with-expat
--with-gdb-datadir=/home/zephyr/utils/gdb-8.3-install/share/gdb (relocatable)
--with-jit-reader-dir=/home/zephyr/utils/gdb-8.3-install/lib/gdb (relocatable)
--without-libunwind-ia64
--without-lzma
--without-babeltrace
--without-intel-pt
--disable-libmcheck
--without-mpfr
--without-python
--without-guile
--disable-source-highlight
--with-separate-debug-dir=/home/zephyr/utils/gdb-8.3-install/lib/debug (relocatable)
Look inside gdb-datadir
by typing ls /home/zephyr/utils/gdb-8.3-install/share/gdb
. If you do not see a python folder, then your gdb
needs to be installed with python
support. Ensure that python-dev
is installed before configuring, compiling and installing your gdb
. Now install the pretty printers by following the instructions given on this page: https://sourceware.org/gdb/wiki/STLSupport.
Congratulations! you now have pretty printers installed.
stringstream
or anifstream
? There is no way to get a file's content this way! – Fawn