1 # Copyright 2003-2019 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 # Find a pathname to a file that we would execute if the shell was asked
17 # to run $arg using the current PATH.
19 proc find_gdb { arg } {
21 # If the arg directly specifies an existing executable file, then
24 if [file executable $arg] then {
28 set result [which $arg]
29 if [string match "/" [ string range $result 0 0 ]] then {
33 # If everything fails, just return the unqualified pathname as default
39 # A helper proc that sets up for self-testing.
40 # EXECUTABLE is the gdb to use.
41 # FUNCTION is the function to break in, either captured_main
42 # or captured_command_loop.
44 proc selftest_setup { executable function } {
47 global INTERNAL_GDBFLAGS
49 # load yourself into the debugger
50 # This can take a relatively long time, particularly for testing where
51 # the executable is being accessed over a network, or where gdb does not
52 # support partial symbols for a particular target and has to load the
53 # entire symbol table. Set the timeout to 10 minutes, which should be
54 # adequate for most environments (it *has* timed out with 5 min on a
55 # SPARCstation SLC under moderate load, so this isn't unreasonable).
56 # After gdb is started, set the timeout to 30 seconds for the duration
57 # of this test, and then back to the original value.
59 set oldtimeout $timeout
61 verbose "Timeout is now $timeout seconds" 2
63 global gdb_file_cmd_debug_info
64 set gdb_file_cmd_debug_info "unset"
66 set result [gdb_load $executable]
67 set timeout $oldtimeout
68 verbose "Timeout is now $timeout seconds" 2
70 if { $result != 0 } then {
74 if { $gdb_file_cmd_debug_info != "debug" } then {
75 untested "no debug information, skipping testcase."
79 # Set a breakpoint at main
80 gdb_test "break $function" \
81 "Breakpoint.*at.* file.*, line.*" \
82 "breakpoint in $function"
85 # It may take a very long time for the inferior gdb to start (lynx),
86 # so we bump it back up for the duration of this command.
89 set description "run until breakpoint at $function"
90 gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
91 -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(.*\\).* at .*main.c:.*$gdb_prompt $" {
94 -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(.*\\).*$gdb_prompt $" {
95 xfail "$description (line numbers scrambled?)"
97 -re "vfork: No more processes.*$gdb_prompt $" {
98 fail "$description (out of virtual memory)"
99 set timeout $oldtimeout
100 verbose "Timeout is now $timeout seconds" 2
103 -re ".*$gdb_prompt $" {
105 set timeout $oldtimeout
106 verbose "Timeout is now $timeout seconds" 2
111 set timeout $oldtimeout
112 verbose "Timeout is now $timeout seconds" 2
117 # A simple way to run some self-tests.
119 proc do_self_tests {function body} {
122 # Are we testing with a remote board? In that case, the target
123 # won't have access to the GDB's auxilliary data files
124 # (data-directory, etc.). It's simpler to just skip.
125 if [is_remote target] {
129 # ... or seemingly testing with a cross debugger? Likely GDB
130 # wouldn't be able to debug itself then...
135 # ... or with a stub-like server? I.e., gdbserver + "target
136 # remote"? In that case we won't be able to pass command line
137 # arguments to GDB, and selftest_setup wants to do exactly that.
142 # Run the test with self. Copy the file executable file in case
143 # this OS doesn't like to edit its own text space.
145 set GDB_FULLPATH [find_gdb $GDB]
147 if {[is_remote host]} {
150 set xgdb [standard_output_file x$tool]
153 # Remove any old copy lying around.
154 remote_file host delete $xgdb
157 set file [remote_download host $GDB_FULLPATH $xgdb]
159 set result [selftest_setup $file $function]
160 if {$result == 0} then {
161 set result [uplevel $body]
165 catch "remote_file host delete $file"
167 if {$result < 0} then {
168 warning "Couldn't test self"