aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-10-05 13:12:42 +0100
committerAndrew Burgess <aburgess@redhat.com>2023-11-20 10:54:17 +0000
commit70fd94b244573225cb04ae41101d495def78b9e6 (patch)
treeab1cdac72867068697707e91404226f27bc9aae9 /gdb/testsuite
parent96619f154a3b9bbd8e3dbd5b4408fa4f27d67f17 (diff)
downloadgdb-70fd94b244573225cb04ae41101d495def78b9e6.zip
gdb-70fd94b244573225cb04ae41101d495def78b9e6.tar.gz
gdb-70fd94b244573225cb04ae41101d495def78b9e6.tar.bz2
gdb: fix reopen_exec_file for files with target: prefix
Following on from this commit: commit f2c4f78c813a9cef38b7e9c9ad18822fb9e19345 Date: Thu Sep 21 16:35:30 2023 +0100 gdb: fix reread_symbols when an objfile has target: prefix In this commit I update reopen_exec_file to correctly handle executables with a target: prefix. Before this commit we used the system 'stat' call, which obviously isn't going to work for files with a target: prefix (files located on a possibly remote target machine). By switching to bfd_stat we will use remote fileio to stat the remote files, which means we should now correctly detect changes in a remote executable. The program_space::ebfd_mtime variable, with which we compare the result of bfd_stat is set with a call to bfd_get_mtime, which in turn calls bfd_stat, so comparing to the result of calling bfd_stat makes sense (I think). As I discussed in the commit f2c4f78c813a, if a BFD is an in-memory BFD, then calling bfd_stat will always return 0, while bfd_get_mtime will always return the time at which the BFD was created. As a result comparing the results will always show the file having changed. I don't believe that GDB can set the main executable to an in-memory BFD object, so, in this commit, I simply assert that the executable is not in-memory. If this ever changes then we would need to decide how to handle this case -- always reload, or never reload. The assert doesn't appear to trigger for our current test suite. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.server/target-exec-file.exp70
1 files changed, 70 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.server/target-exec-file.exp b/gdb/testsuite/gdb.server/target-exec-file.exp
index 9260df8..4086353 100644
--- a/gdb/testsuite/gdb.server/target-exec-file.exp
+++ b/gdb/testsuite/gdb.server/target-exec-file.exp
@@ -52,6 +52,19 @@ set target_exec [gdb_remote_download target $binfile]
# prompt us if this is the right thing to do.
gdb_test_no_output "set confirm off"
+if { [allow_python_tests] } {
+ # Register an event handler for the executable changed event.
+ # This handler just copies the event into a global Python object.
+ gdb_test_multiline "Add connection_removed event" \
+ "python" "" \
+ "global_exec_changed_event = None" "" \
+ "def executable_changed(event):" "" \
+ " global global_exec_changed_event" "" \
+ " global_exec_changed_event = event" "" \
+ "gdb.events.executable_changed.connect (executable_changed)" "" \
+ "end" ""
+}
+
# Start gdbserver, but always in extended-remote mode, and then
# connect to it from GDB.
set res [gdbserver_start "--multi" $target_exec]
@@ -59,6 +72,22 @@ set gdbserver_protocol "extended-remote"
set gdbserver_gdbport [lindex $res 1]
gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
+if { [allow_python_tests] } {
+ # When connecting to a remote target, if the user has not told GDB
+ # which executable to use, then GDB will figure out an executable
+ # from the remote target.
+ #
+ # As a result we expect to have seen an executable changed event.
+ with_test_prefix "after connecting" {
+ gdb_test "python print(global_exec_changed_event)" \
+ "<gdb.ExecutableChangedEvent object at $hex>"
+ gdb_test "python print(global_exec_changed_event.progspace.executable_filename)" \
+ [string_to_regexp target:$target_exec]
+ gdb_test "python print(global_exec_changed_event.reload)" "False"
+ gdb_test_no_output "python global_exec_changed_event = None"
+ }
+}
+
# Issue a 'file' command and parse the output. We look for a couple
# of specific things to ensure that we are correctly reading the exec
# from the remote target.
@@ -104,6 +133,20 @@ gdb_assert { $saw_read_of_remote_exec } \
gdb_assert { $saw_read_of_syms_from_exec } \
"symbols were read from remote exec file"
+if { [allow_python_tests] } {
+ # The 'file' command forces GDB to always load the executable,
+ # even if the same filename is used. In this case, as the
+ # filename is the same, this will show as a reload event.
+ with_test_prefix "after 'file' command" {
+ gdb_test "python print(global_exec_changed_event)" \
+ "<gdb.ExecutableChangedEvent object at $hex>"
+ gdb_test "python print(global_exec_changed_event.progspace.executable_filename)" \
+ [string_to_regexp target:$target_exec]
+ gdb_test "python print(global_exec_changed_event.reload)" "True"
+ gdb_test_no_output "python global_exec_changed_event = None"
+ }
+}
+
# Start the inferior (with the 'start' command), use TESTNAME for any
# pass/fail calls. EXPECT_REREAD should be true or false and
# indicates if we expect to too a line like:
@@ -155,10 +198,24 @@ proc start_inferior { testname expect_reread } {
# see the symbols re-read now.
start_inferior "start inferior the first time" false
+if { [allow_python_tests] } {
+ # The executable hasn't changed.
+ with_test_prefix "after starting inferior for the first time" {
+ gdb_test "python print(global_exec_changed_event)" "None"
+ }
+}
+
# Re-start the inferior. The executable is unchanged so we should not
# see the symbol file being re-read.
start_inferior "start inferior a second time" false
+if { [allow_python_tests] } {
+ # The executable still hasn't changed.
+ with_test_prefix "after starting inferior for the second time" {
+ gdb_test "python print(global_exec_changed_event)" "None"
+ }
+}
+
# Delay for a short while so, when we touch the exec, we know the
# timestamp will change.
sleep 1
@@ -172,3 +229,16 @@ if { $status != 0 } {
# Start the inferior again, we expect to see the symbols being re-read
# from the remote file.
start_inferior "start inferior a third time" true
+
+if { [allow_python_tests] } {
+ # The executable has now changed on disk. This will be a reload
+ # event.
+ with_test_prefix "after starting inferior for the third time" {
+ gdb_test "python print(global_exec_changed_event)" \
+ "<gdb.ExecutableChangedEvent object at $hex>"
+ gdb_test "python print(global_exec_changed_event.progspace.executable_filename)" \
+ [string_to_regexp target:$target_exec]
+ gdb_test "python print(global_exec_changed_event.reload)" "True"
+ gdb_test_no_output "python global_exec_changed_event = None"
+ }
+}