Home | History | Annotate | Line # | Download | only in gdb.server
sysroot.exp revision 1.1.1.1.2.1
      1 # This testcase is part of GDB, the GNU debugger.
      2 #
      3 # Copyright 2019-2023 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 if { [skip_gdbserver_tests] } {
     24     verbose "skipping gdbserver tests"
     25     return -1
     26 }
     27 
     28 standard_testfile
     29 if {[build_executable "failed to prepare" $testfile $srcfile "additional_flags=--no-builtin"] == -1} {
     30     return -1
     31 }
     32 
     33 # Run once with sysroot set to the local filesystem and once set to the remote
     34 # target.
     35 foreach_with_prefix sysroot { "local" "remote" } {
     36     global srcdir
     37     global subdir
     38     global binfile
     39 
     40     if { $sysroot == "local" } {
     41 	set sysroot_command "/"
     42 	set reading_symbols "Reading symbols from $binfile..."
     43 	set timeout_factor 1
     44     } else {
     45 	set sysroot_command "target:"
     46 	set reading_symbols "Reading $binfile from remote target..."
     47 	set timeout_factor 5
     48     }
     49 
     50     # Reading debug info from the remote target can take a bit of time, so
     51     # increase the timeout in that case.
     52     with_timeout_factor $timeout_factor {
     53 	# Restart GDB.
     54 	clean_restart
     55 
     56 	# Make sure we're disconnected, in case we're testing with an
     57 	# extended-remote board, therefore already connected.
     58 	gdb_test "disconnect" ".*"
     59 
     60 	# Start GDBserver.
     61 	set res [gdbserver_start "" $binfile]
     62 	set gdbserver_protocol [lindex $res 0]
     63 	set gdbserver_gdbport [lindex $res 1]
     64 
     65 	# Set the sysroot.
     66 	gdb_test_no_output "set sysroot $sysroot_command"
     67 
     68 	# Connect to gdbserver, making sure GDB reads in the binary correctly.
     69 	set test "connect to remote and read binary"
     70 	if {[gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport $reading_symbols] == 0} {
     71 	    pass $test
     72 	} else {
     73 	    fail $test
     74 	}
     75 
     76 	gdb_breakpoint main
     77 	gdb_test "continue" "Breakpoint $decimal.* main.*" "continue to main"
     78 
     79 	# Test that we can stop inside a library.
     80 	gdb_breakpoint printf
     81 	gdb_test "continue" "Breakpoint $decimal.* (__)?printf.*" \
     82 	    "continue to printf"
     83     }
     84 }
     85