aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.threads/print-threads.exp
blob: 1cbec5f086459c277cbd478ccb636f2dea1b931e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright (C) 1996-2016 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file was written by Daniel Jacobowitz <drow@mvista.com>
# (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com).
#
# It tests miscellaneous actions with multiple threads, including
# handling for thread exit.


standard_testfile

# regexp for "horizontal" text (i.e. doesn't include newline or
# carriage return)
set horiz "\[^\n\r\]*"

if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } {
    return -1
}

# Now we can proceed with the real testing.

clean_restart ${binfile}

gdb_test_no_output "set print sevenbit-strings"
#gdb_test_no_output "set print address off"
gdb_test_no_output "set width 0"

# We'll need this when we send_gdb a ^C to GDB.  Need to do it before we
# run the program and gdb starts saving and restoring tty states.
gdb_test "shell stty intr '^C'" ".*"

proc test_all_threads { name kill } {
    global gdb_prompt inferior_exited_re

    set i 0
    set j 0
    gdb_test_multiple "continue" "all threads ran once" {
	-re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" {
	    set i [expr $i + 1]
	    pass "Hit thread_function breakpoint, $i ($name)"
	    send_gdb "continue\n"
	    exp_continue
	}
	-re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" {
	    set j [expr $j + 1]
	    if { $kill == 1 } {
		pass "Hit kill breakpoint, $j ($name)"
	    } else {
		fail "Hit kill breakpoint, $j ($name) (unexpected)"
	    }
	    send_gdb "continue\n"
	    exp_continue
	}
	-re "$inferior_exited_re normally.\[\r\n\]+$gdb_prompt" {
	    pass "program exited normally"
	    if {$i == 5} {
		pass "all threads ran once ($name)"
	    } else {
		fail "all threads ran once ($name) (total $i threads ran)"
	    }
	}
	-re " received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" {
	    if { $kill == 1 } {
		kfail "gdb/1265" "Running threads ($name) (zombie thread)"
	    } else {
		fail "Running threads ($name) (unknown output)"
	    }
	}
    }
}

# Record the old timeout, we need to extend it for slower tests.
set oldtimeout $timeout

runto_main
gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\."
gdb_test_no_output "set var slow = 0"
test_all_threads "fast" 0

runto_main
gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)"
gdb_test_no_output "set var slow = 1"
# Extend the timeout for slower tests.
set timeout [expr $oldtimeout + 120]
test_all_threads "slow" 0
set timeout $oldtimeout

runto_main
gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)"
gdb_test_no_output "set var slow = 1" "set var slow = 1 (2)"
gdb_breakpoint "kill"
# Extend the timeout for slower tests.
set timeout [expr $oldtimeout + 120]
test_all_threads "slow with kill breakpoint" 1
set timeout $oldtimeout

return 0