From patchwork Tue Feb 28 11:28:07 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: 65746 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 A89ED384F4A7 for ; Tue, 28 Feb 2023 11:31:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A89ED384F4A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677583864; bh=i3Ti9hABtznkwqFw+crk13VmDbyCevU8XYetlQMu0xo=; 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=Xiu8klY9w/GjYXF1TJUR3dg8eMmDihVr0CV5V22sFVo1Gvetxs2PxD9c+J25Ah+Oy w3sFiuirhujlWYRtwLsnXqYP9Yo/wOPJZMm5a1vsEEG6wnJlXQG+dDFarFEZWg3XST swXqH5LEATKO9LMyuf4BM3ovDGmwayP7p4RQMd3w= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by sourceware.org (Postfix) with ESMTPS id B53893858430 for ; Tue, 28 Feb 2023 11:29:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B53893858430 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="396679500" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="396679500" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:29:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="919748225" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="919748225" Received: from ultl2604.iul.intel.com (HELO localhost) ([172.28.48.47]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:29:36 -0800 To: gdb-patches@sourceware.org Subject: [PATCH 09/26] gdbserver: extract out regcache::invalidate and regcache::discard Date: Tue, 28 Feb 2023 12:28:07 +0100 Message-Id: <80ed5ae6e1976610b2dfcf26ebe32f9af4aa9b33.1677582744.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.4 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" Extract out a piece of code from the `regcache_invalidate_thread` function and turn into a new method of regcache named 'invalidate'. We also introduce a small method named 'discard' to give the clients an option to discard the cache without storing the contents. This method is utilized in a downstream debugger. --- gdbserver/regcache.cc | 24 +++++++++++++++++------- gdbserver/regcache.h | 6 ++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 7b6337166ad..1db78951cc2 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -85,18 +85,22 @@ regcache_invalidate_thread (struct thread_info *thread) regcache = thread_regcache_data (thread); - if (regcache == NULL) - return; + if (regcache != nullptr) + regcache->invalidate (); +} - if (regcache->registers_valid) +void +regcache::invalidate () +{ + if (registers_valid) { scoped_restore_current_thread restore_thread; - - switch_to_thread (thread); - store_inferior_registers (regcache, -1); + gdb_assert (this->thread != nullptr); + switch_to_thread (this->thread); + store_inferior_registers (this, -1); } - regcache->registers_valid = 0; + discard (); } /* See regcache.h. */ @@ -121,6 +125,12 @@ regcache_invalidate (void) #endif +void +regcache::discard () +{ + registers_valid = 0; +} + void regcache::initialize (const target_desc *tdesc, unsigned char *regbuf) diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h index 614d5a2561f..b4a9d8864ae 100644 --- a/gdbserver/regcache.h +++ b/gdbserver/regcache.h @@ -78,6 +78,12 @@ struct regcache : public reg_buffer_common /* Copy the contents of SRC into this regcache. */ void copy_from (regcache *src); + + /* Store the cached registers to the target and then discard the cache. */ + void invalidate (); + + /* Discard the cache without storing the registers to the target. */ + void discard (); }; regcache *get_thread_regcache (thread_info *thread, bool fetch = true);