1# manythreads.exp -- Expect script to test stopping many threads
2# Copyright (C) 2004 Free Software Foundation, Inc.
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
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
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.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# This file was written by Jeff Johnston. (jjohnstn@redhat.com)
22
23if $tracelevel then {
24	strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30set testfile "manythreads"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33
34if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
35    return -1
36}
37
38gdb_start
39gdb_reinitialize_dir $srcdir/$subdir
40gdb_load ${binfile}
41gdb_test "set print sevenbit-strings" ""
42runto_main
43
44# We'll need this when we send_gdb a ^C to GDB.  Need to do it before we
45# run the program and gdb starts saving and restoring tty states.
46# On Ultrix, we don't need it and it is really slow (because shell_escape
47# doesn't use vfork).
48if ![istarget "*-*-ultrix*"] then {
49    gdb_test "shell stty intr '^C'" ""
50}
51
52set message "first continue"
53gdb_test_multiple "continue" "first continue" {
54  -re "error:.*$gdb_prompt $" {
55    fail "$message"
56  }
57  -re "Continuing" {
58    pass "$message"
59  }
60}
61
62# Send a Ctrl-C and verify that we can do info threads and continue
63after 1000
64send_gdb "\003"
65set message "stop threads 1"
66gdb_test_multiple "" "stop threads 1" {
67  -re "\\\[New \[^\]\]*\\\]\r\n" {
68    exp_continue
69  }
70  -re "\\\[\[^\]\]* exited\\\]\r\n" {
71    exp_continue
72  }
73  -re "Thread \[^\n\]* executing\r\n" {
74    exp_continue
75  }
76  -re "Program received signal SIGINT.*$gdb_prompt $" {
77    pass "$message"
78  }
79  timeout {
80    fail "$message (timeout)"
81  }
82}
83
84gdb_test "info threads" ".*1 Thread.*.LWP.*"
85
86set message "second continue"
87gdb_test_multiple "continue" "second continue" {
88  -re "error:.*$gdb_prompt $" {
89    fail "$message"
90  }
91  -re "Continuing" {
92    pass "$message"
93  }
94}
95
96# Send another Ctrl-C and verify that we can do info threads and quit
97after 1000
98send_gdb "\003"
99set message "stop threads 2"
100gdb_test_multiple "" "stop threads 2" {
101  -re "\\\[New \[^\]\]*\\\]\r\n" {
102    exp_continue
103  }
104  -re "\\\[\[^\]\]* exited\\\]\r\n" {
105    exp_continue
106  }
107  -re "Thread \[^\n\]* executing\r\n" {
108    exp_continue
109  }
110  -re "Program received signal SIGINT.*$gdb_prompt $" {
111    pass "stop threads 2"
112  }
113}
114
115gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
116    -re "The program is running.  Exit anyway\\? \\(y or n\\) $" {
117	send_gdb "y\n"
118	exp_continue
119    }
120    eof {
121        pass "GDB exits after stopping multithreaded program"
122    }
123    timeout {
124        fail "GDB exits after stopping multithreaded program (timeout)"
125    }
126}
127
128