* gdb.threads/manythreads.exp: Prevent expect buffer overflow
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / manythreads.exp
1 # manythreads.exp -- Expect script to test stopping many threads
2 # Copyright (C) 2004, 2006, 2007 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
23 if $tracelevel then {
24 strace $tracelevel
25 }
26
27 set prms_id 0
28 set bug_id 0
29
30 set testfile "manythreads"
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33
34 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
35 return -1
36 }
37
38 gdb_start
39 gdb_reinitialize_dir $srcdir/$subdir
40 gdb_load ${binfile}
41 gdb_test "set print sevenbit-strings" ""
42 runto_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).
48 if ![istarget "*-*-ultrix*"] then {
49 gdb_test "shell stty intr '^C'" ""
50 }
51
52 set message "first continue"
53 gdb_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
63 after 1000
64 send_gdb "\003"
65 set message "stop threads 1"
66 gdb_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
84 set cmd "info threads"
85 set ok 0
86 gdb_test_multiple $cmd $cmd {
87 -re " 1 Thread " {
88 set ok 1
89 exp_continue
90 }
91 -re ".*\r\n" {
92 # Eat this line and continue, to prevent the buffer overflowing.
93 exp_continue
94 }
95 -re "$gdb_prompt $" {
96 if { $ok } {
97 pass $cmd
98 } else {
99 fail $cmd
100 }
101 }
102 }
103
104 set message "second continue"
105 gdb_test_multiple "continue" "second continue" {
106 -re "error:.*$gdb_prompt $" {
107 fail "$message"
108 }
109 -re "Continuing" {
110 pass "$message"
111 }
112 }
113
114 # Send another Ctrl-C and verify that we can do info threads and quit
115 after 1000
116 send_gdb "\003"
117 set message "stop threads 2"
118 gdb_test_multiple "" "stop threads 2" {
119 -re "\\\[New \[^\]\]*\\\]\r\n" {
120 exp_continue
121 }
122 -re "\\\[\[^\]\]* exited\\\]\r\n" {
123 exp_continue
124 }
125 -re "Thread \[^\n\]* executing\r\n" {
126 exp_continue
127 }
128 -re "Program received signal SIGINT.*$gdb_prompt $" {
129 pass "$message"
130 }
131 timeout {
132 fail "$message (timeout)"
133 }
134 }
135
136 gdb_test_multiple "quit" "GDB exits after stopping multithreaded program" {
137 -re "The program is running. Exit anyway\\? \\(y or n\\) $" {
138 send_gdb "y\n"
139 exp_continue
140 }
141 eof {
142 pass "GDB exits after stopping multithreaded program"
143 }
144 timeout {
145 fail "GDB exits after stopping multithreaded program (timeout)"
146 }
147 }
148
This page took 0.033902 seconds and 5 git commands to generate.