From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677583777; x=1709119777; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=bRIoYCmneZvwcdqGzwSXct0u6gLTNafk8xR0pv681E0=; b=Ms4EwP1Ele5WMWZvxuMeH4+Nc/eV3ZOh3pW4aUhJvYxVnuU3hNTyT+hn nJImuYK11qKuP42sss2aUs1gKpVgC3DW0WDp/O72HKAtbTWIOD6mlJs89 Fk4SKCHMrFxEnvreVW1KT6SWgq3s1WkuVAxPR6uoi6PnmwfrhEhSigvnp 16EdHr7a8l4c8+514uAifabbeCm1sK4ui3Y/oRtXXFqvXt38IY+ZSBshc ymBkOacXr3T4vldDyEb8Hnu7fmDTiuZlqMmxJstD/323ma97z1cJ6NVCN NsQyaaGON/bo0n3P9GjdVHCJmbyLE9dREi7VZRECr0xzQVFzQqRSxKfDx w==; 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 From: Tankut Baris Aktemur 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 List-Id: 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); -- 2.25.1 Intel Deutschland GmbH Registered Address: Am Campeon 10, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928