From patchwork Mon Jun 12 09:28:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 20941 Received: (qmail 78818 invoked by alias); 12 Jun 2017 09:28:33 -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 78797 invoked by uid 89); 12 Jun 2017 09:28:32 -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, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=2346 X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0059.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.59) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Jun 2017 09:28:28 +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.1157.12; Mon, 12 Jun 2017 09:28:29 +0000 Received: from AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::f0a8:fd0f:69e1:e280]) by AM3PR08MB0101.eurprd08.prod.outlook.com ([fe80::f0a8:fd0f:69e1:e280%17]) with mapi id 15.01.1157.017; Mon, 12 Jun 2017 09:28:29 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH] Remove MAX_REGISTER_SIZE from py-unwind.c Date: Mon, 12 Jun 2017 09:28:29 +0000 Message-ID: authentication-results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM3PR08MB0102; 7:Sbv3mD2Biav+oy/UAidYiiSNnCw8yQooEAWFSMvkCjAz8fG7ppJCDP7Mu4L9hBJwwdNogG48NZ9DnqwWP1aR69DZv5PRVmwhVRt6bTB/M+DMGBnT4vAUSu1mxBlWdXVjGd3siW/JaDbPVxv+M28YTERoIZjd1wD9uMM6xmTkAiWjJJFgQTFUZ9eTD7/fY3ltJAXmoasHoNSptO0gJkcbhzFkf0bULervJE2Kf9aswrVj9IrMXH4PzbzYiqNseH0HN/GjGdrW7iYuT+rfMhCdZUsxjdYoGoI9cDwQKp5Gw9Psvs0xJFqifua+guRrhNdJjiYE+5D9RzOMwgjUcH9wow== x-ms-traffictypediagnostic: AM3PR08MB0102: x-ms-office365-filtering-correlation-id: ac132b9a-f4a6-43c8-6680-08d4b175631f 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:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM3PR08MB0102; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM3PR08MB0102; x-forefront-prvs: 03361FCC43 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39400400002)(39840400002)(39450400003)(39860400002)(39850400002)(39410400002)(377424004)(2906002)(8676002)(14454004)(478600001)(33656002)(72206003)(575784001)(86362001)(189998001)(3280700002)(81166006)(305945005)(3660700001)(2900100001)(6512007)(53936002)(7736002)(5660300001)(102836003)(3846002)(38730400002)(110136004)(99286003)(66066001)(54356999)(25786009)(2351001)(5250100002)(4326008)(8936002)(36756003)(82746002)(6486002)(6916009)(5640700003)(2501003)(83716003)(50986999)(6506006)(6436002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0102; H:AM3PR08MB0101.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <960D12FFFF19234199044D1D21AE1AEC@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Jun 2017 09:28:29.4781 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0102 I've moved cached_reg_t from remote.c to regcache.h, then updated py-unwind.c to use cached_reg_t instead of reg_info. Had to make sure registers are individually allocated/deallocated (in the same way as remote.c). Tested on a --enable-targets=all build. All tests in gdb.python/python.exp pass. Also tested with board files unix and native-gdbserver. Ok to commit? Alan. 2017-06-12 Alan Hayward * gdb/remote.c (cached_reg): Move from here... * gdb/regcache.h (cached_reg): ...to here. * gdb/python/py-unwind.c (struct reg_info): Remove. (cached_frame_info): Use cached_reg_t. (pyuw_prev_register): Likewise. (pyuw_sniffer): Use cached_reg_t and allocate registers. (pyuw_dealloc_cache): Free all registers. diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index a5c2873697944c1293fdd9f8265dde078378e6c2..91bd02ead7a56325b391a8f307e628d2293d57a2 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -73,15 +73,6 @@ typedef struct /* The data we keep for a frame we can unwind: frame ID and an array of (register_number, register_value) pairs. */ -struct reg_info -{ - /* Register number. */ - int number; - - /* Register data bytes pointer. */ - gdb_byte data[MAX_REGISTER_SIZE]; -}; - typedef struct { /* Frame ID. */ @@ -93,7 +84,7 @@ typedef struct /* Length of the `reg' array below. */ int reg_count; - struct reg_info reg[]; + cached_reg_t reg[]; } cached_frame_info; extern PyTypeObject pending_frame_object_type @@ -483,14 +474,14 @@ pyuw_prev_register (struct frame_info *this_frame, void **cache_ptr, int regnum) { cached_frame_info *cached_frame = (cached_frame_info *) *cache_ptr; - struct reg_info *reg_info = cached_frame->reg; - struct reg_info *reg_info_end = reg_info + cached_frame->reg_count; + cached_reg_t *reg_info = cached_frame->reg; + cached_reg_t *reg_info_end = reg_info + cached_frame->reg_count; TRACE_PY_UNWIND (1, "%s (frame=%p,...,reg=%d)\n", __FUNCTION__, this_frame, regnum); for (; reg_info < reg_info_end; ++reg_info) { - if (regnum == reg_info->number) + if (regnum == reg_info->num) return frame_unwind_got_bytes (this_frame, regnum, reg_info->data); } @@ -567,9 +558,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, int i; cached_frame - = ((cached_frame_info *) - xmalloc (sizeof (*cached_frame) - + reg_count * sizeof (cached_frame->reg[0]))); + = ((cached_frame_info *) xmalloc (sizeof (*cached_frame))); cached_frame->gdbarch = gdbarch; cached_frame->frame_id = unwind_info->frame_id; cached_frame->reg_count = reg_count; @@ -580,13 +569,14 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, struct value *value = value_object_to_value (reg->value); size_t data_size = register_size (gdbarch, reg->number); - cached_frame->reg[i].number = reg->number; + cached_frame->reg[i].num = reg->number; /* `value' validation was done before, just assert. */ gdb_assert (value != NULL); gdb_assert (data_size == TYPE_LENGTH (value_type (value))); gdb_assert (data_size <= MAX_REGISTER_SIZE); + cached_frame->reg[i].data = (gdb_byte *) xmalloc (data_size); memcpy (cached_frame->reg[i].data, value_contents (value), data_size); } } @@ -601,6 +591,13 @@ static void pyuw_dealloc_cache (struct frame_info *this_frame, void *cache) { TRACE_PY_UNWIND (3, "%s: enter", __FUNCTION__); + cached_frame_info *cached_frame = (cached_frame_info *) cache; + + for (int i = 0; cached_frame->reg_count; i++) + { + xfree (cached_frame->reg[i].data); + } + xfree (cache); } diff --git a/gdb/regcache.h b/gdb/regcache.h index 24521e40ec0bb221d3fd37418d2aa485c08403b7..82026b49a57d64b9688dbce82bbf5c6529fdc651 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -234,6 +234,14 @@ enum regcache_dump_what regcache_dump_remote }; +/* A (register_number, register_value) pair. */ + +typedef struct cached_reg +{ + int num; + gdb_byte *data; +} cached_reg_t; + /* The register cache for storing raw register values. */ class regcache diff --git a/gdb/remote.c b/gdb/remote.c index 1f8607988444fb0221b87e9ef3e93fbec04c42ea..4a0660f7d91574b84ff2e3978e1795f7cb69ad93 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -6308,12 +6308,6 @@ remote_console_output (char *msg) gdb_flush (gdb_stdtarg); } -typedef struct cached_reg -{ - int num; - gdb_byte *data; -} cached_reg_t; - DEF_VEC_O(cached_reg_t); typedef struct stop_reply