]>
Commit | Line | Data |
---|---|---|
3a58abaf AM |
1 | 2005-02-11 Jeff Johnston <jjohnstn@redhat.com> |
2 | ||
3 | * testsuite/gdb.threads/step-thread-exit.c: New testcase. | |
4 | * testsuite/gdb.threads/step-thread-exit.exp: Ditto. | |
5 | ||
6 | Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/step-thread-exit.c | |
7 | =================================================================== | |
8 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
9 | +++ gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/step-thread-exit.c 2008-12-08 22:21:26.000000000 +0100 | |
10 | @@ -0,0 +1,50 @@ | |
11 | +/* This testcase is part of GDB, the GNU debugger. | |
12 | + | |
13 | + Copyright 2005 Free Software Foundation, Inc. | |
14 | + | |
15 | + This program is free software; you can redistribute it and/or modify | |
16 | + it under the terms of the GNU General Public License as published by | |
17 | + the Free Software Foundation; either version 2 of the License, or | |
18 | + (at your option) any later version. | |
19 | + | |
20 | + This program is distributed in the hope that it will be useful, | |
21 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | + GNU General Public License for more details. | |
24 | + | |
25 | + You should have received a copy of the GNU General Public License | |
26 | + along with this program; if not, write to the Free Software | |
27 | + Foundation, Inc., 59 Temple Place - Suite 330, | |
28 | + Boston, MA 02111-1307, USA. */ | |
29 | + | |
30 | +#include <pthread.h> | |
31 | +#include <stdio.h> | |
32 | +#include <stdlib.h> | |
33 | +#include <unistd.h> | |
34 | + | |
35 | +void *thread_function (void *ptr) | |
36 | +{ | |
37 | + int *x = (int *)ptr; | |
38 | + printf("In thread_function, *x is %d\n", *x); | |
39 | +} /* thread_function_end */ | |
40 | + | |
41 | +volatile int repeat = 0; | |
42 | + | |
43 | +main() | |
44 | +{ | |
45 | + int ret; | |
46 | + pthread_t th; | |
47 | + int i = 3; | |
48 | + | |
49 | + ret = pthread_create (&th, NULL, thread_function, &i); | |
50 | + do | |
51 | + { | |
52 | + repeat = 0; | |
53 | + sleep (3); /* sleep */ | |
54 | + } | |
55 | + while (repeat); | |
56 | + pthread_join (th, NULL); | |
57 | + return 0; | |
58 | +} | |
59 | + | |
60 | + | |
61 | Index: gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/step-thread-exit.exp | |
62 | =================================================================== | |
63 | --- /dev/null 1970-01-01 00:00:00.000000000 +0000 | |
64 | +++ gdb-6.8.50.20081128/gdb/testsuite/gdb.threads/step-thread-exit.exp 2008-12-08 22:22:14.000000000 +0100 | |
51a5ef0f | 65 | @@ -0,0 +1,123 @@ |
3a58abaf AM |
66 | +# This testcase is part of GDB, the GNU debugger. |
67 | + | |
68 | +# Copyright 2005 Free Software Foundation, Inc. | |
69 | + | |
70 | +# This program is free software; you can redistribute it and/or modify | |
71 | +# it under the terms of the GNU General Public License as published by | |
72 | +# the Free Software Foundation; either version 2 of the License, or | |
73 | +# (at your option) any later version. | |
74 | +# | |
75 | +# This program is distributed in the hope that it will be useful, | |
76 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
77 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
78 | +# GNU General Public License for more details. | |
79 | +# | |
80 | +# You should have received a copy of the GNU General Public License | |
81 | +# along with this program; if not, write to the Free Software | |
82 | +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
83 | + | |
84 | +# Check that GDB can step over a thread exit. | |
85 | + | |
3a58abaf AM |
86 | +set testfile "step-thread-exit" |
87 | +set srcfile ${testfile}.c | |
88 | +set binfile ${objdir}/${subdir}/${testfile} | |
89 | +if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } { | |
90 | + return -1 | |
91 | +} | |
92 | + | |
93 | +gdb_exit | |
94 | +gdb_start | |
95 | +gdb_reinitialize_dir $srcdir/$subdir | |
96 | +gdb_load ${binfile} | |
97 | + | |
98 | +# Reset the debug file directory so we can't debug within the C library | |
99 | +gdb_test "set debug-file-directory ." "" "" | |
100 | + | |
101 | +# | |
102 | +# Run to `main' where we begin our tests. | |
103 | +# | |
104 | + | |
105 | +if ![runto_main] then { | |
106 | + gdb_suppress_tests | |
107 | +} | |
108 | + | |
109 | +# FIXME: Currently the main thread will escape/exit before our thread finishes | |
110 | +# without this setting. | |
111 | +gdb_test "set scheduler-locking step" | |
112 | +gdb_test "show scheduler-locking" "Mode for locking scheduler during execution is \"step\"." "check scheduler-locking first" | |
113 | + | |
114 | +set sleep_line [expr [gdb_get_line_number "sleep"]] | |
115 | +set end_line [expr [gdb_get_line_number "thread_function_end"]] | |
116 | + | |
117 | +gdb_breakpoint "$end_line" | |
118 | +gdb_test "continue" "Break.*thread_function.*" "continue to thread_function 1" | |
119 | + | |
120 | +# Keep nexting until we cause the thread to exit. We expect the main | |
121 | +# thread to be stopped and a message printed to tell us we have stepped | |
122 | +# over the thread exit. | |
123 | +set test "step over thread exit 1" | |
124 | +gdb_test_multiple "next" "$test" { | |
125 | + -re "\}.*$gdb_prompt $" { | |
126 | + send_gdb "next\n" | |
127 | + exp_continue | |
128 | + } | |
129 | + -re "\[Thread .* exited\].*Program received signal SIGSTOP.*$gdb_prompt $" { | |
130 | + pass "$test" | |
131 | + } | |
132 | + -re "start_thread.*$gdb_prompt $" { | |
133 | + send_gdb "next\n" | |
134 | + exp_continue | |
135 | + } | |
136 | +} | |
137 | + | |
138 | +# Without this fixup we could end up in: | |
139 | +# #0 0x00110416 in __kernel_vsyscall () | |
140 | +# #1 0x0011de26 in __lll_unlock_wake_private () from /lib/libpthread.so.0 | |
141 | +# #2 0x001179f4 in _L_unlock_3164 () from /lib/libpthread.so.0 | |
142 | +# #3 0x00116f01 in pthread_create@@GLIBC_2.1 () from /lib/libpthread.so.0 | |
143 | +# #4 0x08048531 in main () at ../.././gdb/testsuite/gdb.threads/step-thread-exit.c:39 | |
144 | +gdb_breakpoint "$sleep_line" | |
145 | +gdb_test "set repeat=1" "" "Get to the sleep function prepare 1" | |
146 | +gdb_test "continue" "Break.*$sleep_line.*" "Get to the sleep function 1" | |
147 | + | |
148 | +gdb_test "bt" "main.*$sleep_line.*" "backtrace after step 1" | |
149 | + | |
150 | +runto_main | |
151 | +gdb_test "show scheduler-locking" "Mode for locking scheduler during execution is \"step\"." "check scheduler-locking second" | |
152 | + | |
153 | +gdb_breakpoint "$sleep_line" | |
154 | +gdb_breakpoint "$end_line" | |
155 | +set test "continue to thread_function 2" | |
156 | +gdb_test_multiple "continue" "$test" { | |
157 | + -re "Break.*thread_function.*$gdb_prompt $" { | |
158 | + pass $test | |
159 | + } | |
160 | + -re "Break.*$sleep_line.*$gdb_prompt $" { | |
161 | + gdb_test "set repeat=1" "" "" | |
162 | + send_gdb "continue\n" | |
163 | + exp_continue | |
164 | + } | |
165 | +} | |
166 | + | |
167 | +# Keep nexting until we cause the thread to exit. In this case, we | |
168 | +# expect the breakpoint in the main thread to have already triggered | |
169 | +# and so we should stop there with a message that we stepped over | |
170 | +# the thread exit. | |
171 | +set test "step over thread exit 2" | |
172 | +gdb_test_multiple "next" "$test" { | |
173 | + -re "\}.*$gdb_prompt $" { | |
174 | + send_gdb "next\n" | |
175 | + exp_continue | |
176 | + } | |
177 | + -re "\[Thread .* exited\].*Break.*$sleep_line.*$gdb_prompt $" { | |
178 | + pass "$test (breakpoint hit)" | |
179 | + } | |
180 | + -re "\[Thread .* exited\].*$gdb_prompt $" { | |
181 | + pass "$test (breakpoint not hit)" | |
182 | + } | |
183 | + -re "start_thread.*$gdb_prompt $" { | |
184 | + send_gdb "next\n" | |
185 | + exp_continue | |
186 | + } | |
187 | +} | |
188 | + |