1 2005-02-11 Jeff Johnston <jjohnstn@redhat.com>
3 * testsuite/gdb.threads/step-thread-exit.c: New testcase.
4 * testsuite/gdb.threads/step-thread-exit.exp: Ditto.
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
11 +/* This testcase is part of GDB, the GNU debugger.
13 + Copyright 2005 Free Software Foundation, Inc.
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.
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.
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. */
35 +void *thread_function (void *ptr)
37 + int *x = (int *)ptr;
38 + printf("In thread_function, *x is %d\n", *x);
39 +} /* thread_function_end */
41 +volatile int repeat = 0;
49 + ret = pthread_create (&th, NULL, thread_function, &i);
53 + sleep (3); /* sleep */
56 + pthread_join (th, NULL);
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
66 +# This testcase is part of GDB, the GNU debugger.
68 +# Copyright 2005 Free Software Foundation, Inc.
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.
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.
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.
84 +# Check that GDB can step over a thread exit.
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}"]] != "" } {
95 +gdb_reinitialize_dir $srcdir/$subdir
98 +# Reset the debug file directory so we can't debug within the C library
99 +gdb_test "set debug-file-directory ." "" ""
102 +# Run to `main' where we begin our tests.
105 +if ![runto_main] then {
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"
114 +set sleep_line [expr [gdb_get_line_number "sleep"]]
115 +set end_line [expr [gdb_get_line_number "thread_function_end"]]
117 +gdb_breakpoint "$end_line"
118 +gdb_test "continue" "Break.*thread_function.*" "continue to thread_function 1"
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 $" {
129 + -re "\[Thread .* exited\].*Program received signal SIGSTOP.*$gdb_prompt $" {
132 + -re "start_thread.*$gdb_prompt $" {
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"
148 +gdb_test "bt" "main.*$sleep_line.*" "backtrace after step 1"
151 +gdb_test "show scheduler-locking" "Mode for locking scheduler during execution is \"step\"." "check scheduler-locking second"
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 $" {
160 + -re "Break.*$sleep_line.*$gdb_prompt $" {
161 + gdb_test "set repeat=1" "" ""
162 + send_gdb "continue\n"
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
171 +set test "step over thread exit 2"
172 +gdb_test_multiple "next" "$test" {
173 + -re "\}.*$gdb_prompt $" {
177 + -re "\[Thread .* exited\].*Break.*$sleep_line.*$gdb_prompt $" {
178 + pass "$test (breakpoint hit)"
180 + -re "\[Thread .* exited\].*$gdb_prompt $" {
181 + pass "$test (breakpoint not hit)"
183 + -re "start_thread.*$gdb_prompt $" {