old-cross-binutils/gdb/testsuite/gdb.threads/linux-dp.exp

358 lines
10 KiB
Text
Raw Normal View History

# Copyright 1999-2013 Free Software Foundation, Inc.
1999-10-19 02:47:02 +00:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
1999-10-19 02:47:02 +00:00
# (at your option) any later version.
#
1999-10-19 02:47:02 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
1999-10-19 02:47:02 +00:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1999-10-19 02:47:02 +00:00
# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@gnu.org
#### Dining Philosophers, on LinuxThreads - Jim Blandy <jimb@cygnus.com>
####
#### At the moment, GDB's support for LinuxThreads is pretty
#### idiosyncratic --- GDB's output doesn't look much like the output
#### it produces for other thread implementations, messages appear at
#### different times, etc. So these tests are specific to LinuxThreads.
####
#### However, if all goes well, Linux will soon have a libthread_db
#### interface, and GDB will manage it the same way it does other
#### libthread_db-based systems. Then, we can adjust this file to
#### work with any such system.
### Other things we ought to test:
### stepping a thread while others are running
### killing and restarting
### quitting gracefully
# This only works with Linux configurations.
if ![istarget *-*-linux-gnu*] then {
1999-10-19 02:47:02 +00:00
return
}
* gdb.threads/watchpoint-fork.exp (test): Use standard_output_file. Don't declare objdir. * gdb.threads/attach-into-signal.exp: Use standard_testfile, standard_output_file. * gdb.threads/attach-stopped.exp: Use standard_testfile. * gdb.threads/bp_in_thread.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/corethreads.exp: Use standard_testfile. * gdb.threads/execl.exp: Use standard_testfile, standard_output_file, clean_restart. * gdb.threads/fork-child-threads.exp: Use standard_testfile, clean_restart. * gdb.threads/fork-thread-pending.exp: Use standard_testfile, clean_restart. * gdb.threads/gcore-thread.exp: Use standard_testfile. Remove incdir. * gdb.threads/hand-call-in-threads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/ia64-sigill.exp: Use standard_testfile. * gdb.threads/interrupted-hand-call.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/killed.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/leader-exit.exp: Use standard_testfile. * gdb.threads/linux-dp.exp: Use standard_testfile, clean_restart. * gdb.threads/local-watch-wrong-thread.exp: Use standard_testfile, clean_restart. * gdb.threads/manythreads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/multi-create.exp: Use standard_testfile, clean_restart. * gdb.threads/no-unwaited-for-left.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-1.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-2.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-3.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-4.exp: Use standard_testfile. * gdb.threads/pending-step.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/print-threads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/pthread_cond_wait.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/pthreads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/schedlock.exp: Use standard_testfile. Remove incdir. * gdb.threads/sigthread.exp: Use standard_testfile, clean_restart. * gdb.threads/staticthreads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/switch-threads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread-execl.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread-find.exp: Use standard_testfile, clean_restart. * gdb.threads/thread-specific.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread-unwindonsignal.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread_check.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread_events.exp: Use standard_testfile. Remove incdir. * gdb.threads/threadapply.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/threxit-hop-specific.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/tls-nodebug.exp: Use standard_testfile, clean_restart. * gdb.threads/tls-shared.exp: Use standard_testfile, clean_restart, standard_output_file. * gdb.threads/tls-var.exp: Use standard_testfile, standard_output_file. * gdb.threads/tls.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/watchthreads-reorder.exp: Use standard_testfile. * gdb.threads/watchthreads.exp: Use standard_testfile. Remove incdir. * gdb.threads/watchthreads2.exp: Use standard_testfile, clean_restart. Remove incdir.
2012-06-26 19:23:20 +00:00
standard_testfile
if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != ""} {
return -1
1999-10-19 02:47:02 +00:00
}
* gdb.threads/watchpoint-fork.exp (test): Use standard_output_file. Don't declare objdir. * gdb.threads/attach-into-signal.exp: Use standard_testfile, standard_output_file. * gdb.threads/attach-stopped.exp: Use standard_testfile. * gdb.threads/bp_in_thread.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/corethreads.exp: Use standard_testfile. * gdb.threads/execl.exp: Use standard_testfile, standard_output_file, clean_restart. * gdb.threads/fork-child-threads.exp: Use standard_testfile, clean_restart. * gdb.threads/fork-thread-pending.exp: Use standard_testfile, clean_restart. * gdb.threads/gcore-thread.exp: Use standard_testfile. Remove incdir. * gdb.threads/hand-call-in-threads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/ia64-sigill.exp: Use standard_testfile. * gdb.threads/interrupted-hand-call.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/killed.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/leader-exit.exp: Use standard_testfile. * gdb.threads/linux-dp.exp: Use standard_testfile, clean_restart. * gdb.threads/local-watch-wrong-thread.exp: Use standard_testfile, clean_restart. * gdb.threads/manythreads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/multi-create.exp: Use standard_testfile, clean_restart. * gdb.threads/no-unwaited-for-left.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-1.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-2.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-3.exp: Use standard_testfile. * gdb.threads/non-ldr-exc-4.exp: Use standard_testfile. * gdb.threads/pending-step.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/print-threads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/pthread_cond_wait.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/pthreads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/schedlock.exp: Use standard_testfile. Remove incdir. * gdb.threads/sigthread.exp: Use standard_testfile, clean_restart. * gdb.threads/staticthreads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/switch-threads.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread-execl.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread-find.exp: Use standard_testfile, clean_restart. * gdb.threads/thread-specific.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread-unwindonsignal.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread_check.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/thread_events.exp: Use standard_testfile. Remove incdir. * gdb.threads/threadapply.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/threxit-hop-specific.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/tls-nodebug.exp: Use standard_testfile, clean_restart. * gdb.threads/tls-shared.exp: Use standard_testfile, clean_restart, standard_output_file. * gdb.threads/tls-var.exp: Use standard_testfile, standard_output_file. * gdb.threads/tls.exp: Use standard_testfile, clean_restart. Remove incdir. * gdb.threads/watchthreads-reorder.exp: Use standard_testfile. * gdb.threads/watchthreads.exp: Use standard_testfile. Remove incdir. * gdb.threads/watchthreads2.exp: Use standard_testfile, clean_restart. Remove incdir.
2012-06-26 19:23:20 +00:00
clean_restart ${binfile}
gdb_test_no_output "set print sevenbit-strings"
1999-10-19 02:47:02 +00:00
runto_main
# There should be no threads initially.
2010-06-08 Michael Snyder <msnyder@vmware.com> * gdb.ada/assign_1.exp: Use ".*" instead of "" as wildcard regexp. * gdb.ada/boolean_expr.exp: * gdb.ada/frame_args.exp: Ditto. * gdb.ada/lang_switch.exp: Ditto. * gdb.ada/ptype_arith_binop.exp: Ditto. * gdb.ada/ref_param.exp: Ditto. * gdb.ada/type_coercion.exp:Ditto. * gdb.asm/asm-source.exp: Ditto. * gdb.base/attach.exp: Ditto. * gdb.base/bitfields2.exp: Ditto. * gdb.base/call-signal-resume.exp: Ditto. * gdb.base/callfuncs.exp: Ditto. * gdb.base/commands.exp: Ditto. * gdb.base/dbx.exp: Ditto. * gdb.base/default.exp: Ditto. * gdb.base/dump.exp: Ditto. * gdb.base/exprs.exp: Ditto. * gdb.base/freebpcmd.exp: Ditto. * gdb.base/interrupt.exp: Ditto. * gdb.base/list.exp: Ditto. * gdb.base/long_long.exp: Ditto. * gdb.base/maint.exp: Ditto. * gdb.base/ptype.exp: Ditto. * gdb.base/return.exp: Ditto. * gdb.base/setshow.exp: Ditto. * gdb.base/sigbpt.exp: Ditto. * gdb.base/sigrepeat.exp: Ditto. * gdb.cp/classes.exp: Ditto. * gdb.dwarf2/dw2-restore.exp: Ditto. * gdb.gdb/selftest.exp: Ditto. * gdb.multi/base.exp: Ditto. * gdb.multi/bkpt-multi-exec.exp: Ditto. * gdb.python/py-block.exp: Ditto. * gdb.python/py-prettyprint.exp: Ditto. * gdb.python/py-template.exp: Ditto. * gdb.server/ext-attach.exp: Ditto. * gdb.server/ext-run.exp: Ditto. * gdb.server/server-mon.exp: Ditto. * gdb.threads/fork-thread-pending.exp: Ditto. * gdb.threads/hand-call-in-threads.exp: Ditto. * gdb.threads/interrupted-hand-call.exp: Ditto. * gdb.threads/linux-dp.exp: Ditto. * gdb.threads/manythreads.exp: Ditto. * gdb.threads/print-threads.exp: Ditto. * gdb.threads/pthreads.exp: Ditto. * gdb.threads/schedlock.exp: Ditto. * gdb.threads/thread-unwindonsignal.exp: Ditto. * gdb.threads/threadapply.exp: Ditto.
2010-06-10 19:48:20 +00:00
gdb_test "info threads" ".*" "info threads 1"
1999-10-19 02:47:02 +00:00
# Try stepping over the thread creation function.
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: create philosopher"]
set expect_manager -1
1999-10-19 02:47:02 +00:00
for {set i 0} {$i < 5} {incr i} {
gdb_continue_to_breakpoint "about to create philosopher: $i"
set threads_before {}
gdb_test_multiple "info threads" "info threads before: $i" {
-re "info threads\r\n" {
exp_continue
}
-re "^ *Id.*Frame *\[\r\n\]+" {
exp_continue
}
-re "^. +(\[0-9\]+ *Thread \[-0-9a-fx\]+) \[^\n\]*\n" {
verbose -log "found thread $expect_out(1,string)" 2
lappend threads_before $expect_out(1,string)
exp_continue
}
-re "^\[^\n\]*\n" {
verbose -log "skipping line" 2
exp_continue -continue_timer
}
-re "^$gdb_prompt $" {
}
}
set threads_created 0
gdb_test_multiple "next" "create philosopher: $i" {
-re "^next\r\n" {
exp_continue
}
-re "^ *\[_!\] \[0-9\]* \[_!\]\r\n" {
# Ignore program output.
exp_continue -continue_timer
}
-re "^\\\[New \[^\]\n\]+\\\]\[^\n\]+\n" {
incr threads_created
exp_continue
}
-re "^189\[^\n\]+\n" {
exp_continue
}
-re "^$gdb_prompt $" {
1999-12-07 03:56:43 +00:00
}
-re "Program received signal.*(Unknown signal|SIGUSR|Real-time event).*$gdb_prompt $" {
1999-12-07 03:56:43 +00:00
# It would be nice if we could catch the message that GDB prints
# when it first notices that the thread library doesn't support
# debugging, or if we could explicitly ask GDB somehow.
unsupported "This GDB does not support threads on this system."
return -1
}
-re "$gdb_prompt $" {
}
}
if { $threads_created == 0 } {
# Not all targets announce new threads as they are created.
# For example, the GDB
# remote protocol target only finds out about threads when
# they actually report some event like a breakpoint hit,
# or when the user types 'info threads'.
unsupported "create philosopher: $i"
} elseif { $threads_created == 1 } {
if { $expect_manager < 0 } {
set expect_manager 0
}
pass "create philosopher: $i"
} elseif { !$i && $threads_created == 2 } {
# Two threads are created the first time in LinuxThreads,
# where the second is the manager thread. In NPTL, there is none.
set expect_manager 1
pass "create philosopher: $i"
} else {
fail "create philosopher: $i"
}
set threads_after {}
gdb_test_multiple "info threads" "info threads after: $i" {
-re "info threads\r\n" {
exp_continue
}
-re "^ *Id.*Frame *\[\r\n\]+" {
exp_continue
}
-re "^. +(\[0-9\]+ *Thread \[-0-9a-fx\]+) \[^\n\]*\n" {
set name $expect_out(1,string)
for {set j 0} {$j != [llength $threads_before] } {incr j} {
if {$name == [lindex $threads_before $j]} {
set threads_before [lreplace $threads_before $j $j]
set name ""
break
}
}
if { $name != "" } {
lappend threads_after $name
}
exp_continue
}
-re "^\[^\n\]*\n" {
verbose -log "skipping line" 2
exp_continue -continue_timer
}
-re "^$gdb_prompt $" {
if { [llength $threads_before] != 0 } {
fail "info threads after: $i"
} elseif { !$i && [llength $threads_after] == 2 } {
set expect_manager 1
pass "info threads after: $i"
} elseif { [llength $threads_after] == 1 } {
if { $expect_manager < 0 } {
set expect_manager 0
}
pass "info threads after: $i"
} else {
fail "info threads after: $i"
}
}
}
1999-10-19 02:47:02 +00:00
}
set nthreads 6
1999-10-19 02:47:02 +00:00
# Run until there are some threads.
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: info threads 2"]
gdb_continue_to_breakpoint "main thread's sleep"
set info_threads_ptn ".*"
for {set i $nthreads} {$i > 0} {incr i -1} {
append info_threads_ptn "$i *Thread .*"
}
append info_threads_ptn "\[\r\n\]+$gdb_prompt $"
set info_threads_manager_ptn "[expr $nthreads + 1] *Thread .*$info_threads_ptn"
gdb_test_multiple "info threads" "info threads 2" {
-re "$info_threads_manager_ptn" {
# We did see a manager thread. Check that against what we expected.
switch -exact -- $expect_manager {
-1 {
# We weren't sure whether to expect a manager thread.
pass "info threads 2"
}
1 {
# We were expecting a manager thread.
pass "info threads 2"
}
0 {
# We were not expecting to see the manager thread.
fail "info threads 2"
}
}
set expect_manager 1
incr nthreads
}
-re "$info_threads_ptn" {
# We did not see a manager thread. Check that against what we
# expected.
switch -exact -- $expect_manager {
-1 {
# We weren't sure whether to expect a manager thread.
# Don't expect it from here on out.
pass "info threads 2"
}
1 {
# We were expecting a manager thread, but we didn't see one.
fail "info threads 2"
}
0 {
# We were not expecting to see the manager thread.
pass "info threads 2"
}
}
set expect_manager 0
}
}
1999-10-19 02:47:02 +00:00
# Try setting a thread-specific breakpoint.
gdb_breakpoint "print_philosopher thread 5"
gdb_continue_to_breakpoint "thread 5's print"
# When there is no debugging info available for the thread library,
# the backtrace entry for philosopher's caller looks like:
# #2 0x4001c548 in pthread_create () from /lib/libpthread.so.0
# If you do have debug info, the output obviously depends more on the
# exact library in use; under NPTL, you get:
# #2 0x0012b7fc in start_thread (arg=0x21) at pthread_create.c:264
gdb_test "where" "print_philosopher.*philosopher.* \(from .*libpthread\|at pthread_create\|in pthread_create\).*" \
1999-10-19 02:47:02 +00:00
"first thread-specific breakpoint hit"
# Make sure it's catching the right thread. Try hitting the
# breakpoint ten times, and make sure we don't get anyone else.
set only_five 1
for {set i 0} {$only_five > 0 && $i < 10} {incr i} {
gdb_continue_to_breakpoint "thread 5's print, pass: $i"
gdb_test_multiple "info threads" "" {
-re "\[*\] 5 *Thread .* +print_philosopher .*\r\n$gdb_prompt $" {
1999-10-19 02:47:02 +00:00
# Okay this time.
}
-re ".*$gdb_prompt $" {
set only_five 0
}
timeout {
set only_five -1
}
}
}
set name "thread-specific breakpoint is thread-specific"
if {$only_five == 1} { pass $name }
if {$only_five == 0} { fail $name }
if {$only_five == -1} { fail "$name (timeout)" }
### Select a particular thread.
proc select_thread {thread} {
global gdb_prompt
gdb_test "thread $thread" \
"\\\[Switching to thread .*\\\].*" \
"selected thread: $thread"
1999-10-19 02:47:02 +00:00
}
### Select THREAD, check for a plausible backtrace, and make sure
### we're actually selecting a different philosopher each time.
### Return true if the thread had a stack which was not only
### acceptable, but interesting. SEEN should be an array in which
### SEEN(N) exists iff we have found philosopher number N before.
set main_seen 0
set manager_seen 0
1999-10-19 02:47:02 +00:00
proc check_philosopher_stack {thread seen_name} {
global gdb_prompt
upvar $seen_name seen
global main_seen
global expect_manager manager_seen
1999-10-19 02:47:02 +00:00
set name "philosopher is distinct: $thread"
set interesting 0
select_thread $thread
gdb_test_multiple "where" "$name" {
1999-10-19 02:47:02 +00:00
-re ".* in philosopher \\(data=(0x\[0-9a-f\]+).*\r\n$gdb_prompt $" {
set data $expect_out(1,string)
if {[info exists seen($data)]} {
fail $name
} else {
pass $name
set seen($data) yep
}
set interesting 1
}
-re ".* in __pthread_manager \\(.*$gdb_prompt $" {
if {$manager_seen == 1} {
fail "manager thread is distinct: $thread"
} else {
set manager_seen 1
pass "manager thread is distinct: $thread"
}
set interesting 1
}
1999-10-19 02:47:02 +00:00
-re "pthread_start_thread.*\r\n$gdb_prompt $" {
## Maybe the thread hasn't started yet.
pass $name
}
-re ".* in main \\(.*$gdb_prompt $" {
if {$main_seen == 1} {
fail "main is distinct: $thread"
} else {
set main_seen 1
pass "main is distinct: $thread"
}
set interesting 1
}
1999-10-19 02:47:02 +00:00
-re " in \\?\\?.*\r\n$gdb_prompt $" {
## Sometimes we can't get a backtrace. I'm going to call
## this a pass, since we do verify that at least one
## thread was interesting, so we can get more consistent
## test suite totals. But in my heart, I think it should
## be an xfail.
pass $name
}
}
return $interesting
}
set any_interesting 0
catch {unset seen}
array set seen {}
for {set i 1} {$i <= $nthreads} {incr i} {
1999-10-19 02:47:02 +00:00
if [check_philosopher_stack $i seen] {
set any_interesting 1
}
}
unset seen
1999-10-19 02:47:02 +00:00
if {$any_interesting} {
pass "found an interesting thread"
} else {
fail "found an interesting thread"
}
if {$manager_seen == $expect_manager} {
pass "manager thread found (not found) when expected"
} else {
fail "manager thread found (not found) when expected"
}