Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 2003, 2004, 2007, 2008 Free Software Foundation, Inc. |
5b2a3989 JB |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
5b2a3989 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
5b2a3989 JB |
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. | |
e22f8b7c | 12 | # |
5b2a3989 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
5b2a3989 | 15 | |
5b2a3989 JB |
16 | # This file was written by Joel Brobecker (brobecker@gnat.com), derived |
17 | # from xfullpath.exp. | |
18 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
23 | set prms_id 0 | |
24 | set bug_id 0 | |
25 | ||
26 | # are we on a target board | |
c1d88655 | 27 | if { [is_remote target] || ![isnative] } then { |
5b2a3989 JB |
28 | return |
29 | } | |
30 | ||
5b2a3989 JB |
31 | proc setup_test { executable } { |
32 | global gdb_prompt | |
33 | global timeout | |
34 | ||
35 | # load yourself into the debugger | |
36 | # This can take a relatively long time, particularly for testing where | |
37 | # the executable is being accessed over a network, or where gdb does not | |
38 | # support partial symbols for a particular target and has to load the | |
39 | # entire symbol table. Set the timeout to 10 minutes, which should be | |
40 | # adequate for most environments (it *has* timed out with 5 min on a | |
41 | # SPARCstation SLC under moderate load, so this isn't unreasonable). | |
42 | # After gdb is started, set the timeout to 30 seconds for the duration | |
43 | # of this test, and then back to the original value. | |
44 | ||
45 | set oldtimeout $timeout | |
46 | set timeout 600 | |
47 | verbose "Timeout is now $timeout seconds" 2 | |
3e3ffd2b | 48 | |
2db8e78e MC |
49 | global gdb_file_cmd_debug_info |
50 | set gdb_file_cmd_debug_info "unset" | |
51 | ||
3e3ffd2b | 52 | set result [gdb_load $executable] |
5b2a3989 JB |
53 | set timeout $oldtimeout |
54 | verbose "Timeout is now $timeout seconds" 2 | |
55 | ||
2db8e78e MC |
56 | if { $result != 0 } then { |
57 | return -1 | |
58 | } | |
59 | ||
60 | if { $gdb_file_cmd_debug_info != "debug" } then { | |
61 | untested "No debug information, skipping testcase." | |
3e3ffd2b MC |
62 | return -1 |
63 | } | |
64 | ||
5b2a3989 JB |
65 | # Set a breakpoint at main |
66 | gdb_test "break captured_main" \ | |
67 | "Breakpoint.*at.* file.*, line.*" \ | |
68 | "breakpoint in captured_main" | |
69 | ||
70 | # run yourself | |
71 | # It may take a very long time for the inferior gdb to start (lynx), | |
72 | # so we bump it back up for the duration of this command. | |
73 | set timeout 600 | |
74 | ||
75 | set description "run until breakpoint at captured_main" | |
ab89363a | 76 | gdb_test_multiple "run -nw" "$description" { |
5b2a3989 JB |
77 | -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" { |
78 | pass "$description" | |
79 | } | |
80 | -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" { | |
81 | xfail "$description (line numbers scrambled?)" | |
82 | } | |
83 | -re "vfork: No more processes.*$gdb_prompt $" { | |
84 | fail "$description (out of virtual memory)" | |
85 | set timeout $oldtimeout | |
86 | verbose "Timeout is now $timeout seconds" 2 | |
87 | return -1 | |
88 | } | |
89 | -re ".*$gdb_prompt $" { | |
90 | fail "$description" | |
91 | set timeout $oldtimeout | |
92 | verbose "Timeout is now $timeout seconds" 2 | |
93 | return -1 | |
94 | } | |
5b2a3989 JB |
95 | } |
96 | ||
97 | set timeout $oldtimeout | |
98 | verbose "Timeout is now $timeout seconds" 2 | |
99 | ||
100 | return 0 | |
101 | } | |
102 | ||
ab89363a | 103 | proc attach_first_observer { message } { |
5b2a3989 | 104 | gdb_test "set \$first_obs = observer_attach_normal_stop (&observer_test_first_notification_function)" \ |
ab89363a | 105 | "" "$message; attach first observer" |
5b2a3989 JB |
106 | } |
107 | ||
ab89363a | 108 | proc attach_second_observer { message } { |
5b2a3989 | 109 | gdb_test "set \$second_obs = observer_attach_normal_stop (&observer_test_second_notification_function)" \ |
ab89363a | 110 | "" "$message; attach second observer" |
5b2a3989 JB |
111 | } |
112 | ||
ab89363a | 113 | proc attach_third_observer { message } { |
5b2a3989 | 114 | gdb_test "set \$third_obs = observer_attach_normal_stop (&observer_test_third_notification_function)" \ |
ab89363a | 115 | "" "$message; attach third observer" |
5b2a3989 JB |
116 | } |
117 | ||
ab89363a | 118 | proc detach_first_observer { message } { |
5b2a3989 | 119 | gdb_test "call observer_detach_normal_stop (\$first_obs)" \ |
ab89363a | 120 | "" "$message; detach first observer" |
5b2a3989 JB |
121 | } |
122 | ||
ab89363a | 123 | proc detach_second_observer { message } { |
5b2a3989 | 124 | gdb_test "call observer_detach_normal_stop (\$second_obs)" \ |
ab89363a | 125 | "" "$message; detach second observer" |
5b2a3989 JB |
126 | } |
127 | ||
ab89363a | 128 | proc detach_third_observer { message } { |
5b2a3989 | 129 | gdb_test "call observer_detach_normal_stop (\$third_obs)" \ |
ab89363a | 130 | "" "$message; detach third observer" |
5b2a3989 JB |
131 | } |
132 | ||
133 | proc check_counters { first second third message } { | |
134 | gdb_test "print observer_test_first_observer" \ | |
ab89363a AC |
135 | ".\[0-9\]+ =.*$first" \ |
136 | "$message; check first observer counter value" | |
5b2a3989 | 137 | gdb_test "print observer_test_second_observer" \ |
ab89363a AC |
138 | ".\[0-9\]+ =.*$second" \ |
139 | "$message; check second observer counter value" | |
5b2a3989 | 140 | gdb_test "print observer_test_third_observer" \ |
ab89363a AC |
141 | ".\[0-9\]+ =.*$third" \ |
142 | "$message; check third observer counter value" | |
5b2a3989 JB |
143 | } |
144 | ||
ab89363a | 145 | proc reset_counters { message } { |
5b2a3989 | 146 | gdb_test "set variable observer_test_first_observer = 0" "" \ |
ab89363a | 147 | "$message; reset first observer counter" |
5b2a3989 | 148 | gdb_test "set variable observer_test_second_observer = 0" "" \ |
ab89363a | 149 | "$message; reset second observer counter" |
5b2a3989 | 150 | gdb_test "set variable observer_test_third_observer = 0" "" \ |
ab89363a | 151 | "$message; reset third observer counter" |
5b2a3989 JB |
152 | } |
153 | ||
ab89363a AC |
154 | proc test_normal_stop_notifications { first second third message args } { |
155 | # Do any initialization | |
156 | for {set i 0} {$i < [llength $args]} {incr i} { | |
157 | [lindex $args $i] $message | |
158 | } | |
159 | reset_counters $message | |
90990674 JB |
160 | # Call observer_notify_normal_stop. Note that this procedure |
161 | # takes one argument, but this argument is ignored by the observer | |
162 | # callbacks we have installed. So we just pass an arbitrary value. | |
163 | gdb_test "call observer_notify_normal_stop (0)" "" \ | |
ab89363a | 164 | "$message; sending notification" |
5b2a3989 JB |
165 | check_counters $first $second $third $message |
166 | } | |
167 | ||
168 | proc test_observer_normal_stop { executable } { | |
169 | ||
170 | set setup_result [setup_test $executable] | |
171 | if {$setup_result <0} then { | |
172 | return -1 | |
173 | } | |
174 | ||
175 | # First, try sending a notification without any observer attached. | |
ab89363a | 176 | test_normal_stop_notifications 0 0 0 "no observer attached" |
5b2a3989 JB |
177 | |
178 | # Now, attach one observer, and send a notification. | |
ab89363a AC |
179 | test_normal_stop_notifications 0 1 0 "second observer attached" \ |
180 | attach_second_observer | |
5b2a3989 JB |
181 | |
182 | # Remove the observer, and send a notification. | |
ab89363a AC |
183 | test_normal_stop_notifications 0 0 0 "second observer detached" \ |
184 | detach_second_observer | |
5b2a3989 JB |
185 | |
186 | # With a new observer. | |
ab89363a AC |
187 | test_normal_stop_notifications 1 0 0 "1st observer added" \ |
188 | attach_first_observer | |
5b2a3989 JB |
189 | |
190 | # With 2 observers. | |
ab89363a AC |
191 | test_normal_stop_notifications 1 1 0 "2nd observer added" \ |
192 | attach_second_observer | |
5b2a3989 JB |
193 | |
194 | # With 3 observers. | |
ab89363a AC |
195 | test_normal_stop_notifications 1 1 1 "3rd observer added" \ |
196 | attach_third_observer | |
5b2a3989 JB |
197 | |
198 | # Remove middle observer. | |
ab89363a AC |
199 | test_normal_stop_notifications 1 0 1 "2nd observer removed" \ |
200 | detach_second_observer | |
5b2a3989 JB |
201 | |
202 | # Remove first observer. | |
ab89363a AC |
203 | test_normal_stop_notifications 0 0 1 "1st observer removed" \ |
204 | detach_first_observer | |
5b2a3989 JB |
205 | |
206 | # Remove last observer. | |
ab89363a AC |
207 | test_normal_stop_notifications 0 0 0 "3rd observer removed" \ |
208 | detach_third_observer | |
5b2a3989 JB |
209 | |
210 | # Go back to 3 observers, and remove them in a different order... | |
ab89363a AC |
211 | test_normal_stop_notifications 1 1 1 "three observers added" \ |
212 | attach_first_observer \ | |
213 | attach_second_observer \ | |
214 | attach_third_observer | |
5b2a3989 JB |
215 | |
216 | # Remove the third observer. | |
ab89363a AC |
217 | test_normal_stop_notifications 1 1 0 "third observer removed" \ |
218 | detach_third_observer | |
5b2a3989 JB |
219 | |
220 | # Remove the second observer. | |
ab89363a AC |
221 | test_normal_stop_notifications 1 0 0 "second observer removed" \ |
222 | detach_second_observer | |
5b2a3989 JB |
223 | |
224 | # Remove the first observer, no more observers. | |
ab89363a AC |
225 | test_normal_stop_notifications 0 0 0 "first observer removed" \ |
226 | detach_first_observer | |
5b2a3989 JB |
227 | |
228 | return 0 | |
229 | } | |
230 | ||
231 | # Find a pathname to a file that we would execute if the shell was asked | |
232 | # to run $arg using the current PATH. | |
233 | ||
234 | proc find_gdb { arg } { | |
235 | ||
236 | # If the arg directly specifies an existing executable file, then | |
237 | # simply use it. | |
238 | ||
239 | if [file executable $arg] then { | |
240 | return $arg | |
241 | } | |
242 | ||
243 | set result [which $arg] | |
244 | if [string match "/" [ string range $result 0 0 ]] then { | |
245 | return $result | |
246 | } | |
247 | ||
248 | # If everything fails, just return the unqualified pathname as default | |
249 | # and hope for best. | |
250 | ||
251 | return $arg | |
252 | } | |
253 | ||
254 | # Run the test with self. | |
255 | # Copy the file executable file in case this OS doesn't like to edit its own | |
256 | # text space. | |
257 | ||
258 | set GDB_FULLPATH [find_gdb $GDB] | |
259 | ||
260 | # Remove any old copy lying around. | |
261 | remote_file host delete x$tool | |
262 | ||
263 | gdb_start | |
264 | set file [remote_download host $GDB_FULLPATH x$tool] | |
265 | set result [test_observer_normal_stop $file]; | |
266 | gdb_exit; | |
267 | catch "remote_file host delete $file"; | |
268 | ||
269 | if {$result <0} then { | |
270 | warning "Couldn't test self" | |
271 | return -1 | |
272 | } |