Created attachment 14635 [details] test program For some reason, I'm having difficulty getting Python pretty printers to work properly on static members. For example: I compile the included program, foo.cpp: g++ -std=c++20 -ggdb3 -o foo foo.cpp Then I set run gdb on the executable: gdb --quiet foo Here is the session without the pretty printer: Reading symbols from foo... (gdb) start Temporary breakpoint 1 at 0x112d: file foo.cpp, line 22. Starting program: /home/md5i/tmp/gdbtest/foo [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Temporary breakpoint 1, main () at foo.cpp:22 22 X x; (gdb) n 23 } (gdb) p x $1 = {a = {x = 0}, static b = {x = 1}, c = {x = 2}, static d = <same as static member of an already seen type>} (gdb) p x.b $2 = {x = 1} (gdb) p x.d $3 = {x = 3} Pretty much what you would expect, though what is that "<same as ... >" thing? Then, loading the included python pretty printer: (gdb) source foo.py (gdb) p x $4 = {a = {Foo_A_B_C = 0}, static b = {x = 1}, c = {Foo_B_C_A = 2}, static d = <same as static member of an already seen type>} (gdb) p x.b $5 = {Foo_A_B_C = 1} (gdb) p x.d $6 = {Foo_B_C_A = 3} As you can see, b as part of x does not use the pretty printer. And d has the same "<same as ... >" problem as before.
Created attachment 14636 [details] test program (previous was wrong file) I attached the wrong file before.
Created attachment 14637 [details] The python pretty-printer Attached the pretty printer
With gdb-8.1.1 everything is output as expected (including member variable d). And with gdb-8.2.1 onward I can reproduce the behavior of this bug report. So both the <same as static member of an already seen type> output, and the missing pretty printing of static members, start with 8.2.1.
I think the issue is the code to check for a repeated static member is local to cp-valprint, so cp_print_static_field short-circuits value printing to handle this case. This also seems to miss that a union can have a static member. This seems like something that should instead be handled globally by the top-level value printer.
I have a patch.
https://sourceware.org/pipermail/gdb-patches/2023-April/199138.html
The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3c0e312054aa6c46f0efba0ab111f83f0ea4caed commit 3c0e312054aa6c46f0efba0ab111f83f0ea4caed Author: Tom Tromey <tom@tromey.com> Date: Fri Apr 21 18:53:48 2023 -0600 Allow pretty-print of static members Python pretty-printers haven't applied to static members for quite some time. I tracked this down to the call to cp_print_value_fields in cp_print_static_field -- it doesn't let pretty-printers have a chance to print the value. This patch fixes the problem. The way that static members are handled is very weird to me. I tend to think this should be done more globally, like in value_print. However, I haven't made any big change. Reviewed-by: Keith Seitz <keiths@redhat.com> Tested-by: Keith Seitz <keiths@redhat.com> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30057
Fixed.