From: Keith Seitz <keiths@redhat.com>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] [gdb/testsuite] Fix race in gdb.threads/leader-exit.exp
Date: Fri, 24 Jul 2026 10:49:16 -0700 [thread overview]
Message-ID: <b8e65b12-970d-4d5f-91ca-3a01963a47fd@redhat.com> (raw)
In-Reply-To: <20260723114042.703464-2-tdevries@suse.de>
Hi,
On 7/23/26 4:40 AM, Tom de Vries wrote:
>
> The problem is that after the pthread_join is executed:
> ...
> i = pthread_join (main_thread, NULL);
> ...
>
> sleep (10); /* break-here */
> ...
> there's a race between:
> - the breakpoint at break-here triggering, and
> - the "Thread exited" message for the main thread being reported.
While I cannot reproduce this on my local hardware, your analysis
is sound.
> Fix this by:
> - adding a loop before the break location
> - waiting in the loop until the "Thread exited" message is seen
> - sending ^C to get a prompt
> - setting a variable to exit the loop
>
> Likewise in gdb.threads/non-ldr-exc-2.exp.
Sounds like a plan!
> diff --git a/gdb/testsuite/gdb.threads/leader-exit.exp b/gdb/testsuite/gdb.threads/leader-exit.exp
> index b5e6f558ac7..22f27d2d6e8 100644
> --- a/gdb/testsuite/gdb.threads/leader-exit.exp
> +++ b/gdb/testsuite/gdb.threads/leader-exit.exp
> @@ -30,6 +30,28 @@ if {![runto_main]} {
> return
> }
>
> +# Wait for the "Thread exited" message.
> +set re_thread_exited {\[Thread [^\r\n]+ exited\]}
> +set saw_thread_exited 0
> +gdb_test_multiple "continue" "continue to thread exited" {
> + -re $re_thread_exited {
> + set saw_thread_exited 1
> + # Get a prompt.
> + send_gdb "\003"
> + exp_continue
> + }
> + -re -wrap "" {
> + pass $gdb_test_name
> + }
> +}
> +gdb_assert {$saw_thread_exited} "thread exited"
> +if {!$saw_thread_exited} {
> + return
> +}
> +
> +# Let the inferior to exit the wait_for_exit loop.
This comment got a bit jumbled. Superfluous "to"?
> +gdb_test_no_output "set var wait_for_exit = 0"
> +
> gdb_breakpoint [gdb_get_line_number "break-here"]
> gdb_continue_to_breakpoint "break-here" ".* break-here .*"
>
> diff --git a/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp b/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp
> index ead262cc2b5..dfc34f42afe 100644
> --- a/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp
> +++ b/gdb/testsuite/gdb.threads/non-ldr-exc-2.exp
> @@ -37,6 +37,28 @@ proc do_test { lock_sched nonstop } {
> return -1
> }
>
> + # Wait for the "Thread exited" message.
> + set re_thread_exited {\[Thread [^\r\n]+ exited\]}
> + set saw_thread_exited 0
> + gdb_test_multiple "continue" "continue to thread exited" {
> + -re $re_thread_exited {
> + set saw_thread_exited 1
> + # Get a prompt.
> + send_gdb "\003"
> + exp_continue
> + }
> + -re -wrap "" {
> + pass $gdb_test_name
> + }
> + }
> + gdb_assert {$saw_thread_exited} "thread exited"
> + if {!$saw_thread_exited} {
> + return
> + }
> +
> + # Let the inferior to exit the wait_for_exit loop.
Same nit in this comment.
Question: Since this test file now relies on sending the target
an interrupt, does it also need the same "require" on gdb,nointerrupts
that leader-exit.exp has?
Reviewed-By: Keith Seitz <keiths@redhat.com>
Keith
> + gdb_test_no_output "set var wait_for_exit = 0"
> +
> gdb_breakpoint [gdb_get_line_number "break-here"]
> gdb_continue_to_breakpoint "break-here" ".* break-here .*"
>
next prev parent reply other threads:[~2026-07-24 17:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 11:40 [PATCH 0/2] [gdb/testsuite] Two gdb.threads patches Tom de Vries
2026-07-23 11:40 ` [PATCH 1/2] [gdb/testsuite] Fix race in gdb.threads/leader-exit.exp Tom de Vries
2026-07-24 17:49 ` Keith Seitz [this message]
2026-07-25 7:03 ` Tom de Vries
2026-07-23 11:40 ` [PATCH 2/2] [gdb/testsuite] Fix timeout in gdb.threads/vfork-multi-inferior.exp Tom de Vries
2026-07-24 17:52 ` Keith Seitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b8e65b12-970d-4d5f-91ca-3a01963a47fd@redhat.com \
--to=keiths@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tdevries@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox