From patchwork Wed Apr 26 14:03:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 20166 Received: (qmail 50043 invoked by alias); 26 Apr 2017 14:03:18 -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 50029 invoked by uid 89); 26 Apr 2017 14:03:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 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=H*MI:CAH X-HELO: EUR03-DB5-obe.outbound.protection.outlook.com Received: from mail-eopbgr40066.outbound.protection.outlook.com (HELO EUR03-DB5-obe.outbound.protection.outlook.com) (40.107.4.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Apr 2017 14:03:15 +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.1047.13; Wed, 26 Apr 2017 14:03:14 +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; Wed, 26 Apr 2017 14:03:14 +0000 From: Alan Hayward To: Yao Qi CC: "gdb-patches@sourceware.org" , nd Subject: Re: [PATCH] Remove MAX_REGISTER_SIZE from regcache.c Date: Wed, 26 Apr 2017 14:03:13 +0000 Message-ID: References: <562B2F6F-F3C6-4A76-9489-57539F396C94@arm.com> <868tnvukjh.fsf@gmail.com> <7359B5C0-BF61-42E2-9886-B322C1825865@arm.com> <0DADF920-69B9-4F96-A153-6965E56B5DA8@arm.com> <868tneq1xj.fsf@gmail.com> <86efx0ljsv.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; AM3PR08MB0101; 7:Bo/5ik4g0MFnuD8IqloV3YfvQ6NuSSmcX6tgpBUfrlLgLsQhy/Qpn/jrw5zNPtQdM8AqzhDRBBWK5i49z0uB1RwhJfSIZN6WdWnLDMulYXRKfs1f8Kpx6mhhIZVhA2jz9iAkIK2rcz1fVpwTtpS0UG9cwrRoCZOLK0vBuc36WH0yZ+aRp3s9xdVKPLUpFNm30ST2O8ah9qwBmW2qvA83hLJzIB1ChBacsGm4Oxiuo7IfUiZk3gV+T9ZtY+kzxqQHPcAoK1Pwk1PMoYHEdw3wR5Q01rDsJDfgKm1OUZXGFS0Q/rj10GHp2nX0q/cYnBMYpxj4tRCeB6s0naNYXfsb7w== x-ms-office365-filtering-correlation-id: fa16a6ab-ff11-4533-200a-08d48cacfb17 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)(788757137089); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(6072148); SRVR:AM3PR08MB0101; BCL:0; PCL:0; RULEID:; SRVR:AM3PR08MB0101; x-forefront-prvs: 0289B6431E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39450400003)(39400400002)(39860400002)(39840400002)(39850400002)(39410400002)(377454003)(377424004)(24454002)(8936002)(81166006)(93886004)(2906002)(6436002)(82746002)(76176999)(83716003)(54356999)(6512007)(6116002)(38730400002)(39060400002)(2900100001)(5250100002)(8676002)(102836003)(50986999)(5660300001)(6246003)(3660700001)(189998001)(3846002)(33656002)(66066001)(53936002)(86362001)(25786009)(3280700002)(110136004)(2950100002)(4326008)(53546009)(229853002)(305945005)(36756003)(6486002)(7736002)(1411001)(99286003)(6916009)(6506006)(54906002); 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: <34008D07667532409F6D6E1125F83793@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Apr 2017 14:03:13.9081 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0101 > On 21 Apr 2017, at 15:01, Yao Qi wrote: > > On Mon, Apr 10, 2017 at 9:59 AM, Yao Qi wrote: >> >> This patches removes the 2nd argument of regcache_restore, because it >> is only called by regcache_cpy. In regcache_cpy, if regcache_restore >> is called, dst is not readonly, but src is readonly. So this patch >> adds an assert that src is readonly in regcache_restore. >> regcache_cook_read read everything from a readonly regcache cache >> (src)'s register_buffer, and register status is from src->register_status. >> >> gdb: >> >> 2017-04-07 Yao Qi >> >> * regcache.c (regcache_restore): Remove argument 2. Replace >> argument 3 with regcache. Get register status from >> src->register_status and get register contents from >> register_buffer (src, regnum). >> (regcache_cpy): Update. >> > > Tested it again on x86_64-linux. Pushed it in. > > -- > Yao (齐尧) Ok, this leaves the following in regcache.c. Tested on a --enable-targets=all using make check with board files unix and native-gdbserver. Ok to commit? Alan. 2017-04-26 Alan Hayward * regcache.c (regcache_save): Avoid buffer use. (regcache_dump): Avoid buffer use. diff --git a/gdb/regcache.c b/gdb/regcache.c index f9bf992197b8e7bdc3cfc6fc3bafbcf928c49df9..6c1c8b9ee373d8998f771d756542f59e2adde8ff 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -337,7 +337,6 @@ regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, void *src) { struct gdbarch *gdbarch = 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 @@ -356,17 +355,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 = cooked_read (src, regnum, buf); + gdb_byte *dst_buf = register_buffer (dst, regnum); + enum register_status status = cooked_read (src, regnum, dst_buf); - if (status == REG_VALID) - memcpy (register_buffer (dst, regnum), buf, - register_size (gdbarch, regnum)); - else + if (status != REG_VALID) { gdb_assert (status != REG_UNKNOWN); - - memset (register_buffer (dst, regnum), 0, - register_size (gdbarch, regnum)); + memset (dst_buf, 0, register_size (gdbarch, regnum)); } dst->register_status[regnum] = status; } @@ -1334,7 +1329,6 @@ regcache_dump (struct regcache *regcache, struct ui_file *file, int footnote_register_offset = 0; int footnote_register_type_name_null = 0; long register_offset = 0; - gdb_byte buf[MAX_REGISTER_SIZE]; #if 0 fprintf_unfiltered (file, "nr_raw_registers %d\n", @@ -1461,8 +1455,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)); } @@ -1475,9 +1469,30 @@ regcache_dump (struct regcache *regcache, struct ui_file *file, fprintf_unfiltered (file, "Cooked value"); else { + const gdb_byte *buf = NULL; enum register_status status; + struct value *value = NULL; + + if (regnum < regcache->descr->nr_raw_registers) + { + regcache_raw_update (regcache, regnum); + status = regcache_register_status (regcache, regnum); + buf = register_buffer (regcache, regnum); + } + else + { + value = regcache_cooked_read_value (regcache, regnum); + + if (!value_optimized_out (value) + && value_entirely_available (value)) + { + status = REG_VALID; + buf = value_contents_all (value); + } + else + status = REG_UNAVAILABLE; + } - status = regcache_cooked_read (regcache, regnum, buf); if (status == REG_UNKNOWN) fprintf_unfiltered (file, ""); else if (status == REG_UNAVAILABLE) @@ -1486,6 +1501,12 @@ regcache_dump (struct regcache *regcache, struct ui_file *file, print_hex_chars (file, buf, regcache->descr->sizeof_register[regnum], gdbarch_byte_order (gdbarch)); + + if (value != NULL) + { + release_value (value); + value_free (value); + } } }