1# Copyright 2019-2023 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# Test that GDB does not access the remote target's memory when 17# setting a breakpoint on a function that only exists in an inferior 18# that is not bound to the remote target. 19 20load_lib gdbserver-support.exp 21 22standard_testfile server.c 23 24if { [skip_gdbserver_tests] } { 25 return 0 26} 27 28if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \ 29 {debug pthreads}] } { 30 return 31} 32 33# Make sure we're disconnected, in case we're testing with an 34# extended-remote board, therefore already connected. 35gdb_test "disconnect" ".*" 36 37# Leave inferior 1 with the exec target, not connected. Add another 38# inferior, and connect it to gdbserver. 39 40gdb_test "add-inferior" "Added inferior 2" \ 41 "add inferior 2" 42gdb_test "inferior 2" "Switching to inferior 2.*" \ 43 "switch to inferior 2" 44gdb_test "file ${binfile}" ".*" "load file in inferior 2" 45 46set target_exec [gdbserver_download_current_prog] 47 48# Start GDBserver. 49set res [gdbserver_start "" $target_exec] 50 51# Connect to GDBserver. 52set gdbserver_protocol [lindex $res 0] 53set gdbserver_gdbport [lindex $res 1] 54gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport 55 56# Discard any symbol files that we have opened. 57set test "discard symbol table" 58gdb_test_multiple "file" $test { 59 -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $" { 60 gdb_test "y" ".*" $test \ 61 {Discard symbol table from `.*'\? \(y or n\) } "y" 62 } 63} 64 65# At this point: 66# 67# - inferior 1 has symbols, and is not connected to any target. 68# - inferior 2 has no symbols, and is connected to gdbserver. 69 70# Setting a breakpoint at some function by name should set a 71# breakpoint on inferior 1, since it has symbols, and should not 72# result in any access to inferior 2's remote target. 73 74foreach inf_sel {1 2} { 75 with_test_prefix "inf $inf_sel" { 76 gdb_test "inferior $inf_sel" "Switching to inferior $inf_sel.*" \ 77 "switch to inferior" 78 79 gdb_test_no_output "set debug remote 1" 80 81 gdb_test_multiple "break -q main" "set breakpoint" { 82 -re "Sending packet: \\\$qXfer:auxv:read.*$gdb_prompt $" { 83 # Symbol lookup may access the target to read AUXV in 84 # order to determine the debug base for SVR4 linker 85 # namespaces. 86 xfail "$gdb_test_name" 87 } 88 -re "Sending packet.*$gdb_prompt $" { 89 fail "$gdb_test_name" 90 } 91 -re "^break -q main\r\nBreakpoint .* at .*$gdb_prompt $" { 92 pass "$gdb_test_name" 93 } 94 } 95 96 gdb_test_no_output "set debug remote 0" 97 98 delete_breakpoints 99 } 100} 101