This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rust/20239] New: NonZero-optimized enums don't print properly


https://sourceware.org/bugzilla/show_bug.cgi?id=20239

            Bug ID: 20239
           Summary: NonZero-optimized enums don't print properly
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: rust
          Assignee: unassigned at sourceware dot org
          Reporter: manish at mozilla dot com
                CC: tromey at sourceware dot org
  Target Milestone: ---

Rust does an optimization where pointers wrapped in NonZero<T> when used in an
enum may be set to zero to specify a certain variant instead of having a
specific discriminant field. For example, if Option<String> is None, it will be
stored as a String with a null buffer pointer.

gdb can't eval these right now.

If x is Some("123".to_owned()), and y is None::<String>, 

    (gdb) p x
    $1 = <error reading variable>
    (gdb) p y
    $2 = <error reading variable>


If we set the language to C to see the internal representation:

    (gdb) set language c
    Warning: the current language does not match this frame.
    (gdb) p x
    $2 = {RUST$ENCODED$ENUM$0$0$0$0$0$0$None = {__0 = {vec = {buf = {ptr =
{pointer = {__0 = 0x7ffff6c1c008 "123"}, 
                _marker = {<No data fields>}}, cap = 3}, len = 3}}}}
    (gdb) p y
    $3 = {RUST$ENCODED$ENUM$0$0$0$0$0$0$None = {__0 = {vec = {buf = {ptr =
{pointer = {__0 = 0x0}, 
                _marker = {<No data fields>}}, cap = 0}, len = 0}}}}
    (gdb) p xi
    $4 = {{RUST$ENUM$DISR = core::option::Option::Some}, {RUST$ENUM$DISR =
core::option::Option::Some, 
        __0 = 1 '\001'}}
    (gdb) p yi
    $5 = {{RUST$ENUM$DISR = core::option::Option::None}, {RUST$ENUM$DISR =
core::option::Option::None, 
        __0 = 0 '\000'}}


(xi and yi are Some and None of integers, which gdb can print normally in rust
mode)

It seems like the RUST$ENCODED$ENUM$0$0$0$0$0$0$None says "This is a Rust
encoded enum. If the 0th field of the 0th field of the 0th field (... 6 times)
is 0, then this is None"

Additionally, the types don't get printed properly

    (gdb) set language rust
    (gdb) ptype x
    type = enum core::option::Option<collections::string::String> {
      Some,
    }
    (gdb) set language c
    (gdb) ptype x
    type = union core::option::Option<collections::string::String> {
        core::option::Some RUST$ENCODED$ENUM$0$0$0$0$0$0$None;
    }

(we get the same output for y, Some doesn't become None)

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]