Testcases for stepping over thread exit syscall (PR gdb/27338)
[binutils-gdb.git] / gdb / testsuite / gdb.threads / step-over-thread-exit.exp
1 # Copyright 2021-2022 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # Test stepping over a breakpoint installed on an instruction that
17 # exits the thread.
18
19 standard_testfile .c
20
21 set syscalls_src $srcdir/lib/my-syscalls.S
22
23 if { [build_executable "failed to prepare" $testfile \
24 [list $srcfile $syscalls_src] {debug pthreads}] == -1 } {
25 return
26 }
27
28 # Each argument is a different testing axis, most of them obvious.
29 # NS_STOP_ALL is only used if testing "set non-stop on", and indicates
30 # whether to have GDB explicitly stop all threads before continuing to
31 # thread exit.
32 proc test {displaced-stepping non-stop target-non-stop schedlock ns_stop_all} {
33 if {${non-stop} == "off" && $ns_stop_all} {
34 error "invalid arguments"
35 }
36
37 save_vars ::GDBFLAGS {
38 append ::GDBFLAGS " -ex \"maintenance set target-non-stop ${target-non-stop}\""
39 append ::GDBFLAGS " -ex \"set non-stop ${non-stop}\""
40 clean_restart $::binfile
41 }
42
43 gdb_test_no_output "set displaced-stepping ${displaced-stepping}"
44
45 if { ![runto_main] } {
46 return
47 }
48
49 gdb_breakpoint "my_exit_syscall"
50
51 if {$schedlock
52 || (${non-stop} == "on" && $ns_stop_all)} {
53 gdb_test "continue" \
54 "Thread 2 .*hit Breakpoint $::decimal.* my_exit_syscall .*" \
55 "continue until syscall"
56
57 if {${non-stop} == "on"} {
58 # The test only spawns one thread at a time, so this just
59 # stops the main thread.
60 gdb_test_multiple "interrupt -a" "" {
61 -re "$::gdb_prompt " {
62 gdb_test_multiple "" $gdb_test_name {
63 -re "Thread 1 \[^\r\n\]*stopped." {
64 pass $gdb_test_name
65 }
66 }
67 }
68 }
69 }
70
71 gdb_test "thread 2" "Switching to thread 2 .*"
72
73 gdb_test_no_output "set scheduler-locking ${schedlock}"
74
75 gdb_test "continue" \
76 "No unwaited-for children left." \
77 "continue stops when thread exits"
78 } else {
79 gdb_test_no_output "set scheduler-locking ${schedlock}"
80
81 for { set i 0 } { $i < 100 } { incr i } {
82 with_test_prefix "iter $i" {
83 set ok 0
84 set thread "<unknown>"
85 gdb_test_multiple "continue" "" {
86 -re -wrap "Thread ($::decimal) .*hit Breakpoint $::decimal.* my_exit_syscall .*" {
87 set thread $expect_out(1,string)
88 set ok 1
89 }
90 }
91 if {!${ok}} {
92 # Exit if there's a failure to avoid lengthy
93 # timeouts.
94 break
95 }
96
97 if {${non-stop}} {
98 gdb_test "thread $thread" "Switching to thread .*" \
99 "switch to event thread"
100 }
101 }
102 }
103 }
104 }
105
106 foreach_with_prefix displaced-stepping {off auto} {
107 foreach_with_prefix non-stop {off on} {
108 foreach_with_prefix target-non-stop {off on} {
109 if {${non-stop} == "on" && ${target-non-stop} == "off"} {
110 # Invalid combination.
111 continue
112 }
113
114 foreach_with_prefix schedlock {off on} {
115 if {${non-stop} == "on"} {
116 foreach_with_prefix ns_stop_all {0 1} {
117 test ${displaced-stepping} ${non-stop} ${target-non-stop} \
118 ${schedlock} ${ns_stop_all}
119 }
120 } else {
121 test ${displaced-stepping} ${non-stop} ${target-non-stop} ${schedlock} 0
122 }
123 }
124 }
125 }
126 }