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