Boost logo

Boost :

From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2024-08-13 14:11:03


Re: my previous guide to writing inline GDB pretty printers, it turns
out it had bugs. Here is how to fix them.

Firstly, my thanks to Braden Ganetsky for reporting the bugs, then pair
programming over Slack with me late last night to diagnose and fix the
issues. We have cowritten a conversion script which we now believe is
actually correct -- it takes a Python GDB pretty printer, and emits a C
(not C++) header file with all the correct markup. It can be found at:

https://github.com/ned14/quickcpplib/blob/master/scripts/generate_gdb_printer.py

The first bug fixed is correct escaping: we need to double escape the
original Python in the right kind of way to cause the escaped inline
assembler block to emit the right escaped text for GDB to load it
correct as Python. Getting the double escaping correct is tricky, but we
think we have it now.

The second bug fixed is correct composure of multiple inline GDB pretty
printers - Braden found only the first was having any effect. It turns
out this is due to a misreading of the GDB docs from
https://sourceware.org/gdb/current/onlinedocs/gdb.html/dotdebug_005fgdb_005fscripts-section.html#dotdebug_005fgdb_005fscripts-section
where this example:

```
asm(
".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
".ascii \"gdb.inlined-script\\n\"\n"
".ascii \"class test_cmd (gdb.Command):\\n\"\n"
...
```

... does not make it clear that the string "gdb.inlined-script" is
actually the unique identifier of that script used to eliminate
duplicates. It needs to be unique per inlined script unless you
specifically want duplicates, and our Python converter above has
remedied this. Generally you ought to name it after your library and
maybe possibly a git SHA or version depending on how unstable your
library is, and ensure that the pretty printer matches only that version
of your library.

Thanks once again to Braden for his help.

Note that the Outcome GDB pretty printer which has shipped in the
pending Boost release is buggy and will not work properly. The next
Boost release will fix it. You can of course copy the fixed pretty
printer from the github repo over this Boost release.

Niall


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk