1 # Copyright 2003-2004, 2007-2012 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 } {
29 # load yourself into the debugger
30 # This can take a relatively long time, particularly for testing where
31 # the executable is being accessed over a network, or where gdb does not
32 # support partial symbols for a particular target and has to load the
33 # entire symbol table. Set the timeout to 10 minutes, which should be
34 # adequate for most environments (it *has* timed out with 5 min on a
35 # SPARCstation SLC under moderate load, so this isn't unreasonable).
36 # After gdb is started, set the timeout to 30 seconds for the duration
37 # of this test, and then back to the original value.
39 set oldtimeout $timeout
41 verbose "Timeout is now $timeout seconds" 2
43 global gdb_file_cmd_debug_info
44 set gdb_file_cmd_debug_info "unset"
46 set result [gdb_load $executable]
47 set timeout $oldtimeout
48 verbose "Timeout is now $timeout seconds" 2
50 if { $result != 0 } then {
54 if { $gdb_file_cmd_debug_info != "debug" } then {
55 untested "No debug information, skipping testcase."
59 # Set a breakpoint at main
60 gdb_test "break captured_main" \
61 "Breakpoint.*at.* file.*, line.*" \
62 "breakpoint in captured_main"
65 # It may take a very long time for the inferior gdb to start (lynx),
66 # so we bump it back up for the duration of this command.
69 set description "run until breakpoint at captured_main"
70 gdb_test_multiple "run -nw" "$description" {
71 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
74 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
75 xfail "$description (line numbers scrambled?)"
77 -re "vfork: No more processes.*$gdb_prompt $" {
78 fail "$description (out of virtual memory)"
79 set timeout $oldtimeout
80 verbose "Timeout is now $timeout seconds" 2
83 -re ".*$gdb_prompt $" {
85 set timeout $oldtimeout
86 verbose "Timeout is now $timeout seconds" 2
91 set timeout $oldtimeout
92 verbose "Timeout is now $timeout seconds" 2
97 proc attach_first_observer { message } {
98 gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \
99 "$message; attach first observer"
102 proc attach_second_observer { message } {
103 gdb_test_no_output "set \$second_obs = observer_attach_test_notification (&observer_test_second_notification_function)" \
104 "$message; attach second observer"
107 proc attach_third_observer { message } {
108 gdb_test_no_output "set \$third_obs = observer_attach_test_notification (&observer_test_third_notification_function)" \
109 "$message; attach third observer"
112 proc detach_first_observer { message } {
113 gdb_test_no_output "call observer_detach_test_notification (\$first_obs)" \
114 "$message; detach first observer"
117 proc detach_second_observer { message } {
118 gdb_test_no_output "call observer_detach_test_notification (\$second_obs)" \
119 "$message; detach second observer"
122 proc detach_third_observer { message } {
123 gdb_test_no_output "call observer_detach_test_notification (\$third_obs)" \
124 "$message; detach third observer"
127 proc check_counters { first second third message } {
128 gdb_test "print observer_test_first_observer" \
129 ".\[0-9\]+ =.*$first" \
130 "$message; check first observer counter value"
131 gdb_test "print observer_test_second_observer" \
132 ".\[0-9\]+ =.*$second" \
133 "$message; check second observer counter value"
134 gdb_test "print observer_test_third_observer" \
135 ".\[0-9\]+ =.*$third" \
136 "$message; check third observer counter value"
139 proc reset_counters { message } {
140 gdb_test_no_output "set variable observer_test_first_observer = 0" \
141 "$message; reset first observer counter"
142 gdb_test_no_output "set variable observer_test_second_observer = 0" \
143 "$message; reset second observer counter"
144 gdb_test_no_output "set variable observer_test_third_observer = 0" \
145 "$message; reset third observer counter"
148 proc test_notifications { first second third message args } {
149 # Do any initialization
150 for {set i 0} {$i < [llength $args]} {incr i} {
151 [lindex $args $i] $message
153 reset_counters $message
154 # Call observer_notify_test_notification. Note that this procedure
155 # takes one argument, but this argument is ignored by the observer
156 # callbacks we have installed. So we just pass an arbitrary value.
157 gdb_test_no_output "call observer_notify_test_notification (0)" \
158 "$message; sending notification"
159 check_counters $first $second $third $message
162 proc test_observer { executable } {
164 set setup_result [setup_test $executable]
165 if {$setup_result <0} then {
169 # First, try sending a notification without any observer attached.
170 test_notifications 0 0 0 "no observer attached"
172 # Now, attach one observer, and send a notification.
173 test_notifications 0 1 0 "second observer attached" \
174 attach_second_observer
176 # Remove the observer, and send a notification.
177 test_notifications 0 0 0 "second observer detached" \
178 detach_second_observer
180 # With a new observer.
181 test_notifications 1 0 0 "1st observer added" \
182 attach_first_observer
185 test_notifications 1 1 0 "2nd observer added" \
186 attach_second_observer
189 test_notifications 1 1 1 "3rd observer added" \
190 attach_third_observer
192 # Remove middle observer.
193 test_notifications 1 0 1 "2nd observer removed" \
194 detach_second_observer
196 # Remove first observer.
197 test_notifications 0 0 1 "1st observer removed" \
198 detach_first_observer
200 # Remove last observer.
201 test_notifications 0 0 0 "3rd observer removed" \
202 detach_third_observer
204 # Go back to 3 observers, and remove them in a different order...
205 test_notifications 1 1 1 "three observers added" \
206 attach_first_observer \
207 attach_second_observer \
208 attach_third_observer
210 # Remove the third observer.
211 test_notifications 1 1 0 "third observer removed" \
212 detach_third_observer
214 # Remove the second observer.
215 test_notifications 1 0 0 "second observer removed" \
216 detach_second_observer
218 # Remove the first observer, no more observers.
219 test_notifications 0 0 0 "first observer removed" \
220 detach_first_observer
225 # Find a pathname to a file that we would execute if the shell was asked
226 # to run $arg using the current PATH.
228 proc find_gdb { arg } {
230 # If the arg directly specifies an existing executable file, then
233 if [file executable $arg] then {
237 set result [which $arg]
238 if [string match "/" [ string range $result 0 0 ]] then {
242 # If everything fails, just return the unqualified pathname as default
248 # Run the test with self.
249 # Copy the file executable file in case this OS doesn't like to edit its own
252 set GDB_FULLPATH [find_gdb $GDB]
254 # Remove any old copy lying around.
255 remote_file host delete x$tool
258 set file [remote_download host $GDB_FULLPATH x$tool]
259 set result [test_observer $file];
261 catch "remote_file host delete $file";
263 if {$result <0} then {
264 warning "Couldn't test self"