Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.server / connect-with-no-symbol-file.exp
CommitLineData
7d49b1d0
LM
1# This testcase is part of GDB, the GNU debugger.
2
88b9d363 3# Copyright 2016-2022 Free Software Foundation, Inc.
7d49b1d0
LM
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
24load_lib gdbserver-support.exp
25
26standard_testfile
27
28if { [skip_gdbserver_tests] } {
29 return 0
30}
31
5b362f04 32if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } {
7d49b1d0
LM
33 return -1
34}
35
36# Test connecting GDB to GDBserver without loading a symbol file.
37#
38# SYSROOT is the desired sysroot string
39#
40# ACTION is the action to perform to the symbol file on the target.
41# It can be either "permission" to deny access to the file or "delete"
42# to remove the file.
43#
44proc connect_no_symbol_file { sysroot action } {
45 global binfile
46
47 with_test_prefix "setup" {
48 # Copy the symbol file to the target.
49 gdb_remote_download target $binfile.bak $binfile
50
51 # Make sure we're disconnected, in case we're testing with an
52 # extended-remote board, therefore already connected.
d1e36019 53 gdb_test "disconnect" ".*"
7d49b1d0
LM
54
55 # Discard any symbol files that we have opened.
56 gdb_test "file" ".*" "discard symbol table" \
57 {Discard symbol table from `.*'\? \(y or n\) } "y"
58
59 # Set sysroot to something non-target and possibly also invalid so that
60 # GDB is unable to open the symbol file.
61 gdb_test_no_output "set sysroot $sysroot" "adjust sysroot"
62
63 set target_exec [gdbserver_download_current_prog]
64
65 # Start GDBserver.
66 set res [gdbserver_start "" $target_exec]
67
68 set gdbserver_protocol [lindex $res 0]
69 set gdbserver_gdbport [lindex $res 1]
70
71 # Perform test actions to the symbol file on the target.
72 if { $action == "delete" } then {
73 remote_file target delete $binfile
74 } elseif { $action == "permission" } {
75 remote_spawn target "chmod 000 $binfile"
76 }
77
78 # Connect to GDBserver.
79 gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport
80 }
81
82 # Check if GDB succeeded connecting to GDBserver by attempting to detach
83 # from the process.
84 gdb_test "detach" \
85 ".*Detaching from program: , process.*Ending remote debugging.*" \
86 "connection to GDBserver succeeded"
87}
88
89# Make sure we have the original symbol file in a safe place to copy from.
90gdb_remote_download host $binfile $binfile.bak
91
92# Run the test with different permutations.
93foreach_with_prefix sysroot {"" "target:"} {
94 foreach_with_prefix action {"permission" "delete"} {
95 connect_no_symbol_file $sysroot $action
96 }
97}
This page took 0.70837 seconds and 4 git commands to generate.