From patchwork Mon Jul 4 12:42:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Goregaokar X-Patchwork-Id: 13612 Received: (qmail 127247 invoked by alias); 4 Jul 2016 12:42:55 -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 127226 invoked by uid 89); 4 Jul 2016 12:42:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=non-array, 87, 6, nonarray, low_bound X-HELO: mail-wm0-f43.google.com Received: from mail-wm0-f43.google.com (HELO mail-wm0-f43.google.com) (74.125.82.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 04 Jul 2016 12:42:42 +0000 Received: by mail-wm0-f43.google.com with SMTP id f126so102302806wma.1 for ; Mon, 04 Jul 2016 05:42:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=puCo1/E67NReeKxjcwYyrwIpQeaEEeUMY6y7nrNxDzE=; b=BVy646LH0oEGZvxOIYZG0Om9GqZ6nWyqiLvNsuKTNJcVkU39QfLyIUupoK7sMYOKZY eB6Dd1Xq9u3zHHVUgLU+VmeZXfphGL4ON1dSSV6BM9VaGwTtYOOvAbURw55d4cX5gjJD c6mN85v6rUQ0VFepo+jURui8D+wqwAS+zXNbQ8DJCfA9T9+lH0/DFtR4eihHa0Bx6YRW QN+13oblwfWNpnHi8QafqBXzLKVVoDaY5TDu0Xx3m/Bm356+my5skpTuFWxr8ftxIsOY r/ScUra3JA4AFrK4ddHKY4TtPyrUVE8kAURIjLzGkPMYkl1ECgxOemr91+CrqD6xa9ds EgLA== X-Gm-Message-State: ALyK8tL4xamroIpU2DY3jAqikv7XptLEbo624X9ajNWAGKnPaUhS4K95ZjIEj6coa4KF4EW3lTCyt62rI4JLZvKB X-Received: by 10.28.4.140 with SMTP id 134mr10755819wme.91.1467636159241; Mon, 04 Jul 2016 05:42:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.36.215 with HTTP; Mon, 4 Jul 2016 05:42:18 -0700 (PDT) From: Manish Goregaokar Date: Mon, 4 Jul 2016 18:12:18 +0530 Message-ID: Subject: [PATCH] Allow subscripting raw pointers To: gdb-patches@sourceware.org, Tom Tromey X-IsSubscribed: yes This will be useful for dealing with vectors; regardless of our final solution for the Index trait. Right now subscripting vectors requires dancing between C and Rust mode. 2016-07-04 Manish Goregaokar gdb/ChangeLog: * rust-lang.c (rust_subscript): Allow subscripting pointers gdb/testsuite/ChangeLog: * simple.rs: Add test for raw pointer subscripting * simple.exp: Add test expectations --- gdb/rust-lang.c | 6 ++++++ gdb/testsuite/gdb.rust/simple.exp | 1 + gdb/testsuite/gdb.rust/simple.rs | 1 + 3 files changed, 8 insertions(+) diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 1849349..17b20c6 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -1415,6 +1415,12 @@ rust_subscript (struct expression *exp, int *pos, enum noside noside, low_bound = 0; high_bound = value_as_long (len); } + else if (TYPE_CODE (type) == TYPE_CODE_PTR) + { + base = lhs; + low_bound = 0; + high_bound = LONGEST_MAX; + } else error (_("Cannot subscript non-array type")); diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp index 4622f75..32b3785 100644 --- a/gdb/testsuite/gdb.rust/simple.exp +++ b/gdb/testsuite/gdb.rust/simple.exp @@ -73,6 +73,7 @@ gdb_test "print w" " = \\\[1, 2, 3, 4\\\]" gdb_test "ptype w" " = \\\[i32; 4\\\]" gdb_test "print w\[2\]" " = 3" gdb_test "print w\[2\] @ 2" " = \\\[3, 4\\\]" +gdb_test "print w_ptr\[2\]" " = 3" gdb_test "print fromslice" " = 3" gdb_test "print slice\[0\]" " = 3" gdb_test "print slice as &\[i32\]\[0\]" " = 3" diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs index 3d28e27..4980826 100644 --- a/gdb/testsuite/gdb.rust/simple.rs +++ b/gdb/testsuite/gdb.rust/simple.rs @@ -87,6 +87,7 @@ fn main () { let v = Something::Three; let w = [1,2,3,4]; + let w_ptr = &w[0]; let x = (23, 25.5); let y = HiBob {field1: 7, field2: 8}; let z = ByeBob(7, 8);