|
Boost : |
From: ÐмиÑÑий ÐÑÑ
ипов (grisumbras_at_[hidden])
Date: 2024-09-11 19:46:40
Recently Niall Douglas posted about his idea to embed GDB pretty
printers into binaries using a header. At the time I was thinking
about a good way to deploy pretty printers for JSON that facilitates
their autoloading. After Niall's post I experimented a little bit
more, and I came to the conclusion that indeed nothing beats embedding
via a C++ header in terms of convenience.
At the same time I was also thinking about testing that pretty
printers do in fact work. Given that pretty printers (usually) are
implemented as a Python module, it initially looked like one could
just run a Python program and import GDB Python modules. But actually
you cannot. It turns out, though, you can run a Python script with GDB
as the interpreter. After several iterations I arrived at this setup:
https://github.com/boostorg/json/blob/develop/test/printers.cpp. A
script converts this file into a Python script that uses GDB to break
on certain lines and check if a particular expression produces a
particular output when printed.
While doing all this I thought that most of this work can be useful to
other libraries. So, I moved the reusable parts into a separate
directory (https://github.com/boostorg/json/tree/develop/pretty_printers)
and added both a b2 module, and a CMake module.
For B2.
Importing:
https://github.com/boostorg/json/blob/develop/build.jam#L8-L9
https://github.com/boostorg/json/blob/develop/build/Jamfile#L13
(Re)generating the header:
https://github.com/boostorg/json/blob/develop/build/Jamfile#L88-L95
Testing:
https://github.com/boostorg/json/blob/develop/test/Jamfile#L96-L101
For CMake:
Importing:
https://github.com/boostorg/json/blob/develop/CMakeLists.txt#L54-L55
(Re)generating the header:
https://github.com/boostorg/json/blob/develop/CMakeLists.txt#L56-L63
Testing:
https://github.com/boostorg/json/blob/develop/test/CMakeLists.txt#L80-L88
My questions to the community: do you find this useful? Would you use
it in your Boost or non-Boost library? If you do, the module should be
moved to tools rather than stay in libs/json.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk