RE: [PATCH] kill all threadapply processes at end of test

Carl Love via Gdb-patches
2021-05-18T15:29:38Z

Tom, Simon, GDB maintainers:

I looked at re-writing the test and using pthread barrier as suggested
by Simon. I also went back and worked on my previous attempt to track
the pids to be detached, then at the end re-attach the pids. I was
able to get the second approach to work. The pthread barrier approach
didn't seem to be very obvious how to implement.

The following patch passes in a string to proc thr_apply_detach. Each
pid is appended to the string before detaching from the pid. After the
test is done, the test iterates thru the list of pids attaching to each
one then killing the process.

The patch has been tested on Power to ensure that it passes
successfully and does not leave any threadapply processes running after
the test finishes.

Please let me know if you have suggestions on the patch and if it is
accepatble to commit to mainline. Thanks.

Carl

------------------------------------------------------

gdb/testsuite/ChangeLog:

2021-05-18 Carl Love <cel@us.ibm.com>

* gdb.threads/threadapply.exp (thr_apply_detach): Add detach_pids
argument and return. Add test, gdb_test_multiple, lappend pids to
detach_pids.
Add foreach i loop on detach_pids, add gdb_test tests to attach and
kill each pid.
---
gdb/testsuite/gdb.threads/threadapply.exp | 26 +++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/threadapply.exp b/gdb/testsuite/gdb.threads/threadapply.exp
index ebc1cf15ad6..d39a9798d7c 100644
--- a/gdb/testsuite/gdb.threads/threadapply.exp
+++ b/gdb/testsuite/gdb.threads/threadapply.exp
@@ -69,7 +69,7 @@ gdb_test "down" "#0.*thread_function.*" "go down and check selected frame"
# exits due to the command run via thread apply. Regression test for
# PR threads/13217.

-proc thr_apply_detach {thread_set} {
+proc thr_apply_detach {thread_set detach_pids} {
with_test_prefix "thread apply $thread_set" {
global binfile
global break_line
@@ -84,15 +84,30 @@ proc thr_apply_detach {thread_set} {
gdb_breakpoint "$break_line"
gdb_continue_to_breakpoint "all threads started"

+ set test "get inferior pid"
+ set pid -1
+
+ gdb_test_multiple "info inferior 1" "$test" {
+ -re "process (\[0-9\]*).*" {
+ set pid $expect_out(1,string)
+ pass "$test"
+ }
+ }
+
+ lappend detach_pids $pid
+
gdb_test "thread apply $thread_set detach" "Thread .*"
gdb_test "thread" "No thread selected" "switched to no thread selected"
+ return $detach_pids
}
}

# Test both "all" and a thread list, because those are implemented as
# different commands in GDB.
+set detach_pids ""
+
foreach thread_set {"all" "1.1 1.2 1.3"} {
- thr_apply_detach $thread_set
+ set detach_pids [thr_apply_detach $thread_set $detach_pids]
}

# Test killing and removing inferiors from a command run via "thread
@@ -229,3 +244,10 @@ proc kill_and_remove_inferior {thread_set} {
foreach_with_prefix thread_set {"all" "1.1"} {
kill_and_remove_inferior $thread_set
}
+
+# Make sure all of the threadapply processes are terminated
+foreach i $detach_pids {
+# puts $i
+ gdb_test "attach $i" ".*" "Attach to $i" ".*A program is being debugged already.*" "y"
+ gdb_test "kill" ".*" "KILL $i" ".*Kill the program being debugged.*" "y"
+}
--
2.27.0