Add "info connections" command, "info inferiors" connection number/string
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / fork-plus-threads.exp
CommitLineData
b811d2c2 1# Copyright (C) 2015-2020 Free Software Foundation, Inc.
4dd63d48
PA
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# This test verifies that threads created by the child fork are
17# properly handled. Specifically, GDB used to have a bug where it
18# would leave child fork threads stuck stopped, even though "info
19# threads" would show them running.
20#
21# See https://sourceware.org/bugzilla/show_bug.cgi?id=18600
22
a8f077dc
DB
23# In remote mode, we cannot continue debugging after all
24# inferiors have terminated, and this test requires that.
25if { [target_info exists gdb_protocol]
26 && [target_info gdb_protocol] == "remote" } {
27 continue
28}
29
4dd63d48
PA
30standard_testfile
31
32proc do_test { detach_on_fork } {
33 global GDBFLAGS
34 global srcfile testfile
35 global gdb_prompt
36
37 set saved_gdbflags $GDBFLAGS
38 set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""]
39
40 if {[prepare_for_testing "failed to prepare" \
41 $testfile $srcfile {debug pthreads}] == -1} {
42 set GDBFLAGS $saved_gdbflags
43 return -1
44 }
45
46 set GDBFLAGS $saved_gdbflags
47
48 if ![runto_main] then {
bc6c7af4 49 fail "can't run to main"
4dd63d48
PA
50 return 0
51 }
52
53 gdb_test_no_output "set detach-on-fork $detach_on_fork"
54 set test "continue &"
55 gdb_test_multiple $test $test {
56 -re "$gdb_prompt " {
57 pass $test
58 }
59 }
60
998d452a
PA
61 # gdbserver had a bug that resulted in reporting the fork child's
62 # initial stop to gdb, which gdb does not expect, in turn
63 # resulting in a broken session, like:
64 #
65 # [Thread 31536.31536] #16 stopped. <== BAD
66 # [New Thread 31547.31547]
67 # [Inferior 10 (process 31536) exited normally]
68 # [New Thread 31547.31560]
69 #
70 # [Thread 31547.31547] #18 stopped. <== BAD
71 # Cannot remove breakpoints because program is no longer writable. <== BAD
72 # Further execution is probably impossible. <== BAD
73 # [Inferior 11 (process 31547) exited normally]
74 # [Inferior 1 (process 31454) exited normally]
75 #
76 # These variables track whether we see such broken behavior.
77 set saw_cannot_remove_breakpoints 0
78 set saw_thread_stopped 0
79
4dd63d48
PA
80 set test "inferior 1 exited"
81 gdb_test_multiple "" $test {
998d452a
PA
82 -re "Cannot remove breakpoints" {
83 set saw_cannot_remove_breakpoints 1
84 exp_continue
85 }
86 -re "Thread \[^\r\n\]+ stopped\\." {
87 set saw_thread_stopped 1
88 exp_continue
89 }
59bd512b
TV
90 -re "Thread \[^\r\n\]+ exited" {
91 # Avoid timeout with check-read1
92 exp_continue
93 }
94 -re "New Thread \[^\r\n\]+" {
95 # Avoid timeout with check-read1
96 exp_continue
97 }
4dd63d48
PA
98 -re "Inferior 1 \(\[^\r\n\]+\) exited normally" {
99 pass $test
100 }
101 }
102
998d452a
PA
103 gdb_assert !$saw_cannot_remove_breakpoints \
104 "no failure to remove breakpoints"
105 gdb_assert !$saw_thread_stopped \
106 "no spurious thread stop"
107
4dd63d48
PA
108 gdb_test "info threads" "No threads\." \
109 "no threads left"
69dde7dc
PA
110
111 gdb_test "info inferiors" \
121b3efd 112 "Num\[ \t\]+Description\[ \t\]+Connection\[ \t\]+Executable\[ \t\]+\r\n\\* 1 \[^\r\n\]+" \
69dde7dc 113 "only inferior 1 left"
4dd63d48
PA
114}
115
116foreach detach_on_fork {"on" "off"} {
117 with_test_prefix "detach-on-fork=$detach_on_fork" {
118 do_test $detach_on_fork
119 }
120}
This page took 0.521052 seconds and 4 git commands to generate.