1 # Copyright 2019-2020 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 if { [skip_gdbserver_tests] } {
28 if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
33 # Make sure we're disconnected, in case we're testing with an
34 # extended-remote board, therefore already connected.
35 gdb_test "disconnect" ".*"
37 # Leave inferior 1 with the exec target, not connected. Add another
38 # inferior, and connect it to gdbserver.
40 gdb_test "add-inferior" "Added inferior 2" \
42 gdb_test "inferior 2" "Switching to inferior 2.*" \
43 "switch to inferior 2"
44 gdb_test "file ${binfile}" ".*" "load file in inferior 2"
46 set target_exec [gdbserver_download_current_prog]
49 set res [gdbserver_start "" $target_exec]
51 # Connect to GDBserver.
52 set gdbserver_protocol [lindex $res 0]
53 set gdbserver_gdbport [lindex $res 1]
54 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
56 # Discard any symbol files that we have opened.
57 set test "discard symbol table"
58 gdb_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"
67 # - inferior 1 has symbols, and is not connected to any target.
68 # - inferior 2 has no symbols, and is connected to gdbserver.
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.
74 gdb_test_no_output "set debug remote 1"
76 foreach inf_sel {1 2} {
77 with_test_prefix "inf $inf_sel" {
78 gdb_test "inferior $inf_sel" "Switching to inferior $inf_sel.*" \
81 set test "set breakpoint"
82 gdb_test_multiple "break main" $test {
83 -re "Sending packet.*$gdb_prompt $" {
86 -re "^break main\r\nBreakpoint .* at .*$gdb_prompt $" {