]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.server/ext-attach.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.server / ext-attach.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2007-2024 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 attaching to already-running programs using extended-remote.
19
20 load_lib gdbserver-support.exp
21 load_lib trace-support.exp
22
23 standard_testfile
24
25 require allow_gdbserver_tests
26
27 require can_spawn_for_attach
28
29 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
30 return -1
31 }
32
33 # Run the test. TARGET_NON_STOP and TARGET_ASYNC should be 'on'
34 # or 'off'. TO_DISABLE should be either the empty string, or
35 # something that can be passed to gdbserver's --disable-packet command
36 # line option.
37 proc run_test { target_async target_non_stop to_disable } {
38 save_vars { ::GDBFLAGS } {
39 append ::GDBFLAGS " -ex \"maint set target-non-stop $target_non_stop\""
40 append ::GDBFLAGS " -ex \"maintenance set target-async ${target_async}\""
41
42 # If GDB and GDBserver are both running locally, set the sysroot to avoid
43 # reading files via the remote protocol.
44 if { ![is_remote host] && ![is_remote target] } {
45 set ::GDBFLAGS "$::GDBFLAGS -ex \"set sysroot\""
46 }
47
48 clean_restart $::binfile
49 }
50
51 # Make sure we're disconnected, in case we're testing with an
52 # extended-remote board, therefore already connected.
53 gdb_test "disconnect" ".*"
54
55 if {[gdb_target_supports_trace]} {
56 # Test predefined TSVs are uploaded.
57 gdb_test_sequence "info tvariables" "check uploaded tsv" {
58 "\[\r\n\]+Name\[\t \]+Initial\[\t \]+Current"
59 "\[\r\n\]+\\\$trace_timestamp 0"
60 }
61 }
62
63 set target_exec [gdbserver_download_current_prog]
64 if { $to_disable != "" } {
65 set gdbserver_opts "--disable-packet=${to_disable}"
66 } else {
67 set gdbserver_opts ""
68 }
69 gdbserver_start_extended $gdbserver_opts
70
71 gdb_test_no_output "set remote exec-file $target_exec" "set remote exec-file"
72
73 set test_spawn_id [spawn_wait_for_attach $::binfile]
74 set testpid [spawn_id_get_pid $test_spawn_id]
75
76 gdb_test "attach $testpid" \
77 "Attaching to program: .*, process $testpid.*(in|at).*" \
78 "attach to remote program 1"
79
80 gdb_test "backtrace" ".*main.*" "backtrace 1"
81
82 gdb_test "detach" "Detaching from program.*process.*"
83 gdb_test "backtrace" "No stack\\." "backtrace with no program"
84
85 gdb_test "attach $testpid" \
86 "Attaching to program: .*, process $testpid.*(in|at).*" \
87 "attach to remote program 2"
88 gdb_test "backtrace" ".*main.*" "backtrace 2"
89
90 gdb_test "kill" "" "kill" "Kill the program being debugged. .y or n. " "y"
91 gdb_test_no_output "monitor exit"
92
93 kill_wait_spawned_process $test_spawn_id
94 }
95
96 foreach_with_prefix target_async {"on" "off" } {
97 foreach_with_prefix target_non_stop {"off" "on"} {
98 foreach_with_prefix to_disable { "" Tthread T } {
99 run_test ${target_async} ${target_non_stop} $to_disable
100 }
101 }
102 }