From patchwork Tue Feb 28 11:28:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 65756 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE9E7385559E for ; Tue, 28 Feb 2023 11:32:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE9E7385559E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677583943; bh=eBkQHA1E0yynWc6J+nQSGNkGG+CqDWdE8hxDGtZjwf0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dz1mK54JZYl9QyZQ5pG3fLV4Q2f5kOp7h7WFeiXqPoSjtTAVSFk8KfG6NZSFBIPEy ZT7tT3XxUi8CQySY+IUoAHt83z0fwgdRNpOvvIP1+wY+DpM0m1NATSZSuYyyDiR/7z Z4f7GiWrN2njP/8lpErWU4/VO710BnlpJLcX0qlA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by sourceware.org (Postfix) with ESMTPS id 24E8D385782B for ; Tue, 28 Feb 2023 11:31:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 24E8D385782B X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="336401798" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="336401798" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:31:23 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="817058343" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="817058343" Received: from ultl2604.iul.intel.com (HELO localhost) ([172.28.48.47]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:31:22 -0800 To: gdb-patches@sourceware.org Subject: [PATCH 25/26] gdbserver: refuse null argument in regcache::supply_regblock Date: Tue, 28 Feb 2023 12:28:23 +0100 Message-Id: <39a4774140afc2f7253756971398fc2cabceb289.1677582745.git.tankut.baris.aktemur@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tankut Baris Aktemur via Gdb-patches From: "Aktemur, Tankut Baris" Reply-To: Tankut Baris Aktemur Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The regcache::supply_regblock method implements two different behaviors based on whether its 'buf' argument is null. The null behavior is used only in tracepoint.cc. Refuse the null pointer argument and use the 'discard' method to obtain that second behavior. Note that the original code resets register statuses to REG_UNAVAILABLE, but 'discard' sets them to REG_UNKNOWN. For the current purposes of resetting the regcache, the difference does not seem to be important. --- gdbserver/regcache.cc | 19 +++++-------------- gdbserver/regcache.h | 3 +-- gdbserver/tracepoint.cc | 8 ++++---- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 4533e9e9b12..cfb68774402 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -390,22 +390,13 @@ supply_register_by_name_zeroed (struct regcache *regcache, void regcache::supply_regblock (const void *buf) { - if (buf != nullptr) - { - memcpy (registers, buf, tdesc->registers_size); -#ifndef IN_PROCESS_AGENT - for (int i = 0; i < tdesc->reg_defs.size (); i++) - set_register_status (i, REG_VALID); -#endif - } - else - { - memset (registers, 0, tdesc->registers_size); + gdb_assert (buf != nullptr); + + memcpy (registers, buf, tdesc->registers_size); #ifndef IN_PROCESS_AGENT - for (int i = 0; i < tdesc->reg_defs.size (); i++) - set_register_status (i, REG_UNAVAILABLE); + for (int i = 0; i < tdesc->reg_defs.size (); i++) + set_register_status (i, REG_VALID); #endif - } } #ifndef IN_PROCESS_AGENT diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h index be412bc3765..216044889ec 100644 --- a/gdbserver/regcache.h +++ b/gdbserver/regcache.h @@ -103,8 +103,7 @@ struct regcache : public reg_buffer_common void registers_from_string (const char *buf); /* Supply the whole register set whose contents are stored in BUF, - to this regcache. If BUF is NULL, all the registers' values are - recorded as unavailable. */ + to this regcache. BUF cannot be NULL. */ void supply_regblock (const void *buf); /* Return the pointer to the register with number REGNUM. */ diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc index 9833e7c3b0f..9622d53cd82 100644 --- a/gdbserver/tracepoint.cc +++ b/gdbserver/tracepoint.cc @@ -4707,7 +4707,7 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx) { fctx->regcache_initted = 1; fctx->regcache.initialize (ipa_tdesc, fctx->regspace); - fctx->regcache.supply_regblock (nullptr); + fctx->regcache.discard (); supply_fast_tracepoint_registers (&fctx->regcache, fctx->regs); } regcache = &fctx->regcache; @@ -4722,7 +4722,7 @@ get_context_regcache (struct tracepoint_hit_ctx *ctx) { sctx->regcache_initted = 1; sctx->regcache.initialize (ipa_tdesc, sctx->regspace); - sctx->regcache.supply_regblock (nullptr); + sctx->regcache.discard (); /* Pass down the tracepoint address, because REGS doesn't include the PC, but we know what it must have been. */ supply_static_tracepoint_registers (&sctx->regcache, @@ -5179,8 +5179,8 @@ fetch_traceframe_registers (int tfnum, struct regcache *regcache, int regnum) dataptr = traceframe_find_regblock (tframe, tfnum); if (dataptr == NULL) { - /* Mark registers unavailable. */ - regcache->supply_regblock (nullptr); + /* Wipe out the cache. */ + regcache->discard (); /* We can generally guess at a PC, although this will be misleading for while-stepping frames and multi-location