You are not logged in.
My gdb doesn't pretty print STL containers. Does anyone know how to enable that feature?
From what I could find the pretty printers should be listed with 'info pretty-printers'. I only seem to have one for mpx_boud128:
(gdb) info pretty-printer
global pretty-printers:
builtin
mpx_bound128
It seems like like the pretty printers are located in the '/usr/share/gdb/auto-load/usr/lib' directory, and I do have some files there:
ᐅ ls -l /usr/share/gdb/auto-load/usr/lib/
total 20
-rw-r--r-- 1 root root 197 Sep 11 22:40 libglib-2.0.so.0.7800.0-gdb.py
-rw-r--r-- 1 root root 200 Sep 11 22:40 libgobject-2.0.so.0.7800.0-gdb.py
-rw-r--r-- 1 root root 201 Sep 21 14:32 libgstreamer-1.0.so.0.2206.0-gdb.py
-rw-r--r-- 1 root root 2891 Apr 3 2023 libisl.so.23.3.0-gdb.py
-rw-r--r-- 1 root root 2384 Aug 2 09:06 libstdc++.so.6.0.32-gdb.py
Specifically, the 'libstdc++' one is provided by gcc.
Looking at the configuration of gdb, this folder should be automatically loaded ('--with-auto-load-dir'):
ᐅ gdb --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=/usr/share/gdb (relocatable)
--with-jit-reader-dir=/usr/lib/gdb (relocatable)
--without-libunwind-ia64
--with-lzma
--without-babeltrace
--without-intel-pt
--with-mpfr
--without-xxhash
--with-python=/usr (relocatable)
--with-python-libdir=/usr/lib (relocatable)
--with-debuginfod
--with-guile
--enable-source-highlight
--enable-threading
--with-separate-debug-dir=/usr/lib/debug (relocatable)
--with-system-gdbinit=/etc/gdb/gdbinit
("Relocatable" means the directory can be moved with the GDB installation
tree, and GDB will still find it.)
Looking the 'strace' of a gdb run I can see that it tries to readlink the 'auto-load' directory, but then doesn't open any files in it:
readlink("/usr/share", 0x7ffeb4f9a340, 1023) = -1 EINVAL (Invalid argument)
readlink("/usr/share/gdb", 0x7ffeb4f9a340, 1023) = -1 EINVAL (Invalid argument)
readlink("/usr/share/gdb/auto-load", 0x7ffeb4f9a340, 1023) = -1 EINVAL (Invalid argument)
newfstatat(3, "", {st_mode=S_IFIFO|0600, st_size=0, ...}, AT_EMPTY_PATH) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3828926, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
I also tried to 'load' the python file, but that fails with "You can't do that when your target is " followed by `exec' or `None' (depending on whether I started gdb with an executable or not).
(gdb) load /usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.32-gdb.py
You can't do that when your target is `exec'
Any suggestions?
Offline
I just struggled with pretty printing too. And I figured out my problem was in my ~/.gdbinit, where I modified the safe path using command
set auto-load safe-path /foo/bar
and the pretty printers didn't have permission to run. But your problem may be on different place.
It works like this. GDB tries to auto-load some scripts for every object file the program needs (i.e. the executable file and all shared libraries). When your program loads shared library /usr/lib/libstdc++.so.6.0.32, it should try to load script /usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.32-gdb.py, which setups pretty printing for STL containers. The actual pretty printers are stored in /usr/share/gcc-12.2.1/python/libstdcxx/. But it depends on configuration of gdb.
It searches for the scripts in auto-load script-directory. Path to this directory can be seen by running this command in gdb terminal:
(gdb) show auto-load scripts-directory
List of directories from which to load auto-loaded scripts is $debugdir:$datadir/auto-load.
The default value contain two paths: $debugdir (usually evaluated to /usr/lib/debug) and $datadir/auto-load (usually evaluated to /usr/share/gdb/auto-load). Value of $datadir can be seen by
(gdb) show data-dir
GDB's data directory is "/usr/share/gdb".
But it also needs to verify, if it is permitted to run the script. This is defined by option auto-load safe-path:
(gdb) show auto-load safe-path
List of directories from which it is safe to auto-load files is $debugdir:$datadir/auto-load.
As you can see, there is also the $datadir/auto-load.
You can debug the auto-loading by running this command in the gdb console before you run your program:
(gdb) set debug auto-load
Offline