Fix PR threads/19422 - show which thread caused stop
[binutils-gdb.git] / gdb / testsuite / gdb.threads / non-ldr-exc-2.exp
1 # Copyright 2009-2016 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 # Test that when a thread other than the main thread execs, we follow
17 # through to the new incarnation of the main thread, even if the main
18 # thread had already exited before the exec.
19
20 # No exec event support in the remote protocol.
21 if { [is_remote target] } then {
22 continue
23 }
24
25 standard_testfile
26 set executable ${testfile}
27
28 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
29 return -1
30 }
31
32 proc do_test { lock_sched nonstop } {
33 with_test_prefix "lock-sched=$lock_sched,non-stop=$nonstop" {
34 global executable
35
36 save_vars { GDBFLAGS } {
37 append GDBFLAGS " -ex \"set non-stop $nonstop\""
38 clean_restart ${executable}
39 }
40
41 if ![runto_main] {
42 return -1
43 }
44
45 gdb_breakpoint [gdb_get_line_number "break-here"]
46 gdb_continue_to_breakpoint "break-here" ".* break-here .*"
47
48 if { $nonstop == "on" } {
49 gdb_test "thread 2" "Switching.*"
50 }
51
52 gdb_test "info threads" \
53 "\r\n\[ \t\]*Id\[ \t\]+Target\[ \t\]+Id\[ \t\]+Frame\[ \t\]*\r\n\\* 2 *Thread \[^\r\n\]* at \[^\r\n\]*" \
54 "single thread left"
55
56 # Also test with sched-lock to make sure we can follow the
57 # non-leader thread execing even though the main thread wasn't
58 # resumed before the exec.
59 if { $lock_sched } {
60 gdb_test_no_output "set scheduler-locking on"
61 }
62
63 gdb_test "continue" \
64 ".*is executing new program.*Breakpoint 1, main.* at .*" \
65 "continue over exec"
66 }
67 }
68
69 foreach nonstop {"on" "off"} {
70 foreach schedlock {"on" "off"} {
71 if {$schedlock == "on" && $nonstop == "on"} {
72 # Schedule locking has no effect in nonstop mode.
73 continue
74 }
75 do_test $schedlock $nonstop
76 }
77 }