Home | History | Annotate | Line # | Download | only in gdb.server
      1      1.1  christos # This testcase is part of GDB, the GNU debugger.
      2      1.1  christos #
      3  1.1.1.3  christos # Copyright 2019-2024 Free Software Foundation, Inc.
      4      1.1  christos #
      5      1.1  christos # This program is free software; you can redistribute it and/or modify
      6      1.1  christos # it under the terms of the GNU General Public License as published by
      7      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      8      1.1  christos # (at your option) any later version.
      9      1.1  christos #
     10      1.1  christos # This program is distributed in the hope that it will be useful,
     11      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13      1.1  christos # GNU General Public License for more details.
     14      1.1  christos #
     15      1.1  christos # You should have received a copy of the GNU General Public License
     16      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17      1.1  christos 
     18      1.1  christos # Test that GDB can correctly read the binary and shared libraries
     19      1.1  christos # with different sysroot setups: local and "target:".
     20      1.1  christos 
     21      1.1  christos load_lib gdbserver-support.exp
     22      1.1  christos 
     23  1.1.1.3  christos require allow_gdbserver_tests
     24      1.1  christos 
     25      1.1  christos standard_testfile
     26      1.1  christos if {[build_executable "failed to prepare" $testfile $srcfile "additional_flags=--no-builtin"] == -1} {
     27      1.1  christos     return -1
     28      1.1  christos }
     29      1.1  christos 
     30  1.1.1.3  christos set target_binfile [gdb_remote_download target $binfile]
     31  1.1.1.3  christos set host_binfile [gdb_remote_download host $binfile]
     32  1.1.1.3  christos 
     33      1.1  christos # Run once with sysroot set to the local filesystem and once set to the remote
     34      1.1  christos # target.
     35  1.1.1.3  christos set modes {}
     36  1.1.1.3  christos if { ( ![is_remote host] && ![is_remote target ] )
     37  1.1.1.3  christos      || [board_info host name] == [board_info target name] } {
     38  1.1.1.3  christos     # Local means that gdb and gdbserver look at the same file system.  That's
     39  1.1.1.3  christos     # not the case for remote host or remote target, unless
     40  1.1.1.3  christos     # remote host == remote target.
     41  1.1.1.3  christos     lappend modes "local"
     42  1.1.1.3  christos }
     43  1.1.1.3  christos lappend modes "remote"
     44  1.1.1.3  christos 
     45  1.1.1.3  christos foreach_with_prefix sysroot $modes {
     46      1.1  christos     global srcdir
     47      1.1  christos     global subdir
     48      1.1  christos     global binfile
     49      1.1  christos 
     50      1.1  christos     if { $sysroot == "local" } {
     51      1.1  christos 	set sysroot_command "/"
     52  1.1.1.3  christos 	set reading_symbols "Reading symbols from $host_binfile..."
     53  1.1.1.2  christos 	set timeout_factor 1
     54      1.1  christos     } else {
     55      1.1  christos 	set sysroot_command "target:"
     56  1.1.1.3  christos 	set reading_symbols "Reading .*$target_binfile from remote target..."
     57  1.1.1.2  christos 	set timeout_factor 5
     58      1.1  christos     }
     59      1.1  christos 
     60  1.1.1.2  christos     # Reading debug info from the remote target can take a bit of time, so
     61  1.1.1.2  christos     # increase the timeout in that case.
     62  1.1.1.2  christos     with_timeout_factor $timeout_factor {
     63  1.1.1.2  christos 	# Restart GDB.
     64  1.1.1.2  christos 	clean_restart
     65  1.1.1.2  christos 
     66  1.1.1.2  christos 	# Make sure we're disconnected, in case we're testing with an
     67  1.1.1.2  christos 	# extended-remote board, therefore already connected.
     68  1.1.1.2  christos 	gdb_test "disconnect" ".*"
     69  1.1.1.2  christos 
     70  1.1.1.2  christos 	# Start GDBserver.
     71  1.1.1.3  christos 	set res [gdbserver_start "" $target_binfile]
     72  1.1.1.2  christos 	set gdbserver_protocol [lindex $res 0]
     73  1.1.1.2  christos 	set gdbserver_gdbport [lindex $res 1]
     74  1.1.1.2  christos 
     75  1.1.1.2  christos 	# Set the sysroot.
     76  1.1.1.2  christos 	gdb_test_no_output "set sysroot $sysroot_command"
     77  1.1.1.2  christos 
     78  1.1.1.2  christos 	# Connect to gdbserver, making sure GDB reads in the binary correctly.
     79  1.1.1.2  christos 	set test "connect to remote and read binary"
     80  1.1.1.2  christos 	if {[gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport $reading_symbols] == 0} {
     81  1.1.1.2  christos 	    pass $test
     82  1.1.1.2  christos 	} else {
     83  1.1.1.2  christos 	    fail $test
     84  1.1.1.2  christos 	}
     85  1.1.1.2  christos 
     86  1.1.1.2  christos 	gdb_breakpoint main
     87  1.1.1.2  christos 	gdb_test "continue" "Breakpoint $decimal.* main.*" "continue to main"
     88  1.1.1.2  christos 
     89  1.1.1.2  christos 	# Test that we can stop inside a library.
     90  1.1.1.2  christos 	gdb_breakpoint printf
     91  1.1.1.2  christos 	gdb_test "continue" "Breakpoint $decimal.* (__)?printf.*" \
     92  1.1.1.2  christos 	    "continue to printf"
     93      1.1  christos     }
     94      1.1  christos }
     95