| # This testcase is part of GDB, the GNU debugger. |
| # |
| # Copyright 2024-2025 Free Software Foundation, Inc. |
| # |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 3 of the License, or |
| # (at your option) any later version. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| # GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| |
| # Setup a number of directories in the debug-file-directory, start gdbserver |
| # and connect GDB. The debug information is downloaded from the last |
| # directory in the debug-file-directory. |
| # |
| # We are checking that GDB reports 'Reading <filename> from remote target' |
| # only for the paths that are actually being read, and not for paths that |
| # GDB is simply probing for existence. |
| |
| load_lib gdbserver-support.exp |
| |
| require allow_gdbserver_tests |
| require {!is_remote host} |
| |
| standard_testfile |
| |
| if {[build_executable "failed to prepare" $testfile $srcfile \ |
| {debug build-id}] == -1} { |
| return -1 |
| } |
| |
| # Split out BINFILE.debug. Remove debug from BINFILE. |
| if {[gdb_gnu_strip_debug $binfile] != 0} { |
| return -1 |
| } |
| |
| # Get the '.build-id/xx/xxx...xxx' part of the filename. |
| set build_id_filename [build_id_debug_filename_get $binfile] |
| |
| set hidden_binfile [standard_output_file "hidden_$testfile"] |
| set hidden_debuginfo [standard_output_file "hidden_$testfile.debug"] |
| |
| # Hide (rename) BINFILE and associated debug information, this should ensure |
| # GDB can't find it directly. |
| remote_exec build "mv $binfile $hidden_binfile" |
| remote_exec build "mv ${binfile}.debug $hidden_debuginfo" |
| |
| # Helper called from gdb_finish when the 'target' is remote. Ensure the |
| # debug directory we create is deleted. |
| proc cleanup_remote_target {} { |
| remote_exec target "rm -fr debug/" |
| } |
| |
| if { ![is_remote target] } { |
| set gdbserver_dir [standard_output_file "gdbserver-dir"]/ |
| } else { |
| lappend gdb_finish_hooks cleanup_remote_target |
| set gdbserver_dir "" |
| } |
| |
| # Copy files to the target (if needed). |
| set target_binfile [gdb_remote_download target $hidden_binfile] |
| set target_debuginfo [gdb_remote_download target $hidden_debuginfo] |
| |
| # Setup the debug information on the target. |
| remote_exec target \ |
| "mkdir -p ${gdbserver_dir}debug/[file dirname $build_id_filename]" |
| remote_exec target \ |
| "ln -sf $target_debuginfo ${gdbserver_dir}debug/$build_id_filename" |
| |
| # Reading debug info from the remote target can take a bit of time, so |
| # increase the timeout. |
| with_timeout_factor 5 { |
| # Restart GDB. |
| clean_restart |
| |
| # Add some dummy entries to the debug-file-directory search list. |
| gdb_test_no_output "set debug-file-directory xxx:yyy:debug" |
| |
| # Set the sysroot. |
| gdb_test_no_output "set sysroot target:" |
| |
| # Make sure we're disconnected, in case we're testing with an |
| # extended-remote board, therefore already connected. |
| gdb_test "disconnect" ".*" |
| |
| # Start gdbserver. This needs to be done after starting GDB. When |
| # gdbserver is running local to GDB, start gdbserver in a sub-directory, |
| # this prevents GDB from finding the debug information itself. |
| if { ![is_remote target] } { |
| with_cwd $gdbserver_dir { |
| set res [gdbserver_start "" $target_binfile] |
| } |
| } else { |
| set res [gdbserver_start "" $target_binfile] |
| } |
| set gdbserver_protocol [lindex $res 0] |
| set gdbserver_gdbport [lindex $res 1] |
| |
| # Connect to gdbserver. The output will be placed into the global |
| # GDB_TARGET_REMOTE_CMD_MSG, and we'll match against this below. |
| gdb_assert {[gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] == 0} \ |
| "connect to gdbserver" |
| |
| gdb_assert { ![regexp "Reading xxx/\[^\r\n\]+ from remote target\\.\\.\\.\r\n" \ |
| $gdb_target_remote_cmd_msg] \ |
| && ![regexp "Reading yyy/\[^\r\n\]+ from remote target\\.\\.\\.\r\n" \ |
| $gdb_target_remote_cmd_msg] } \ |
| "check xxx/ and yyy/ are not mentioned" |
| |
| gdb_assert { [regexp "Reading debug/[string_to_regexp $build_id_filename] from remote target\\.\\.\\.\r\n" \ |
| $gdb_target_remote_cmd_msg] } \ |
| "check debug information is found" |
| } |