GNU Binutils with patches for OS216
修订版 | f0fd41c1926984fd1a524ff551286cba694539a0 (tree) |
---|---|
时间 | 2017-02-04 14:14:36 |
作者 | Tom Tromey <tom@trom...> |
Commiter | Tom Tromey |
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.
@@ -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 | + | |
1 | 7 | 2017-02-03 Pedro Alves <palves@redhat.com> |
2 | 8 | |
3 | 9 | * cli/cli-interp.c (cli_interp_base::cli_interp_base) |
@@ -977,6 +977,8 @@ rust_print_type (struct type *type, const char *varstring, | ||
977 | 977 | skip_to = 0; |
978 | 978 | } |
979 | 979 | } |
980 | + else if (TYPE_NFIELDS (type) == 1) | |
981 | + skip_to = 0; | |
980 | 982 | |
981 | 983 | for (i = 0; i < TYPE_NFIELDS (type); ++i) |
982 | 984 | { |
@@ -989,7 +991,9 @@ rust_print_type (struct type *type, const char *varstring, | ||
989 | 991 | if (TYPE_NFIELDS (variant_type) > skip_to) |
990 | 992 | { |
991 | 993 | 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)); | |
993 | 997 | int j; |
994 | 998 | |
995 | 999 | fputs_filtered (is_tuple ? "(" : "{", stream); |
@@ -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 | + | |
1 | 6 | 2017-02-02 Pedro Alves <palves@redhat.com> |
2 | 7 | |
3 | 8 | * gdb.mi/mi-logging.exp: Add "redirect while already logging" |
@@ -110,6 +110,18 @@ gdb_test "print univariant.a" " = 1" | ||
110 | 110 | gdb_test "print univariant_anon" " = simple::UnivariantAnon::Foo\\(1\\)" |
111 | 111 | gdb_test "print univariant_anon.0" " = 1" |
112 | 112 | |
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 | + | |
113 | 125 | gdb_test_sequence "ptype simple::ByeBob" "" { |
114 | 126 | " = struct simple::ByeBob \\(" |
115 | 127 | " i32," |