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