From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id B7A703945C22 for ; Tue, 14 Apr 2020 17:55:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B7A703945C22 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-KlCH8hsEOjqKjoB8PUGJtg-1; Tue, 14 Apr 2020 13:54:56 -0400 X-MC-Unique: KlCH8hsEOjqKjoB8PUGJtg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0701EDB62 for ; Tue, 14 Apr 2020 17:54:56 +0000 (UTC) Received: from cascais.Home (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9885B9F9AC for ; Tue, 14 Apr 2020 17:54:55 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 26/28] Don't write to inferior_ptid in ravenscar-thread.c Date: Tue, 14 Apr 2020 18:54:32 +0100 Message-Id: <20200414175434.8047-27-palves@redhat.com> In-Reply-To: <20200414175434.8047-1-palves@redhat.com> References: <20200414175434.8047-1-palves@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-29.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, 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: Tue, 14 Apr 2020 17:55:03 -0000 gdb/ChangeLog: yyyy-mm-dd Pedro Alves =09* ravenscar-thread.c (ravenscar_thread_target): Update. =09(ravenscar_thread_target::update_inferior_ptid): Rename to ... =09(ravenscar_thread_target::add_active_thread): ... this. Don't =09set m_base_ptid here. Update to avoid referencing inferior_ptid. =09(ravenscar_thread_target::wait): Don't write to inferior_ptid. --- gdb/ravenscar-thread.c | 49 ++++++++++++++++++++++++----------------------= --- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index fd3beb03ec..93e02b1f40 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -77,8 +77,11 @@ static const target_info ravenscar_target_info =3D { struct ravenscar_thread_target final : public target_ops { ravenscar_thread_target () + : m_base_ptid (inferior_ptid) { - update_inferior_ptid (); + thread_info *thr =3D add_active_thread (); + if (thr !=3D nullptr) + switch_to_thread (thr); } =20 const target_info &info () const override @@ -126,9 +129,9 @@ struct ravenscar_thread_target final : public target_op= s /* PTID of the last thread that received an event. This can be useful to determine the associated task that received the event, to make it the current task. */ - ptid_t m_base_ptid =3D null_ptid; + ptid_t m_base_ptid; =20 - void update_inferior_ptid (); + thread_info *add_active_thread (); ptid_t active_task (int cpu); bool task_is_currently_active (ptid_t ptid); bool runtime_initialized (); @@ -213,37 +216,36 @@ get_base_thread_from_ravenscar_task (ptid_t ptid) return ptid_t (ptid.pid (), base_cpu, 0); } =20 -/* Fetch the ravenscar running thread from target memory and - update inferior_ptid accordingly. */ +/* Fetch the ravenscar running thread from target memory, make sure + there's a corresponding thread in the thread list, and return it. + If the runtime is not initialized, return NULL. */ =20 -void -ravenscar_thread_target::update_inferior_ptid () +thread_info * +ravenscar_thread_target::add_active_thread () { process_stratum_target *proc_target =3D as_process_stratum_target (this->beneath ()); =20 int base_cpu; =20 - m_base_ptid =3D inferior_ptid; - - gdb_assert (!is_ravenscar_task (inferior_ptid)); + gdb_assert (!is_ravenscar_task (m_base_ptid)); base_cpu =3D ravenscar_get_thread_base_cpu (m_base_ptid); =20 - /* If the runtime has not been initialized yet, the inferior_ptid is - the only ptid that there is. */ if (!runtime_initialized ()) - return; + return nullptr; =20 /* Make sure we set m_base_ptid before calling active_task as the latter relies on it. */ - inferior_ptid =3D active_task (base_cpu); - gdb_assert (inferior_ptid !=3D null_ptid); + ptid_t active_ptid =3D active_task (base_cpu); + gdb_assert (active_ptid !=3D null_ptid); =20 /* The running thread may not have been added to system.tasking.debug's list yet; so ravenscar_update_thread_list may not always add it to the thread list. Add it here. */ - if (!find_thread_ptid (proc_target, inferior_ptid)) - add_thread (proc_target, inferior_ptid); + thread_info *active_thr =3D find_thread_ptid (proc_target, active_ptid); + if (active_thr =3D=3D nullptr) + active_thr =3D add_thread (proc_target, active_ptid); + return active_thr; } =20 /* The Ravenscar Runtime exports a symbol which contains the ID of @@ -343,12 +345,11 @@ ravenscar_thread_target::wait (ptid_t ptid, =3D as_process_stratum_target (this->beneath ()); ptid_t event_ptid; =20 - inferior_ptid =3D m_base_ptid; if (ptid !=3D minus_one_ptid) ptid =3D m_base_ptid; event_ptid =3D beneath->wait (ptid, status, 0); - /* Find any new threads that might have been created, and update - inferior_ptid to the active thread. + /* Find any new threads that might have been created, and return the + active thread. =20 Only do it if the program is still alive, though. Otherwise, this causes problems when debugging through the remote protocol, @@ -357,13 +358,11 @@ ravenscar_thread_target::wait (ptid_t ptid, if (status->kind !=3D TARGET_WAITKIND_EXITED && status->kind !=3D TARGET_WAITKIND_SIGNALLED) { - inferior_ptid =3D event_ptid; + m_base_ptid =3D event_ptid; this->update_thread_list (); - this->update_inferior_ptid (); + return this->add_active_thread ()->ptid; } - else - inferior_ptid =3D m_base_ptid; - return inferior_ptid; + return m_base_ptid; } =20 /* Add the thread associated to the given TASK to the thread list --=20 2.14.5