From patchwork Fri Apr 7 08:32: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: 19888 Received: (qmail 105140 invoked by alias); 7 Apr 2017 08:32:57 -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 105128 invoked by uid 89); 7 Apr 2017 08:32:56 -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, MIME_BASE64_BLANKS, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2145 X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-ve1eur01on0070.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Apr 2017 08:32:54 +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_128_CBC_SHA256_P256) id 15.1.1005.10; Fri, 7 Apr 2017 08:32:53 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::5931:f431:f97d:943d]) by AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::5931:f431:f97d:943d%16]) with mapi id 15.01.1005.022; Fri, 7 Apr 2017 08:32:53 +0000 From: Alan Hayward To: Yao Qi CC: "gdb-patches@sourceware.org" , nd Subject: Re: [PATCH 7/11] Add BFIN_MAX_REGISTER_SIZE Date: Fri, 7 Apr 2017 08:32:52 +0000 Message-ID: References: <86tw63p2rx.fsf@gmail.com> <86d1croshn.fsf@gmail.com> In-Reply-To: <86d1croshn.fsf@gmail.com> authentication-results: gmail.com; dkim=none (message not signed) header.d=none; gmail.com; dmarc=none action=none header.from=arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-microsoft-exchange-diagnostics: 1; AM3PR08MB0101; 7:4ZUNImo3VkNcOiRNhAQfwZT+BhsPs51XeZsA42WfTFdsekIkJFD2aRrXC2cp8tM1+PXmKsE+AYQjReR5ml/pnC7170JxbIfnkQTPz24tICjg9zj686TGrOwsN0izYz/GcE5gxy/FKqjPwuMPequeP2DYK8b5PetcqUQoOkKmmMbkrni3TuJbY1W1t0skJuuxEnLWap1tmv2gN1WW6BcvwEBa5ronOHUH5qcrPXcP0S6EFREqUIvt6RXhei3IFkyxkH78g/pC4SYgL+6ybdL6Frpq4gQo4cDTMcs3cJf4Sgmoe70N6bSwLQ5bcON0iaWv2zZZk72zCWQkUPZLoP1usg== x-ms-office365-filtering-correlation-id: 8a73c2a5-b475-4081-7077-08d47d90af13 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081); SRVR:AM3PR08MB0101; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(20161123562025)(6072148); SRVR:AM3PR08MB0101; BCL:0; PCL:0; RULEID:; SRVR:AM3PR08MB0101; x-forefront-prvs: 0270ED2845 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(39840400002)(39450400003)(39410400002)(39850400002)(39400400002)(377424004)(24454002)(53546009)(33656002)(8676002)(38730400002)(110136004)(4326008)(25786009)(39060400002)(81166006)(93886004)(1411001)(36756003)(5250100002)(54356999)(50986999)(76176999)(66066001)(6506006)(6436002)(305945005)(7736002)(6486002)(2950100002)(6916009)(229853002)(6246003)(3846002)(102836003)(6116002)(6512007)(99286003)(54906002)(5660300001)(2906002)(53936002)(8936002)(3280700002)(3660700001)(86362001)(189998001)(2900100001)(83716003)(82746002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0101; H:AM3PR08MB0101.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Apr 2017 08:32:52.7728 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0101 > On 5 Apr 2017, at 15:10, Yao Qi wrote: > > Alan Hayward writes: > >> Is it not clearer code to add and use a macro rather than a magic number ? >> > > Macro is better, but "buf[4]" is not that magic, because it is only used > within bfin_pseudo_register_read, or we can define ASTAT_REGISTER_SIZE. > >> It’s also not obvious anywhere that the astat register is 32bits. I had to go >> digging inside regformats/reg-bfin.dat before I found it out. > > It is easier to figure out the size of a specific register than the max > size of a set of registers. > >> >> Given that BFIN_MAX_REGISTER_SIZE is also 4, it compiles to the same >> size anyway. > > "gdb_byte buf[BFIN_MAX_REGISTER_SIZE]" is fine to me. Could you define > BFIN_MAX_REGISTER_SIZE in bfin-tdep.c instead of .h? It is not used > elsewhere. > Ok, pushed the following: 2017-04-07 Alan Hayward * bfin-tdep.c (BFIN_MAX_REGISTER_SIZE): Add. (bfin_pseudo_register_read): Use BFIN_MAX_REGISTER_SIZE. (bfin_pseudo_register_write): Likewise diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c index 3df1ba387a323dc6827b1189432f8877d1833184..c590a9132c00f539b5c6e57b8f156845ff50acad 100644 --- a/gdb/bfin-tdep.c +++ b/gdb/bfin-tdep.c @@ -241,6 +241,8 @@ static const int map_gcc_gdb[] = BFIN_LB1_REGNUM }; +/* Big enough to hold the size of the largest register in bytes. */ +#define BFIN_MAX_REGISTER_SIZE 4 struct bfin_frame_cache { @@ -689,7 +691,7 @@ static enum register_status bfin_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, int regnum, gdb_byte *buffer) { - gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE); + gdb_byte buf[BFIN_MAX_REGISTER_SIZE]; enum register_status status; if (regnum != BFIN_CC_REGNUM) @@ -710,7 +712,7 @@ static void bfin_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, int regnum, const gdb_byte *buffer) { - gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE); + gdb_byte buf[BFIN_MAX_REGISTER_SIZE]; if (regnum != BFIN_CC_REGNUM) internal_error (__FILE__, __LINE__,