Commit | Line | Data |
---|---|---|
9b254dd1 DJ |
1 | # Copyright (C) 1996, 1997, 2002, 2003, 2007, 2008 |
2 | # Free Software Foundation, Inc. | |
0312286c DJ |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
0312286c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
0312286c DJ |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
e22f8b7c | 13 | # |
0312286c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0312286c DJ |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Daniel Jacobowitz <drow@mvista.com> | |
21 | # (parts based on pthreads.exp by Fred Fish (fnf@cygnus.com). | |
22 | # | |
23 | # It tests miscellaneous actions with multiple threads, including | |
24 | # handling for thread exit. | |
25 | ||
26 | if $tracelevel then { | |
27 | strace $tracelevel | |
28 | } | |
29 | ||
30 | set prms_id 0 | |
31 | set bug_id 0 | |
32 | ||
33 | set testfile "print-threads" | |
34 | set srcfile ${testfile}.c | |
35 | set binfile ${objdir}/${subdir}/${testfile} | |
36 | ||
37 | # regexp for "horizontal" text (i.e. doesn't include newline or | |
38 | # carriage return) | |
39 | set horiz "\[^\n\r\]*" | |
40 | ||
b5ab8ff3 | 41 | if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } { |
0312286c DJ |
42 | return -1 |
43 | } | |
44 | ||
45 | # Now we can proceed with the real testing. | |
46 | ||
47 | # Start with a fresh gdb. | |
48 | ||
49 | gdb_exit | |
50 | gdb_start | |
51 | gdb_reinitialize_dir $srcdir/$subdir | |
52 | gdb_load ${binfile} | |
53 | ||
54 | gdb_test "set print sevenbit-strings" "" | |
55 | #gdb_test "set print address off" "" | |
56 | gdb_test "set width 0" "" | |
57 | ||
58 | # We'll need this when we send_gdb a ^C to GDB. Need to do it before we | |
59 | # run the program and gdb starts saving and restoring tty states. | |
60 | # On Ultrix, we don't need it and it is really slow (because shell_escape | |
61 | # doesn't use vfork). | |
62 | if ![istarget "*-*-ultrix*"] then { | |
63 | gdb_test "shell stty intr '^C'" "" | |
64 | } | |
65 | ||
66 | proc test_all_threads { name kill } { | |
67 | global gdb_prompt | |
68 | ||
69 | set i 0 | |
70 | set j 0 | |
71 | send_gdb "continue\n" | |
72 | gdb_expect { | |
73 | -re "Breakpoint \[0-9\]+, thread_function \\(arg=.*\\) at .*print-threads.c:\[0-9\]+.*$gdb_prompt" { | |
74 | set i [expr $i + 1] | |
75 | pass "Hit thread_function breakpoint, $i ($name)" | |
76 | send_gdb "continue\n" | |
77 | exp_continue | |
78 | } | |
79 | -re "Breakpoint \[0-9\]+, .* kill \\(.*\\) .*$gdb_prompt" { | |
80 | set j [expr $j + 1] | |
81 | if { $kill == 1 } { | |
82 | pass "Hit kill breakpoint, $j ($name)" | |
83 | } else { | |
84 | fail "Hit kill breakpoint, $j ($name) (unexpected)" | |
85 | } | |
86 | send_gdb "continue\n" | |
87 | exp_continue | |
88 | } | |
89 | -re "Program exited normally\\.\[\r\n\]+$gdb_prompt" { | |
90 | pass "program exited normally" | |
91 | if {$i == 5} { | |
92 | pass "all threads ran once ($name)" | |
93 | } else { | |
94 | fail "all threads ran once ($name) (total $i threads ran)" | |
95 | } | |
96 | } | |
027c0295 | 97 | -re "Program received signal SIGTRAP.*(Thread \[-0-9a-fx\]* \\(zombie\\)|0x00000000 in ).*$gdb_prompt $" { |
f56973f8 DJ |
98 | if { $kill == 1 } { |
99 | kfail "gdb/1265" "Running threads ($name) (zombie thread)" | |
100 | } else { | |
101 | fail "Running threads ($name) (unknown output)" | |
102 | } | |
103 | } | |
0312286c DJ |
104 | -re "$gdb_prompt" { |
105 | fail "Running threads ($name) (unknown output)" | |
106 | } | |
107 | timeout { | |
108 | fail "Running threads ($name) (timeout)" | |
109 | } | |
110 | } | |
111 | } | |
112 | ||
113 | runto_main | |
114 | gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." | |
115 | gdb_test "set var slow = 0" "" | |
116 | test_all_threads "fast" 0 | |
117 | ||
118 | runto_main | |
119 | gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (2)" | |
120 | gdb_test "set var slow = 1" "" | |
121 | test_all_threads "slow" 0 | |
122 | ||
123 | runto_main | |
124 | gdb_test "break thread_function" "Breakpoint \[0-9\]+ at 0x\[0-9a-f\]+: file .*print-threads.c, line \[0-9\]*\\." "break thread_function (3)" | |
125 | gdb_test "set var slow = 1" "" "set var slow = 1 (2)" | |
6afcfa39 | 126 | gdb_breakpoint "kill" |
0312286c DJ |
127 | test_all_threads "slow with kill breakpoint" 1 |
128 | ||
129 | return 0 |