From: Andrew Burgess Date: Wed, 14 Jan 2026 19:31:24 +0000 (+0000) Subject: gdb/testsuite: fix failure in gdb.server/fetch-exec-and-args.exp X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae6c314e014249a96c070eec58e5a2ae1cf103dc;p=thirdparty%2Fbinutils-gdb.git gdb/testsuite: fix failure in gdb.server/fetch-exec-and-args.exp Bug PR gdb/33792 reported a gdb.server/fetch-exec-and-args.exp FAIL when using the native-gdbserver board: FAIL: gdb.server/fetch-exec-and-args.exp: packet=on: set_remote_exec=false: test_server_with_no_exec: show remote exec-file The actual test output looks like this: (gdb) show remote exec-file The remote exec-file is unset, using automatic value "/tmp/build/gdb/testsuite/outputs/gdb.server/fetch-exec-and-args/fetch-exec-and-args". (gdb) FAIL: gdb.server/fetch-exec-and-args.exp: packet=on: set_remote_exec=false: test_server_with_no_exec: show remote exec-file This test actually fails with native-gdbsever and native-extended-gdbserver boards. The problem is that these boards clear the sysroot. This exact test has the following conditions: + The qExecAndArgs is in use (see 'packet=on'). + We're not explicitly doing 'set remote exec-file ...' (see 'set_remote_exec=false'). + The test starts gdbserver without an executable (see 'test_server_with_no_exec'). + And because of the native-gdbsever board, the sysroot is "". What this means is that GDB knows that gdbserver doesn't have an executable thanks to qExecAndArgs, the user hasn't set an executable for GDB to use when starting a new inferior, but GDB does know that GDB and gdbserver can see the same filesystem due to the sysroot setting. GDB will then automatically use the current executable as the remote executable name. The test script doesn't expect this case, and so the test fails. Fix this by adjusting the script to expect the 'using automatic value ...' text when appropriate. I also extended the test_server_with_no_exec proc to take a new flag 'clear_sysroot', we now run the test with the sysroot set to 'target:' and with the sysroot set to "", even when using the 'unix' board. Additionally, I ran the test through check-all-boards and found one additional failure, when using --host_board=local-remote-host-native and --target_board=local-remote-host-native. In this case GDB copies the executable to the remote host, which changes its filename. When the filename appears in the 'using automatic value ...' text, I was expecting the filename assuming a local host. I could fix this, but it doesn't seem worth the extra complexity for this one test, so I've just set the test to be skipped for that one configuration. Now, when using check-all-boards, I'm seeing no failures. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33792 Approved-By: Simon Marchi --- diff --git a/gdb/testsuite/gdb.server/fetch-exec-and-args.exp b/gdb/testsuite/gdb.server/fetch-exec-and-args.exp index d85cd94fb1d..36189dec602 100644 --- a/gdb/testsuite/gdb.server/fetch-exec-and-args.exp +++ b/gdb/testsuite/gdb.server/fetch-exec-and-args.exp @@ -54,11 +54,22 @@ proc check_show_args { packet } { # 'off' and reflects whether the qExecAndArgs packet is turned on or # off. FILENAME is what we expect to see included in the output, and # is converted to a regexp by this function. -proc check_remote_exec_file { packet filename } { +# +# The AUTO_FILENAME should only be set when PACKET is on and FILENAME +# is the empty sting. If AUTO_FILENAME is set, then this is the +# filename that GDB is using for the remote executable based on the +# current executable's filename. For example, if the sysroot is empty +# then GDB can use the current executable as the remote executable. +proc check_remote_exec_file { packet filename { auto_filename "" } } { if { $filename eq "" } { if { $packet } { - set remote_exec_re \ - "The remote exec-file is unset, the remote has no default executable set\\." + if { $auto_filename ne "" } { + set remote_exec_re \ + "The remote exec-file is unset, using automatic value \"[string_to_regexp $auto_filename]\"\\." + } else { + set remote_exec_re \ + "The remote exec-file is unset, the remote has no default executable set\\." + } } else { set remote_exec_re \ "The remote exec-file is unset, the default remote executable will be used\\." @@ -260,9 +271,35 @@ proc_with_prefix test_remote_exec_warning {} { # filename when starting gdbserver. # # Connect to the remote server, and check 'show remote exec-file'. -proc_with_prefix test_server_with_no_exec { packet set_remote_exec } { +proc_with_prefix test_server_with_no_exec { packet set_remote_exec clear_sysroot } { + # For remote hosts GDB copies the executable to the host, changing + # its filename. We can figure out the new exec filename, but it's + # additional work, so just don't bother. We only need to bail out + # though in the precise case that the executable filename will be + # used in the output. + if {!$set_remote_exec && $clear_sysroot && [is_remote host]} { + return + } + clean_restart + set sysroot "*UNKNOWN*" + gdb_test_multiple "show sysroot" "" { + -re -wrap "^The current system root is \"(\[^\r\n\]*)\"\\." { + set sysroot $expect_out(1,string) + pass $gdb_test_name + } + } + if { $sysroot ne "target:" && $sysroot ne "" } { + return + } + + if { $clear_sysroot } { + gdb_test_no_output "set sysroot" + } else { + gdb_test_no_output "set sysroot target:" + } + gdb_test "disconnect" ".*" gdb_file_cmd $::binfile @@ -277,13 +314,18 @@ proc_with_prefix test_server_with_no_exec { packet set_remote_exec } { gdb_test_no_output "set remote exec-file $target_exec" \ "set remote exec-file" set expected_filename $target_exec + set auto_filename "" + } elseif { $clear_sysroot } { + set expected_filename "" + set auto_filename $::binfile } else { set expected_filename "" + set auto_filename "" } gdbserver_start_extended - check_remote_exec_file $packet $expected_filename + check_remote_exec_file $packet $expected_filename $auto_filename } # This override prevents the remote exec-file from being set when @@ -298,7 +340,10 @@ with_override extended_gdbserver_load_last_file do_nothing { test_exec_and_arg_fetch $packet foreach_with_prefix set_remote_exec { true false } { - test_server_with_no_exec $packet $set_remote_exec + foreach_with_prefix clear_sysroot { true false } { + test_server_with_no_exec $packet $set_remote_exec \ + $clear_sysroot + } } }