1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2007-2015 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 attaching to already-running programs using extended-remote.
20 load_lib gdbserver-support.exp
21 load_lib trace-support.exp
25 if { [skip_gdbserver_tests] } {
29 # We need to use TCL's exec to get the pid.
30 if [is_remote target] then {
34 if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} {
38 # Make sure we're disconnected, in case we're testing with an
39 # extended-remote board, therefore already connected.
40 gdb_test "disconnect" ".*"
42 set target_exec [gdbserver_download_current_prog]
43 gdbserver_start_extended
45 gdb_test_no_output "set remote exec-file $target_exec" "set remote exec-file"
47 set testpid [spawn_wait_for_attach $binfile]
49 gdb_test "attach $testpid" \
50 "Attaching to program: .*, process $testpid.*(in|at).*" \
51 "attach to remote program 1"
53 if { [gdb_target_supports_trace] } then {
54 # Test predefined TSVs are uploaded.
55 gdb_test_sequence "info tvariables" "check uploaded tsv" {
56 "\[\r\n\]+Name\[\t \]+Initial\[\t \]+Current"
57 "\[\r\n\]+\\\$trace_timestamp 0"
61 gdb_test "backtrace" ".*main.*" "backtrace 1"
63 gdb_test "detach" "Detaching from program.*process.*"
64 gdb_test "backtrace" "No stack\\." "backtrace with no program"
66 gdb_test "attach $testpid" \
67 "Attaching to program: .*, process $testpid.*(in|at).*" \
68 "attach to remote program 2"
69 gdb_test "backtrace" ".*main.*" "backtrace 2"
71 gdb_test "kill" "" "kill" "Kill the program being debugged.*" "y"
72 gdb_test_no_output "monitor exit"