This is the mail archive of the gdb-cvs@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]

[binutils-gdb] Print Rust unsized array types a bit more nicely


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

commit e6cf65f283b8be44014fad0ad0aebfbcc71fceac
Author: Tom Tromey <tom@tromey.com>
Date:   Sun May 21 17:00:10 2017 -0600

    Print Rust unsized array types a bit more nicely
    
    It's a bit difficult to create an unsized array type in Rust, but if
    you do, right now ptype will show something like "[u8; ]".  It really
    should print "[u8]", though, which is what this patch implements.
    
    This is part of PR 21466.
    
    Built and regtested on x86-64 Fedora 25.  I'm checking this in.
    
    ChangeLog
    2017-05-21  Tom Tromey  <tom@tromey.com>
    
    	PR rust/21466:
    	* rust-lang.c (rust_print_type) <TYPE_CODE_ARRAY>: Print unsized
    	arrays as "[T]", not "[T; ]".
    
    testsuite/ChangeLog
    2017-05-21  Tom Tromey  <tom@tromey.com>
    
    	PR rust/21466:
    	* gdb.rust/unsized.exp: New file.
    	* gdb.rust/unsized.rs: New file.

Diff:
---
 gdb/ChangeLog                      |  6 ++++++
 gdb/rust-lang.c                    |  5 ++---
 gdb/testsuite/ChangeLog            |  6 ++++++
 gdb/testsuite/gdb.rust/unsized.exp | 35 +++++++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.rust/unsized.rs  | 33 +++++++++++++++++++++++++++++++++
 5 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1cc5dc9..c0fcb22 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-21  Tom Tromey  <tom@tromey.com>
+
+	PR rust/21466:
+	* rust-lang.c (rust_print_type) <TYPE_CODE_ARRAY>: Print unsized
+	arrays as "[T]", not "[T; ]".
+
 2017-05-19  Tom Tromey  <tom@tromey.com>
 
 	PR rust/21484:
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index dce184c..d4cda1f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -893,13 +893,12 @@ rust_print_type (struct type *type, const char *varstring,
 	fputs_filtered ("[", stream);
 	rust_print_type (TYPE_TARGET_TYPE (type), NULL,
 			 stream, show - 1, level, flags);
-	fputs_filtered ("; ", stream);
 
 	if (TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCEXPR
 	    || TYPE_HIGH_BOUND_KIND (TYPE_INDEX_TYPE (type)) == PROP_LOCLIST)
-	  fprintf_filtered (stream, "variable length");
+	  fprintf_filtered (stream, "; variable length");
 	else if (get_array_bounds (type, &low_bound, &high_bound))
-	  fprintf_filtered (stream, "%s", 
+	  fprintf_filtered (stream, "; %s",
 			    plongest (high_bound - low_bound + 1));
 	fputs_filtered ("]", stream);
       }
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index adbf398..c16f201 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-21  Tom Tromey  <tom@tromey.com>
+
+	PR rust/21466:
+	* gdb.rust/unsized.exp: New file.
+	* gdb.rust/unsized.rs: New file.
+
 2017-05-19  Tom Tromey  <tom@tromey.com>
 
 	PR rust/21484:
diff --git a/gdb/testsuite/gdb.rust/unsized.exp b/gdb/testsuite/gdb.rust/unsized.exp
new file mode 100644
index 0000000..700b214
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/unsized.exp
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test expression parsing and evaluation that requires Rust compiler.
+
+load_lib rust-support.exp
+if {[skip_rust_tests]} {
+    continue
+}
+
+standard_testfile .rs
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
+    return -1
+}
+
+set line [gdb_get_line_number "set breakpoint here"]
+if {![runto ${srcfile}:$line]} {
+    untested "could not run to breakpoint"
+    return -1
+}
+
+gdb_test "ptype *us" \
+    " = struct \[a-z:\]*V<\\\[u8\\\]> {.* data: \\\[u8\\\],.*}"
diff --git a/gdb/testsuite/gdb.rust/unsized.rs b/gdb/testsuite/gdb.rust/unsized.rs
new file mode 100644
index 0000000..7081a11
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/unsized.rs
@@ -0,0 +1,33 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#![allow(dead_code)]
+#![allow(unused_variables)]
+#![allow(unused_assignments)]
+
+struct V<T: ?Sized> {
+    data: T,
+}
+
+type Unsized = V<[u8]>;
+
+fn ignore<T>(x: T) { }
+
+fn main() {
+    let v: Box<V<[u8; 3]>> = Box::new(V { data: [1, 2, 3] });
+    let us: Box<Unsized> = v;
+
+    ignore(us);     // set breakpoint here
+}


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