[Libreoffice] gdb pretty printers landed in master

David Tardon dtardon at redhat.com
Thu Aug 25 01:41:02 PDT 2011

Hi all,

as the subject says, I pushed my gdb pretty printers into master.

== What is it? ==

gdb 7 includes support for scripting in Python, which, among other
useful things, allows to write pretty printers for arbitrary data types
(did you ever wish that rtl::OString be shown like a string? Your wish
has come true :)

== What is there? ==

We have pretty printers for, e.g., the following:
* rtl and tools' strings
* some tools' types like Date, Time, BigInt...
* UNO stuff, like Any or Sequence
* some other, probably less useful, stuff, like SvArray

== How do I use it? ==

First thing, you need gdb 7.x with enabled support for python.
Everything should work with gdb 7.0, but I suggest using at least 7.2,
as there are some really nice improvements there. Then it depends on
what do you want to use it for:

1. for devel. installation

The pretty printers are activated automatically on make dev-install,
unless smoketest failed. You can always (re)activate them by running

install-gdb-printers -a "$SOLARVER/$INPATH/installation/opt" -L

in build env. (The install-gdb-printers script is probably going to
change yet, but the arguments should stay the same.)

2. for arbitrary installation

It is possible (or it should be possible :) to use the
install-gdb-printers script to create auto-loaders (see the next
section) in arbitrary installation directory. If you don't want to do
that for any reason, it is still possible to load the pretty printers
unconditionally. Just add the following snippet to your ~/.gdbinit :

import os.path
import sys

import gdb

pythondir = '/path/to/build/solenv/gdb'

if pythondir not in sys.path:
    sys.path.insert(0, pythondir)

from libreoffice import cppu, sal, svl, sw, tl

# ... the same for sal, svl, sw and tl


== How does it work? ==

To make it as easy to use as possible with devel. installations (i.e.,
without any set up required of the developer), the pretty printers are
split by libraries and auto-loaders are used to load them into gdb. An
auto-loader is just a python file that sits next to the library it loads
pretty printers for, with the same name as the library plus -gdb.py
suffix. The auto-loaders are created (from solenv/gdb/autoload.template)
by install-gdb-printers script, which is run as part of make dev-install.

(There is actually even simpler way to associate a pretty printer file
with a library, through special section .debug_gdb_scripts, but that is
only available from gdb 7.2 up.)

More information about the LibreOffice mailing list