From patchwork Thu Aug 17 08:47:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 22176 Received: (qmail 100164 invoked by alias); 17 Aug 2017 08:47:47 -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 97283 invoked by uid 89); 17 Aug 2017 08:47:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 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, UNSUBSCRIBE_BODY autolearn=ham version=3.3.2 spammy= X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr50080.outbound.protection.outlook.com (HELO EUR03-VE1-obe.outbound.protection.outlook.com) (40.107.5.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Aug 2017 08:47:43 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com (10.160.211.19) by AM3PR08MB0101.eurprd08.prod.outlook.com (10.160.211.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1341.17; Thu, 17 Aug 2017 08:47:40 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::b8e2:8809:e2b2:ae37]) by AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::b8e2:8809:e2b2:ae37%14]) with mapi id 15.01.1341.024; Thu, 17 Aug 2017 08:47:40 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH 2/7] Regcache: Only target_regcache reads/writes go to the target Date: Thu, 17 Aug 2017 08:47:40 +0000 Message-ID: <9C3CF11A-EBAE-432D-ABB6-37E88A10CBB4@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM3PR08MB0101; 6:1fbMaJtv+IZqffe5DLVNGT5PwRKboN47c7ma/6pukEth4SFwVgB3Q8Zg2koydhf3Gxk5xdOyaTTaq84pUrhqJ1e625BEObnaj8W8ShfQGAAIv4BqemiOz+hAbjZuijh0OM2qSYeRQigEaMZmYUAq0PviJUqZj1nsj9NOEK78qKlnduja6g/wYBlhVa20/nt2mpaXMeE7GSEj//9ZtxqMuSKzfqN4m7khLexTrohav+U6/QT51CtAouCpPRLnjz0gWyseX61YGOH/rZYCAtHvIhz03Bb/KEAjvNaaS6NoVkWBWulFIQo8+uJDhYE/31WAaDRY858DPzz4gmdTzmFsiA==; 5:a8BJDmdDQEomVOzA6etfTjaat3lsmS5AB/Okwkkqiff/MmLg46odG4OBQJvhmV9oB/Gg2p/RG6ziuxHYu6ict+TRw91AnbbhWmfmul0E2xmhxFtGz4CBPQX54DQMR1LiArFpsq2tAImrbtrW1XUYDw==; 24:EaQCcckkBqULw6gPHvRIeqoyyE2esIeD1P9I/ZBz5stDKBWvgb8dwb1M6cvcwExZLqBpnK708Z1u2nM5JCd/ZDH2YvgixDPnJFZ7N0O7s8Y=; 7:Rfrjq9DLATfldOoGjzd7w69BnFPz/wOgn8RBiu0tnLSERLAQz7qFAdcLDwcNnW3UvG5ssXyvQUGpyJoGmQne8wAjRMyjzqJRjqyM1upyjW1HvrCzN9RpNNdTGtxwHNVuv7UijkCU7zKTk/mG8M1TGf6ilhjNOlnZ8zH2TQC0VeyCQ7Ao3+P6xItapJaQGIJLNnmVEKMk3wlTNJaRJbQkQ0EQtAMNh/TeL98qXFyOlTM= x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: 0943dc05-c829-4695-f082-08d4e54c9e5f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(48565401081)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM3PR08MB0101; x-ms-traffictypediagnostic: AM3PR08MB0101: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM3PR08MB0101; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM3PR08MB0101; x-forefront-prvs: 0402872DA1 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(199003)(377424004)(189002)(81166006)(68736007)(86362001)(3280700002)(478600001)(189998001)(2501003)(5640700003)(99286003)(5660300001)(2906002)(6436002)(25786009)(7736002)(53936002)(3660700001)(33656002)(3846002)(305945005)(6512007)(36756003)(102836003)(101416001)(97736004)(8936002)(6116002)(66066001)(14454004)(50986999)(6916009)(2900100001)(8676002)(54356999)(6486002)(106356001)(105586002)(72206003)(6506006)(81156014)(2351001)(82746002)(83716003)(4326008)(110136004)(5890100001)(5250100002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0101; H:AM3PR08MB0101.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <6E47F3E3D51B6B4A88D448426AD346A6@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Aug 2017 08:47:40.2039 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0101 X-IsSubscribed: yes This patch ensures that only a target_regcache can call down to the target. This is done by virtualising raw_read, raw_write and raw_update. In a target_regcache, these functions continue to work as they have always done. A target_regcache cannot be readonly, so does not need to check this. In a regcache, these functions now do not call down to the target. Effectively, raw_read becomes raw_collect, raw_write becomes raw_set_cached_value and raw_update becomes a no op. There are no other functions in regcache that call down to the target. Functions such as raw_read_unsigned or cooked_write all use the above three functions. Tested on a --enable-targets=all build with board files unix, native-gdbserver and unittest.exp. 2017-08-16 Alan Hayward * regcache.h: (regcache::raw_update): No op function. * regcache.c (target_regcache::raw_update): Retain existing functionality. (regcache::raw_read): Do not read from target. (target_regcache::raw_read): Retain existing functionality. (regcache::raw_write): Do not write to target. (target_regcache::raw_write): Retain existing functionality. diff --git a/gdb/regcache.h b/gdb/regcache.h index bc3f24cffe1413d521998ab3c8081833a2735754..aeac54e8d7b91e2bcf6a3e1ce8e781c3f994306b 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -242,7 +242,8 @@ typedef struct cached_reg } cached_reg_t; -/* A register cache. This is not connected to a target and ptid is unset. */ +/* A register cache. This is not connected to a target - reads and writes will + not be passed through to a target and ptid is unset. */ class regcache { @@ -283,14 +284,8 @@ public: enum register_status cooked_read (int regnum, gdb_byte *buf); void cooked_write (int regnum, const gdb_byte *buf); - enum register_status raw_read (int regnum, gdb_byte *buf); - - /* class regcache is only extended in unit test, so only mark it - virtual when selftest is enabled. */ -#if GDB_SELF_TEST - virtual -#endif - void raw_write (int regnum, const gdb_byte *buf); + virtual enum register_status raw_read (int regnum, gdb_byte *buf); + virtual void raw_write (int regnum, const gdb_byte *buf); template> enum register_status raw_read (int regnum, T *val); @@ -306,7 +301,7 @@ public: template> void cooked_write (int regnum, T val); - void raw_update (int regnum); + virtual void raw_update (int regnum) {} void raw_collect (int regnum, void *buf) const; @@ -403,12 +398,19 @@ private: }; -/* A register cache that can be attached to a target. ptid can be set. */ +/* A register cache attached to a target. Reads and writes of register values + will be passed through to the target and ptid can be set. */ class target_regcache : public regcache { public: + /* Overridden regcache methods. These versions will pass the read/write + through to the target. */ + enum register_status raw_read (int regnum, gdb_byte *buf); + virtual void raw_write (int regnum, const gdb_byte *buf); + void raw_update (int regnum); + ptid_t ptid () const { return m_ptid; diff --git a/gdb/regcache.c b/gdb/regcache.c index 3d6ca86006fa59463069808f6e5b355028c4d3cc..524ac5754f6d2c1b00097b15a40b928845e45a59 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -597,16 +597,14 @@ regcache_raw_update (struct regcache *regcache, int regnum) } void -regcache::raw_update (int regnum) +target_regcache::raw_update (int regnum) { gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); /* Make certain that the register cache is up-to-date with respect - to the current thread. This switching shouldn't be necessary - only there is still only one target side register cache. Sigh! - On the bright side, at least there is a regcache object. */ + to the current thread. */ - if (!m_readonly_p && get_register_status (regnum) == REG_UNKNOWN) + if (get_register_status (regnum) == REG_UNKNOWN) { target_fetch_registers (this, regnum); @@ -627,7 +625,16 @@ regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf) enum register_status regcache::raw_read (int regnum, gdb_byte *buf) { + raw_collect (regnum, buf); + return (enum register_status) m_register_status[regnum]; +} + +enum register_status +target_regcache::raw_read (int regnum, gdb_byte *buf) +{ gdb_assert (buf != NULL); + + /* Read register value from the target into the regcache. */ raw_update (regnum); if (m_register_status[regnum] != REG_VALID) @@ -895,11 +902,25 @@ regcache_raw_write (struct regcache *regcache, int regnum, void regcache::raw_write (int regnum, const gdb_byte *buf) { + gdb_assert (buf != NULL); + gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); + gdb_assert (!m_readonly_p); + + /* On the sparc, writing %g0 is a no-op, so we don't even want to + change the registers array if something writes to this register. */ + if (gdbarch_cannot_store_register (arch (), regnum)) + return; + + raw_set_cached_value (regnum, buf); +} + +void +target_regcache::raw_write (int regnum, const gdb_byte *buf) +{ struct cleanup *old_chain; gdb_assert (buf != NULL); gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers); - gdb_assert (!m_readonly_p); /* On the sparc, writing %g0 is a no-op, so we don't even want to change the registers array if something writes to this register. */