Re: How to load C++ pretty-printers

Eli Zaretskii <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
> Date: Sat, 16 Mar 2019 10:25:43 -0400
> From: Simon Marchi <[email protected]>
> Cc: asmwarrior <[email protected]>, [email protected]
> 
> If it can help, I have something similar to that in my .gdbinit (whereas 
> asmwarrior has put the same content in a separate file, my.gdb, which 
> they then source by hand).
> 
> When libstdc++ is linked dynamically with a program and you debug that 
> program, GDB will "auto-load" the file corresponding to the libstdc++ 
> shared library.  In my case, it's at 
> "/usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.25-gdb.py".  This 
> file tries to find where the GCC-provided libstdc++ pretty printers are 
> installed, and adds this path to the Python import path.  It then calls 
> register_libstdcxx_printers, a function provided by the libstdc++ pretty 
> printers.
> 
> When libstdc++ is linked statically, the auto-load does not happen, as 
> you mentioned.  So the idea here is to replicate what the auto-load 
> script does, but by hand.
> 
> In my case, I have these lines to adjust the Python import path to add 
> GCC's pretty printers directory:
> 
>    python import sys
>    python sys.path.insert(0, '/usr/share/gcc-8.2.1/python')
> 
> And then I manually trigger the GDB auto-load script, that would 
> normally be sourced automatically when loading the libstdc++ shared lib:
> 
>    source /usr/share/gdb/auto-load/usr/lib/libstdc++.so.6.0.25-gdb.py

Ah, thanks, this script was the missing piece.  In the MinGW GCC
distribution it installs into lib/gcc/mingw32/VERSION/, where VERSION
is the GCC version.  The script is also named differently, due to the
MS-Windows .dll.a import library.

So, for the record, I now have this in my ~/.gdbinit

  python import sys
  python sys.path.insert(0, 'd:/usr/share/gcc-7.3.0/python')
  source d:/usr/lib/gcc/mingw32/7.3.0/libstdc++.dll.a-gdb.py

(The last line both imports the function register_libstdcxx_printers,
and calls that function.)

> The "set auto-load safe-path" line is to define it is safe to auto-load 
> things from.  If you are missing something, you should know quickly 
> enough, as GDB will print you a warning, saying it didn't auto-load X, 
> because X is not in a safe path (as well as information about how to 
> adjust it).

Yes, I already have auto-load safe-path set to not get in the way.

Thanks.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.