xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.threads/fork-thread-pending.exp (revision 4f645668ed707e1f969c546666f8c8e45e6f8888)
1# Copyright (C) 2009-2019 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# Only GNU/Linux is known to support `set follow-fork-mode child'.
17#
18if { ! [istarget "*-*-linux*"] } {
19    return 0
20}
21
22standard_testfile
23
24if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
25    return -1
26}
27
28clean_restart ${binfile}
29
30if ![runto_main] then {
31   fail "can't run to main"
32   return 0
33}
34
35gdb_test_no_output "set follow-fork-mode child" "1, set follow-fork-mode child"
36gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "1, insert fork catchpoint"
37gdb_breakpoint "start" "" "1, set breakpoint at start"
38
39gdb_test "continue" "Catchpoint.*" "1, get to the fork event"
40
41gdb_test "info threads" " Thread .* Thread .* Thread .* Thread .*" "1, multiple threads found"
42
43gdb_test "thread 1" ".*" "1, switched away from event thread"
44
45gdb_test "continue" "Not resuming.*" "1, refused to resume"
46
47set test "1, followed to the child, found one thread"
48gdb_test_multiple "info threads" "metest" {
49    -re " Thread .* Thread .*$gdb_prompt $" {
50	fail "$test"
51    }
52    -re " Thread .*$gdb_prompt $" {
53	pass "$test"
54    }
55    -re "$gdb_prompt $" {
56	fail "$test (unknown output)"
57    }
58    timeout {
59	fail "$test (timeout)"
60    }
61}
62
63gdb_test "continue" "Breakpoint 3, start.*" "1, get to the spawned thread in fork child"
64
65set test "1, followed to the child, found two threads"
66gdb_test_multiple "info threads" "$test" {
67    -re " Thread .* Thread .* Thread .*$gdb_prompt $" {
68	fail "$test"
69    }
70    -re " Thread .* Thread .*$gdb_prompt $" {
71	pass "$test"
72    }
73    -re "$gdb_prompt $" {
74	fail "$test (unknown output)"
75    }
76    timeout {
77	fail "$test (timeout)"
78    }
79}
80
81# Start over, but this time, don't switch away from the fork event thread.
82
83gdb_exit
84gdb_start
85gdb_reinitialize_dir $srcdir/$subdir
86
87gdb_load ${binfile}
88if ![runto_main] then {
89   fail "can't run to main"
90   return 0
91}
92
93gdb_test_no_output "set follow-fork-mode child" "2, set follow-fork-mode child"
94gdb_test "catch fork" "Catchpoint \[0-9\]* \\(fork\\)" "2, insert fork catchpoint"
95gdb_breakpoint "start"
96
97gdb_test "continue" "Catchpoint.*" "2, get to the fork event"
98
99gdb_test "info threads" " Thread .* Thread .* Thread .* Thread .*" "2, multiple threads found"
100
101gdb_test "continue" "Breakpoint 3, start.*" "2, get to the spawned thread in fork child"
102
103set test "2, followed to the child, found two threads"
104gdb_test_multiple "info threads" "$test" {
105    -re " Thread .* Thread .* Thread .*$gdb_prompt $" {
106	fail "$test"
107    }
108    -re " Thread .* Thread .*$gdb_prompt $" {
109	pass "$test"
110    }
111    -re "$gdb_prompt $" {
112	fail "$test (unknown output)"
113    }
114    timeout {
115	fail "$test (timeout)"
116    }
117}
118