1 # Copyright (C) 2009-2017 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Only GNU/Linux is known to support `set follow-fork-mode child'.
18 if { ! [istarget "*-*-linux*"] } {
24 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
28 clean_restart ${binfile}
30 if ![runto_main] then {
31 fail "can't run to main"
35 gdb_test_no_output "set follow-fork-mode child" "1, set follow-fork-mode child"
36 gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "1, insert fork catchpoint"
37 gdb_breakpoint "start" "" "1, set breakpoint at start"
39 gdb_test "continue" "Catchpoint.*" "1, get to the fork event"
41 gdb_test "info threads" " Thread .* Thread .* Thread .* Thread .*" "1, multiple threads found"
43 gdb_test "thread 1" ".*" "1, switched away from event thread"
45 gdb_test "continue" "Not resuming.*" "1, refused to resume"
47 set test "1, followed to the child, found one thread"
48 gdb_test_multiple "info threads" "metest" {
49 -re " Thread .* Thread .*$gdb_prompt $" {
52 -re " Thread .*$gdb_prompt $" {
56 fail "$test (unknown output)"
59 fail "$test (timeout)"
63 gdb_test "continue" "Breakpoint 3, start.*" "1, get to the spawned thread in fork child"
65 set test "1, followed to the child, found two threads"
66 gdb_test_multiple "info threads" "$test" {
67 -re " Thread .* Thread .* Thread .*$gdb_prompt $" {
70 -re " Thread .* Thread .*$gdb_prompt $" {
74 fail "$test (unknown output)"
77 fail "$test (timeout)"
81 # Start over, but this time, don't switch away from the fork event thread.
85 gdb_reinitialize_dir $srcdir/$subdir
88 if ![runto_main] then {
89 fail "can't run to main"
93 gdb_test_no_output "set follow-fork-mode child" "2, set follow-fork-mode child"
94 gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "2, insert fork catchpoint"
95 gdb_breakpoint "start"
97 gdb_test "continue" "Catchpoint.*" "2, get to the fork event"
99 gdb_test "info threads" " Thread .* Thread .* Thread .* Thread .*" "2, multiple threads found"
101 gdb_test "continue" "Breakpoint 3, start.*" "2, get to the spawned thread in fork child"
103 set test "2, followed to the child, found two threads"
104 gdb_test_multiple "info threads" "$test" {
105 -re " Thread .* Thread .* Thread .*$gdb_prompt $" {
108 -re " Thread .* Thread .*$gdb_prompt $" {
111 -re "$gdb_prompt $" {
112 fail "$test (unknown output)"
115 fail "$test (timeout)"