From patchwork Tue Feb 28 11:28:04 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: 65742 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 0014C384DD0B for ; Tue, 28 Feb 2023 11:30:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0014C384DD0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677583835; bh=8/H0/5PIp1rZMtwfHVvwkqOKQmq3JP1hGlKv+SDU968=; 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=RWOTEmO63JNDjAd0knGEJZY73K7P8LK//X39dTGVMkepB9Dp70bp5bxRUdyEq69c1 szerl+QusdzVF0wcgkfaw5JeRL5Vc6YZd0oRFyJZi+ydIqxMibdU35MiyO0t6lFDeX 4OPtdq0e1tQk/3ZXLQis58zydAH/kfFgbSQ+/Rbo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id BC6503858004 for ; Tue, 28 Feb 2023 11:29:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC6503858004 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="314536354" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="314536354" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:29:17 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="738120528" X-IronPort-AV: E=Sophos;i="5.98,221,1673942400"; d="scan'208";a="738120528" Received: from ultl2604.iul.intel.com (HELO localhost) ([172.28.48.47]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2023 03:29:16 -0800 To: gdb-patches@sourceware.org Subject: [PATCH 06/26] gdbserver: turn part of get_thread_regcache into regcache::fetch Date: Tue, 28 Feb 2023 12:28:04 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 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 in get_thread_regcache that fetches the registers from the target, and turn it into a method of 'regcache'. --- gdbserver/regcache.cc | 23 +++++++++++++++-------- gdbserver/regcache.h | 3 +++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 2a8dc17ed6a..89ecdfec6f3 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -48,19 +48,26 @@ get_thread_regcache (struct thread_info *thread, bool fetch) regcache->thread = thread; } - if (fetch && regcache->registers_valid == 0) + if (fetch) + regcache->fetch (); + + return regcache; +} + +void +regcache::fetch () +{ + if (registers_valid == 0) { scoped_restore_current_thread restore_thread; + gdb_assert (this->thread != nullptr); + switch_to_thread (this->thread); - switch_to_thread (thread); /* Invalidate all registers, to prevent stale left-overs. */ - memset (regcache->register_status, REG_UNAVAILABLE, - regcache->tdesc->reg_defs.size ()); - fetch_inferior_registers (regcache, -1); - regcache->registers_valid = 1; + memset (register_status, REG_UNAVAILABLE, tdesc->reg_defs.size ()); + fetch_inferior_registers (this, -1); + registers_valid = 1; } - - return regcache; } /* See gdbsupport/common-regcache.h. */ diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h index 053ed08b20f..7eae6cb724a 100644 --- a/gdbserver/regcache.h +++ b/gdbserver/regcache.h @@ -67,6 +67,9 @@ struct regcache : public reg_buffer_common /* See gdbsupport/common-regcache.h. */ bool raw_compare (int regnum, const void *buf, int offset) const override; + + /* Fetch the registers from the target, if not done already. */ + void fetch (); }; void regcache_cpy (struct regcache *dst, struct regcache *src);