From patchwork Mon Nov 19 18:24:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30202 Received: (qmail 65754 invoked by alias); 19 Nov 2018 18:24:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 65589 invoked by uid 89); 19 Nov 2018 18:24:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=beta, Three, corner, meanwhile X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.89) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 19 Nov 2018 18:24:32 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway21.websitewelcome.com (Postfix) with ESMTP id AF17F40132466 for ; Mon, 19 Nov 2018 12:24:12 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id OoDUg1e0OPvAdOoDUgj4hY; Mon, 19 Nov 2018 12:24:12 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zynN1xhCsxmD5dlKnaXtXSQSDFH3eyC+seCMISP1kpg=; b=FOQ4+/8yBDRsVTLtZEpimdJ7rC kxrBEKcWSfNrUqS/IzDtaOTegLbHlLqCA3kyZ2S9KzWVtNr/VAuFlDxGeMgoWRF+3CwoLVkvbVDgp t8mIS5+e9xWuLm4Iy5dsj2htP; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:38198 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gOoDU-004NCD-GI; Mon, 19 Nov 2018 12:24:12 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [FYI v2] Handle TYPE_CODE_PTR when printing Rust types Date: Mon, 19 Nov 2018 11:24:08 -0700 Message-Id: <20181119182408.9001-1-tom@tromey.com> This changes the Rust type printers to handle TYPE_CODE_PTR. The current approach is not ideal, because currently the code can't distinguish between mut and const, or between pointers and references. (These are debuginfo deficiencies, for which there are rustc bugs on file.) Meanwhile, this at least clears up the case seen in PR rust/23625. Tested on x86-64 Fedora 28. The nightly compiler gives the best results, but I regression-tested with stable and beta as well. gdb/ChangeLog 2018-11-16 Tom Tromey PR rust/23625: * rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR. gdb/testsuite/ChangeLog 2018-11-19 Tom Tromey PR rust/23625: * gdb.rust/simple.exp: Add ptype test. Update expected output. * gdb.rust/expr.exp: Update expected output. Change one test. --- gdb/ChangeLog | 5 +++++ gdb/rust-lang.c | 14 ++++++++++++++ gdb/testsuite/ChangeLog | 6 ++++++ gdb/testsuite/gdb.rust/expr.exp | 4 ++-- gdb/testsuite/gdb.rust/simple.exp | 13 +++++++------ 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 436446c9f0b..3939d235cfc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2018-11-16 Tom Tromey + + PR rust/23625: + * rust-lang.c (rust_internal_print_type): Handle TYPE_CODE_PTR. + 2018-11-19 Simon Marchi * infrun.c (displaced_step_inferior_states): Change type to diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 152413a612f..0a327ee6195 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -918,6 +918,20 @@ rust_internal_print_type (struct type *type, const char *varstring, } break; + case TYPE_CODE_PTR: + { + if (TYPE_NAME (type) != nullptr) + fputs_filtered (TYPE_NAME (type), stream); + else + { + /* We currently can't distinguish between pointers and + references. */ + fputs_filtered ("*mut ", stream); + type_print (TYPE_TARGET_TYPE (type), "", stream, 0); + } + } + break; + default: c_printer: c_print_type (type, varstring, stream, show, level, flags); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index e7693a07f54..daa283994c2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-11-19 Tom Tromey + + PR rust/23625: + * gdb.rust/simple.exp: Add ptype test. Update expected output. + * gdb.rust/expr.exp: Update expected output. Change one test. + 2018-11-19 Tom Tromey * gdb.rust/simple.rs: Don't initialize empty_enum_value. diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp index 22e6b49b542..ec230c1a1a8 100644 --- a/gdb/testsuite/gdb.rust/expr.exp +++ b/gdb/testsuite/gdb.rust/expr.exp @@ -134,8 +134,8 @@ gdb_test "ptype \[23usize; 4\]" " = \\\[usize; 4\\\]" gdb_test "print \[mut 23usize; 4\]" " = \\\[23, 23, 23, 23\\\]" # Test lexer corner cases. -gdb_test "print 0x0 as *const ()" " = \\\(\\\(\\\) \\*\\\) 0x0" -gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\\(\\\) \\\(\\*\\\)\\\(i64\\\)\\\) 0x0" +gdb_test "print 0x0 as *mut ()" " = \\\(\\*mut \\\(\\\)\\\) 0x0" +gdb_test "print 0x0 as fn(i64) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\\\) 0x0" gdb_test "print r#" "syntax error in expression, near `#'\\." gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22" diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index 956a6ca6fee..f02ff676db6 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -54,6 +54,7 @@ gdb_test "print *&c" " = 0" gdb_test "print *(&c as &i32)" " = 0" gdb_test "print *(&c as *const i32)" " = 0" gdb_test "print *(&c as *mut i32)" " = 0" +gdb_test "ptype &c as *mut i32" "\\*mut i32" gdb_test "print/c f\[0\]" " = 104 'h'" @@ -68,8 +69,8 @@ gdb_test "print f" " = \"hi bob\"" gdb_test "print fslice" " = \"bob\"" gdb_test "print &f\[3..\]" " = \"bob\"" -gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\"" -gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]" +gdb_test "print g" " = \\(\\*mut \\\[u8; 6\\\]\\) $hex b\"hi bob\"" +gdb_test "ptype g" " = \\*mut \\\[u8; 6\\\]" gdb_test "print v" " = simple::Something::Three" gdb_test_sequence "ptype v" "" { @@ -91,19 +92,19 @@ gdb_test "print slice as &\[i32\]\[0\]" " = 3" gdb_test_sequence "ptype slice" "" { " = struct &\\\[i32\\\] \\{" - " data_ptr: i32 \\*," + " data_ptr: \\*mut i32," " length: usize," "\\}" } gdb_test_sequence "ptype &slice\[..\]" "" { " = struct &\\\[i32\\\] \\{" - " data_ptr: i32 \\*," + " data_ptr: \\*mut i32," " length: usize," "\\}" } gdb_test_sequence "ptype &b\[..\]" "" { " = struct &\\\[\\*gdb\\*\\\] \\{" - " data_ptr: i32 \\*," + " data_ptr: \\*mut i32," " length: usize," "\\}" } @@ -281,7 +282,7 @@ gdb_test "print 23..97.0" "Range expression with different types" gdb_test "print (*parametrized.next.val)" \ " = simple::ParametrizedStruct {next: simple::ParametrizedEnum<\[a-z:\]*Box>>::Empty, value: 1}" gdb_test "print parametrized.next.val" \ - " = \\(simple::ParametrizedStruct \\*\\) $hex" + " = \\(\\*mut simple::ParametrizedStruct\\) $hex" gdb_test "print parametrized" \ " = simple::ParametrizedStruct \\{next: simple::ParametrizedEnum<\[a-z:\]*Box>>::Val\\{val: $hex\\}, value: 0\\}"