Commit | Line | Data |
---|---|---|
4dd63d48 PA |
1 | # Copyright (C) 2015 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 | # 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 | ||
23 | standard_testfile | |
24 | ||
25 | proc do_test { detach_on_fork } { | |
26 | global GDBFLAGS | |
27 | global srcfile testfile | |
28 | global gdb_prompt | |
29 | ||
30 | set saved_gdbflags $GDBFLAGS | |
31 | set GDBFLAGS [concat $GDBFLAGS " -ex \"set non-stop on\""] | |
32 | ||
33 | if {[prepare_for_testing "failed to prepare" \ | |
34 | $testfile $srcfile {debug pthreads}] == -1} { | |
35 | set GDBFLAGS $saved_gdbflags | |
36 | return -1 | |
37 | } | |
38 | ||
39 | set GDBFLAGS $saved_gdbflags | |
40 | ||
41 | if ![runto_main] then { | |
42 | fail "Can't run to main" | |
43 | return 0 | |
44 | } | |
45 | ||
46 | gdb_test_no_output "set detach-on-fork $detach_on_fork" | |
47 | set test "continue &" | |
48 | gdb_test_multiple $test $test { | |
49 | -re "$gdb_prompt " { | |
50 | pass $test | |
51 | } | |
52 | } | |
53 | ||
998d452a PA |
54 | # gdbserver had a bug that resulted in reporting the fork child's |
55 | # initial stop to gdb, which gdb does not expect, in turn | |
56 | # resulting in a broken session, like: | |
57 | # | |
58 | # [Thread 31536.31536] #16 stopped. <== BAD | |
59 | # [New Thread 31547.31547] | |
60 | # [Inferior 10 (process 31536) exited normally] | |
61 | # [New Thread 31547.31560] | |
62 | # | |
63 | # [Thread 31547.31547] #18 stopped. <== BAD | |
64 | # Cannot remove breakpoints because program is no longer writable. <== BAD | |
65 | # Further execution is probably impossible. <== BAD | |
66 | # [Inferior 11 (process 31547) exited normally] | |
67 | # [Inferior 1 (process 31454) exited normally] | |
68 | # | |
69 | # These variables track whether we see such broken behavior. | |
70 | set saw_cannot_remove_breakpoints 0 | |
71 | set saw_thread_stopped 0 | |
72 | ||
4dd63d48 PA |
73 | set test "inferior 1 exited" |
74 | gdb_test_multiple "" $test { | |
998d452a PA |
75 | -re "Cannot remove breakpoints" { |
76 | set saw_cannot_remove_breakpoints 1 | |
77 | exp_continue | |
78 | } | |
79 | -re "Thread \[^\r\n\]+ stopped\\." { | |
80 | set saw_thread_stopped 1 | |
81 | exp_continue | |
82 | } | |
4dd63d48 PA |
83 | -re "Inferior 1 \(\[^\r\n\]+\) exited normally" { |
84 | pass $test | |
85 | } | |
86 | } | |
87 | ||
998d452a PA |
88 | gdb_assert !$saw_cannot_remove_breakpoints \ |
89 | "no failure to remove breakpoints" | |
90 | gdb_assert !$saw_thread_stopped \ | |
91 | "no spurious thread stop" | |
92 | ||
4dd63d48 PA |
93 | gdb_test "info threads" "No threads\." \ |
94 | "no threads left" | |
69dde7dc PA |
95 | |
96 | gdb_test "info inferiors" \ | |
97 | "Num\[ \t\]+Description\[ \t\]+Executable\[ \t\]+\r\n\\* 1 \[^\r\n\]+" \ | |
98 | "only inferior 1 left" | |
4dd63d48 PA |
99 | } |
100 | ||
101 | foreach detach_on_fork {"on" "off"} { | |
102 | with_test_prefix "detach-on-fork=$detach_on_fork" { | |
103 | do_test $detach_on_fork | |
104 | } | |
105 | } |