From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id F2666395BC3C for ; Wed, 13 May 2020 20:53:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F2666395BC3C 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-358-9xfaz5ecOfOhdapR3DaJTA-1; Wed, 13 May 2020 16:53:43 -0400 X-MC-Unique: 9xfaz5ecOfOhdapR3DaJTA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A122100726B for ; Wed, 13 May 2020 20:53:42 +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 1BBB361538 for ; Wed, 13 May 2020 20:53:41 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v8 3/6] gdb/infrun: extract out a code piece into 'mark_non_executing_threads' function Date: Wed, 13 May 2020 21:53:35 +0100 Message-Id: <20200513205338.14233-4-palves@redhat.com> In-Reply-To: <20200513205338.14233-1-palves@redhat.com> References: <20200513205338.14233-1-palves@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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, 13 May 2020 20:53:48 -0000 From: Tankut Baris Aktemur This is a refactoring. The extracted function is placed deliberately before 'stop_all_threads' because the function will be re-used there in a subsequent patch for handling an exit status kind received from a thread that GDB attempted to stop. gdb/ChangeLog: 2019-11-04 Tankut Baris Aktemur * infrun.c (handle_inferior_event): Extract out a piece of code into... (mark_non_executing_threads): ...this new function. Change-Id: I2b088f4a724f4260cb37068264964525cf62a118 --- gdb/infrun.c | 77 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index db88a1eef15..c5bf2d0ad74 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4712,6 +4712,47 @@ save_waitstatus (struct thread_info *tp, const target_waitstatus *ws) } } +/* Mark the non-executing threads accordingly. In all-stop, all + threads of all processes are stopped when we get any event + reported. In non-stop mode, only the event thread stops. */ + +static void +mark_non_executing_threads (process_stratum_target *target, + ptid_t event_ptid, + struct target_waitstatus ws) +{ + ptid_t mark_ptid; + + if (!target_is_non_stop_p ()) + mark_ptid = minus_one_ptid; + else if (ws.kind == TARGET_WAITKIND_SIGNALLED + || ws.kind == TARGET_WAITKIND_EXITED) + { + /* If we're handling a process exit in non-stop mode, even + though threads haven't been deleted yet, one would think + that there is nothing to do, as threads of the dead process + will be soon deleted, and threads of any other process were + left running. However, on some targets, threads survive a + process exit event. E.g., for the "checkpoint" command, + when the current checkpoint/fork exits, linux-fork.c + automatically switches to another fork from within + target_mourn_inferior, by associating the same + inferior/thread to another fork. We haven't mourned yet at + this point, but we must mark any threads left in the + process as not-executing so that finish_thread_state marks + them stopped (in the user's perspective) if/when we present + the stop to the user. */ + mark_ptid = ptid_t (event_ptid.pid ()); + } + else + mark_ptid = event_ptid; + + set_executing (target, mark_ptid, false); + + /* Likewise the resumed flag. */ + set_resumed (target, mark_ptid, false); +} + /* See infrun.h. */ void @@ -5145,41 +5186,7 @@ handle_inferior_event (struct execution_control_state *ecs) } } - /* Mark the non-executing threads accordingly. In all-stop, all - threads of all processes are stopped when we get any event - reported. In non-stop mode, only the event thread stops. */ - { - ptid_t mark_ptid; - - if (!target_is_non_stop_p ()) - mark_ptid = minus_one_ptid; - else if (ecs->ws.kind == TARGET_WAITKIND_SIGNALLED - || ecs->ws.kind == TARGET_WAITKIND_EXITED) - { - /* If we're handling a process exit in non-stop mode, even - though threads haven't been deleted yet, one would think - that there is nothing to do, as threads of the dead process - will be soon deleted, and threads of any other process were - left running. However, on some targets, threads survive a - process exit event. E.g., for the "checkpoint" command, - when the current checkpoint/fork exits, linux-fork.c - automatically switches to another fork from within - target_mourn_inferior, by associating the same - inferior/thread to another fork. We haven't mourned yet at - this point, but we must mark any threads left in the - process as not-executing so that finish_thread_state marks - them stopped (in the user's perspective) if/when we present - the stop to the user. */ - mark_ptid = ptid_t (ecs->ptid.pid ()); - } - else - mark_ptid = ecs->ptid; - - set_executing (ecs->target, mark_ptid, false); - - /* Likewise the resumed flag. */ - set_resumed (ecs->target, mark_ptid, false); - } + mark_non_executing_threads (ecs->target, ecs->ptid, ecs->ws); switch (ecs->ws.kind) { -- 2.14.5