GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.server / target-exec-file.exp
blob9a24b7a772098b17723b980347f99b9e2a273f0c
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2023-2024 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Test GDB's handling of using a file with a 'target:' prefix as the
19 # executable file. This test includes checking what happens when the
20 # file on the target system changes and GDB needs to reload it.
22 load_lib gdbserver-support.exp
24 require allow_gdbserver_tests !use_gdb_stub
26 standard_testfile
28 if { [build_executable "failed to prepare" $testfile $srcfile debug] } {
29 return -1
32 clean_restart
34 # Some boards specifically set the sysroot to the empty string to
35 # avoid copying files from the target. But for this test we do want
36 # to copy files from the target, so set the sysroot back to 'target:'.
38 # This is fine so long as we're not using a board file that sets the
39 # sysroot to something else -- but none of the standard boards do
40 # this, and plenty of other tests mess with the sysroot, so I guess we
41 # don't worry about that too much.
42 gdb_test "set sysroot target:" ".*"
44 # Make sure we're disconnected, in case we're testing with an
45 # extended-remote board, therefore already connected.
46 gdb_test "disconnect" ".*"
48 # Ensure the executable is on the target.
49 set target_exec [gdb_remote_download target $binfile]
51 # We're going to be restarting the inferior. Lets ask GDB not to
52 # prompt us if this is the right thing to do.
53 gdb_test_no_output "set confirm off"
55 if { [allow_python_tests] } {
56 # Register an event handler for the executable changed event.
57 # This handler just copies the event into a global Python object.
58 gdb_test_multiline "Add connection_removed event" \
59 "python" "" \
60 "global_exec_changed_event = None" "" \
61 "def executable_changed(event):" "" \
62 " global global_exec_changed_event" "" \
63 " global_exec_changed_event = event" "" \
64 "gdb.events.executable_changed.connect (executable_changed)" "" \
65 "end" ""
68 # Start gdbserver, but always in extended-remote mode, and then
69 # connect to it from GDB.
70 set res [gdbserver_start "--multi" $target_exec]
71 set gdbserver_protocol "extended-remote"
72 set gdbserver_gdbport [lindex $res 1]
73 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
75 if { [allow_python_tests] } {
76 # When connecting to a remote target, if the user has not told GDB
77 # which executable to use, then GDB will figure out an executable
78 # from the remote target.
80 # As a result we expect to have seen an executable changed event.
81 with_test_prefix "after connecting" {
82 gdb_test "python print(global_exec_changed_event)" \
83 "<gdb.ExecutableChangedEvent object at $hex>"
84 gdb_test "python print(global_exec_changed_event.progspace.executable_filename)" \
85 [string_to_regexp target:$target_exec]
86 gdb_test "python print(global_exec_changed_event.reload)" "False"
87 gdb_test_no_output "python global_exec_changed_event = None"
91 # Issue a 'file' command and parse the output. We look for a couple
92 # of specific things to ensure that we are correctly reading the exec
93 # from the remote target.
94 set saw_read_of_remote_exec false
95 set saw_read_of_syms_from_exec false
96 gdb_test_multiple "file target:$target_exec" "run file command" {
97 -re "^file target:\[^\r\n\]+\r\n" {
98 exp_continue
101 -re "^Reading (\[^\r\n\]+) from remote target\\.\\.\\.\r\n" {
102 set filename $expect_out(1,string)
103 if { $filename eq $target_exec } {
104 set saw_read_of_remote_exec true
106 exp_continue
109 -re "^warning: File transfers from remote targets can be slow\[^\r\n\]+\r\n" {
110 exp_continue
113 -re "^Reading symbols from target:(\[^\r\n\]+)\\.\\.\\.\r\n" {
114 set filename $expect_out(1,string)
115 if { $filename eq $target_exec } {
116 set saw_read_of_syms_from_exec true
118 exp_continue
121 -re "^Expanding full symbols from \[^\r\n\]+\r\n" {
122 exp_continue
125 -re "^$gdb_prompt $" {
126 pass $gdb_test_name
130 gdb_assert { $saw_read_of_remote_exec } \
131 "exec was read from the remote target"
133 gdb_assert { $saw_read_of_syms_from_exec } \
134 "symbols were read from remote exec file"
136 if { [allow_python_tests] } {
137 # The 'file' command forces GDB to always load the executable,
138 # even if the same filename is used. In this case, as the
139 # filename is the same, this will show as a reload event.
140 with_test_prefix "after 'file' command" {
141 gdb_test "python print(global_exec_changed_event)" \
142 "<gdb.ExecutableChangedEvent object at $hex>"
143 gdb_test "python print(global_exec_changed_event.progspace.executable_filename)" \
144 [string_to_regexp target:$target_exec]
145 gdb_test "python print(global_exec_changed_event.reload)" "True"
146 gdb_test_no_output "python global_exec_changed_event = None"
150 # Start the inferior (with the 'start' command), use TESTNAME for any
151 # pass/fail calls. EXPECT_REREAD should be true or false and
152 # indicates if we expect to too a line like:
154 # `FILE' has changed; re-reading symbols.
155 proc start_inferior { testname expect_reread } {
156 with_test_prefix $testname {
157 if { [gdb_start_cmd] < 0 } {
158 fail "start command"
159 return -1
162 set saw_reread false
163 gdb_test_multiple "" "stopped at main" {
164 -re "^start\\s*\r\n" {
165 exp_continue
167 -re "^`\[^\r\n\]+' has changed; re-reading symbols\\.\r\n" {
168 set saw_reread true
169 exp_continue
171 -re "^Reading \[^\r\n\]+ from remote target\\.\\.\\.\r\n" {
172 exp_continue
174 -re "^Expanding full symbols from \[^\r\n\]+\\.\\.\\.\r\n" {
175 exp_continue
177 -re "^Temporary breakpoint $::decimal at $::hex: \[^\r\n\]+\r\n" {
178 exp_continue
180 -re "^Starting program: \[^\r\n\]+\r\n" {
181 exp_continue
183 -re "^\\s*\r\n" {
184 exp_continue
186 -re "^Temporary breakpoint $::decimal, main \\(\\) at .*$::gdb_prompt $" {
187 pass $testname
191 gdb_assert { $expect_reread == $saw_reread } \
192 "check symbol re-read behavior"
196 # Start the inferior for the first time. The symbols were already
197 # read from the file when the 'file' command was used, we should not
198 # see the symbols re-read now.
199 start_inferior "start inferior the first time" false
201 if { [allow_python_tests] } {
202 # The executable hasn't changed.
203 with_test_prefix "after starting inferior for the first time" {
204 gdb_test "python print(global_exec_changed_event)" "None"
208 # Re-start the inferior. The executable is unchanged so we should not
209 # see the symbol file being re-read.
210 start_inferior "start inferior a second time" false
212 if { [allow_python_tests] } {
213 # The executable still hasn't changed.
214 with_test_prefix "after starting inferior for the second time" {
215 gdb_test "python print(global_exec_changed_event)" "None"
219 # Delay for a short while so, when we touch the exec, we know the
220 # timestamp will change.
221 sleep 1
222 set res [remote_exec target "touch $target_exec"]
223 set status [lindex $res 0]
224 if { $status != 0 } {
225 fail "touching executable on target"
226 return -1
229 # Start the inferior again, we expect to see the symbols being re-read
230 # from the remote file.
231 start_inferior "start inferior a third time" true
233 if { [allow_python_tests] } {
234 # The executable has now changed on disk. This will be a reload
235 # event.
236 with_test_prefix "after starting inferior for the third time" {
237 gdb_test "python print(global_exec_changed_event)" \
238 "<gdb.ExecutableChangedEvent object at $hex>"
239 gdb_test "python print(global_exec_changed_event.progspace.executable_filename)" \
240 [string_to_regexp target:$target_exec]
241 gdb_test "python print(global_exec_changed_event.reload)" "True"
242 gdb_test_no_output "python global_exec_changed_event = None"