From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id DD6F73875467 for ; Wed, 5 Aug 2020 19:08:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DD6F73875467 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D6263116A73; Wed, 5 Aug 2020 15:08:47 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 2gxI-qp7uE9k; Wed, 5 Aug 2020 15:08:47 -0400 (EDT) Received: from murgatroyd.Home (75-166-101-103.hlrn.qwest.net [75.166.101.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 938D0116A6F; Wed, 5 Aug 2020 15:08:47 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 10/12] Fetch registers from correct thread in ravenscar-thread.c Date: Wed, 5 Aug 2020 13:08:39 -0600 Message-Id: <20200805190841.2506771-11-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200805190841.2506771-1-tromey@adacore.com> References: <20200805190841.2506771-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Wed, 05 Aug 2020 19:08:49 -0000 Fabien also noticed that gdb would not report a stop correctly when using Ravenscar. This patch fixes the bug by making a few changes: * ravenscar_thread_target::wait now updates the inferior ptid before updating the thread list. This ensures that a new thread is correctly associated with the underlying CPU. * The fetch_registers, store_registers, and prepare_to_store methods now save and restore the regcache's ptid before doing the operation on the underlying live thread. This ensures that gdb informs the remote of a thread it knows about, as opposed to using a Ravenscar thread, which probably will not be recognized. 2020-07-08 Tom Tromey * ravenscar-thread.c (ravenscar_thread_target::wait): Call update_inferior_ptid before update_thread_list. (temporarily_change_regcache_ptid): New class. (ravenscar_thread_target::fetch_registers) (ravenscar_thread_target::store_registers) (ravenscar_thread_target::prepare_to_store): Use base thread when forwarding operation. --- gdb/ChangeLog | 10 +++++ gdb/ravenscar-thread.c | 85 +++++++++++++++++++++++++++++++++--------- 2 files changed, 77 insertions(+), 18 deletions(-) diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index 91f09209bbc..459e5ea3ed3 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -457,20 +457,55 @@ ravenscar_thread_target::pid_to_str (ptid_t ptid) return string_printf ("Ravenscar Thread %#x", (int) ptid.tid ()); } +/* Temporarily set the ptid of a regcache to some other value. When + this object is destroyed, the regcache's original ptid is + restored. */ + +class temporarily_change_regcache_ptid +{ +public: + + temporarily_change_regcache_ptid (struct regcache *regcache, ptid_t new_ptid) + : m_regcache (regcache), + m_save_ptid (regcache->ptid ()) + { + m_regcache->set_ptid (new_ptid); + } + + ~temporarily_change_regcache_ptid () + { + m_regcache->set_ptid (m_save_ptid); + } + +private: + + /* The regcache. */ + struct regcache *m_regcache; + /* The saved ptid. */ + ptid_t m_save_ptid; +}; + void ravenscar_thread_target::fetch_registers (struct regcache *regcache, int regnum) { ptid_t ptid = regcache->ptid (); - if (runtime_initialized () - && is_ravenscar_task (ptid) - && !task_is_currently_active (ptid)) + if (runtime_initialized () && is_ravenscar_task (ptid)) { - struct gdbarch *gdbarch = regcache->arch (); - struct ravenscar_arch_ops *arch_ops - = gdbarch_ravenscar_ops (gdbarch); + if (task_is_currently_active (ptid)) + { + ptid_t base = get_base_thread_from_ravenscar_task (ptid); + temporarily_change_regcache_ptid changer (regcache, base); + beneath ()->fetch_registers (regcache, regnum); + } + else + { + struct gdbarch *gdbarch = regcache->arch (); + struct ravenscar_arch_ops *arch_ops + = gdbarch_ravenscar_ops (gdbarch); - arch_ops->fetch_registers (regcache, regnum); + arch_ops->fetch_registers (regcache, regnum); + } } else beneath ()->fetch_registers (regcache, regnum); @@ -482,15 +517,22 @@ ravenscar_thread_target::store_registers (struct regcache *regcache, { ptid_t ptid = regcache->ptid (); - if (runtime_initialized () - && is_ravenscar_task (ptid) - && !task_is_currently_active (ptid)) + if (runtime_initialized () && is_ravenscar_task (ptid)) { - struct gdbarch *gdbarch = regcache->arch (); - struct ravenscar_arch_ops *arch_ops - = gdbarch_ravenscar_ops (gdbarch); + if (task_is_currently_active (ptid)) + { + ptid_t base = get_base_thread_from_ravenscar_task (ptid); + temporarily_change_regcache_ptid changer (regcache, base); + beneath ()->store_registers (regcache, regnum); + } + else + { + struct gdbarch *gdbarch = regcache->arch (); + struct ravenscar_arch_ops *arch_ops + = gdbarch_ravenscar_ops (gdbarch); - arch_ops->store_registers (regcache, regnum); + arch_ops->store_registers (regcache, regnum); + } } else beneath ()->store_registers (regcache, regnum); @@ -501,11 +543,18 @@ ravenscar_thread_target::prepare_to_store (struct regcache *regcache) { ptid_t ptid = regcache->ptid (); - if (runtime_initialized () - && is_ravenscar_task (ptid) - && !task_is_currently_active (ptid)) + if (runtime_initialized () && is_ravenscar_task (ptid)) { - /* Nothing. */ + if (task_is_currently_active (ptid)) + { + ptid_t base = get_base_thread_from_ravenscar_task (ptid); + temporarily_change_regcache_ptid changer (regcache, base); + beneath ()->prepare_to_store (regcache); + } + else + { + /* Nothing. */ + } } else beneath ()->prepare_to_store (regcache); -- 2.26.2