[Bug python/23662] New: gdb.Value does not understand discriminated unions

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug python/23662] New: gdb.Value does not understand discriminated unions

cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23662

            Bug ID: 23662
           Summary: gdb.Value does not understand discriminated unions
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: tromey at sourceware dot org
  Target Milestone: ---

Rust enums are now represented as discriminated unions in gdb.
gdb.Value should be extended to understand these.
The most basic support would be a way to find out which
member of the union is active.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug python/23662] gdb.Value does not understand discriminated unions

cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23662

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
This came up again in https://github.com/rust-lang/rust/issues/62839

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug python/23662] gdb.Value does not understand discriminated unions

cvs-commit at gcc dot gnu.org
In reply to this post by cvs-commit at gcc dot gnu.org
https://sourceware.org/bugzilla/show_bug.cgi?id=23662

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
I have been thinking about this a little.  It would be good for
my purposes (and IMO for gdb) to solve this in a way that unifies
the Rust case with the Ada case.  While in Rust only enums need
to be treated this way, in Ada a structure can have multiple
optional fields with different conditions.

One idea is to have gdb.Type always list all the possible fields,
but note some of them as "optional" or "variant" or something like
that (on the gdb.Field object).  One possible difficulty here is
that, in Ada, the position and size can vary (but perhaps this is
a side problem.)

Then, we would add a method to gdb.Value to indicate whether
a given field is active for that value.  For Rust this would make
it simple to see the active variant.  (It seems slightly less
ergonomic than simply querying the Value directly for the active
variant, but on the other hand that approach wouldn't really
make sense for Ada.)

Maybe gdb.Type could have a "can_vary" attribute as well, so that
it's easier for the user to tell whether special treatment is needed.

Doing this fully, including Ada, will require some internal restructuring
of variant types in gdb.  However, I think the basic API could be
implemented in a Rust-specific way, then expanded to cover Ada later.

--
You are receiving this mail because:
You are on the CC list for the bug.