1 # This testcase is part of GDB, the GNU debugger. 2 # 3 # Copyright 2019-2024 Free Software Foundation, Inc. 4 # 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. 9 # 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. 14 # 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/>. 17 18 # Test that GDB can correctly read the binary and shared libraries 19 # with different sysroot setups: local and "target:". 20 21 load_lib gdbserver-support.exp 22 23 require allow_gdbserver_tests 24 25 standard_testfile 26 if {[build_executable "failed to prepare" $testfile $srcfile "additional_flags=--no-builtin"] == -1} { 27 return -1 28 } 29 30 set target_binfile [gdb_remote_download target $binfile] 31 set host_binfile [gdb_remote_download host $binfile] 32 33 # Run once with sysroot set to the local filesystem and once set to the remote 34 # target. 35 set modes {} 36 if { ( ![is_remote host] && ![is_remote target ] ) 37 || [board_info host name] == [board_info target name] } { 38 # Local means that gdb and gdbserver look at the same file system. That's 39 # not the case for remote host or remote target, unless 40 # remote host == remote target. 41 lappend modes "local" 42 } 43 lappend modes "remote" 44 45 foreach_with_prefix sysroot $modes { 46 global srcdir 47 global subdir 48 global binfile 49 50 if { $sysroot == "local" } { 51 set sysroot_command "/" 52 set reading_symbols "Reading symbols from $host_binfile..." 53 set timeout_factor 1 54 } else { 55 set sysroot_command "target:" 56 set reading_symbols "Reading .*$target_binfile from remote target..." 57 set timeout_factor 5 58 } 59 60 # Reading debug info from the remote target can take a bit of time, so 61 # increase the timeout in that case. 62 with_timeout_factor $timeout_factor { 63 # Restart GDB. 64 clean_restart 65 66 # Make sure we're disconnected, in case we're testing with an 67 # extended-remote board, therefore already connected. 68 gdb_test "disconnect" ".*" 69 70 # Start GDBserver. 71 set res [gdbserver_start "" $target_binfile] 72 set gdbserver_protocol [lindex $res 0] 73 set gdbserver_gdbport [lindex $res 1] 74 75 # Set the sysroot. 76 gdb_test_no_output "set sysroot $sysroot_command" 77 78 # Connect to gdbserver, making sure GDB reads in the binary correctly. 79 set test "connect to remote and read binary" 80 if {[gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport $reading_symbols] == 0} { 81 pass $test 82 } else { 83 fail $test 84 } 85 86 gdb_breakpoint main 87 gdb_test "continue" "Breakpoint $decimal.* main.*" "continue to main" 88 89 # Test that we can stop inside a library. 90 gdb_breakpoint printf 91 gdb_test "continue" "Breakpoint $decimal.* (__)?printf.*" \ 92 "continue to printf" 93 } 94 } 95