Commit | Line | Data |
---|---|---|
2d717e4f DJ |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
88b9d363 | 3 | # Copyright 2007-2022 Free Software Foundation, Inc. |
2d717e4f DJ |
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 | |
a0743c90 | 21 | load_lib trace-support.exp |
2d717e4f | 22 | |
b0963d73 | 23 | standard_testfile |
2d717e4f DJ |
24 | |
25 | if { [skip_gdbserver_tests] } { | |
26 | return 0 | |
27 | } | |
28 | ||
60b3033e | 29 | if {![can_spawn_for_attach]} { |
2d717e4f DJ |
30 | return 0 |
31 | } | |
32 | ||
6eccc2c8 AB |
33 | if {[build_executable "failed to prepare" $testfile $srcfile debug]} { |
34 | return -1 | |
35 | } | |
8dc558a0 | 36 | |
6eccc2c8 AB |
37 | # Run the test. TARGET_NON_STOP and TARGET_ASYNC should be 'on' |
38 | # or 'off'. TO_DISABLE should be either the empty string, or | |
39 | # something that can be passed to gdbserver's --disable-packet command | |
40 | # line option. | |
41 | proc run_test { target_async target_non_stop to_disable } { | |
42 | save_vars { ::GDBFLAGS } { | |
43 | append ::GDBFLAGS " -ex \"maint set target-non-stop $target_non_stop\"" | |
44 | append ::GDBFLAGS " -ex \"maintenance set target-async ${target_async}\"" | |
45 | ||
46 | # If GDB and GDBserver are both running locally, set the sysroot to avoid | |
47 | # reading files via the remote protocol. | |
48 | if { ![is_remote host] && ![is_remote target] } { | |
49 | set ::GDBFLAGS "$::GDBFLAGS -ex \"set sysroot\"" | |
50 | } | |
51 | ||
52 | clean_restart $::binfile | |
8dc558a0 | 53 | } |
2d717e4f | 54 | |
6eccc2c8 AB |
55 | # Make sure we're disconnected, in case we're testing with an |
56 | # extended-remote board, therefore already connected. | |
57 | gdb_test "disconnect" ".*" | |
a1999d40 | 58 | |
6eccc2c8 AB |
59 | if { [gdb_target_supports_trace] } then { |
60 | # Test predefined TSVs are uploaded. | |
61 | gdb_test_sequence "info tvariables" "check uploaded tsv" { | |
62 | "\[\r\n\]+Name\[\t \]+Initial\[\t \]+Current" | |
63 | "\[\r\n\]+\\\$trace_timestamp 0" | |
64 | } | |
65 | } | |
2d717e4f | 66 | |
6eccc2c8 AB |
67 | set target_exec [gdbserver_download_current_prog] |
68 | if { $to_disable != "" } { | |
69 | set gdbserver_opts "--disable-packet=${to_disable}" | |
70 | } else { | |
71 | set gdbserver_opts "" | |
72 | } | |
73 | gdbserver_start_extended $gdbserver_opts | |
2d717e4f | 74 | |
6eccc2c8 | 75 | gdb_test_no_output "set remote exec-file $target_exec" "set remote exec-file" |
2d717e4f | 76 | |
6eccc2c8 AB |
77 | set test_spawn_id [spawn_wait_for_attach $::binfile] |
78 | set testpid [spawn_id_get_pid $test_spawn_id] | |
a0743c90 | 79 | |
6eccc2c8 AB |
80 | gdb_test "attach $testpid" \ |
81 | "Attaching to program: .*, process $testpid.*(in|at).*" \ | |
82 | "attach to remote program 1" | |
83 | ||
84 | gdb_test "backtrace" ".*main.*" "backtrace 1" | |
a0743c90 | 85 | |
6eccc2c8 AB |
86 | gdb_test "detach" "Detaching from program.*process.*" |
87 | gdb_test "backtrace" "No stack\\." "backtrace with no program" | |
2d717e4f | 88 | |
6eccc2c8 AB |
89 | gdb_test "attach $testpid" \ |
90 | "Attaching to program: .*, process $testpid.*(in|at).*" \ | |
91 | "attach to remote program 2" | |
92 | gdb_test "backtrace" ".*main.*" "backtrace 2" | |
2d717e4f | 93 | |
6eccc2c8 AB |
94 | gdb_test "kill" "" "kill" "Kill the program being debugged. .y or n. " "y" |
95 | gdb_test_no_output "monitor exit" | |
2d717e4f | 96 | |
6eccc2c8 AB |
97 | kill_wait_spawned_process $test_spawn_id |
98 | } | |
2c8c5d37 | 99 | |
6eccc2c8 AB |
100 | # Don't run with target_async set to "off". There are bugs with the |
101 | # extended-remote target when async mode is off and we try to attach. | |
102 | # These bugs have been fixed in the master branch. | |
103 | foreach_with_prefix target_async {"on"} { | |
104 | foreach_with_prefix target_non_stop {"off" "on"} { | |
105 | foreach_with_prefix to_disable { "" Tthread T } { | |
106 | run_test ${target_async} ${target_non_stop} $to_disable | |
107 | } | |
108 | } | |
109 | } |