From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id n/BkGKZJDGrwzgcAWB0awg (envelope-from ) for ; Tue, 19 May 2026 07:29:42 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WIfFdaC1; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 53E021E062; Tue, 19 May 2026 07:29:42 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4F8201E062 for ; Tue, 19 May 2026 07:29:40 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 808FB4BAD15B for ; Tue, 19 May 2026 11:29:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 808FB4BAD15B Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WIfFdaC1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 485E84BA798F for ; Tue, 19 May 2026 11:29:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 485E84BA798F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 485E84BA798F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779190151; cv=none; b=I5ffmm6FrilG4UGIKA23TnEZSp8JMpgBcO1qLqlI4mQvW2qmqbV6g6MbTQPp7gO+EUZDwqnvSK4SXKLuj3KRmgQhyccNoVzrkaQ71OhlE35M+3eglezwKGjWCcvpxFH4S0x4k+9vYG5XahvgjDJUfxSTOgAeqDcFNbZfhIUgN8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779190151; c=relaxed/simple; bh=Mn1eDDo7bOt1i8n1XQf+Py9T8zHX8bczPvt113PdUIo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ms/5hyktnz+b6WKOtSV6B8ZUnZPw0rhwfqixcNCma6skyx9IUBEe9bzqtBz62xHREs0hV2vPJJ03BcwwvA1aI/0Q2em41Sd3Tl2HBxtfnYtChJbQhC7S6qFXXwYDHMOQYIfgS9gBnqdsvEiFfzpXItATzvm1eFSsVRAqxFrzdCk= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WIfFdaC1 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 485E84BA798F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779190150; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RCZ6HyXH8f20TgSNeC19Sa38q0+j3Uty9yRsC+aCww4=; b=WIfFdaC1PIuWYtBU5Fr+po1aGOrg5Bse0dHd7yTSrFrvkqI2A8NdSpY7Z/OtaCellrHiHe hIJo32J7X9Df7glDs3medN9zZAaTLOQ/a/PHBCbQf0o1GKWJL/bEtCUjMd7MW1kAlk2wZD S+CTBfyH+cdByIKwa3LMWlS+e4/crGM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-U94myYwJOjyV9gmQdCcYuQ-1; Tue, 19 May 2026 07:29:09 -0400 X-MC-Unique: U94myYwJOjyV9gmQdCcYuQ-1 X-Mimecast-MFC-AGG-ID: U94myYwJOjyV9gmQdCcYuQ_1779190148 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48fd9c22b8fso28185575e9.3 for ; Tue, 19 May 2026 04:29:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779190148; x=1779794948; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RCZ6HyXH8f20TgSNeC19Sa38q0+j3Uty9yRsC+aCww4=; b=Az6bU4U52VcglZOmGf4aEUOBfS5fxp9IcM0rBRCPrYS34XEGqu4DF340dEV0YMbqIx 1JrjbrgWUfsOcrauKfgWPPgjTuzaHnGG57g0lhZMGet/qDzZ8hEH544P1ezQ9FoEj/r8 EDkjpLTat8+NiY652KzHipgsqWDoMpa5UFbTNHEOsrwFuDPgHpe2/dIJ/rbZooqPyWek VzxFigD7FiQzkjO7NMu8ZnjRo6fSZrOTRcu3XaAlCGTKmX2+HDQIZmBDkaqyrVHQfkuJ TOL6b5ZL8kjyhBUzLUZB/aOckjB750nU+HhQi7xFwdCZfmBoZDseKNRDJUUfypI5E7In qM4g== X-Forwarded-Encrypted: i=1; AFNElJ9eZQlWgaxAMxDTaTnVw7b0rpytlDvYUGhkK5c+2PTE77LBqjd1mQnFCLp0+RfXSBjL6doG7Uw7Qdm6Vw==@sourceware.org X-Gm-Message-State: AOJu0Yyw6cvugoIM2kJihrZGzY3KZNSz5poMOTDGa5bVZyMimAQWbV3o rtXhM1qhcRrmQoHDhagp1nSTU6gwtmsiq9Ar2biYd9Os9/QVPy3zo8tupMjp1bPj6gwW5KRZSkm 3HHMYqYpuEBPPxpxtr503V97uw5V4tEzDEVIHEP2mRsNCojoCGGvbSjWRuyFmD/37QT7YFzQ= X-Gm-Gg: Acq92OGth1oJH7EKZRZSRdARaNKwBc+lhyPoSg6jPqmtPf7fxjB6EpIG58d9N0NxGdr ofiRZ/OmrnaC7tB7RuMVZhfL5CCLWkUOjCFyI/Z3x5xLJJv4fn3rq32MjNQD/dWNOgj5neT0no8 1AXl6aO3tQZNVmZLbaeZZAHucgov5Qhq8jaRBglJwedHTx3UDIKa5pb36H+JT4rZq5FTn0A0dxF 2xGlyVtnNBsWweFEHduFJbkQLkHGFqJZCj2A93sj6Be+DZjAdDGOt2VPjyaJXuH5hhqQ366odP7 AQEBXyi92jB7GoFymjaB3Zz0oyxA0ipuPOdxkX5qG6dKrgv2wIa31P6iCfEQdSlz/kftSeCa+S7 crKnOj5khMiAEXtVP X-Received: by 2002:a05:600c:4a1a:b0:48a:592c:e655 with SMTP id 5b1f17b1804b1-48fe6325f25mr179174845e9.17.1779190147783; Tue, 19 May 2026 04:29:07 -0700 (PDT) X-Received: by 2002:a05:600c:4a1a:b0:48a:592c:e655 with SMTP id 5b1f17b1804b1-48fe6325f25mr179174525e9.17.1779190147278; Tue, 19 May 2026 04:29:07 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48fe4c90b27sm331674265e9.8.2026.05.19.04.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 May 2026 04:29:06 -0700 (PDT) From: Andrew Burgess To: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [PATCH] Sync thread state after infcalls with "set unwind-on-* on" (PR gdb/34148) In-Reply-To: <20260518191838.1301993-1-pedro@palves.net> References: <20260518191838.1301993-1-pedro@palves.net> Date: Tue, 19 May 2026 12:29:05 +0100 Message-ID: <87h5o3zlha.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: W5xO-px61w8S6se9uUsqEf7ICekZ5D5qaD8eJaB_NII_1779190148 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Pedro Alves writes: > Commit 519774805a1 ("Don't pretend infcalls don't set the inferior > running (PR gdb/34082)") removed the special case in proceed that > skipped set_state(THREAD_RUNNING) for infcalls. That fixed > gdb.threads/hand-call-new-thread.exp, but introduced a regression in > gdb.compile/compile.exp: > > ... > set unwind-on-signal on > (gdb) PASS: gdb.compile/compile.exp: set unwind-on-signal on > compile code *(volatile int *) 0 = 0; > The program being debugged received signal SIGSEGV, Segmentation fault > while in a function called from GDB. GDB has restored the context > to what it was before the call. To change this behavior use > "set unwind-on-signal off". Evaluation of the expression containing > the function (_gdb_expr) will be abandoned. > (gdb) PASS: gdb.compile/compile.exp: compile code segfault second > break 132 > Breakpoint 2 at 0x555555555262: file .../compile.c, line 132. > (gdb) continue > Cannot execute this command while the selected thread is running. > (gdb) FAIL: gdb.compile/compile.exp: continue to breakpoint: break-here > > The "compile code" command before the FAIL is an infcall under the > hood. That hits SIGSEGV with "set unwind-on-signal on" in effect, so > GDB unwinds and abandons the call. After that, "continue" is rejected > because the thread is still marked THREAD_RUNNING from the proceed > that started the infcall. > > When an infcall is unwound due to a signal, timeout, or terminating > exception, call_thread_fsm::should_notify_stop returns false, and so > normal_stop is not called from fetch_inferior_event. normal_stop is > what would normally call finish_thread_state to sync the public thread > state back to THREAD_STOPPED. run_inferior_call has a fallback > finish_thread_state call for that purpose, but it is gated on > stop_stack_dummy == STOP_STACK_DUMMY, which is only true for > successful calls. > > Before the commit mentioned above, proceed never marked an infcall's > thread as THREAD_RUNNING, so the missing RUNNING => STOPPED transition > was harmless. The old comment in infcall.c about the > finish_thread_state call claimed "If the infcall does NOT succeed, > normal_stop will have already finished the thread states", but that > was already incorrect for the unwind paths. It just happened to not > matter. > > Fix this by dropping the STOP_STACK_DUMMY guard and updating the > comment to describe the actual rule: sync regardless of how the call > ended. The !was_running check is kept since it is there to exclude > the in-cond-eval case, where the thread is meant to stay marked > running. finish_thread_state is idempotent, so the call is harmless > on paths where normal_stop also ran. > > Extend gdb.base/unwindonsignal.exp to exercise the "set > unwind-on-signal on" path without having to rely on the "compile code" > feature. Without the fix, the test fails like so: > > info threads > Id Target Id Frame > * 1 Thread 0x7ffff7f8f740 (LWP 239019) "unwindonsignal" (running) > (gdb) FAIL: gdb.base/unwindonsignal.exp: thread is stopped > continue > Cannot execute this command while the selected thread is running. > (gdb) FAIL: gdb.base/unwindonsignal.exp: continue until exit at after unwound infcall > > Similarly, extend gdb.cp/gdb2495.exp for "set > unwind-on-terminating-exception on", and gdb.base/infcall-timeout.exp > for "set unwind-on-timeout on". Both would fail without the code fix, > too. > > With the fix, gdb.compile/compile.exp now passes cleanly. > > Tested on x86_64-unknown-linux-gnu. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34148 Thanks for fixing this, and for the great explanation. This LGTM. Approved-By: Andrew Burgess Thanks, Andrew > Change-Id: Idef0dcd4dd751b501869c58b752f77d4dadb6c72 > commit-id: 1a8b36d4 > --- > gdb/infcall.c | 23 ++++++++++++++-------- > gdb/testsuite/gdb.base/infcall-timeout.exp | 13 ++++++++++++ > gdb/testsuite/gdb.base/unwindonsignal.exp | 10 ++++++++++ > gdb/testsuite/gdb.cp/gdb2495.exp | 6 ++++++ > 4 files changed, 44 insertions(+), 8 deletions(-) > > diff --git a/gdb/infcall.c b/gdb/infcall.c > index 8b26f541de6..e6b24ff5310 100644 > --- a/gdb/infcall.c > +++ b/gdb/infcall.c > @@ -918,12 +918,20 @@ run_inferior_call (std::unique_ptr sm, > current_ui->register_file_handler (); > } > > - /* If the infcall does NOT succeed, normal_stop will have already > - finished the thread states. However, on success, normal_stop > - defers here, so that we can set back the thread states to what > - they were before the call. Note that we must also finish the > - state of new threads that might have spawned while the call was > - running. The main cases to handle are: > + /* Sync the user/frontend thread states from the internal thread > + states. proceed marked threads in resume_ptid as THREAD_RUNNING > + for this infcall; we must now sync them back, regardless of how > + the call ended. For the success path and for the unwind paths > + (unwind-on-{signal,timeout,terminating-exception}), > + call_thread_fsm::should_notify_stop returns false and normal_stop > + is skipped -- this call is the canonical place to do the sync. > + For other failure paths normal_stop does run and has already > + finished the thread state; finish_thread_state is idempotent, so > + calling it again here is harmless. Note that we must also finish > + the state of new threads that might have spawned while the call > + was running. > + > + The main cases to handle are: > > - "(gdb) print foo ()", or any other command that evaluates an > expression at the prompt. (The thread was marked stopped before.) > @@ -934,8 +942,7 @@ run_inferior_call (std::unique_ptr sm, > evaluates true and thus we'll present a user-visible stop is > decided elsewhere. */ > if (!was_running > - && call_thread_ptid == inferior_ptid > - && stop_stack_dummy == STOP_STACK_DUMMY) > + && call_thread_ptid == inferior_ptid) > finish_thread_state (call_thread->inf->process_target (), > user_visible_resume_ptid (0)); > > diff --git a/gdb/testsuite/gdb.base/infcall-timeout.exp b/gdb/testsuite/gdb.base/infcall-timeout.exp > index 37aa6c0ef54..99d29624337 100644 > --- a/gdb/testsuite/gdb.base/infcall-timeout.exp > +++ b/gdb/testsuite/gdb.base/infcall-timeout.exp > @@ -86,6 +86,19 @@ proc run_test { target_async target_non_stop non_stop unwind } { > gdb_test "bt" \ > ".* function_that_never_returns .*.*" > } > + > + # After the infcall, the thread should be stopped. Regression > + # test for PR gdb/34148. > + if {$non_stop} { > + # Check the main thread only, in case we have system-spawned > + # threads. > + set thread_filter "1" > + } else { > + set thread_filter "" > + } > + gdb_test "info threads -running $thread_filter" \ > + "No threads matched\\." \ > + "thread is stopped" > } > > foreach_with_prefix target_async { "on" "off" } { > diff --git a/gdb/testsuite/gdb.base/unwindonsignal.exp b/gdb/testsuite/gdb.base/unwindonsignal.exp > index aed8ef6f4c7..2ae8cc4a6dd 100644 > --- a/gdb/testsuite/gdb.base/unwindonsignal.exp > +++ b/gdb/testsuite/gdb.base/unwindonsignal.exp > @@ -86,3 +86,13 @@ gdb_test_multiple "maint print dummy-frames" \ > pass $gdb_test_name > } > } > + > +# After the unwound infcall, the thread should be stopped, and a > +# subsequent resumption command should be accepted. Regression test > +# for PR gdb/34148. > + > +gdb_test "info threads -running" \ > + "No threads matched\\." \ > + "thread is stopped" > + > +gdb_continue_to_end "after unwound infcall" > diff --git a/gdb/testsuite/gdb.cp/gdb2495.exp b/gdb/testsuite/gdb.cp/gdb2495.exp > index aa5a2a16e43..60396494161 100644 > --- a/gdb/testsuite/gdb.cp/gdb2495.exp > +++ b/gdb/testsuite/gdb.cp/gdb2495.exp > @@ -64,6 +64,12 @@ gdb_test "p exceptions.throw_function()" \ > "The program being debugged entered a std::terminate call, .*" \ > "call a function that raises an exception without a handler." > > +# Make sure that the thread is stopped. Regression test for PR > +# gdb/34148. > +gdb_test "info threads -running" \ > + "No threads matched\\." \ > + "thread is stopped" > + > # Make sure that after rewinding we are back at the call parent. > gdb_test "bt" \ > "#0 main.*" \ > > base-commit: f6c1ca239d932db39a6f19d9bd343f4f4fddba76 > -- > 2.53.0