From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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=1677583757; x=1709119757; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=QX44/xDtf9cyqHOZUYoO0OXZbAOWeEymGljTpTjMOxM=; b=VKSPXxEx4fyW7YpuZIW/ACzizIVA79VNLPijL2R8wOnQ4mzV3XXaw2u7 0VIKuUFaMFayihZxYUucJC7/65qi4u921WjDJMRKqUr1oYQpZGZBmPmoG fiYAbNnVQDW3qyRzPhHShNRTQhXZKaJz/jpqcrDjdt+Hlx4foU2dBuXma 9M5sfG4kF/n14U2Yh4/D12pQXReHy2esdzAssegBVKJoYAYA5QfkL2bgr ZV4Ru9PXinkHd8VUGnQMpVfY5bFPtt9WliipOf7pQ3j9D36KNh0lgCUXw l3vsk/SAbmN7sEegMMYVoRvmghQWJCH1Xd5cWCDZ8JKGDDdmmGQ5dnlH6 g==; 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 From: Tankut Baris Aktemur 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 List-Id: 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); -- 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