Bug 30816 - [meta] Pretty-printing v2
Summary: [meta] Pretty-printing v2
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 14.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks: 10252 10659 12806 14363
  Show dependency treegraph
 
Reported: 2023-08-31 16:57 UTC by Tom Tromey
Modified: 2023-09-26 15:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Tromey 2023-08-31 16:57:54 UTC
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.
Comment 1 Tom Tromey 2023-08-31 19:13:10 UTC
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.
Comment 2 Tom Tromey 2023-08-31 19:15:58 UTC
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.
Comment 3 Tom Tromey 2023-08-31 20:01:46 UTC
It occurs to me I got the dependencies wrong.
Pretty-printing v2 is needed to fix these other bugs.
Comment 4 Tom Tromey 2023-09-04 17:02:06 UTC
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.
Comment 5 Tom Tromey 2023-09-08 19:24:49 UTC
I have an initial patch to add the base class
and update the gdb-provided printers, and DAP.
Will submit once I write docs.
Comment 7 Sourceware Commits 2023-09-26 15:30:25 UTC
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>
Comment 8 Tom Tromey 2023-09-26 15:35:02 UTC
Fixed.