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