]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.gdb/observer.exp
2004-08-27 Michael Chastain <mec.gnu@mindspring.com>
[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
50 set result [gdb_load $executable]
51 set timeout $oldtimeout
52 verbose "Timeout is now $timeout seconds" 2
53
54 if { [lindex $result 0] != "" } then {
55 return -1
56 }
57
58 # Set a breakpoint at main
59 gdb_test "break captured_main" \
60 "Breakpoint.*at.* file.*, line.*" \
61 "breakpoint in captured_main"
62
63 # run yourself
64 # It may take a very long time for the inferior gdb to start (lynx),
65 # so we bump it back up for the duration of this command.
66 set timeout 600
67
68 set description "run until breakpoint at captured_main"
69 gdb_test_multiple "run -nw" "$description" {
70 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
71 pass "$description"
72 }
73 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
74 xfail "$description (line numbers scrambled?)"
75 }
76 -re "vfork: No more processes.*$gdb_prompt $" {
77 fail "$description (out of virtual memory)"
78 set timeout $oldtimeout
79 verbose "Timeout is now $timeout seconds" 2
80 return -1
81 }
82 -re ".*$gdb_prompt $" {
83 fail "$description"
84 set timeout $oldtimeout
85 verbose "Timeout is now $timeout seconds" 2
86 return -1
87 }
88 }
89
90 set timeout $oldtimeout
91 verbose "Timeout is now $timeout seconds" 2
92
93 return 0
94 }
95
96 proc attach_first_observer { message } {
97 gdb_test "set \$first_obs = observer_attach_normal_stop (&observer_test_first_notification_function)" \
98 "" "$message; attach first observer"
99 }
100
101 proc attach_second_observer { message } {
102 gdb_test "set \$second_obs = observer_attach_normal_stop (&observer_test_second_notification_function)" \
103 "" "$message; attach second observer"
104 }
105
106 proc attach_third_observer { message } {
107 gdb_test "set \$third_obs = observer_attach_normal_stop (&observer_test_third_notification_function)" \
108 "" "$message; attach third observer"
109 }
110
111 proc detach_first_observer { message } {
112 gdb_test "call observer_detach_normal_stop (\$first_obs)" \
113 "" "$message; detach first observer"
114 }
115
116 proc detach_second_observer { message } {
117 gdb_test "call observer_detach_normal_stop (\$second_obs)" \
118 "" "$message; detach second observer"
119 }
120
121 proc detach_third_observer { message } {
122 gdb_test "call observer_detach_normal_stop (\$third_obs)" \
123 "" "$message; detach third observer"
124 }
125
126 proc check_counters { first second third message } {
127 gdb_test "print observer_test_first_observer" \
128 ".\[0-9\]+ =.*$first" \
129 "$message; check first observer counter value"
130 gdb_test "print observer_test_second_observer" \
131 ".\[0-9\]+ =.*$second" \
132 "$message; check second observer counter value"
133 gdb_test "print observer_test_third_observer" \
134 ".\[0-9\]+ =.*$third" \
135 "$message; check third observer counter value"
136 }
137
138 proc reset_counters { message } {
139 gdb_test "set variable observer_test_first_observer = 0" "" \
140 "$message; reset first observer counter"
141 gdb_test "set variable observer_test_second_observer = 0" "" \
142 "$message; reset second observer counter"
143 gdb_test "set variable observer_test_third_observer = 0" "" \
144 "$message; reset third observer counter"
145 }
146
147 proc test_normal_stop_notifications { first second third message args } {
148 # Do any initialization
149 for {set i 0} {$i < [llength $args]} {incr i} {
150 [lindex $args $i] $message
151 }
152 reset_counters $message
153 # Call observer_notify_normal_stop. Note that this procedure
154 # takes one argument, but this argument is ignored by the observer
155 # callbacks we have installed. So we just pass an arbitrary value.
156 gdb_test "call observer_notify_normal_stop (0)" "" \
157 "$message; sending notification"
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 attached"
170
171 # Now, attach one observer, and send a notification.
172 test_normal_stop_notifications 0 1 0 "second observer attached" \
173 attach_second_observer
174
175 # Remove the observer, and send a notification.
176 test_normal_stop_notifications 0 0 0 "second observer detached" \
177 detach_second_observer
178
179 # With a new observer.
180 test_normal_stop_notifications 1 0 0 "1st observer added" \
181 attach_first_observer
182
183 # With 2 observers.
184 test_normal_stop_notifications 1 1 0 "2nd observer added" \
185 attach_second_observer
186
187 # With 3 observers.
188 test_normal_stop_notifications 1 1 1 "3rd observer added" \
189 attach_third_observer
190
191 # Remove middle observer.
192 test_normal_stop_notifications 1 0 1 "2nd observer removed" \
193 detach_second_observer
194
195 # Remove first observer.
196 test_normal_stop_notifications 0 0 1 "1st observer removed" \
197 detach_first_observer
198
199 # Remove last observer.
200 test_normal_stop_notifications 0 0 0 "3rd observer removed" \
201 detach_third_observer
202
203 # Go back to 3 observers, and remove them in a different order...
204 test_normal_stop_notifications 1 1 1 "three observers added" \
205 attach_first_observer \
206 attach_second_observer \
207 attach_third_observer
208
209 # Remove the third observer.
210 test_normal_stop_notifications 1 1 0 "third observer removed" \
211 detach_third_observer
212
213 # Remove the second observer.
214 test_normal_stop_notifications 1 0 0 "second observer removed" \
215 detach_second_observer
216
217 # Remove the first observer, no more observers.
218 test_normal_stop_notifications 0 0 0 "first observer removed" \
219 detach_first_observer
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 }