Commit | Line | Data |
---|---|---|
d137e6dc PA |
1 | # Copyright (C) 2011-2014 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 that GDB doesn't inadvertently resume the stepped thread when a | |
17 | # signal arrives while stepping over the breakpoint that last caused a | |
18 | # stop, when the thread that hit that breakpoint is not the stepped | |
19 | # thread. | |
20 | ||
21 | standard_testfile | |
22 | set executable ${testfile} | |
23 | ||
24 | if [target_info exists gdb,nosignals] { | |
25 | verbose "Skipping ${testfile}.exp because of nosignals." | |
26 | return -1 | |
27 | } | |
28 | ||
29 | # Test uses host "kill". | |
30 | if { [is_remote target] } { | |
31 | return -1 | |
32 | } | |
33 | ||
34 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ | |
35 | executable [list debug "incdir=${objdir}"]] != "" } { | |
36 | return -1 | |
37 | } | |
38 | ||
39 | proc get_value {var test} { | |
40 | global expect_out | |
41 | global gdb_prompt | |
42 | global decimal | |
43 | ||
44 | set value -1 | |
45 | gdb_test_multiple "print $var" "$test" { | |
46 | -re ".*= ($decimal).*\r\n$gdb_prompt $" { | |
47 | set value $expect_out(1,string) | |
48 | pass "$test" | |
49 | } | |
50 | } | |
51 | return ${value} | |
52 | } | |
53 | ||
54 | # Start with a fresh gdb. | |
55 | ||
56 | clean_restart $executable | |
57 | ||
58 | if ![runto_main] { | |
59 | return -1 | |
60 | } | |
61 | ||
62 | gdb_breakpoint [gdb_get_line_number "set wait-thread-2 breakpoint here"] | |
63 | gdb_continue_to_breakpoint "run to wait-thread-2 breakpoint" | |
64 | gdb_test "info threads" "" "info threads with thread 2" | |
65 | ||
66 | gdb_breakpoint [gdb_get_line_number "set wait-thread-3 breakpoint here"] | |
67 | gdb_continue_to_breakpoint "run to breakpoint" | |
68 | gdb_test "info threads" "" "info threads with thread 3" | |
69 | ||
70 | set testpid [get_value "pid" "get pid of inferior"] | |
1dfdac32 MK |
71 | if { $testpid == -1 } { |
72 | return -1 | |
73 | } | |
d137e6dc PA |
74 | |
75 | gdb_test "set scheduler-locking on" | |
76 | ||
77 | gdb_breakpoint [gdb_get_line_number "set breakpoint child_two here"] | |
78 | gdb_breakpoint [gdb_get_line_number "set breakpoint child_one here"] | |
79 | ||
80 | gdb_test "thread 3" "" "switch to thread 3 to run to its breakpoint" | |
81 | gdb_continue_to_breakpoint "run to breakpoint in thread 3" | |
82 | ||
83 | gdb_test "thread 2" "" "switch to thread 2 to run to its breakpoint" | |
84 | gdb_continue_to_breakpoint "run to breakpoint in thread 2" | |
85 | ||
86 | delete_breakpoints | |
87 | ||
88 | gdb_test "b *\$pc" "" "set breakpoint to be stepped over" | |
89 | # Make sure the first loop breaks without hitting the breakpoint | |
90 | # again. | |
91 | gdb_test "p *myp = 0" " = 0" "force loop break in thread 2" | |
92 | ||
93 | # We want "print" to make sure the target reports the signal to the | |
94 | # core. | |
95 | gdb_test "handle SIGUSR1 print nostop pass" "" "" | |
96 | ||
97 | # Queue a signal in thread 2. | |
98 | remote_exec host "kill -SIGUSR1 ${testpid}" | |
99 | ||
100 | gdb_test "thread 3" "" "switch to thread 3 for stepping" | |
101 | set my_number [get_value "my_number" "get my_number"] | |
102 | set cnt_before [get_value "args\[$my_number\]" "get count before step"] | |
103 | gdb_test "set scheduler-locking off" | |
104 | ||
105 | # Make sure we're exercising the paths we want to. | |
106 | gdb_test "set debug infrun 1" | |
107 | ||
108 | gdb_test \ | |
109 | "step" \ | |
99619bea | 110 | ".*need to step-over.*resume \\(step=1.*signal arrived while stepping over breakpoint.*switching back to stepped thread.*stepped to a different line.*callme.*" \ |
d137e6dc PA |
111 | "step" |
112 | ||
113 | set cnt_after [get_value "args\[$my_number\]" "get count after step"] | |
114 | ||
115 | # Test that GDB doesn't inadvertently resume the stepped thread when a | |
116 | # signal arrives while stepping over a breakpoint in another thread. | |
117 | ||
118 | set test "stepped thread under control" | |
119 | if { $cnt_before + 1 == $cnt_after } { | |
120 | pass $test | |
121 | } else { | |
122 | fail $test | |
123 | } |