775e83de40dd26ac8535ba4f059fea4cf3aa947e
[external/binutils.git] / gdb / testsuite / gdb.server / connect-stopped-target.exp
1 # Copyright 2010-2017 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
15
16 # Check that when GDB connects to a stopped target in either non-stop
17 # or all-stop modes, "target remote" does not return with the remote
18 # thread marked running.
19
20 load_lib gdbserver-support.exp
21 load_lib prelink-support.exp
22
23 if {[skip_gdbserver_tests]} {
24     return
25 }
26
27 standard_testfile
28 set executable ${testfile}
29
30 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
31     return -1
32 }
33
34 proc do_test {nonstop} {
35     global binfile
36     global gdb_prompt
37     global hex
38
39     clean_restart $binfile
40
41     # Make sure we're disconnected, in case we're testing with an
42     # extended-remote board, therefore already connected.
43     gdb_test "disconnect" ".*"
44
45     gdb_test "set non-stop $nonstop"
46
47     set res [gdbserver_spawn ""]
48     set gdbserver_protocol [lindex $res 0]
49     set gdbserver_gdbport [lindex $res 1]
50
51     gdb_test_multiple "define connect" "define user command: connect" {
52         -re "Type commands for definition of \"connect\".\r\nEnd with a line saying just \"end\".\r\n>$" {
53             gdb_test [join [list \
54                                 "target $gdbserver_protocol $gdbserver_gdbport" \
55                                 "info threads" \
56                                 "p /x \$pc" \
57                                 "end" \
58                                ] "\n"] \
59                 "" \
60                 "define user command: connect"
61         }
62     }
63
64     # In non-stop mode, "target remote" used to return before the
65     # already-stopped thread was marked stopped.  Because of that, a
66     # script (or fast user) could see the target as running right
67     # after connection:
68     #
69     # (gdb) connect
70     #   Id   Target Id         Frame
71     # * 1    Thread 31179      (running)
72     # Target is executing.
73     # (gdb)
74     gdb_test "connect" " = $hex" "connect and print pc"
75     gdb_test "print /x \$pc" " = $hex" "print pc again"
76 }
77
78 foreach nonstop { "off" "on" } {
79     with_test_prefix "non-stop=$nonstop" {
80         do_test $nonstop
81     }
82 }