1 # Copyright 2003-2013 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Joel Brobecker (brobecker@gnat.com), derived
20 # are we on a target board
21 if { [is_remote target] || ![isnative] } then {
25 proc setup_test { executable } {
28 global INTERNAL_GDBFLAGS
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.
40 set oldtimeout $timeout
42 verbose "Timeout is now $timeout seconds" 2
44 global gdb_file_cmd_debug_info
45 set gdb_file_cmd_debug_info "unset"
47 set result [gdb_load $executable]
48 set timeout $oldtimeout
49 verbose "Timeout is now $timeout seconds" 2
51 if { $result != 0 } then {
55 if { $gdb_file_cmd_debug_info != "debug" } then {
56 untested "No debug information, skipping testcase."
60 # Set a breakpoint at main
61 gdb_test "break captured_main" \
62 "Breakpoint.*at.* file.*, line.*" \
63 "breakpoint in captured_main"
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.
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 $" {
75 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
76 xfail "$description (line numbers scrambled?)"
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
84 -re ".*$gdb_prompt $" {
86 set timeout $oldtimeout
87 verbose "Timeout is now $timeout seconds" 2
92 set timeout $oldtimeout
93 verbose "Timeout is now $timeout seconds" 2
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"
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"
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"
113 proc detach_first_observer { message } {
114 gdb_test_no_output "call observer_detach_test_notification (\$first_obs)" \
115 "$message; detach first observer"
118 proc detach_second_observer { message } {
119 gdb_test_no_output "call observer_detach_test_notification (\$second_obs)" \
120 "$message; detach second observer"
123 proc detach_third_observer { message } {
124 gdb_test_no_output "call observer_detach_test_notification (\$third_obs)" \
125 "$message; detach third observer"
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"
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"
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
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
163 proc test_observer { executable } {
165 set setup_result [setup_test $executable]
166 if {$setup_result <0} then {
170 # First, try sending a notification without any observer attached.
171 test_notifications 0 0 0 "no observer attached"
173 # Now, attach one observer, and send a notification.
174 test_notifications 0 1 0 "second observer attached" \
175 attach_second_observer
177 # Remove the observer, and send a notification.
178 test_notifications 0 0 0 "second observer detached" \
179 detach_second_observer
181 # With a new observer.
182 test_notifications 1 0 0 "1st observer added" \
183 attach_first_observer
186 test_notifications 1 1 0 "2nd observer added" \
187 attach_second_observer
190 test_notifications 1 1 1 "3rd observer added" \
191 attach_third_observer
193 # Remove middle observer.
194 test_notifications 1 0 1 "2nd observer removed" \
195 detach_second_observer
197 # Remove first observer.
198 test_notifications 0 0 1 "1st observer removed" \
199 detach_first_observer
201 # Remove last observer.
202 test_notifications 0 0 0 "3rd observer removed" \
203 detach_third_observer
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
211 # Remove the third observer.
212 test_notifications 1 1 0 "third observer removed" \
213 detach_third_observer
215 # Remove the second observer.
216 test_notifications 1 0 0 "second observer removed" \
217 detach_second_observer
219 # Remove the first observer, no more observers.
220 test_notifications 0 0 0 "first observer removed" \
221 detach_first_observer
226 # Find a pathname to a file that we would execute if the shell was asked
227 # to run $arg using the current PATH.
229 proc find_gdb { arg } {
231 # If the arg directly specifies an existing executable file, then
234 if [file executable $arg] then {
238 set result [which $arg]
239 if [string match "/" [ string range $result 0 0 ]] then {
243 # If everything fails, just return the unqualified pathname as default
249 # Run the test with self.
250 # Copy the file executable file in case this OS doesn't like to edit its own
253 set GDB_FULLPATH [find_gdb $GDB]
255 # Remove any old copy lying around.
256 remote_file host delete x$tool
259 set file [remote_download host $GDB_FULLPATH x$tool]
260 set result [test_observer $file];
262 catch "remote_file host delete $file";
264 if {$result <0} then {
265 warning "Couldn't test self"