From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 5C04B3858D28; Tue, 2 Apr 2024 17:44:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C04B3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712079867; bh=xtVhljQJTceehT5GMXMO+sSv7LewyHmmjsRKjXc5ZGM=; h=From:To:Subject:Date:From; b=oXDj8NRYeyYOdKBNVyoi0fNk/74O+tXQ2Sz0G/d3oqF2YT2Q2D5c6cPn9NDGLJWHJ 5e7bQLfD6kIAdYCUJ3fyiSqQvQ8ki32rmgg8VUNHFOT5s3520PlCkEMR5YaME6hvcG SIqQZdvOHNBdzD6blHQ+3tqi51bTNi2byHW+H/Y4= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Print type name when printing Rust slice X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 051889c8104c3c959b903d08e9afbcb7e9670c43 X-Git-Newrev: 251cedaeb57fe1e0fd28798f476fbee75373bbf4 Message-Id: <20240402174427.5C04B3858D28@sourceware.org> Date: Tue, 2 Apr 2024 17:44:27 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D251cedaeb57f= e1e0fd28798f476fbee75373bbf4 commit 251cedaeb57fe1e0fd28798f476fbee75373bbf4 Author: Tom Tromey Date: Thu Mar 7 12:57:07 2024 -0700 Print type name when printing Rust slice =20 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: =20 (gdb) print slice $80 =3D &[i32] [3] =20 The patch changed this to just =20 (gdb) print slice $80 =3D [3] =20 This patch restores the previous behavior. =20 Reviewed-By: Simon Marchi Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30330 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31517 Diff: --- gdb/rust-lang.c | 11 +++++++++++ gdb/testsuite/gdb.rust/simple.exp | 2 +- gdb/testsuite/gdb.rust/unsized.exp | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 64e40577a69..53e7356c451 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -475,6 +475,17 @@ rust_language::val_print_slice } } =20 + /* 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 () =3D=3D TYPE_CODE_ARRAY) + { + type_print (orig_type, "", stream, -1); + gdb_printf (stream, " "); + } + value_print_inner (val, stream, recurse, options); } =20 diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/sim= ple.exp index 7f5fbad7a3f..1e6fc94400e 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -317,7 +317,7 @@ proc test_one_slice {svar length base range} { global hex =20 # Just accept any array here. - set result " =3D \\\[.*\\\]" + set result " =3D &\\\[.*\\\] \\\[.*\\\]" =20 gdb_test "print $svar" $result gdb_test "print &${base}\[${range}\]" $result diff --git a/gdb/testsuite/gdb.rust/unsized.exp b/gdb/testsuite/gdb.rust/un= sized.exp index fab655790e6..ea5f281cb3d 100644 --- a/gdb/testsuite/gdb.rust/unsized.exp +++ b/gdb/testsuite/gdb.rust/unsized.exp @@ -33,6 +33,6 @@ if {![runto ${srcfile}:$line]} { gdb_test "ptype us" " =3D .*V<\\\[u8\\\]>.*" =20 if {[rust_at_least 1.61]} { - gdb_test "print us2" " =3D \\\[1, 2, 3\\\]" + gdb_test "print us2" " =3D .*u8.* \\\[1, 2, 3\\\]" gdb_test "ptype us2" "type =3D .*" }