From patchwork Fri Feb 24 10:03:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 19366 Received: (qmail 12216 invoked by alias); 24 Feb 2017 10:03:12 -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 12199 invoked by uid 89); 24 Feb 2017 10:03:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 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=simulator X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com Received: from mail-db5eur01on0044.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (104.47.2.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 24 Feb 2017 10:03:09 +0000 Received: from VI1PR0801MB1822.eurprd08.prod.outlook.com (10.168.68.7) by VI1PR0801MB1822.eurprd08.prod.outlook.com (10.168.68.7) 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:03:06 +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:03:06 +0000 From: Alan Hayward To: "gdb-patches@sourceware.org" CC: nd Subject: [PATCH] Remove MAX_REGISTER_SIZE from remote-sim.c Date: Fri, 24 Feb 2017 10:03:06 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-office365-filtering-correlation-id: 7c83f237-ca9b-4b2e-878d-08d45c9c5469 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:VI1PR0801MB1822; x-microsoft-exchange-diagnostics: 1; VI1PR0801MB1822; 7:YJO0+Uow/0rQipQD/+SnoqNybmVjGosXNqyZmF0OJXuU0xA9qvX4vWOOY4xOuuD2sV//W24DqrLr/SY4AVoVE1XqTs0l/1sstMwuO8m3VpFoPm5dy3GpfwPliQniLVRESabDq0mEseYwHymiwymM98sm0oCGiLDF49DWiNgwMyTTOXnb8lf1ZDH9X91mi3dWyzrMM7ihryRkoBwMpWPry2qkQ8GJvr6P/JKMH3I7XYrjOorcdU3vWxevguj5z27VPST+8TkwlYv4r2w9CRKLzdT9XFIEZoiwgzsQ39/mO3ffUWpl46Al7MC5+EYOUyPP1d5gSmt0kEuNpRv82d2L0A== 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)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123555025)(20161123558025)(20161123562025)(20161123564025)(6072148); SRVR:VI1PR0801MB1822; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1822; x-forefront-prvs: 0228DDDDD7 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39450400003)(39840400002)(39860400002)(39850400002)(39410400002)(377424004)(189002)(199003)(105586002)(2900100001)(68736007)(2351001)(8676002)(305945005)(106116001)(106356001)(4326007)(6116002)(102836003)(3280700002)(3660700001)(3846002)(92566002)(2906002)(6916009)(8936002)(81166006)(81156014)(36756003)(5660300001)(53936002)(450100001)(2501003)(122556002)(33656002)(189998001)(101416001)(7736002)(50986999)(54356999)(66066001)(110136004)(97736004)(6512007)(5640700003)(6506006)(6436002)(25786008)(82746002)(575784001)(77096006)(86362001)(99286003)(6486002)(83716003)(38730400002)(104396002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0801MB1822; H:VI1PR0801MB1822.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <3C74FC5BFF9A38459EE0112516DF4F34@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2017 10:03:06.5296 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1822 Used a std::vector in the first case and struct value in the second. Tested using make check with board files unix and native-gdbserver. Ok to commit? Alan. 2017-02-21 Alan Hayward * gdb/remote-sim.c (gdbsim_fetch_register): Use vec instead of array. (gdbsim_store_register): Read register using value. diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index b0c68c617e365c0ea18ac2eca525598b688ffbb5..aeceb06a557eb31778d0a85194fb47ea311eec09 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -439,6 +439,9 @@ gdbsim_fetch_register (struct target_ops *ops, return; } + int regsize = register_size (gdbarch, regno); + std::vector buf (regsize); + switch (gdbarch_register_sim_regno (gdbarch, regno)) { case LEGACY_SIM_REGNO_IGNORE: @@ -447,38 +450,32 @@ gdbsim_fetch_register (struct target_ops *ops, { /* For moment treat a `does not exist' register the same way as an ``unavailable'' register. */ - gdb_byte buf[MAX_REGISTER_SIZE]; int nr_bytes; - memset (buf, 0, MAX_REGISTER_SIZE); - regcache_raw_supply (regcache, regno, buf); + regcache_raw_supply (regcache, regno, buf.data ()); break; } default: { static int warn_user = 1; - gdb_byte buf[MAX_REGISTER_SIZE]; int nr_bytes; gdb_assert (regno >= 0 && regno < gdbarch_num_regs (gdbarch)); - memset (buf, 0, MAX_REGISTER_SIZE); nr_bytes = sim_fetch_register (sim_data->gdbsim_desc, gdbarch_register_sim_regno (gdbarch, regno), - buf, - register_size (gdbarch, regno)); + buf.data (), regsize); if (nr_bytes > 0 - && nr_bytes != register_size (gdbarch, regno) && warn_user) + && nr_bytes != regsize && warn_user) { fprintf_unfiltered (gdb_stderr, "Size of register %s (%d/%d) " "incorrect (%d instead of %d))", gdbarch_register_name (gdbarch, regno), regno, - gdbarch_register_sim_regno - (gdbarch, regno), - nr_bytes, register_size (gdbarch, regno)); + gdbarch_register_sim_regno (gdbarch, regno), + nr_bytes, regsize); warn_user = 0; } /* FIXME: cagney/2002-05-27: Should check `nr_bytes == 0' @@ -486,13 +483,13 @@ gdbsim_fetch_register (struct target_ops *ops, which registers are fetchable. */ /* Else if (nr_bytes < 0): an old simulator, that doesn't think to return the register size. Just assume all is ok. */ - regcache_raw_supply (regcache, regno, buf); + regcache_raw_supply (regcache, regno, buf.data ()); if (remote_debug) { fprintf_unfiltered (gdb_stdlog, "gdbsim_fetch_register: %d", regno); /* FIXME: We could print something more intelligible. */ - dump_mem (buf, register_size (gdbarch, regno)); + dump_mem (buf.data (), regsize); } break; } @@ -516,15 +513,14 @@ gdbsim_store_register (struct target_ops *ops, } else if (gdbarch_register_sim_regno (gdbarch, regno) >= 0) { - gdb_byte tmp[MAX_REGISTER_SIZE]; - int nr_bytes; - - regcache_cooked_read (regcache, regno, tmp); - nr_bytes = sim_store_register (sim_data->gdbsim_desc, - gdbarch_register_sim_regno - (gdbarch, regno), - tmp, register_size (gdbarch, regno)); - if (nr_bytes > 0 && nr_bytes != register_size (gdbarch, regno)) + int regsize = register_size (gdbarch, regno); + int sim_regno = gdbarch_register_sim_regno (gdbarch, regno); + + struct value *value = regcache_cooked_read_value (regcache, regno); + int nr_bytes = sim_store_register (sim_data->gdbsim_desc, sim_regno, + value_contents_all (value), regsize); + + if (nr_bytes > 0 && nr_bytes != regsize) internal_error (__FILE__, __LINE__, _("Register size different to expected")); if (nr_bytes < 0) @@ -538,8 +534,11 @@ gdbsim_store_register (struct target_ops *ops, { fprintf_unfiltered (gdb_stdlog, "gdbsim_store_register: %d", regno); /* FIXME: We could print something more intelligible. */ - dump_mem (tmp, register_size (gdbarch, regno)); + dump_mem (value_contents_all (value), regsize); } + + release_value (value); + value_free (value); } }