From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102358 invoked by alias); 24 Feb 2017 10:19:19 -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 102334 invoked by uid 89); 24 Feb 2017 10:19:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 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=becuase, cooked, Cooked X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com Received: from mail-db5eur01on0064.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (104.47.2.64) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Feb 2017 10:19:15 +0000 Received: from VI1PR0801MB1822.eurprd08.prod.outlook.com (10.168.68.7) by VI1PR0801MB1824.eurprd08.prod.outlook.com (10.168.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.919.13; Fri, 24 Feb 2017 10:19:12 +0000 Received: from VI1PR0801MB1822.eurprd08.prod.outlook.com ([10.168.68.7]) by VI1PR0801MB1822.eurprd08.prod.outlook.com ([10.168.68.7]) with mapi id 15.01.0919.018; Fri, 24 Feb 2017 10:19:12 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH] Remove MAX_REGISTER_SIZE from regcache.c Date: Fri, 24 Feb 2017 10:19:00 -0000 Message-ID: <562B2F6F-F3C6-4A76-9489-57539F396C94@arm.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-office365-filtering-correlation-id: 67874009-6a14-46a3-b4be-08d45c9e93d6 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(48565401081);SRVR:VI1PR0801MB1824; x-microsoft-exchange-diagnostics: 1;VI1PR0801MB1824;7:JEh6ND2sPk/Sodou9pJnVzek0pdorOg7M5PyCdLAN3DOBy2ZSRMHf4rLnngAvT7B7s7ditZ7Kz1Arz/1jS0Ixg89DL6/4WTMl2LAT9sfA2H3LsKCLZGqGbho80xkeZfV7zB7eDcPBMqC9paa9YeQ451jL2tReq5zqMSrneE3z2q/e9pJVRUGtfynaG1pexYV1w//ZsVP885ByJDfdpjBVLrjHz5dgJO5LnHWgnGSs98ZywHvlAP2YK9zIVlZs2qUeTEH0Ojkwr/x2UZh/tOZqnWcxM9avteCQiNG7S3z1koHHHmXVAQDhAQrWZmEfvOSWKB5PVu/jy6fwd6bluDRow== 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)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123560025)(20161123558025)(6072148);SRVR:VI1PR0801MB1824;BCL:0;PCL:0;RULEID:;SRVR:VI1PR0801MB1824; x-forefront-prvs: 0228DDDDD7 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(39450400003)(39410400002)(39850400002)(39840400002)(39860400002)(199003)(189002)(377424004)(5660300001)(6512007)(2900100001)(2351001)(6916009)(122556002)(66066001)(6436002)(99286003)(105586002)(106116001)(106356001)(6506006)(6486002)(4326007)(77096006)(2501003)(2906002)(36756003)(6116002)(3846002)(102836003)(82746002)(53936002)(54356999)(3280700002)(8936002)(8676002)(33656002)(68736007)(575784001)(3660700001)(86362001)(101416001)(81156014)(50986999)(83716003)(305945005)(81166006)(7736002)(97736004)(189998001)(110136004)(450100001)(5640700003)(38730400002)(25786008)(92566002)(104396002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0801MB1824;H:VI1PR0801MB1822.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-Type: text/plain; charset="us-ascii" Content-ID: <74EAD58B195B0944B0A5A849D199C954@eurprd08.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2017 10:19:11.6428 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1824 X-SW-Source: 2017-02/txt/msg00672.txt.bz2 Also adds functionality to calculate maximum register size. Cannot remove buffer from regcache_restore becuase we need to keep the register value if the read fails. Leaves two asserts check with MAX_REGISTER_SIZE which must be kept until MAX_REGISTER_SIZE is fully removed from all files. Tested using make check with board files unix and native-gdbserver. Ok to commit? Alan. 2017-02-24 Alan Hayward * 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. index 59233308f926ebd52db9958cba168daacc77c1ee..a4a47c8f738ee5df69074375a3f= 169558891cf0e 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -206,6 +206,8 @@ extern struct type *register_type (struct gdbarch *gdba= rch, int regnum); extern int register_size (struct gdbarch *gdbarch, int regnum); +/* Return the size of the largest register. */ +extern long max_register_size (struct gdbarch *gdbarch); /* 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..0da184cb7c6ea3a171139a40676= 658322e62ad2e 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -73,6 +73,9 @@ struct regcache_descr /* Cached table containing the type of each register. */ struct type **register_type; + + /* Size of the largest register. */ + long max_register_size; }; 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 *regcach= e, int n) return register_size (get_regcache_arch (regcache), n); } +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. */ struct regcache @@ -327,7 +341,6 @@ regcache_save (struct regcache *dst, regcache_cooked_re= ad_ftype *cooked_read, void *src) { struct gdbarch *gdbarch =3D dst->descr->gdbarch; - gdb_byte buf[MAX_REGISTER_SIZE]; int regnum; /* The DST should be `read-only', if it wasn't then the save would @@ -346,17 +359,13 @@ regcache_save (struct regcache *dst, regcache_cooked_= 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); - 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; /* 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; - 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_f= ile *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]; #if 0 fprintf_unfiltered (file, "nr_raw_registers %d\n", @@ -1451,8 +1459,8 @@ regcache_dump (struct regcache *regcache, struct ui_f= ile *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); - 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); } }