• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

修订版f0fd41c1926984fd1a524ff551286cba694539a0 (tree)
时间2017-02-04 14:14:36
作者Tom Tromey <tom@trom...>
CommiterTom Tromey

Log Message

Fix ptype of single-member Rust enums

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.

更改概述

差异

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
1+2017-02-03 Tom Tromey <tom@tromey.com>
2+
3+ PR rust/21097:
4+ * rust-lang.c (rust_print_type) <TYPE_CODE_UNION>: Handle enums
5+ with a single member.
6+
17 2017-02-03 Pedro Alves <palves@redhat.com>
28
39 * cli/cli-interp.c (cli_interp_base::cli_interp_base)
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -977,6 +977,8 @@ rust_print_type (struct type *type, const char *varstring,
977977 skip_to = 0;
978978 }
979979 }
980+ else if (TYPE_NFIELDS (type) == 1)
981+ skip_to = 0;
980982
981983 for (i = 0; i < TYPE_NFIELDS (type); ++i)
982984 {
@@ -989,7 +991,9 @@ rust_print_type (struct type *type, const char *varstring,
989991 if (TYPE_NFIELDS (variant_type) > skip_to)
990992 {
991993 int first = 1;
992- bool is_tuple = rust_tuple_variant_type_p (variant_type);
994+ bool is_tuple = (TYPE_NFIELDS (type) == 1
995+ ? rust_tuple_struct_type_p (variant_type)
996+ : rust_tuple_variant_type_p (variant_type));
993997 int j;
994998
995999 fputs_filtered (is_tuple ? "(" : "{", stream);
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
1+2017-02-03 Tom Tromey <tom@tromey.com>
2+
3+ PR rust/21097:
4+ * gdb.rust/simple.exp: Add new tests.
5+
16 2017-02-02 Pedro Alves <palves@redhat.com>
27
38 * gdb.mi/mi-logging.exp: Add "redirect while already logging"
--- a/gdb/testsuite/gdb.rust/simple.exp
+++ b/gdb/testsuite/gdb.rust/simple.exp
@@ -110,6 +110,18 @@ gdb_test "print univariant.a" " = 1"
110110 gdb_test "print univariant_anon" " = simple::UnivariantAnon::Foo\\(1\\)"
111111 gdb_test "print univariant_anon.0" " = 1"
112112
113+gdb_test_sequence "ptype simple::Univariant" "" {
114+ "type = enum simple::Univariant \\{"
115+ " Foo\\{a: u8\\},"
116+ "\\}"
117+}
118+
119+gdb_test_sequence "ptype simple::UnivariantAnon" "" {
120+ "type = enum simple::UnivariantAnon \\{"
121+ " Foo\\(u8\\),"
122+ "\\}"
123+}
124+
113125 gdb_test_sequence "ptype simple::ByeBob" "" {
114126 " = struct simple::ByeBob \\("
115127 " i32,"