]>
Commit | Line | Data |
---|---|---|
c5a57081 JB |
1 | # Copyright (C) 2004, 2007-2008, 2010-2012 Free Software Foundation, |
2 | # Inc. | |
5a437975 DE |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | # Test making hand function calls in multiple threads. | |
18 | ||
19 | set NR_THREADS 4 | |
20 | ||
0efbbabc | 21 | standard_testfile |
5a437975 | 22 | |
0efbbabc | 23 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "additional_flags=-DNR_THREADS=$NR_THREADS"]] != "" } { |
5a437975 DE |
24 | return -1 |
25 | } | |
26 | ||
27 | # Some targets can't do function calls, so don't even bother with this | |
28 | # test. | |
29 | if [target_info exists gdb,cannot_call_functions] { | |
30 | setup_xfail "*-*-*" 2416 | |
31 | fail "This target can not call functions" | |
32 | continue | |
33 | } | |
34 | ||
35 | proc get_dummy_frame_number { } { | |
9db70545 | 36 | global gdb_prompt |
5a437975 | 37 | |
9db70545 MS |
38 | gdb_test_multiple "bt" "" { |
39 | -re "#(\[0-9\]*) *<function called from gdb>.*$gdb_prompt $" { | |
40 | return $expect_out(1,string) | |
41 | } | |
42 | -re "$gdb_prompt $" { | |
43 | return "" | |
44 | } | |
45 | timeout { | |
46 | return "" | |
47 | } | |
48 | } | |
49 | return "" | |
5a437975 DE |
50 | } |
51 | ||
0efbbabc | 52 | clean_restart ${binfile} |
5a437975 DE |
53 | |
54 | if { ![runto_main] } { | |
55 | fail "Can't run to main" | |
56 | return 0 | |
57 | } | |
58 | ||
59 | gdb_test "break all_threads_running" \ | |
60 | "Breakpoint 2 at .*: file .*${srcfile}, line .*" \ | |
61 | "breakpoint on all_threads_running" | |
62 | ||
63 | gdb_test "break hand_call" \ | |
64 | "Breakpoint 3 at .*: file .*${srcfile}, line .*" \ | |
65 | "breakpoint on hand_call" | |
66 | ||
67 | # Run the program and make sure GDB reports that we stopped after | |
68 | # hitting breakpoint 2 in all_threads_running(). | |
69 | ||
70 | gdb_test "continue" \ | |
71 | ".*Breakpoint 2, all_threads_running ().*" \ | |
72 | "run to all_threads_running" | |
73 | ||
74 | # Before we start making hand function calls, turn on scheduler locking. | |
75 | ||
12b5d08a | 76 | gdb_test_no_output "set scheduler-locking on" "enable scheduler locking" |
5a437975 DE |
77 | gdb_test "show scheduler-locking" ".* locking scheduler .* is \"on\"." "show scheduler locking on" |
78 | ||
79 | # Now hand-call a function in each thread, having the function | |
80 | # stop without returning. | |
81 | ||
82 | # Add one for the main thread. | |
83 | set total_nr_threads [expr $NR_THREADS + 1] | |
84 | ||
85 | # Thread numbering in gdb is origin-1, so begin numbering at 1. | |
86 | for { set i 1 } { $i <= $total_nr_threads } { incr i } { | |
87 | set thread_nr $i | |
f6978de9 MS |
88 | gdb_test "thread $thread_nr" ".*" \ |
89 | "prepare to make hand call, thread $thread_nr" | |
90 | gdb_test "call hand_call()" "Breakpoint 3, .*" \ | |
91 | "hand call, thread $thread_nr" | |
5a437975 DE |
92 | } |
93 | ||
94 | # Now have each hand-called function return. | |
95 | ||
96 | # Turn confirmation off for the "return" command. | |
12b5d08a | 97 | gdb_test_no_output "set confirm off" |
5a437975 DE |
98 | |
99 | clear_xfail "*-*-*" | |
100 | ||
101 | for { set i 1 } { $i <= $total_nr_threads } { incr i } { | |
102 | set thread_nr $i | |
f6978de9 MS |
103 | gdb_test "thread $thread_nr" ".*" \ |
104 | "prepare to discard hand call, thread $thread_nr" | |
5a437975 DE |
105 | set frame_number [get_dummy_frame_number] |
106 | if { "$frame_number" == "" } { | |
107 | fail "dummy stack frame number, thread $thread_nr" | |
108 | # Need something. | |
109 | set frame_number 0 | |
110 | } else { | |
111 | pass "dummy stack frame number, thread $thread_nr" | |
112 | } | |
113 | # Pop the dummy frame. | |
f6978de9 MS |
114 | gdb_test "frame $frame_number" ".*" "setting frame, thread $thread_nr" |
115 | gdb_test "return" ".*" "discard hand call, thread $thread_nr" | |
5a437975 DE |
116 | # In case getting the dummy frame number failed, re-enable for next iter. |
117 | clear_xfail "*-*-*" | |
118 | } | |
119 | ||
120 | # Make sure all dummy frames got popped. | |
121 | ||
122 | gdb_test_multiple "maint print dummy-frames" "all dummies popped" { | |
123 | -re ".*stack=.*$gdb_prompt $" { | |
124 | fail "all dummies popped" | |
125 | } | |
126 | -re ".*$gdb_prompt $" { | |
127 | pass "all dummies popped" | |
128 | } | |
129 | } | |
130 | ||
12b5d08a MS |
131 | # Before we resume the full program, turn off scheduler locking. |
132 | gdb_test_no_output "set scheduler-locking off" "disable scheduler locking" | |
5a437975 DE |
133 | gdb_test "show scheduler-locking" ".* locking scheduler .* is \"off\"." "show scheduler locking off" |
134 | ||
135 | # Continue one last time, the program should exit normally. | |
136 | # | |
137 | # ??? This currently doesn't work because gdb doesn't know how to singlestep | |
138 | # over reported breakpoints that weren't in the last thread to run. | |
139 | # Commented out until then. | |
140 | # | |
141 | # For reference sake ... | |
142 | # An alternative is to manually work around the issue by manually setting | |
143 | # the thread back to the first thread: the program is still at the | |
144 | # all_threads_running breakpoint, which wasn't the last thread to run, | |
145 | # and gdb doesn't know how to singlestep over reported breakpoints that | |
146 | # weren't in the last thread to run. | |
f6978de9 | 147 | #gdb_test "thread 1" ".*" "set thread to 1, prepare to resume" |
5a437975 DE |
148 | # |
149 | #gdb_continue_to_end "hand-call-in-threads" | |
150 | ||
151 | return 0 |