From patchwork Wed Jun 6 15:16:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 27662 Received: (qmail 102167 invoked by alias); 6 Jun 2018 15:17:12 -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 101897 invoked by uid 89); 6 Jun 2018 15:17:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 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, SPF_PASS autolearn=ham version=3.3.2 spammy=5011 X-HELO: EUR02-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr10087.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.107.1.87) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 06 Jun 2018 15:17:08 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from C02TF0U7HF1T.arm.com (217.140.96.140) by AM4PR0802MB2132.eurprd08.prod.outlook.com (2603:10a6:200:5c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.841.14; Wed, 6 Jun 2018 15:16:52 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH v2 04/10] Add regcache raw_compare method Date: Wed, 6 Jun 2018 16:16:23 +0100 Message-Id: <20180606151629.36602-5-alan.hayward@arm.com> In-Reply-To: <20180606151629.36602-1-alan.hayward@arm.com> References: <20180606151629.36602-1-alan.hayward@arm.com> MIME-Version: 1.0 X-ClientProxiedBy: CWLP265CA0083.GBRP265.PROD.OUTLOOK.COM (2603:10a6:401:50::23) To AM4PR0802MB2132.eurprd08.prod.outlook.com (2603:10a6:200:5c::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-TrafficTypeDiagnostic: AM4PR0802MB2132: NoDisclaimer: True X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-MS-Exchange-SenderADCheck: 1 X-Forefront-PRVS: 06952FC175 Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Office365-Filtering-Correlation-Id: c1b6558d-d001-41d0-3ce9-08d5cbc08880 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2018 15:16:52.4401 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1b6558d-d001-41d0-3ce9-08d5cbc08880 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2132 X-IsSubscribed: yes raw_compare returns the same as a memcmp (0 for success, the diff otherwise). Kept with tristate return as this feels potentally more useful than a simple true/false return. (Happy to change if not). 2018-06-06 Alan Hayward gdb/ * common/common-regcache.h (raw_compare): New function. * regcache.c (regcache::raw_compare): Likewise. * regcache.h (regcache::raw_compare): New declaration. gdbserver/ * regcache.c (regcache::raw_compare): New function. * regcache.h (regcache::raw_compare): New declaration. --- gdb/common/common-regcache.h | 1 + gdb/gdbserver/regcache.c | 10 ++++++++++ gdb/gdbserver/regcache.h | 5 +++++ gdb/regcache.c | 15 +++++++++++++++ gdb/regcache.h | 11 +++++++++++ 5 files changed, 42 insertions(+) diff --git a/gdb/common/common-regcache.h b/gdb/common/common-regcache.h index 487da0a7fb..e91439bec5 100644 --- a/gdb/common/common-regcache.h +++ b/gdb/common/common-regcache.h @@ -67,6 +67,7 @@ struct reg_buffer_common virtual ~reg_buffer_common () = default; virtual void raw_supply (int regnum, const void *buf) = 0; virtual void raw_collect (int regnum, void *buf) const = 0; + virtual int raw_compare (int regnum, const void *buf, int offset) const = 0; virtual register_status get_register_status (int regnum) const = 0; }; diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c index 857721ee3d..9648428349 100644 --- a/gdb/gdbserver/regcache.c +++ b/gdb/gdbserver/regcache.c @@ -501,3 +501,13 @@ regcache::get_register_status (int regnum) const return REG_VALID; #endif } + +/* See gdbserver/regcache.h. */ + +int +regcache::raw_compare (int regnum, const void *buf, int offset) const +{ + gdb_assert (register_size (tdesc, regnum) > offset); + return memcmp (buf, register_data (this, regnum, 1) + offset, + register_size (tdesc, regnum) - offset); +} diff --git a/gdb/gdbserver/regcache.h b/gdb/gdbserver/regcache.h index 1842f1d9cf..b26f39a8ad 100644 --- a/gdb/gdbserver/regcache.h +++ b/gdb/gdbserver/regcache.h @@ -50,6 +50,11 @@ struct regcache : public reg_buffer_common void raw_collect (int regnum, void *buf) const override; + /* Compare the contents of the register stored in the regcache (ignoring the + first OFFSET bytes) to the contents of BUF (without any offset). Returns + the same result as memcmp. */ + int raw_compare (int regnum, const void *buf, int offset) const override; + enum register_status get_register_status (int regnum) const override; }; diff --git a/gdb/regcache.c b/gdb/regcache.c index a914b548ca..383e355e9f 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1082,6 +1082,21 @@ regcache::collect_regset (const struct regset *regset, transfer_regset (regset, NULL, regnum, NULL, buf, size); } +/* See regcache.h. */ + +int +regcache::raw_compare (int regnum, const void *buf, int offset) const +{ + const char *regbuf; + size_t size; + + gdb_assert (buf != NULL); + assert_regnum (regnum); + + regbuf = (const char *) register_buffer (regnum); + size = m_descr->sizeof_register[regnum]; + return memcmp (buf, regbuf + offset, size - offset); +} /* Special handling for register PC. */ diff --git a/gdb/regcache.h b/gdb/regcache.h index b559a10752..03fb4f2452 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -169,6 +169,12 @@ public: gdb_assert (false); } + virtual int raw_compare (int regnum, const void *buf, + int offset) const override + { + gdb_assert (false); + } + protected: /* Assert on the range of REGNUM. */ void assert_regnum (int regnum) const; @@ -325,6 +331,11 @@ public: void collect_regset (const struct regset *regset, int regnum, void *buf, size_t size) const; + /* Compare the contents of the register stored in the regcache (ignoring the + first OFFSET bytes) to the contents of BUF (without any offset). Returns + the same result as memcmp. */ + int raw_compare (int regnum, const void *buf, int offset) const override; + /* Return REGCACHE's ptid. */ ptid_t ptid () const