From patchwork Thu Apr 27 08:55:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 20180 Received: (qmail 37022 invoked by alias); 27 Apr 2017 08:55:56 -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 35978 invoked by uid 89); 27 Apr 2017 08:55:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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, KAM_LOTSOFHASH, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Supply, Went X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr30080.outbound.protection.outlook.com (HELO EUR03-AM5-obe.outbound.protection.outlook.com) (40.107.3.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Apr 2017 08:55:53 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com (10.160.211.19) by AM3PR08MB0102.eurprd08.prod.outlook.com (10.160.211.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1061.12; Thu, 27 Apr 2017 08:55:52 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::c065:778f:9924:8660]) by AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::c065:778f:9924:8660%14]) with mapi id 15.01.1047.019; Thu, 27 Apr 2017 08:55:52 +0000 From: Alan Hayward To: Yao Qi CC: "gdb-patches@sourceware.org" , nd Subject: Re: [PATCH 8/11] Add FRV_MAX_REGISTER_SIZE Date: Thu, 27 Apr 2017 08:55:52 +0000 Message-ID: <22BD364F-A9A9-4E21-BC47-96A320760640@arm.com> References: <3B3BD949-1C9D-44FF-AB6A-03091ECA49D0@arm.com> <867f2rw9br.fsf@gmail.com> In-Reply-To: authentication-results: gmail.com; dkim=none (message not signed) header.d=none; gmail.com; dmarc=none action=none header.from=arm.com; x-microsoft-exchange-diagnostics: 1; AM3PR08MB0102; 7:ebhhfebJ86yGgdw/2R8+If992Q3Ls+umAP5pCey8nPLJbc6Pq/fo1h7wd8l7BH54L0fHev0Y5a2fQL8EN5CTHHvYZXQSfWklJ/KLnG5VL06NzpmECX5SQWEIOpuZ5sho40k29L4Cq08PxmGzilfouGOfolkfbWNsGENClniSxXyWsrIWfL4pJBzw3/AAw/ArUz7iJgCS1TUIEVIclQKXVR56+XH1cIaKNFREixubkpcUaK5BGaeBex/O0Mqka5Gk+1mFPt0Ug4eQeQn9Y/akAzXHHegZguegZEqGrB7hRCJpQJZq9FjuqQy04JPP0YnhS4DPgalLeuUpycw4/LzDnQ== x-ms-office365-filtering-correlation-id: 040e5752-bf32-464c-6973-08d48d4b3580 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081); SRVR:AM3PR08MB0102; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123560025)(20161123562025)(20161123555025)(6072148); SRVR:AM3PR08MB0102; BCL:0; PCL:0; RULEID:; SRVR:AM3PR08MB0102; x-forefront-prvs: 029097202E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39400400002)(39410400002)(39450400003)(39850400002)(39840400002)(39860400002)(377424004)(24454002)(305945005)(39060400002)(25786009)(38730400002)(110136004)(229853002)(3660700001)(53546009)(6916009)(6486002)(3280700002)(6506006)(1411001)(7736002)(2950100002)(76176999)(189998001)(6246003)(66066001)(2906002)(8676002)(53936002)(2900100001)(8936002)(50986999)(54356999)(4326008)(6436002)(81166006)(33656002)(54906002)(575784001)(36756003)(86362001)(5250100002)(99286003)(5660300001)(6116002)(83716003)(102836003)(6512007)(82746002)(3846002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0102; H:AM3PR08MB0101.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <1E644D87DA1C494BB31EC456C48DC3B5@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Apr 2017 08:55:52.3822 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0102 > On 12 Apr 2017, at 09:27, Alan Hayward wrote: > > >> On 11 Apr 2017, at 11:02, Yao Qi wrote: >> >> Alan Hayward writes: >> >>> - char zerobuf[MAX_REGISTER_SIZE]; >>> + char zerobuf[FRV_MAX_REGISTER_SIZE]; >>> >>> - memset (zerobuf, 0, MAX_REGISTER_SIZE); >>> + memset (zerobuf, 0, FRV_MAX_REGISTER_SIZE); >>> >>> /* gr0 always contains 0. Also, the kernel passes the TBR value in >>> this slot. */ >> >> The code here fills some gr registers with zeros, >> >> /* gr0 always contains 0. Also, the kernel passes the TBR value in >> this slot. */ >> regcache_raw_supply (regcache, first_gpr_regnum, zerobuf); >> >> /* Fill gr32, ..., gr63 with zeros. */ >> for (regi = first_gpr_regnum + 32; regi <= last_gpr_regnum; regi++) >> regcache_raw_supply (regcache, regi, zerobuf); >> >> the size of these gr registers are know, 8 bytes. It won't be changed. >> We can do, >> >> gdb_byte zerobuf[8] = { 0 }; >> >> the code is still easy to read. If you really dislike magic number (IMO, 8 >> is not a magic number in this context), you can define FRR_GR_REGISTER_SIZE. >> >> Alternatively, you can add a new regache api, regcache_raw_supply_zero. >> Many places can use this api, and some uses of MAX_REGISTER_SIZE can be >> removed too, for example, >> >> regcache_raw_supply (regcache, MIPS_ZERO_REGNUM, zerobuf); >> >> -- >> Yao (齐尧) > > Went with the simpler solution. > > I don't have a FRV machine to test on. > Tested on a --enable-targets=all build using make check with board files > unix and native-gdbserver. > Looking again at my later patches, I agree that regcache_raw_supply_zero would be useful in other places too. I considered making regcache_raw_supply_zero call regcache_raw_supply, but in the end it made more sense to make it completely separate. I don't have a FRV machine to test on. Tested on a --enable-targets=all build using make check with board files unix and native-gdbserver. Ok to commit? Alan. 2017-04-27 Alan Hayward * gdb/frv-linux-tdep.c (frv_linux_supply_gregset): Call regcache_raw_supply_zero * gdb/regcache.c (regcache_raw_supply_zero): New. * gdb/regcache.h (regcache_raw_supply_zero): New declaration. diff --git a/gdb/frv-linux-tdep.c b/gdb/frv-linux-tdep.c index eb87f93058b0287e8f05c585d1b6aa1ff2bffb78..d52eb2163437e32029c989c2caecce8533f11a65 100644 --- a/gdb/frv-linux-tdep.c +++ b/gdb/frv-linux-tdep.c @@ -413,17 +413,14 @@ frv_linux_supply_gregset (const struct regset *regset, int regnum, const void *gregs, size_t len) { int regi; - char zerobuf[MAX_REGISTER_SIZE]; - - memset (zerobuf, 0, MAX_REGISTER_SIZE); /* gr0 always contains 0. Also, the kernel passes the TBR value in this slot. */ - regcache_raw_supply (regcache, first_gpr_regnum, zerobuf); + regcache_raw_supply_zero (regcache, first_gpr_regnum); /* Fill gr32, ..., gr63 with zeros. */ for (regi = first_gpr_regnum + 32; regi <= last_gpr_regnum; regi++) - regcache_raw_supply (regcache, regi, zerobuf); + regcache_raw_supply_zero (regcache, regi); regcache_supply_regset (regset, regcache, regnum, gregs, len); } diff --git a/gdb/regcache.h b/gdb/regcache.h index f201f0c084f40ccf276a7e1ba19050cbc11208ad..ff6e583a48f9200f4a46ea5fcca69bfdd2862dac 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -152,6 +152,12 @@ extern void regcache_raw_supply (struct regcache *regcache, extern void regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf); +/* Supply register REGNUM with zeroed value to REGCACHE. This is not the same + as calling regcache_raw_supply with NULL (which will set the state to + unavailable). */ + +extern void regcache_raw_supply_zero (struct regcache *regcache, int regnum); + /* Collect register REGNUM from SOURCE_REGCACHE and store its contents to DEST_REGCACHE. */ extern void regcache_raw_copy (const struct regcache *dest_regcache, diff --git a/gdb/regcache.c b/gdb/regcache.c index 20e43f486ff02f15000bebee2a4eb03db53111d4..03f7d216f7d2fb8dd2e5b1189c9743ed37facb30 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1125,6 +1125,27 @@ regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf) memcpy (buf, regbuf, size); } +/* Supply register REGNUM with zeroed value to REGCACHE. This is not the same + as calling regcache_raw_supply with NULL (which will set the state to + unavailable). */ + +void +regcache_raw_supply_zero (struct regcache *regcache, int regnum) +{ + void *regbuf; + size_t size; + + gdb_assert (regcache != NULL); + gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); + gdb_assert (!regcache->readonly_p); + + regbuf = register_buffer (regcache, regnum); + size = regcache->descr->sizeof_register[regnum]; + + memset (regbuf, 0, size); + regcache->register_status[regnum] = REG_VALID; +} + void regcache_raw_copy (const struct regcache *dest_regcache, int regnum, struct regcache *src_regcache)