]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.gdb/observer.exp
* gdb.gdb/observer.exp (test_normal_stop_notifications): Update
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.gdb / observer.exp
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
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 # Call observer_notify_normal_stop. Note that this procedure
157 # takes one argument, but this argument is ignored by the observer
158 # callbacks we have installed. So we just pass an arbitrary value.
159 gdb_test "call observer_notify_normal_stop (0)" "" \
160 "sending notification ($message)"
161 check_counters $first $second $third $message
162 }
163
164 proc test_observer_normal_stop { executable } {
165
166 set setup_result [setup_test $executable]
167 if {$setup_result <0} then {
168 return -1
169 }
170
171 # First, try sending a notification without any observer attached.
172 test_normal_stop_notifications 0 0 0 "no observer"
173
174 # Now, attach one observer, and send a notification.
175 attach_second_observer
176 test_normal_stop_notifications 0 1 0 "one observer"
177
178 # Remove the observer, and send a notification.
179 detach_second_observer
180 test_normal_stop_notifications 0 0 0 "no observer"
181
182 # With a new observer.
183 attach_first_observer
184 test_normal_stop_notifications 1 0 0 "a new observer"
185
186 # With 2 observers.
187 attach_second_observer
188 test_normal_stop_notifications 1 1 0 "2 observers"
189
190 # With 3 observers.
191 attach_third_observer
192 test_normal_stop_notifications 1 1 1 "3 observers"
193
194 # Remove middle observer.
195 detach_second_observer
196 test_normal_stop_notifications 1 0 1 "middle observer removed"
197
198 # Remove first observer.
199 detach_first_observer
200 test_normal_stop_notifications 0 0 1 "first observer removed"
201
202 # Remove last observer.
203 detach_third_observer
204 test_normal_stop_notifications 0 0 0 "last observer removed"
205
206 # Go back to 3 observers, and remove them in a different order...
207 attach_first_observer
208 attach_second_observer
209 attach_third_observer
210 test_normal_stop_notifications 1 1 1 "3 observers again"
211
212 # Remove the third observer.
213 detach_third_observer
214 test_normal_stop_notifications 1 1 0 "third observer removed"
215
216 # Remove the second observer.
217 detach_second_observer
218 test_normal_stop_notifications 1 0 0 "second observer removed"
219
220 # Remove the first observer, no more observers.
221 detach_first_observer
222 test_normal_stop_notifications 0 0 0 "last observer removed"
223
224 return 0
225 }
226
227 # Find a pathname to a file that we would execute if the shell was asked
228 # to run $arg using the current PATH.
229
230 proc find_gdb { arg } {
231
232 # If the arg directly specifies an existing executable file, then
233 # simply use it.
234
235 if [file executable $arg] then {
236 return $arg
237 }
238
239 set result [which $arg]
240 if [string match "/" [ string range $result 0 0 ]] then {
241 return $result
242 }
243
244 # If everything fails, just return the unqualified pathname as default
245 # and hope for best.
246
247 return $arg
248 }
249
250 # Run the test with self.
251 # Copy the file executable file in case this OS doesn't like to edit its own
252 # text space.
253
254 set GDB_FULLPATH [find_gdb $GDB]
255
256 # Remove any old copy lying around.
257 remote_file host delete x$tool
258
259 gdb_start
260 set file [remote_download host $GDB_FULLPATH x$tool]
261 set result [test_observer_normal_stop $file];
262 gdb_exit;
263 catch "remote_file host delete $file";
264
265 if {$result <0} then {
266 warning "Couldn't test self"
267 return -1
268 }