From patchwork Wed Feb 5 13:19:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 37694 Received: (qmail 130831 invoked by alias); 5 Feb 2020 13:19:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 130119 invoked by uid 89); 5 Feb 2020 13:19:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=UD:pid X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2020 13:19:31 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 23712204DA; Wed, 5 Feb 2020 08:19:30 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 3ABB6202DF; Wed, 5 Feb 2020 08:19:28 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 159442816C; Wed, 5 Feb 2020 08:19:28 -0500 (EST) X-Gerrit-PatchSet: 2 Date: Wed, 5 Feb 2020 08:19:27 -0500 From: "Tankut Baris Aktemur (Code Review)" To: Pedro Alves , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v2] infrun: extract out a code piece into 'mark_non_executing_threads' fu... X-Gerrit-Change-Id: I2b088f4a724f4260cb37068264964525cf62a118 X-Gerrit-Change-Number: 507 X-Gerrit-ChangeURL: X-Gerrit-Commit: e0688d41ca0cd6013f7950fa1b08bb5e65cdf8b1 In-Reply-To: References: Reply-To: tankut.baris.aktemur@intel.com, palves@redhat.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20200205131928.159442816C@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/507 ...................................................................... infrun: extract out a code piece into 'mark_non_executing_threads' function 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 --- M gdb/infrun.c 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index fd72a74..9224376 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4673,6 +4673,47 @@ } } +/* 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 @@ -5107,41 +5148,7 @@ } } - /* 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) {