]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.gdb/observer.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.gdb / observer.exp
1 # Copyright 2003-2013 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 3 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, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Joel Brobecker (brobecker@gnat.com), derived
17 # from xfullpath.exp.
18
19
20 # are we on a target board
21 if { [is_remote target] || ![isnative] } then {
22 return
23 }
24
25 proc setup_test { executable } {
26 global gdb_prompt
27 global timeout
28 global INTERNAL_GDBFLAGS
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
43
44 global gdb_file_cmd_debug_info
45 set gdb_file_cmd_debug_info "unset"
46
47 set result [gdb_load $executable]
48 set timeout $oldtimeout
49 verbose "Timeout is now $timeout seconds" 2
50
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."
57 return -1
58 }
59
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"
71 gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
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 }
90 }
91
92 set timeout $oldtimeout
93 verbose "Timeout is now $timeout seconds" 2
94
95 return 0
96 }
97
98 proc attach_first_observer { message } {
99 gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \
100 "$message; attach first observer"
101 }
102
103 proc attach_second_observer { message } {
104 gdb_test_no_output "set \$second_obs = observer_attach_test_notification (&observer_test_second_notification_function)" \
105 "$message; attach second observer"
106 }
107
108 proc attach_third_observer { message } {
109 gdb_test_no_output "set \$third_obs = observer_attach_test_notification (&observer_test_third_notification_function)" \
110 "$message; attach third observer"
111 }
112
113 proc detach_first_observer { message } {
114 gdb_test_no_output "call observer_detach_test_notification (\$first_obs)" \
115 "$message; detach first observer"
116 }
117
118 proc detach_second_observer { message } {
119 gdb_test_no_output "call observer_detach_test_notification (\$second_obs)" \
120 "$message; detach second observer"
121 }
122
123 proc detach_third_observer { message } {
124 gdb_test_no_output "call observer_detach_test_notification (\$third_obs)" \
125 "$message; detach third observer"
126 }
127
128 proc check_counters { first second third message } {
129 gdb_test "print observer_test_first_observer" \
130 ".\[0-9\]+ =.*$first" \
131 "$message; check first observer counter value"
132 gdb_test "print observer_test_second_observer" \
133 ".\[0-9\]+ =.*$second" \
134 "$message; check second observer counter value"
135 gdb_test "print observer_test_third_observer" \
136 ".\[0-9\]+ =.*$third" \
137 "$message; check third observer counter value"
138 }
139
140 proc reset_counters { message } {
141 gdb_test_no_output "set variable observer_test_first_observer = 0" \
142 "$message; reset first observer counter"
143 gdb_test_no_output "set variable observer_test_second_observer = 0" \
144 "$message; reset second observer counter"
145 gdb_test_no_output "set variable observer_test_third_observer = 0" \
146 "$message; reset third observer counter"
147 }
148
149 proc test_notifications { first second third message args } {
150 # Do any initialization
151 for {set i 0} {$i < [llength $args]} {incr i} {
152 [lindex $args $i] $message
153 }
154 reset_counters $message
155 # Call observer_notify_test_notification. Note that this procedure
156 # takes one argument, but this argument is ignored by the observer
157 # callbacks we have installed. So we just pass an arbitrary value.
158 gdb_test_no_output "call observer_notify_test_notification (0)" \
159 "$message; sending notification"
160 check_counters $first $second $third $message
161 }
162
163 proc test_observer { executable } {
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.
171 test_notifications 0 0 0 "no observer attached"
172
173 # Now, attach one observer, and send a notification.
174 test_notifications 0 1 0 "second observer attached" \
175 attach_second_observer
176
177 # Remove the observer, and send a notification.
178 test_notifications 0 0 0 "second observer detached" \
179 detach_second_observer
180
181 # With a new observer.
182 test_notifications 1 0 0 "1st observer added" \
183 attach_first_observer
184
185 # With 2 observers.
186 test_notifications 1 1 0 "2nd observer added" \
187 attach_second_observer
188
189 # With 3 observers.
190 test_notifications 1 1 1 "3rd observer added" \
191 attach_third_observer
192
193 # Remove middle observer.
194 test_notifications 1 0 1 "2nd observer removed" \
195 detach_second_observer
196
197 # Remove first observer.
198 test_notifications 0 0 1 "1st observer removed" \
199 detach_first_observer
200
201 # Remove last observer.
202 test_notifications 0 0 0 "3rd observer removed" \
203 detach_third_observer
204
205 # Go back to 3 observers, and remove them in a different order...
206 test_notifications 1 1 1 "three observers added" \
207 attach_first_observer \
208 attach_second_observer \
209 attach_third_observer
210
211 # Remove the third observer.
212 test_notifications 1 1 0 "third observer removed" \
213 detach_third_observer
214
215 # Remove the second observer.
216 test_notifications 1 0 0 "second observer removed" \
217 detach_second_observer
218
219 # Remove the first observer, no more observers.
220 test_notifications 0 0 0 "first observer removed" \
221 detach_first_observer
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]
260 set result [test_observer $file];
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 }