From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 52366 invoked by alias); 23 Mar 2017 14:45:45 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 52334 invoked by uid 89); 23 Mar 2017 14:45:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 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=cooked, (unknown) X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0045.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Mar 2017 14:45:42 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com (10.160.211.19) by AM3PR08MB0104.eurprd08.prod.outlook.com (10.160.211.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.14; Thu, 23 Mar 2017 14:45:39 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::a542:8c73:7479:1ad3]) by AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::a542:8c73:7479:1ad3%15]) with mapi id 15.01.0991.017; Thu, 23 Mar 2017 14:45:39 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: Re: [PATCH] Remove MAX_REGISTER_SIZE from regcache.c Date: Thu, 23 Mar 2017 14:45:00 -0000 Message-ID: <57078D19-76C9-4FE2-84E1-F46AAC48957B@arm.com> References: <562B2F6F-F3C6-4A76-9489-57539F396C94@arm.com> In-Reply-To: <562B2F6F-F3C6-4A76-9489-57539F396C94@arm.com> authentication-results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-microsoft-exchange-diagnostics: 1;AM3PR08MB0104;7:AooU6EHJmgCwkbZ3ZfBsI3LuBGWYDtb8NaENMCksdeidALt36XGWPpP1knvOM9abUJtgPbauji5WHcSH/lvjhAlOpK5QPtqg31187JgR+/vqRd8I67YlBOMIkLZKtR3AAkT9tad+GEHz/YjgwlVmZ4w7ALPSim8bY8k3FT3z9xUxtnCZIiEBq/3LR/QeCCs4wt6n3OMypNP1599mJyGxwcsSGnlvDYezvISSMEvHrWsxcgwh5DluZ/ZJDYeADtxvKpzHOoxjpUg2jl94iJWMbdlmWrhtcL7es5TvMMnRPMET1J99EB4HxtzmCNNLcMlbccocNoA2E1Vrke5VBm4Fug== x-ms-office365-filtering-correlation-id: 8198d20b-2672-4979-61e4-08d471fb463c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081);SRVR:AM3PR08MB0104; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123562025)(20161123558025)(20161123555025)(20161123564025)(20161123560025)(6072148);SRVR:AM3PR08MB0104;BCL:0;PCL:0;RULEID:;SRVR:AM3PR08MB0104; x-forefront-prvs: 0255DF69B9 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(39410400002)(39450400003)(39850400002)(39860400002)(39840400002)(377424004)(24454002)(5250100002)(81166006)(3280700002)(2501003)(2906002)(110136004)(4326008)(82746002)(38730400002)(575784001)(102836003)(2900100001)(8676002)(8936002)(6246003)(3660700001)(86362001)(3846002)(6116002)(99286003)(6512007)(6916009)(83716003)(229853002)(2950100002)(53936002)(189998001)(305945005)(6436002)(2351001)(5660300001)(6486002)(5640700003)(7736002)(6506006)(53546009)(66066001)(25786009)(33656002)(76176999)(54356999)(50986999)(36756003);DIR:OUT;SFP:1101;SCL:1;SRVR:AM3PR08MB0104;H:AM3PR08MB0101.eurprd08.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: <2A6A6DA578917E4EB7EC0397769BF2F1@eurprd08.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Mar 2017 14:45:39.0956 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0104 X-SW-Source: 2017-03/txt/msg00419.txt.bz2 Ping. > On 24 Feb 2017, at 10:19, Alan Hayward wrote: >=20 > Also adds functionality to calculate maximum register size. >=20 > Cannot remove buffer from regcache_restore becuase we need to keep the > register value if the read fails. >=20 > Leaves two asserts check with MAX_REGISTER_SIZE which must be kept > until MAX_REGISTER_SIZE is fully removed from all files. >=20 > Tested using make check with board files unix and native-gdbserver. >=20 > Ok to commit? >=20 > Alan. >=20 > 2017-02-24 Alan Hayward >=20 > * regcache.c (struct regcache_descr): Add max_register_size > (init_regcache_descr): Calculate maximum register size. > (max_register_size): New function. > (regcache_save): Avoid buffer use. > (regcache_restore): Use vec instead of array. > (regcache_dump): Avoid buffer use. > * regcache.h (struct regcache_descr): Add max_register_size > (max_register_size): New function. >=20 >=20 > index 59233308f926ebd52db9958cba168daacc77c1ee..a4a47c8f738ee5df69074375a= 3f169558891cf0e 100644 > --- a/gdb/regcache.h > +++ b/gdb/regcache.h > @@ -206,6 +206,8 @@ extern struct type *register_type (struct gdbarch *gd= barch, int regnum); >=20 > extern int register_size (struct gdbarch *gdbarch, int regnum); >=20 > +/* Return the size of the largest register. */ > +extern long max_register_size (struct gdbarch *gdbarch); >=20 > /* Save/restore a register cache. The set of registers saved / > restored into the DST regcache determined by the save_reggroup / > diff --git a/gdb/regcache.c b/gdb/regcache.c > index 31aa1baf7ef69c27c00e45e3c8d4eb3c41dc4203..0da184cb7c6ea3a171139a406= 76658322e62ad2e 100644 > --- a/gdb/regcache.c > +++ b/gdb/regcache.c > @@ -73,6 +73,9 @@ struct regcache_descr >=20 > /* Cached table containing the type of each register. */ > struct type **register_type; > + > + /* Size of the largest register. */ > + long max_register_size; > }; >=20 > static void * > @@ -126,6 +129,8 @@ init_regcache_descr (struct gdbarch *gdbarch) > descr->register_offset[i] =3D offset; > offset +=3D descr->sizeof_register[i]; > gdb_assert (MAX_REGISTER_SIZE >=3D descr->sizeof_register[i]); > + descr->max_register_size =3D std::max (descr->max_register_size, > + descr->sizeof_register[i]); > } > /* Set the real size of the raw register cache buffer. */ > descr->sizeof_raw_registers =3D offset; > @@ -136,6 +141,8 @@ init_regcache_descr (struct gdbarch *gdbarch) > descr->register_offset[i] =3D offset; > offset +=3D descr->sizeof_register[i]; > gdb_assert (MAX_REGISTER_SIZE >=3D descr->sizeof_register[i]); > + descr->max_register_size =3D std::max (descr->max_register_size, > + descr->sizeof_register[i]); > } > /* Set the real size of the readonly register cache buffer. */ > descr->sizeof_cooked_registers =3D offset; > @@ -187,6 +194,13 @@ regcache_register_size (const struct regcache *regca= che, int n) > return register_size (get_regcache_arch (regcache), n); > } >=20 > +long > +max_register_size (struct gdbarch *gdbarch) > +{ > + struct regcache_descr *descr =3D regcache_descr (gdbarch); > + return descr->max_register_size; > +} > + > /* The register cache for storing raw register values. */ >=20 > struct regcache > @@ -327,7 +341,6 @@ regcache_save (struct regcache *dst, regcache_cooked_= read_ftype *cooked_read, > void *src) > { > struct gdbarch *gdbarch =3D dst->descr->gdbarch; > - gdb_byte buf[MAX_REGISTER_SIZE]; > int regnum; >=20 > /* The DST should be `read-only', if it wasn't then the save would > @@ -346,17 +359,13 @@ regcache_save (struct regcache *dst, regcache_cooke= d_read_ftype *cooked_read, > { > if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup)) > { > - enum register_status status =3D cooked_read (src, regnum, buf); > + gdb_byte *dst_buf =3D register_buffer (dst, regnum); > + enum register_status status =3D cooked_read (src, regnum, dst_buf); >=20 > - if (status =3D=3D REG_VALID) > - memcpy (register_buffer (dst, regnum), buf, > - register_size (gdbarch, regnum)); > - else > + if (status !=3D REG_VALID) > { > gdb_assert (status !=3D REG_UNKNOWN); > - > - memset (register_buffer (dst, regnum), 0, > - register_size (gdbarch, regnum)); > + memset (dst_buf, 0, register_size (gdbarch, regnum)); > } > dst->register_status[regnum] =3D status; > } > @@ -369,7 +378,7 @@ regcache_restore (struct regcache *dst, > void *cooked_read_context) > { > struct gdbarch *gdbarch =3D dst->descr->gdbarch; > - gdb_byte buf[MAX_REGISTER_SIZE]; > + std::vector buf (max_register_size (gdbarch)); > int regnum; >=20 > /* The dst had better not be read-only. If it is, the `restore' > @@ -385,9 +394,9 @@ regcache_restore (struct regcache *dst, > { > enum register_status status; >=20 > - status =3D cooked_read (cooked_read_context, regnum, buf); > + status =3D cooked_read (cooked_read_context, regnum, buf.data ()); > if (status =3D=3D REG_VALID) > - regcache_cooked_write (dst, regnum, buf); > + regcache_cooked_write (dst, regnum, buf.data ()); > } > } > } > @@ -1324,7 +1333,6 @@ regcache_dump (struct regcache *regcache, struct ui= _file *file, > int footnote_register_offset =3D 0; > int footnote_register_type_name_null =3D 0; > long register_offset =3D 0; > - gdb_byte buf[MAX_REGISTER_SIZE]; >=20 > #if 0 > fprintf_unfiltered (file, "nr_raw_registers %d\n", > @@ -1451,8 +1459,8 @@ regcache_dump (struct regcache *regcache, struct ui= _file *file, > fprintf_unfiltered (file, ""); > else > { > - regcache_raw_read (regcache, regnum, buf); > - print_hex_chars (file, buf, > + regcache_raw_update (regcache, regnum); > + print_hex_chars (file, register_buffer (regcache, regnum), > regcache->descr->sizeof_register[regnum], > gdbarch_byte_order (gdbarch)); > } > @@ -1465,17 +1473,19 @@ regcache_dump (struct regcache *regcache, struct = ui_file *file, > fprintf_unfiltered (file, "Cooked value"); > else > { > - enum register_status status; > + struct value *value =3D regcache_cooked_read_value (regcache, > + regnum); >=20 > - status =3D regcache_cooked_read (regcache, regnum, buf); > - if (status =3D=3D REG_UNKNOWN) > - fprintf_unfiltered (file, ""); > - else if (status =3D=3D REG_UNAVAILABLE) > + if (value_optimized_out (value) > + || !value_entirely_available (value)) > fprintf_unfiltered (file, ""); > else > - print_hex_chars (file, buf, > + print_hex_chars (file, value_contents_all (value), > regcache->descr->sizeof_register[regnum], > gdbarch_byte_order (gdbarch)); > + > + release_value (value); > + value_free (value); > } > } >=20