The current pretty-printer API is somewhat simple -- too simple. Over the years a number of desirable additions have been identified. This bug is a meta-bug to track all of these. Some came up in the context of DAP: https://sourceware.org/pipermail/gdb-patches/2023-June/200503.html These aren't too different from some varobj desires: it would be nice to be able to query a printer to get an expression that would evaluate to to the particular child. The main issue with changing pretty-printers is that we never advertised that we may extend the API. So one main goal of v2 should be to fix this -- not just for the additions we need now, but also for any future changes.
One idea in the DAP thread is to let pretty-printers indicate how many children they have, and to allow random access to children. This can be faster in many cases.
Another idea is to see what is missing to fully implement natvis, see https://github.com/asarium/gdb-natvis https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/debugger/create-custom-views-of-native-objects?view=vs-2015#BKMK_Using_Natvis_files The first link says "synthetic" which I think is covered by bug#12806.
It occurs to me I got the dependencies wrong. Pretty-printing v2 is needed to fix these other bugs.
I think this can probably be done pretty easily. gdb can supply a pretty-printer base class, and then the core can recognize when a printer object is derived from this class, and make any extra calls it likes. With this setup we don't need to change the registration API at all.
I have an initial patch to add the base class and update the gdb-provided printers, and DAP. Will submit once I write docs.
https://sourceware.org/pipermail/gdb-patches/2023-September/202342.html
The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fb282576998ca7ce70526dea42d41a7f418879c9 commit fb282576998ca7ce70526dea42d41a7f418879c9 Author: Tom Tromey <tromey@adacore.com> Date: Thu Sep 7 13:40:29 2023 -0600 Introduce gdb.ValuePrinter There was an earlier thread about adding new methods to pretty-printers: https://sourceware.org/pipermail/gdb-patches/2023-June/200503.html We've known about the need for printer extensibility for a while, but have been hampered by backward-compatibilty concerns: gdb never documented that printers might acquire new methods, and so existing printers may have attribute name clashes. To solve this problem, this patch adds a new pretty-printer tag class that signals to gdb that the printer follows new extensibility rules. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30816 Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Fixed.