From patchwork Fri Oct 18 13:27:03 2019 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: 35134 Received: (qmail 53772 invoked by alias); 18 Oct 2019 13:27:08 -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 53761 invoked by uid 89); 18 Oct 2019 13:27:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 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=23703 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; Fri, 18 Oct 2019 13:27:06 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 2ADBD20940; Fri, 18 Oct 2019 09:27:05 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 6C3E2206FC for ; Fri, 18 Oct 2019 09:27:03 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 161B020AF6 for ; Fri, 18 Oct 2019 09:27:03 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Fri, 18 Oct 2019 09:27:03 -0400 From: "Tankut Baris Aktemur (Code Review)" To: gdb-patches@sourceware.org Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] infrun: mark an exited thread non-executing when attempting to stop X-Gerrit-Change-Id: I7cec98f40283773b79255d998511da434e9cd408 X-Gerrit-Change-Number: 133 X-Gerrit-ChangeURL: X-Gerrit-Commit: 411a56782f5b12f8bc852b6a163d8fed3df12ca3 References: Reply-To: tankut.baris.aktemur@intel.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Tankut Baris Aktemur has uploaded a new change for review. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/133 ...................................................................... infrun: mark an exited thread non-executing when attempting to stop In stop_all_threads, GDB sends signals to other threads in an attempt to stop them. While in a typical scenario the expected wait status is TARGET_WAITKIND_STOPPED, it is possible that the thread GDB attempted to stop has already terminated. If so, a waitstatus other than TARGET_WAITKIND_STOPPED would be received. In that case, mark the thread as not-executing and set its state to THREAD_EXITED. If a wait status that denotes thread termination is ignored, GDB goes into an infinite loop in stop_all_threads. E.g.: ~~~ $ gdb ./a.out (gdb) start ... (gdb) add-inferior -exec ./a.out ... (gdb) inferior 2 ... (gdb) start ... (gdb) set schedule-multiple on (gdb) set debug infrun 2 (gdb) continue Continuing. infrun: clear_proceed_status_thread (process 23419) infrun: clear_proceed_status_thread (process 23703) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: proceed: resuming process 23419 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 23419] at 0x55555555514e infrun: infrun_async(1) infrun: prepare_to_wait infrun: proceed: resuming process 23703 infrun: resume (step=0, signal=GDB_SIGNAL_0), trap_expected=0, current thread [process 23703] at 0x55555555514e infrun: prepare_to_wait infrun: target_wait (-1.0.0, status) = infrun: 23703.23703.0 [process 23703], infrun: status->kind = exited, status = 42 infrun: handle_inferior_event status->kind = exited, status = 42 [Inferior 2 (process 23703) exited with code 052] infrun: stop_waiting infrun: stop_all_threads infrun: stop_all_threads, pass=0, iterations=0 infrun: process 23419 executing, need stop infrun: target_wait (-1.0.0, status) = infrun: 23419.23419.0 [process 23419], infrun: status->kind = exited, status = 42 infrun: stop_all_threads status->kind = exited, status = 42 process 23419 infrun: process 23419 executing, already stopping infrun: target_wait (-1.0.0, status) = infrun: -1.0.0 [process -1], infrun: status->kind = no-resumed infrun: stop_all_threads status->kind = no-resumed process -1 infrun: process 23419 executing, already stopping infrun: target_wait (-1.0.0, status) = infrun: -1.0.0 [process -1], infrun: status->kind = no-resumed infrun: stop_all_threads status->kind = no-resumed process -1 infrun: process 23419 executing, already stopping infrun: target_wait (-1.0.0, status) = infrun: -1.0.0 [process -1], infrun: status->kind = no-resumed infrun: stop_all_threads status->kind = no-resumed process -1 infrun: process 23419 executing, already stopping infrun: target_wait (-1.0.0, status) = infrun: -1.0.0 [process -1], infrun: status->kind = no-resumed infrun: stop_all_threads status->kind = no-resumed process -1 infrun: process 23419 executing, already stopping ~~~ And this polling goes on forever. This patch prevents the infinite looping behavior. gdb/ChangeLog: 2019-10-18 Tankut Baris Aktemur * infrun.c (stop_all_threads): Do NOT ignore TARGET_WAITKIND_NO_RESUMED, TARGET_WAITKIND_THREAD_EXITED, TARGET_WAITKIND_EXITED, TARGET_WAITKIND_SIGNALLED wait statuses received from threads we attempt to stop; mark the corresponding thread as THREAD_EXITED and not-executing. Change-Id: I7cec98f40283773b79255d998511da434e9cd408 --- M gdb/infrun.c 1 file changed, 9 insertions(+), 0 deletions(-) diff --git a/gdb/infrun.c b/gdb/infrun.c index 66a066f..01fcbf6 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4383,6 +4383,15 @@ { /* All resumed threads exited or one thread/process exited/signalled. */ + thread_info *t = find_thread_ptid (event_ptid); + if (t != nullptr) + { + t->stop_requested = 0; + t->executing = 0; + t->resumed = 0; + t->control.may_range_step = 0; + t->state = THREAD_EXITED; + } } else {