1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2016-2024 Free Software Foundation, Inc.
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.
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.
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/>.
18 # Test GDB's ability to properly connect to GDBserver with no pre-opened
19 # symbol file. If GDB is buggy, it will drop the connection when
20 # it attempts to open the symbol file indicated by GDBserver and fails.
22 # This test is only meaningful for standard remote connections.
24 load_lib gdbserver-support.exp
28 require allow_gdbserver_tests
30 if { [build_executable "failed to prepare" $testfile $srcfile debug] } {
34 # Test connecting GDB to GDBserver without loading a symbol file.
36 # SYSROOT is the desired sysroot string
38 # ACTION is the action to perform to the symbol file on the target.
39 # It can be either "permission" to deny access to the file or "delete"
42 proc connect_no_symbol_file { sysroot action } {
45 with_test_prefix "setup" {
46 # Restore original $binfile.
47 gdb_remote_download build $binfile.bak $binfile
49 # Copy the symbol file to the target.
50 set target_exec [gdb_remote_download target $binfile]
52 # Make sure we're disconnected, in case we're testing with an
53 # extended-remote board, therefore already connected.
54 gdb_test "disconnect" ".*"
56 # Set sysroot to something non-target and possibly also invalid so that
57 # GDB is unable to open the symbol file.
58 gdb_test_no_output "set sysroot $sysroot" "adjust sysroot"
61 set res [gdbserver_start "" $target_exec]
63 set gdbserver_protocol [lindex $res 0]
64 set gdbserver_gdbport [lindex $res 1]
66 # Perform test actions to the symbol file on the target.
67 if {$action == "delete"} {
68 remote_file target delete $target_exec
69 } elseif { $action == "permission" } {
70 remote_exec target "chmod 000 $target_exec"
73 # Connect to GDBserver.
74 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
77 # Check if GDB succeeded connecting to GDBserver by attempting to detach
79 # Use an explicit fail clause to prevent the implicit clause matching
80 # "Ending remote debugging" from triggering, which would cause silent
83 gdb_test_multiple "detach" "" {
84 -re "\r\nDetaching from \[^\r\n\]*" {
91 gdb_assert $ok "connection to GDBserver succeeded"
93 # GDB will register /proc/PID/exe as the executable for some of
94 # these tests. Once the test has finished the inferior will still
95 # have /proc/PID/exe registered as its executable even though that
96 # file no longer exists (most likely). GDB will then complain
97 # about the inferior's executable having disappeared. Silence
98 # these warnings by removing any registered file from the
100 gdb_test "with confirm off -- file" \
102 "No executable file now\\." \
103 "No symbol file now\\."]
106 # Make sure we have the original symbol file in a safe place to copy from.
107 gdb_remote_download build $binfile $binfile.bak
109 # Start with no executable loaded.
112 # Run the test with different permutations.
113 foreach_with_prefix sysroot {"" "target:"} {
114 foreach_with_prefix action {"permission" "delete"} {
115 connect_no_symbol_file $sysroot $action