How can I reload a pretty printer?

meator meator.dev@gmail.com
Tue Jul 25 16:13:55 GMT 2023


Hi. When writing a pretty printer, I want to repeatedly test it. This is 
pretty complicated because GDB has no builtin mechanisms to do such 
thing (that I know of) and breakpoint() pretty much can not be used 
because GDB's Python doesn't have access to the capable pty so 
interactive use of PDB is impossible. Even the classic "printf style" 
debugging doesn't work because Python's print() doesn't work 
(gdb.write() has to be used instead).

I need to test the pretty printer often because the official Python 
interface documentation is quite lacking and the interface itself is 
imperfect^1. Accessing the docstrings of the Python interface is 
difficult because the gdb module nor other modules can be imported in 
standalone Python (I've tried to add it to $PYTHONPATH but with no 
success; How are you supposed to access the docstrings?).

Therefore my last solution is to load the pretty printer, try it in gdb, 
modify the pretty printer and repeat. But a pretty printer can be 
sourced only once because the second source call will fail due to the 
fact that the pretty printer is already registered. I have to restart 
GDB every time I modify the pretty printer which is extremely 
impractical. Is there a way to live reload the pretty printer?

1: There is no sane way to call member functions through gdb.Value which 
is kind of important in C++: https://stackoverflow.com/q/22774067/13840624


More information about the Gdb mailing list