Commit | Line | Data |
---|---|---|
c906108c | 1 | # step2.exp -- Expect script to test gdb step.c |
0fb0cc75 | 2 | # Copyright (C) 1992, 1997, 2007, 2008, 2009 Free Software Foundation, Inc. |
c906108c SS |
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 |
c906108c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
c906108c SS |
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 | # |
c906108c | 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/>. |
c906108c | 16 | |
c906108c SS |
17 | # This file was written by Jeff Law. (law@cygnus.com) |
18 | # | |
19 | ||
20 | ||
21 | if $tracelevel then { | |
22 | strace $tracelevel | |
23 | } | |
24 | ||
25 | set program_exited 0 | |
26 | ||
27 | # A simple and crude test to see that we can step two threads independently | |
28 | proc test_multi_threaded_stepping {} { | |
29 | global gdb_prompt | |
30 | global hex | |
31 | global srcfile | |
32 | global decimal | |
33 | ||
34 | # Set breakpoints in code that we know is executed in only | |
35 | # thread of control. | |
36 | gdb_test "break thread1" \ | |
37 | "Break.* at $hex: file .*$srcfile, line $decimal\\." | |
38 | gdb_test "break thread2" \ | |
39 | "Break.* at $hex: file .*$srcfile, line $decimal\\." | |
40 | ||
41 | # the order in which things happen is indeterminate. So we basically | |
42 | # look for a set of events and note that each one happens and that | |
43 | # all of the required events have happened when we're done. | |
44 | # | |
45 | # Right now we only verify that both threads start and that they | |
46 | # both call pthread_cond_wait twice. | |
47 | set thread1started 0 | |
48 | set thread1condwait 0 | |
49 | set thread2started 0 | |
50 | set thread2condwait 0 | |
51 | ||
52 | send_gdb "run\n" | |
53 | gdb_expect { | |
54 | -re "The program .* has been started already.*y or n. $" { | |
55 | send_gdb "y\n" | |
56 | exp_continue | |
57 | } | |
58 | -re ".*Breakpoint \[0-9\]+,.*thread1.* at .*$srcfile:.*\[\t \].*$gdb_prompt $" { | |
59 | if { $thread1started != 0 } then { | |
60 | fail "thread1 started" | |
61 | return | |
62 | } else { | |
63 | set thread1started 1 | |
64 | pass "thread1 started" | |
65 | } | |
66 | send_gdb "step\n" | |
67 | exp_continue | |
68 | } | |
69 | -re ".*Breakpoint \[0-9\]+,.*thread2.* at .*$srcfile:.*\[\t \].*$gdb_prompt $" { | |
70 | if { $thread2started != 0 } then { | |
71 | fail "thread2 started" | |
72 | return | |
73 | } else { | |
74 | set thread2started 1 | |
75 | pass "thread2 started" | |
76 | } | |
77 | send_gdb "step\n" | |
78 | exp_continue | |
79 | } | |
80 | -re ".*pthread_cond_wait.*cv_a.*$gdb_prompt" { | |
81 | if { $thread1started == 0 } then { | |
82 | fail "thread1 condwait" | |
83 | return | |
84 | } | |
85 | if { $thread1condwait < 2 } then { | |
86 | pass "thread1 condwait" | |
87 | incr thread1condwait | |
88 | } | |
89 | if { $thread2condwait == 2 } then { | |
90 | pass "multi threaded stepping" | |
91 | return | |
92 | } | |
93 | send_gdb "step\n" | |
94 | exp_continue | |
95 | } | |
96 | ||
97 | -re ".*pthread_cond_wait.*cv_b.*$gdb_prompt" { | |
98 | if { $thread2started == 0 } then { | |
99 | fail "thread2 condwait" | |
100 | return | |
101 | } | |
102 | if { $thread2condwait < 2 } then { | |
103 | pass "thread2 condwait" | |
104 | incr thread2condwait | |
105 | } | |
106 | if { $thread1condwait == 2 } then { | |
107 | pass "multi threaded stepping" | |
108 | return | |
109 | } | |
110 | send_gdb "step\n" | |
111 | exp_continue | |
112 | } | |
113 | ||
114 | -re "$gdb_prompt" { | |
115 | send_gdb "step\n" | |
116 | exp_continue | |
117 | } | |
118 | default { fail "multi threaded stepping" } | |
119 | } | |
120 | } | |
121 | ||
122 | # Check to see if we have an executable to test. If not, then either we | |
123 | # haven't tried to compile one, or the compilation failed for some reason. | |
124 | # In either case, just notify the user and skip the tests in this file. | |
125 | ||
126 | set binfile "step" | |
127 | set srcfile "step.c" | |
128 | ||
129 | if ![file exists $objdir/$subdir/$binfile] then { | |
130 | if $all_flag then { | |
131 | warning "$binfile does not exist; tests suppressed." | |
132 | } | |
133 | return | |
134 | } | |
135 | ||
136 | set prms_id 0 | |
137 | set bug_id 0 | |
138 | ||
139 | # Start with a fresh gdb. | |
140 | ||
141 | gdb_exit | |
142 | gdb_start | |
143 | gdb_reinitialize_dir $srcdir/$subdir | |
144 | gdb_load $objdir/$subdir/$binfile | |
145 | ||
146 | test_multi_threaded_stepping |