From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 51E143857341; Fri, 15 Apr 2022 17:36:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51E143857341 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] Implement value_print for Rust X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 506ec52e8805d8edd538d6bd11750489a8c8bbee X-Git-Newrev: 1c9cc05244f67c4e5a888394b2c9a309164ca02d Message-Id: <20220415173602.51E143857341@sourceware.org> Date: Fri, 15 Apr 2022 17:36:02 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Apr 2022 17:36:02 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1c9cc05244f6= 7c4e5a888394b2c9a309164ca02d commit 1c9cc05244f67c4e5a888394b2c9a309164ca02d Author: Tom Tromey Date: Sun Mar 27 15:29:28 2022 -0600 Implement value_print for Rust =20 This adds an implementation of the value_print method to Rust. As described in PR rust/22254, this removes a bit of weird-looking output from some "print"s -- because c_value_print is bypassed. I don't have a test for the bug that inspired this patch, because I only know how to reproduce it when using a relatively old Rust compiler. However, the new "cast-printing" code in value_print is required, because omitting this causes some existing tests to fail. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D22254 Diff: --- gdb/rust-lang.c | 21 +++++++++++++++++++++ gdb/rust-lang.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index d4a221abb08..bf8dba99ecd 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -624,6 +624,27 @@ rust_language::value_print_inner } } =20 +/* See language.h. */ + +void +rust_language::value_print + (struct value *val, struct ui_file *stream, + const struct value_print_options *options) const +{ + value_print_options opts =3D *options; + opts.deref_ref =3D true; + + struct type *type =3D check_typedef (value_type (val)); + if (type->is_pointer_or_reference ()) + { + gdb_printf (stream, "("); + type_print (value_type (val), "", stream, -1); + gdb_printf (stream, ") "); + } + + return common_val_print (val, stream, 0, &opts, this); +} + =0C =20 static void diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h index 0e89b8822cb..514494a2c82 100644 --- a/gdb/rust-lang.h +++ b/gdb/rust-lang.h @@ -125,6 +125,11 @@ public: =20 /* See language.h. */ =20 + void value_print (struct value *val, struct ui_file *stream, + const struct value_print_options *options) const override; + + /* See language.h. */ + struct block_symbol lookup_symbol_nonlocal (const char *name, const struct block *block, const domain_enum domain) const override