diff options
author | Pedro Alves <pedro@palves.net> | 2023-11-14 11:47:15 +0000 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2023-11-15 18:03:54 +0000 |
commit | d2eca84d73a66cf93acbf14522efc835e4446f57 (patch) | |
tree | 653c576fe7eca6c6af197bbbf114a4adf18e2101 /gdb/testsuite | |
parent | 7d21600b31fe959b758ed475a2211d6805047df9 (diff) | |
download | gdb-d2eca84d73a66cf93acbf14522efc835e4446f57.zip gdb-d2eca84d73a66cf93acbf14522efc835e4446f57.tar.gz gdb-d2eca84d73a66cf93acbf14522efc835e4446f57.tar.bz2 |
Fix gdb.threads/threads-after-exec.exp race
Simon noticed that gdb.threads/threads-after-exec.exp was racy. You
can consistenly reproduce it (at git hash
319b460545dc79280e2904dcc280057cf71fb753), with:
$ taskset -c 0 make check TESTS="gdb.threads/threads-after-exec.exp"
gdb.log shows:
(...)
Thread 3 "threads-after-e" hit Catchpoint 2 (exec'd .../gdb.threads/threads-after-exec/threads-after-exec), 0x00007ffff7fe3290
in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) PASS: gdb.threads/threads-after-exec.exp: continue until exec
info threads
Id Target Id Frame
* 3 process 1443269 "threads-after-e" 0x00007ffff7fe3290 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) FAIL: gdb.threads/threads-after-exec.exp: info threads
(...)
maint info linux-lwps
LWP Ptid Thread ID
1443269.1443269.0 1.3
(gdb) FAIL: gdb.threads/threads-after-exec.exp: maint info linux-lwps
The FAILs happen because the .exp file expects that after the exec,
the only thread has GDB thread number 1, but it has instead 3.
This is yet another case of zombie leader detection making things a
bit fuzzy.
In the passing case, we have:
continue
Continuing.
[New Thread 0x7ffff7bff640 (LWP 603183)]
[Thread 0x7ffff7bff640 (LWP 603183) exited]
process 603180 is executing new program: .../gdb.threads/threads-after-exec/threads-after-exec
While in the failing case, we have (note remarks on the rhs):
continue
Continuing.
[New Thread 0x7ffff7bff640 (LWP 600205)]
[Thread 0x7ffff7f95740 (LWP 600202) exited] <<< gdb deletes leader thread, thread 1.
[New LWP 600202] <<< gdb adds it back -- this is now thread 3.
[Thread 0x7ffff7bff640 (LWP 600205) exited]
process 600202 is executing new program: .../threads-after-exec/threads-after-exec
The testcase only has two threads, yet GDB presented the exec for
thread 3. This is GDB deleting the leader (the backend detected it
was zombie, due to the exec), and then adding the leader back when it
saw the exec event.
I've recorded some thoughts about this in PR gdb/31069.
For now, this commit just makes the testcase cope with the non-one
thread number, as the number is not important for what this test is
exercising.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31069
Change-Id: Id80b5c73f09c9e0005efeb494cca5d066ac3bbae
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.threads/threads-after-exec.exp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gdb/testsuite/gdb.threads/threads-after-exec.exp b/gdb/testsuite/gdb.threads/threads-after-exec.exp index cd8adf9..8d5a518 100644 --- a/gdb/testsuite/gdb.threads/threads-after-exec.exp +++ b/gdb/testsuite/gdb.threads/threads-after-exec.exp @@ -32,14 +32,18 @@ proc do_test { } { gdb_test "continue" "Catchpoint $::decimal .*" "continue until exec" # Confirm we only have one thread in the thread list. - gdb_test "info threads" "\\* 1\[ \t\]+\[^\r\n\]+.*" + gdb_test "p \$_inferior_thread_count" " = 1" + + # Get the post-exec thread number. Due to PR gdb/31069 ("Zombie + # leader detection racy") this isn't always thread 1.1. + set cur_thr [get_integer_valueof "\$_thread" 0] if {[istarget *-*-linux*] && [gdb_is_target_native]} { # Confirm there's only one LWP in the list as well, and that - # it is bound to thread 1.1. + # it is bound to the existing GDB thread. set inf_pid [get_inferior_pid] gdb_test_multiple "maint info linux-lwps" "" { - -wrap -re "Thread ID *\r\n$inf_pid\.$inf_pid\.0\[ \t\]+1\.1 *" { + -wrap -re "Thread ID *\r\n$inf_pid\.$inf_pid\.0\[ \t\]+1\.$cur_thr *" { pass $gdb_test_name } } |