]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Print type name when printing Rust slice
authorTom Tromey <tromey@adacore.com>
Thu, 7 Mar 2024 19:57:07 +0000 (12:57 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 2 Apr 2024 17:37:32 +0000 (11:37 -0600)
The recent change to how unsized Rust values are printed included a
small regression from past behavior.  Previously, a slice's type would
be printed, like:

    (gdb) print slice
    $80 = &[i32] [3]

The patch changed this to just

    (gdb) print slice
    $80 = [3]

This patch restores the previous behavior.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30330
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31517

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

index 64e40577a69681c2e1e050d5cbb962517a2e4218..53e7356c451e7a02ec91466dfdfa2c4f5ef30cb2 100644 (file)
@@ -475,6 +475,17 @@ rust_language::val_print_slice
        }
     }
 
+  /* Print the slice type here.  This was gdb's historical behavior
+     (from before unsized types were generically handled) and helps
+     make it clear that the user is seeing a slice, not an array.
+     Only arrays must be handled as the other cases are handled by
+     value_print_inner.  */
+  if (type->code () == TYPE_CODE_ARRAY)
+    {
+      type_print (orig_type, "", stream, -1);
+      gdb_printf (stream, " ");
+    }
+
   value_print_inner (val, stream, recurse, options);
 }
 
index 7f5fbad7a3fae342870b0af1a7aed69dec6673a8..1e6fc94400e10ec113216e467771657ddcf0929f 100644 (file)
@@ -317,7 +317,7 @@ proc test_one_slice {svar length base range} {
        global hex
 
        # Just accept any array here.
-       set result " = \\\[.*\\\]"
+       set result " = &\\\[.*\\\] \\\[.*\\\]"
 
        gdb_test "print $svar" $result
        gdb_test "print &${base}\[${range}\]" $result
index fab655790e6729e2e479f862238915219b7c0fbb..ea5f281cb3d7c65cede1e4aacb3086a667b3709b 100644 (file)
@@ -33,6 +33,6 @@ if {![runto ${srcfile}:$line]} {
 gdb_test "ptype us" " = .*V<\\\[u8\\\]>.*"
 
 if {[rust_at_least 1.61]} {
-    gdb_test "print us2" " = \\\[1, 2, 3\\\]"
+    gdb_test "print us2" " = .*u8.* \\\[1, 2, 3\\\]"
     gdb_test "ptype us2" "type = .*"
 }