-# Copyright 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
-# Free Software Foundation, Inc.
+# Copyright 1999-2013 Free Software Foundation, Inc.
# 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
### killing and restarting
### quitting gracefully
-if $tracelevel then {
- strace $tracelevel
-}
-
-set prms_id 0
-set bug_id 0
# This only works with Linux configurations.
if ![istarget *-*-linux-gnu*] then {
return
}
-set testfile "linux-dp"
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
-if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug libs=-lpthread}] != ""} {
+standard_testfile
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != ""} {
return -1
}
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
+clean_restart ${binfile}
+gdb_test_no_output "set print sevenbit-strings"
runto_main
# There should be no threads initially.
-gdb_test "info threads" "" "info threads 1"
+gdb_test "info threads" ".*" "info threads 1"
# Try stepping over the thread creation function.
gdb_breakpoint [gdb_get_line_number "linuxthreads.exp: create philosopher"]
set expect_manager -1
for {set i 0} {$i < 5} {incr i} {
gdb_continue_to_breakpoint "about to create philosopher: $i"
- send_gdb "info threads\n"
set threads_before {}
- gdb_expect {
+ gdb_test_multiple "info threads" "info threads before: $i" {
-re "info threads\r\n" {
exp_continue
}
- -re "^. +(\[0-9\]+ Thread \[-0-9a-fx\]+) \[^\n\]*\n" {
+ -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 "^$gdb_prompt $" {
}
- timeout {
- fail "(timeout) info threads before: $i"
- }
}
- send_gdb "next\n"
set threads_created 0
- gdb_expect {
+ gdb_test_multiple "next" "create philosopher: $i" {
-re "^next\r\n" {
exp_continue
}
}
-re "$gdb_prompt $" {
}
- timeout {
- fail "(timeout) create philosopher: $i"
- }
}
if { $threads_created == 0 } {
# Not all targets announce new threads as they are created.
fail "create philosopher: $i"
}
- send_gdb "info threads\n"
set threads_after {}
- gdb_expect {
+ gdb_test_multiple "info threads" "info threads after: $i" {
-re "info threads\r\n" {
exp_continue
}
- -re "^. +(\[0-9\]+ Thread \[-0-9a-fx\]+) \[^\n\]*\n" {
+ -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]} {
fail "info threads after: $i"
}
}
- timeout {
- fail "(timeout) info threads after: $i"
- }
}
-
}
set nthreads 6
# 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 ""
+set info_threads_ptn ".*"
for {set i $nthreads} {$i > 0} {incr i -1} {
- append info_threads_ptn "$i Thread .*"
+ 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"
+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" {
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:
-# #1 0x4001c548 in pthread_create () from /lib/libpthread.so.0
+# #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\).*" \
+gdb_test "where" "print_philosopher.*philosopher.* \(from .*libpthread\|at pthread_create\|in pthread_create\).*" \
"first thread-specific breakpoint hit"
# Make sure it's catching the right thread. Try hitting the
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"
- send_gdb "info threads\n"
- gdb_expect {
- -re "\\* 5 Thread .* print_philosopher .*\r\n$gdb_prompt $" {
+ gdb_test_multiple "info threads" "" {
+ -re "\[*\] 5 *Thread .* +print_philosopher .*\r\n$gdb_prompt $" {
# Okay this time.
}
-re ".*$gdb_prompt $" {
proc select_thread {thread} {
global gdb_prompt
- send_gdb "thread $thread\n"
- gdb_expect {
- -re "\\\[Switching to thread .*\\\].*\r\n$gdb_prompt $" {
- pass "selected thread: $thread"
- }
- -re "$gdb_prompt $" {
- fail "selected thread: $thread"
- }
- timeout {
- fail "selected thread: $thread (timeout)"
- }
- }
+ gdb_test "thread $thread" \
+ "\\\[Switching to thread .*\\\].*" \
+ "selected thread: $thread"
}
### Select THREAD, check for a plausible backtrace, and make sure
set interesting 0
select_thread $thread
- send_gdb "where\n"
- gdb_expect {
+ gdb_test_multiple "where" "$name" {
-re ".* in philosopher \\(data=(0x\[0-9a-f\]+).*\r\n$gdb_prompt $" {
set data $expect_out(1,string)
if {[info exists seen($data)]} {
## be an xfail.
pass $name
}
- -re "$gdb_prompt $" {
- fail $name
- }
- timeout {
- fail "$name (timeout)"
- }
}
return $interesting
}
set any_interesting 0
+catch {unset seen}
array set seen {}
-unset seen
for {set i 1} {$i <= $nthreads} {incr i} {
if [check_philosopher_stack $i seen] {
set any_interesting 1
}
}
+unset seen
if {$any_interesting} {
pass "found an interesting thread"