1 # Copyright
2003, 2004, 2007 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
26 # are we
on a target board
27 if { [is_remote target
] ||
![isnative
] } then {
31 proc setup_test
{ executable
} {
35 #
load yourself into the debugger
36 # This can take a relatively long time
, particularly
for testing where
37 # the executable is being accessed over a network
, or where gdb does not
38 # support partial symbols
for a particular target and has to
load the
39 # entire symbol table.
Set the timeout to
10 minutes
, which should be
40 # adequate
for most environments
(it
*has
* timed out with
5 min on a
41 # SPARCstation SLC under moderate
load, so this isn
't unreasonable).
42 # After gdb is started, set the timeout to 30 seconds for the duration
43 # of this test, and then back to the original value.
45 set oldtimeout $timeout
47 verbose "Timeout is now $timeout seconds" 2
49 global gdb_file_cmd_debug_info
50 set gdb_file_cmd_debug_info "unset"
52 set result [gdb_load $executable]
53 set timeout $oldtimeout
54 verbose "Timeout is now $timeout seconds" 2
56 if { $result != 0 } then {
60 if { $gdb_file_cmd_debug_info != "debug" } then {
61 untested "No debug information, skipping testcase."
65 # Set a breakpoint at main
66 gdb_test "break captured_main" \
67 "Breakpoint.*at.* file.*, line.*" \
68 "breakpoint in captured_main"
71 # It may take a very long time for the inferior gdb to start (lynx),
72 # so we bump it back up for the duration of this command.
75 set description "run until breakpoint at captured_main"
76 gdb_test_multiple "run -nw" "$description" {
77 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
80 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
81 xfail "$description (line numbers scrambled?)"
83 -re "vfork: No more processes.*$gdb_prompt $" {
84 fail "$description (out of virtual memory)"
85 set timeout $oldtimeout
86 verbose "Timeout is now $timeout seconds" 2
89 -re ".*$gdb_prompt $" {
91 set timeout $oldtimeout
92 verbose "Timeout is now $timeout seconds" 2
97 set timeout $oldtimeout
98 verbose "Timeout is now $timeout seconds" 2
103 proc attach_first_observer { message } {
104 gdb_test "set \$first_obs = observer_attach_normal_stop (&observer_test_first_notification_function)" \
105 "" "$message; attach first observer"
108 proc attach_second_observer { message } {
109 gdb_test "set \$second_obs = observer_attach_normal_stop (&observer_test_second_notification_function)" \
110 "" "$message; attach second observer"
113 proc attach_third_observer { message } {
114 gdb_test "set \$third_obs = observer_attach_normal_stop (&observer_test_third_notification_function)" \
115 "" "$message; attach third observer"
118 proc detach_first_observer { message } {
119 gdb_test "call observer_detach_normal_stop (\$first_obs)" \
120 "" "$message; detach first observer"
123 proc detach_second_observer { message } {
124 gdb_test "call observer_detach_normal_stop (\$second_obs)" \
125 "" "$message; detach second observer"
128 proc detach_third_observer { message } {
129 gdb_test "call observer_detach_normal_stop (\$third_obs)" \
130 "" "$message; detach third observer"
133 proc check_counters { first second third message } {
134 gdb_test "print observer_test_first_observer" \
135 ".\[0-9\]+ =.*$first" \
136 "$message; check first observer counter value"
137 gdb_test "print observer_test_second_observer" \
138 ".\[0-9\]+ =.*$second" \
139 "$message; check second observer counter value"
140 gdb_test "print observer_test_third_observer" \
141 ".\[0-9\]+ =.*$third" \
142 "$message; check third observer counter value"
145 proc reset_counters { message } {
146 gdb_test "set variable observer_test_first_observer = 0" "" \
147 "$message; reset first observer counter"
148 gdb_test "set variable observer_test_second_observer = 0" "" \
149 "$message; reset second observer counter"
150 gdb_test "set variable observer_test_third_observer = 0" "" \
151 "$message; reset third observer counter"
154 proc test_normal_stop_notifications { first second third message args } {
155 # Do any initialization
156 for {set i 0} {$i < [llength $args]} {incr i} {
157 [lindex $args $i] $message
159 reset_counters $message
160 # Call observer_notify_normal_stop. Note that this procedure
161 # takes one argument, but this argument is ignored by the observer
162 # callbacks we have installed. So we just pass an arbitrary value.
163 gdb_test "call observer_notify_normal_stop (0)" "" \
164 "$message; sending notification"
165 check_counters $first $second $third $message
168 proc test_observer_normal_stop { executable } {
170 set setup_result [setup_test $executable]
171 if {$setup_result <0} then {
175 # First, try sending a notification without any observer attached.
176 test_normal_stop_notifications 0 0 0 "no observer attached"
178 # Now, attach one observer, and send a notification.
179 test_normal_stop_notifications 0 1 0 "second observer attached" \
180 attach_second_observer
182 # Remove the observer, and send a notification.
183 test_normal_stop_notifications 0 0 0 "second observer detached" \
184 detach_second_observer
186 # With a new observer.
187 test_normal_stop_notifications 1 0 0 "1st observer added" \
188 attach_first_observer
191 test_normal_stop_notifications 1 1 0 "2nd observer added" \
192 attach_second_observer
195 test_normal_stop_notifications 1 1 1 "3rd observer added" \
196 attach_third_observer
198 # Remove middle observer.
199 test_normal_stop_notifications 1 0 1 "2nd observer removed" \
200 detach_second_observer
202 # Remove first observer.
203 test_normal_stop_notifications 0 0 1 "1st observer removed" \
204 detach_first_observer
206 # Remove last observer.
207 test_normal_stop_notifications 0 0 0 "3rd observer removed" \
208 detach_third_observer
210 # Go back to 3 observers, and remove them in a different order...
211 test_normal_stop_notifications 1 1 1 "three observers added" \
212 attach_first_observer \
213 attach_second_observer \
214 attach_third_observer
216 # Remove the third observer.
217 test_normal_stop_notifications 1 1 0 "third observer removed" \
218 detach_third_observer
220 # Remove the second observer.
221 test_normal_stop_notifications 1 0 0 "second observer removed" \
222 detach_second_observer
224 # Remove the first observer, no more observers.
225 test_normal_stop_notifications 0 0 0 "first observer removed" \
226 detach_first_observer
231 # Find a pathname to a file that we would execute if the shell was asked
232 # to run $arg using the current PATH.
234 proc find_gdb { arg } {
236 # If the arg directly specifies an existing executable file, then
239 if [file executable $arg] then {
243 set result [which $arg]
244 if [string match "/" [ string range $result 0 0 ]] then {
248 # If everything fails, just return the unqualified pathname as default
254 # Run the test with self.
255 # Copy the file executable file in case this OS doesn't like to edit its own
258 set GDB_FULLPATH
[find_gdb $GDB
]
260 # Remove
any old copy lying around.
261 remote_file host
delete x$tool
264 set file
[remote_download host $GDB_FULLPATH x$tool
]
265 set result
[test_observer_normal_stop $file
];
267 catch
"remote_file host delete $file";
269 if {$result
<0} then {
270 warning
"Couldn't test self"