]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/lib/selftest-support.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / selftest-support.exp
CommitLineData
213516ef 1# Copyright 2003-2023 Free Software Foundation, Inc.
c95aea6b
TT
2
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.
7#
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.
12#
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/>.
15
16# Find a pathname to a file that we would execute if the shell was asked
17# to run $arg using the current PATH.
18
19proc find_gdb { arg } {
20
21 # If the arg directly specifies an existing executable file, then
22 # simply use it.
23
d4c45423 24 if {[file executable $arg]} {
c95aea6b
TT
25 return $arg
26 }
27
28 set result [which $arg]
d4c45423 29 if {[string match "/" [ string range $result 0 0 ]]} {
c95aea6b
TT
30 return $result
31 }
32
33 # If everything fails, just return the unqualified pathname as default
34 # and hope for best.
35
36 return $arg
37}
38
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.
41e37c9d
TV
43# Return 0 in case of success, -1 in case of failure, and -2 in case of
44# skipping the test-case.
c95aea6b
TT
45
46proc selftest_setup { executable function } {
47 global gdb_prompt
c95aea6b
TT
48 global INTERNAL_GDBFLAGS
49
50 # load yourself into the debugger
c95aea6b
TT
51
52 global gdb_file_cmd_debug_info
53 set gdb_file_cmd_debug_info "unset"
54
55 set result [gdb_load $executable]
c95aea6b 56
d4c45423 57 if {$result != 0} {
c95aea6b
TT
58 return -1
59 }
60
d4c45423 61 if {$gdb_file_cmd_debug_info != "debug"} {
bc6c7af4 62 untested "no debug information, skipping testcase."
41e37c9d 63 return -2
c95aea6b
TT
64 }
65
41e37c9d
TV
66 # Set a breakpoint at $function.
67 if { [gdb_breakpoint $function "no-message"] != 1 } {
68 untested "Cannot set breakpoint at $function, skipping testcase."
69 return -2
70 }
c95aea6b
TT
71
72 # run yourself
c95aea6b
TT
73
74 set description "run until breakpoint at $function"
75 gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
70ee0000 76 -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(.*\\).* at .*main.c:.*$gdb_prompt $" {
c95aea6b
TT
77 pass "$description"
78 }
70ee0000 79 -re "Starting program.*Breakpoint \[0-9\]+,.*$function \\(.*\\).*$gdb_prompt $" {
c95aea6b
TT
80 xfail "$description (line numbers scrambled?)"
81 }
82 -re "vfork: No more processes.*$gdb_prompt $" {
83 fail "$description (out of virtual memory)"
c95aea6b
TT
84 return -1
85 }
86 -re ".*$gdb_prompt $" {
87 fail "$description"
c95aea6b
TT
88 return -1
89 }
90 }
91
c95aea6b
TT
92 return 0
93}
94
95# A simple way to run some self-tests.
96
97proc do_self_tests {function body} {
98 global GDB tool
99
dad0c6d2
PA
100 # Are we testing with a remote board? In that case, the target
101 # won't have access to the GDB's auxilliary data files
102 # (data-directory, etc.). It's simpler to just skip.
103 if [is_remote target] {
104 return
105 }
106
107 # ... or seemingly testing with a cross debugger? Likely GDB
108 # wouldn't be able to debug itself then...
109 if ![isnative] {
110 return
111 }
112
113 # ... or with a stub-like server? I.e., gdbserver + "target
114 # remote"? In that case we won't be able to pass command line
115 # arguments to GDB, and selftest_setup wants to do exactly that.
079670b9 116 if [use_gdb_stub] {
e379b391
TT
117 return
118 }
119
c95aea6b
TT
120 # Run the test with self. Copy the file executable file in case
121 # this OS doesn't like to edit its own text space.
122
123 set GDB_FULLPATH [find_gdb $GDB]
124
bdfe0594
TT
125 if {[is_remote host]} {
126 set xgdb x$tool
127 } else {
128 set xgdb [standard_output_file x$tool]
129 }
130
c95aea6b 131 # Remove any old copy lying around.
bdfe0594 132 remote_file host delete $xgdb
c95aea6b
TT
133
134 gdb_start
bdfe0594 135 set file [remote_download host $GDB_FULLPATH $xgdb]
c95aea6b 136
687e348e
SM
137 # When debugging GDB with GDB, some operations can take a relatively long
138 # time, especially if the build is non-optimized. Bump the timeout for the
139 # duration of the test.
140 with_timeout_factor 10 {
141 set result [selftest_setup $file $function]
d4c45423 142 if {$result == 0} {
687e348e
SM
143 set result [uplevel $body]
144 }
c95aea6b
TT
145 }
146
147 gdb_exit
148 catch "remote_file host delete $file"
149
d4c45423 150 if {$result == -1} {
c95aea6b
TT
151 warning "Couldn't test self"
152 }
153}