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

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

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

glaubitz at physik dot fu-berlin.de
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

glaubitz at physik dot fu-berlin.de
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

glaubitz at physik dot fu-berlin.de
In reply to this post by glaubitz at physik dot fu-berlin.de
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.
Reply | Threaded
Open this post in threaded view
|

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

glaubitz at physik dot fu-berlin.de
In reply to this post by glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=23662

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |tromey at sourceware dot org

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
I have some patches to do this.  I'll submit them reasonably soon.

The approach I ended up taking is that for a static type, you can
see that it is dynamic, and see which fields may have dynamic
offsets (this can happen in Ada, but not in Rust).

For the actual type of a value, Python will get the "resolved" type,
which only contains the currently active fields.  In Rust this
will include the artificial discriminant field.

--
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

Sourceware - gdb-prs mailing list
In reply to this post by glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=23662

--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
https://sourceware.org/pipermail/gdb-patches/2020-April/167463.html

--
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

Sourceware - gdb-prs mailing list
In reply to this post by glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=23662

--- Comment #5 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <[hidden email]>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1acda8039ba681e88416a7da6a6e3abdcae6b86b

commit 1acda8039ba681e88416a7da6a6e3abdcae6b86b
Author: Tom Tromey <[hidden email]>
Date:   Fri Apr 24 13:40:31 2020 -0600

    Add Python support for dynamic types

    This changes the gdb Python API to add support for dynamic types.  In
    particular, this adds an attribute to gdb.Type, and updates some
    attributes to reflect dynamic sizes and field offsets.

    There's still no way to get the dynamic type from one of its concrete
    instances.  This could perhaps be added if needed.

    gdb/ChangeLog
    2020-04-24  Tom Tromey  <[hidden email]>

            PR python/23662:
            * python/py-type.c (convert_field): Handle
            FIELD_LOC_KIND_DWARF_BLOCK.
            (typy_get_sizeof): Handle TYPE_HAS_DYNAMIC_LENGTH.
            (typy_get_dynamic): Nw function.
            (type_object_getset): Add "dynamic".
            * NEWS: Add entry.

    gdb/doc/ChangeLog
    2020-04-24  Tom Tromey  <[hidden email]>

            PR python/23662:
            * python.texi (Types In Python): Document new features.

    gdb/testsuite/ChangeLog
    2020-04-24  Tom Tromey  <[hidden email]>

            PR python/23662:
            * gdb.ada/variant.exp: Add Python checks.
            * gdb.rust/simple.exp: Add dynamic type checks.

--
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

Sourceware - gdb-prs mailing list
In reply to this post by glaubitz at physik dot fu-berlin.de
https://sourceware.org/bugzilla/show_bug.cgi?id=23662

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.1
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #6 from Tom Tromey <tromey at sourceware dot org> ---
Fixed.

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