]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.server/connect-with-no-symbol-file.exp
efddccd2a19b50b1c16fed93b4261b14cf22f899
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.server / connect-with-no-symbol-file.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2016-2023 Free Software Foundation, Inc.
4
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.
9 #
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.
14 #
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/>.
17
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.
21 #
22 # This test is only meaningful for standard remote connections.
23
24 load_lib gdbserver-support.exp
25
26 standard_testfile
27
28 require allow_gdbserver_tests
29
30 if { [build_executable "failed to prepare" $testfile $srcfile debug] } {
31 return -1
32 }
33
34 # Test connecting GDB to GDBserver without loading a symbol file.
35 #
36 # SYSROOT is the desired sysroot string
37 #
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"
40 # to remove the file.
41 #
42 proc connect_no_symbol_file { sysroot action } {
43 global binfile
44
45 with_test_prefix "setup" {
46 # Restore original $binfile.
47 gdb_remote_download build $binfile.bak $binfile
48
49 # Copy the symbol file to the target.
50 set target_exec [gdb_remote_download target $binfile]
51
52 # Make sure we're disconnected, in case we're testing with an
53 # extended-remote board, therefore already connected.
54 gdb_test "disconnect" ".*"
55
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"
59
60 # Start GDBserver.
61 set res [gdbserver_start "" $target_exec]
62
63 set gdbserver_protocol [lindex $res 0]
64 set gdbserver_gdbport [lindex $res 1]
65
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"
71 }
72
73 # Connect to GDBserver.
74 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
75 }
76
77 # Check if GDB succeeded connecting to GDBserver by attempting to detach
78 # from the process.
79 # Use an explicit fail clause to prevent the implicit clause matching
80 # "Ending remote debugging" from triggering, which would cause silent
81 # failure.
82 set ok 0
83 gdb_test_multiple "detach" "" {
84 -re "\r\nDetaching from \[^\r\n\]*" {
85 set ok 1
86 exp_continue
87 }
88 -re -wrap "" {
89 }
90 }
91 gdb_assert $ok "connection to GDBserver succeeded"
92 }
93
94 # Make sure we have the original symbol file in a safe place to copy from.
95 gdb_remote_download build $binfile $binfile.bak
96
97 # Start with no executable loaded.
98 clean_restart
99
100 # Run the test with different permutations.
101 foreach_with_prefix sysroot {"" "target:"} {
102 foreach_with_prefix action {"permission" "delete"} {
103 connect_no_symbol_file $sysroot $action
104 }
105 }