]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix ptype of single-member Rust enums
authorTom Tromey <tom@tromey.com>
Sat, 4 Feb 2017 05:11:46 +0000 (22:11 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 4 Feb 2017 05:14:36 +0000 (22:14 -0700)
While looking into PR rust/21097, I found that ptype of a
single-element enum in Rust did not always format the result properly.
In particular, it would leave out the members of a tuple struct.
Further testing showed that it also did the wrong thing for ordinary
struct members as well.

This patch fixes these problems.  I'm marking it as being associated
with the PR, since that is where the discovery was made; but this
doesn't actually fix that PR (which I think ultimately is due to a
Rust compiler bug).

Built and regtested on x86-64 Fedora 25, using the system Rust
compiler.  I'm checking this in.

2017-02-03  Tom Tromey  <tom@tromey.com>

PR rust/21097:
* rust-lang.c (rust_print_type) <TYPE_CODE_UNION>: Handle enums
with a single member.

2017-02-03  Tom Tromey  <tom@tromey.com>

PR rust/21097:
* gdb.rust/simple.exp: Add new tests.

gdb/ChangeLog
gdb/rust-lang.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.rust/simple.exp

index 2016c816cfece3b357e2263700339bc5e7516060..f13305ce3e32152d45694562426273ff51e80281 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-03  Tom Tromey  <tom@tromey.com>
+
+       PR rust/21097:
+       * rust-lang.c (rust_print_type) <TYPE_CODE_UNION>: Handle enums
+       with a single member.
+
 2017-02-03  Pedro Alves  <palves@redhat.com>
 
        * cli/cli-interp.c (cli_interp_base::cli_interp_base)
index a8048242860c7c1d6d588f7927dd2f23cb2b0cfb..105b094e5743dc7586aff6045eb5afefec8480db 100644 (file)
@@ -977,6 +977,8 @@ rust_print_type (struct type *type, const char *varstring,
                skip_to = 0;
              }
          }
+       else if (TYPE_NFIELDS (type) == 1)
+         skip_to = 0;
 
        for (i = 0; i < TYPE_NFIELDS (type); ++i)
          {
@@ -989,7 +991,9 @@ rust_print_type (struct type *type, const char *varstring,
            if (TYPE_NFIELDS (variant_type) > skip_to)
              {
                int first = 1;
-               bool is_tuple = rust_tuple_variant_type_p (variant_type);
+               bool is_tuple = (TYPE_NFIELDS (type) == 1
+                                ? rust_tuple_struct_type_p (variant_type)
+                                : rust_tuple_variant_type_p (variant_type));
                int j;
 
                fputs_filtered (is_tuple ? "(" : "{", stream);
index 8c5942859a3b808d38438b2f7108a10fcc1b1457..c098bd01c752120cd4d9c15e25146b8131107d70 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-03  Tom Tromey  <tom@tromey.com>
+
+       PR rust/21097:
+       * gdb.rust/simple.exp: Add new tests.
+
 2017-02-02  Pedro Alves  <palves@redhat.com>
 
        * gdb.mi/mi-logging.exp: Add "redirect while already logging"
index 50ed70b6062489a046eb788459daada8240cc244..0bcc83e822b4b6968f6decd82eafb08a9739da00 100644 (file)
@@ -110,6 +110,18 @@ gdb_test "print univariant.a" " = 1"
 gdb_test "print univariant_anon" " = simple::UnivariantAnon::Foo\\(1\\)"
 gdb_test "print univariant_anon.0" " = 1"
 
+gdb_test_sequence "ptype simple::Univariant" "" {
+    "type = enum simple::Univariant \\{"
+    "  Foo\\{a: u8\\},"
+    "\\}"
+}
+
+gdb_test_sequence "ptype simple::UnivariantAnon" "" {
+    "type = enum simple::UnivariantAnon \\{"
+    "  Foo\\(u8\\),"
+    "\\}"
+}
+
 gdb_test_sequence "ptype simple::ByeBob" "" {
     " = struct simple::ByeBob \\("
     "  i32,"