PR gdb/18717: internal error if non-leader thread exits process
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / hand-call-in-threads.exp
1 # Copyright (C) 2004-2015 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 making hand function calls in multiple threads.
17
18 set NR_THREADS 4
19
20 standard_testfile
21
22 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-DNR_THREADS=$NR_THREADS"]] != "" } {
23 return -1
24 }
25
26 # Some targets can't do function calls, so don't even bother with this
27 # test.
28 if [target_info exists gdb,cannot_call_functions] {
29 setup_xfail "*-*-*" 2416
30 fail "This target can not call functions"
31 continue
32 }
33
34 proc get_dummy_frame_number { } {
35 global gdb_prompt
36
37 gdb_test_multiple "bt" "" {
38 -re "#(\[0-9\]*) *<function called from gdb>.*$gdb_prompt $" {
39 return $expect_out(1,string)
40 }
41 -re "$gdb_prompt $" {
42 return ""
43 }
44 timeout {
45 return ""
46 }
47 }
48 return ""
49 }
50
51 clean_restart ${binfile}
52
53 if { ![runto_main] } {
54 fail "Can't run to main"
55 return 0
56 }
57
58 gdb_test "break all_threads_running" \
59 "Breakpoint 2 at .*: file .*${srcfile}, line .*" \
60 "breakpoint on all_threads_running"
61
62 gdb_test "break hand_call" \
63 "Breakpoint 3 at .*: file .*${srcfile}, line .*" \
64 "breakpoint on hand_call"
65
66 # Run the program and make sure GDB reports that we stopped after
67 # hitting breakpoint 2 in all_threads_running().
68
69 gdb_test "continue" \
70 ".*Breakpoint 2, all_threads_running ().*" \
71 "run to all_threads_running"
72
73 # Before we start making hand function calls, turn on scheduler locking.
74
75 gdb_test_no_output "set scheduler-locking on" "enable scheduler locking"
76 gdb_test "show scheduler-locking" ".* locking scheduler .* is \"on\"." "show scheduler locking on"
77
78 # Now hand-call a function in each thread, having the function
79 # stop without returning.
80
81 # Add one for the main thread.
82 set total_nr_threads [expr $NR_THREADS + 1]
83
84 # Thread numbering in gdb is origin-1, so begin numbering at 1.
85 for { set i 1 } { $i <= $total_nr_threads } { incr i } {
86 set thread_nr $i
87 gdb_test "thread $thread_nr" ".*" \
88 "prepare to make hand call, thread $thread_nr"
89 gdb_test "call hand_call()" "Breakpoint 3, .*" \
90 "hand call, thread $thread_nr"
91 }
92
93 # Now have each hand-called function return.
94
95 # Turn confirmation off for the "return" command.
96 gdb_test_no_output "set confirm off"
97
98 clear_xfail "*-*-*"
99
100 for { set i 1 } { $i <= $total_nr_threads } { incr i } {
101 set thread_nr $i
102 gdb_test "thread $thread_nr" ".*" \
103 "prepare to discard hand call, thread $thread_nr"
104 set frame_number [get_dummy_frame_number]
105 if { "$frame_number" == "" } {
106 fail "dummy stack frame number, thread $thread_nr"
107 # Need something.
108 set frame_number 0
109 } else {
110 pass "dummy stack frame number, thread $thread_nr"
111 }
112 # Pop the dummy frame.
113 gdb_test "frame $frame_number" ".*" "setting frame, thread $thread_nr"
114 gdb_test "return" ".*" "discard hand call, thread $thread_nr"
115 # In case getting the dummy frame number failed, re-enable for next iter.
116 clear_xfail "*-*-*"
117 }
118
119 # Make sure all dummy frames got popped.
120
121 gdb_test_multiple "maint print dummy-frames" "all dummies popped" {
122 -re ".*stack=.*$gdb_prompt $" {
123 fail "all dummies popped"
124 }
125 -re ".*$gdb_prompt $" {
126 pass "all dummies popped"
127 }
128 }
129
130 # Before we resume the full program, turn off scheduler locking.
131 gdb_test_no_output "set scheduler-locking off" "disable scheduler locking"
132 gdb_test "show scheduler-locking" ".* locking scheduler .* is \"off\"." "show scheduler locking off"
133
134 # Continue one last time, the program should exit normally.
135 #
136 # ??? This currently doesn't work because gdb doesn't know how to singlestep
137 # over reported breakpoints that weren't in the last thread to run.
138 # Commented out until then.
139 #
140 # For reference sake ...
141 # An alternative is to manually work around the issue by manually setting
142 # the thread back to the first thread: the program is still at the
143 # all_threads_running breakpoint, which wasn't the last thread to run,
144 # and gdb doesn't know how to singlestep over reported breakpoints that
145 # weren't in the last thread to run.
146 #gdb_test "thread 1" ".*" "set thread to 1, prepare to resume"
147 #
148 #gdb_continue_to_end "hand-call-in-threads"
149
150 return 0
This page took 0.033212 seconds and 4 git commands to generate.