1 # Copyright 2019-2024 Free Software Foundation, Inc.
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.
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.
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/>.
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.
20 load_lib gdbserver-support.exp
22 standard_testfile server.c
24 require allow_gdbserver_tests
26 if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
30 set host_binfile [gdb_remote_download host $binfile]
32 # Make sure we're disconnected, in case we're testing with an
33 # extended-remote board, therefore already connected.
34 gdb_test "disconnect" ".*"
36 # Leave inferior 1 with the exec target, not connected. Add another
37 # inferior, and connect it to gdbserver.
39 gdb_test "add-inferior" "Added inferior 2" \
41 gdb_test "inferior 2" "Switching to inferior 2.*" \
42 "switch to inferior 2"
43 gdb_test "file ${host_binfile}" ".*" "load file in inferior 2"
45 set target_exec [gdbserver_download_current_prog]
48 set res [gdbserver_start "" $target_exec]
50 # Connect to GDBserver.
51 set gdbserver_protocol [lindex $res 0]
52 set gdbserver_gdbport [lindex $res 1]
53 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
55 # Discard any symbol files that we have opened.
56 set test "discard symbol table"
57 gdb_test_multiple "file" $test {
58 -re "A program is being debugged already..*Are you sure you want to change the file.*y or n. $" {
59 gdb_test "y" ".*" $test \
60 {Discard symbol table from `.*'\? \(y or n\) } "y"
66 # - inferior 1 has symbols, and is not connected to any target.
67 # - inferior 2 has no symbols, and is connected to gdbserver.
69 # Setting a breakpoint at some function by name should set a
70 # breakpoint on inferior 1, since it has symbols, and should not
71 # result in any access to inferior 2's remote target.
73 foreach inf_sel {1 2} {
74 with_test_prefix "inf $inf_sel" {
75 gdb_test "inferior $inf_sel" "Switching to inferior $inf_sel.*" \
78 gdb_test_no_output "set debug remote 1"
80 gdb_test_multiple "break -q main" "set breakpoint" {
81 -re "Sending packet: \\\$qXfer:auxv:read.*$gdb_prompt $" {
82 # Symbol lookup may access the target to read AUXV in
83 # order to determine the debug base for SVR4 linker
85 xfail "$gdb_test_name"
87 -re "Sending packet.*$gdb_prompt $" {
90 -re "^break -q main\r\nBreakpoint .* at .*$gdb_prompt $" {
95 gdb_test_no_output "set debug remote 0"