2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Joel Brobecker (brobecker@gnat.com), derived
31 # are we on a target board
32 if [is_remote target] {
36 proc setup_test { executable } {
40 # load yourself into the debugger
41 # This can take a relatively long time, particularly for testing where
42 # the executable is being accessed over a network, or where gdb does not
43 # support partial symbols for a particular target and has to load the
44 # entire symbol table. Set the timeout to 10 minutes, which should be
45 # adequate for most environments (it *has* timed out with 5 min on a
46 # SPARCstation SLC under moderate load, so this isn't unreasonable).
47 # After gdb is started, set the timeout to 30 seconds for the duration
48 # of this test, and then back to the original value.
50 set oldtimeout $timeout
52 verbose "Timeout is now $timeout seconds" 2
53 if {[gdb_load $executable] <0} then {
54 set timeout $oldtimeout
55 verbose "Timeout is now $timeout seconds" 2
58 set timeout $oldtimeout
59 verbose "Timeout is now $timeout seconds" 2
61 # Set a breakpoint at main
62 gdb_test "break captured_main" \
63 "Breakpoint.*at.* file.*, line.*" \
64 "breakpoint in captured_main"
67 # It may take a very long time for the inferior gdb to start (lynx),
68 # so we bump it back up for the duration of this command.
71 set description "run until breakpoint at captured_main"
74 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
77 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
78 xfail "$description (line numbers scrambled?)"
80 -re "vfork: No more processes.*$gdb_prompt $" {
81 fail "$description (out of virtual memory)"
82 set timeout $oldtimeout
83 verbose "Timeout is now $timeout seconds" 2
86 -re ".*$gdb_prompt $" {
88 set timeout $oldtimeout
89 verbose "Timeout is now $timeout seconds" 2
93 fail "$description (timeout)"
97 set timeout $oldtimeout
98 verbose "Timeout is now $timeout seconds" 2
103 proc attach_first_observer { } {
104 gdb_test "set \$first_obs = observer_attach_normal_stop (&observer_test_first_notification_function)" \
105 "" "attach first observer"
108 proc attach_second_observer { } {
109 gdb_test "set \$second_obs = observer_attach_normal_stop (&observer_test_second_notification_function)" \
110 "" "attach second observer"
113 proc attach_third_observer { } {
114 gdb_test "set \$third_obs = observer_attach_normal_stop (&observer_test_third_notification_function)" \
115 "" "attach third observer"
118 proc detach_first_observer { } {
119 gdb_test "call observer_detach_normal_stop (\$first_obs)" \
120 "" "detach first observer"
123 proc detach_second_observer { } {
124 gdb_test "call observer_detach_normal_stop (\$second_obs)" \
125 "" "detach second observer"
128 proc detach_third_observer { } {
129 gdb_test "call observer_detach_normal_stop (\$third_obs)" \
130 "" "detach third observer"
133 proc check_counters { first second third message } {
134 gdb_test "print observer_test_first_observer" \
135 ".\[0-9\]+ =.*$first" \
136 "check first observer counter value ($message)"
137 gdb_test "print observer_test_second_observer" \
138 ".\[0-9\]+ =.*$second" \
139 "check second observer counter value ($message)"
140 gdb_test "print observer_test_third_observer" \
141 ".\[0-9\]+ =.*$third" \
142 "check third observer counter value ($message)"
145 proc reset_counters { } {
146 gdb_test "set variable observer_test_first_observer = 0" "" \
147 "reset first observer counter"
148 gdb_test "set variable observer_test_second_observer = 0" "" \
149 "reset second observer counter"
150 gdb_test "set variable observer_test_third_observer = 0" "" \
151 "reset third observer counter"
154 proc test_normal_stop_notifications { first second third message } {
156 # Call observer_notify_normal_stop. Note that this procedure
157 # takes one argument, but this argument is ignored by the observer
158 # callbacks we have installed. So we just pass an arbitrary value.
159 gdb_test "call observer_notify_normal_stop (0)" "" \
160 "sending notification ($message)"
161 check_counters $first $second $third $message
164 proc test_observer_normal_stop { executable } {
166 set setup_result [setup_test $executable]
167 if {$setup_result <0} then {
171 # First, try sending a notification without any observer attached.
172 test_normal_stop_notifications 0 0 0 "no observer"
174 # Now, attach one observer, and send a notification.
175 attach_second_observer
176 test_normal_stop_notifications 0 1 0 "one observer"
178 # Remove the observer, and send a notification.
179 detach_second_observer
180 test_normal_stop_notifications 0 0 0 "no observer"
182 # With a new observer.
183 attach_first_observer
184 test_normal_stop_notifications 1 0 0 "a new observer"
187 attach_second_observer
188 test_normal_stop_notifications 1 1 0 "2 observers"
191 attach_third_observer
192 test_normal_stop_notifications 1 1 1 "3 observers"
194 # Remove middle observer.
195 detach_second_observer
196 test_normal_stop_notifications 1 0 1 "middle observer removed"
198 # Remove first observer.
199 detach_first_observer
200 test_normal_stop_notifications 0 0 1 "first observer removed"
202 # Remove last observer.
203 detach_third_observer
204 test_normal_stop_notifications 0 0 0 "last observer removed"
206 # Go back to 3 observers, and remove them in a different order...
207 attach_first_observer
208 attach_second_observer
209 attach_third_observer
210 test_normal_stop_notifications 1 1 1 "3 observers again"
212 # Remove the third observer.
213 detach_third_observer
214 test_normal_stop_notifications 1 1 0 "third observer removed"
216 # Remove the second observer.
217 detach_second_observer
218 test_normal_stop_notifications 1 0 0 "second observer removed"
220 # Remove the first observer, no more observers.
221 detach_first_observer
222 test_normal_stop_notifications 0 0 0 "last observer removed"
227 # Find a pathname to a file that we would execute if the shell was asked
228 # to run $arg using the current PATH.
230 proc find_gdb { arg } {
232 # If the arg directly specifies an existing executable file, then
235 if [file executable $arg] then {
239 set result [which $arg]
240 if [string match "/" [ string range $result 0 0 ]] then {
244 # If everything fails, just return the unqualified pathname as default
250 # Run the test with self.
251 # Copy the file executable file in case this OS doesn't like to edit its own
254 set GDB_FULLPATH [find_gdb $GDB]
256 # Remove any old copy lying around.
257 remote_file host delete x$tool
260 set file [remote_download host $GDB_FULLPATH x$tool]
261 set result [test_observer_normal_stop $file];
263 catch "remote_file host delete $file";
265 if {$result <0} then {
266 warning "Couldn't test self"