1 # Copyright 2004, 2007-2012 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Daniel Jacobowitz <drow@mvista.com>.
17 # It tests that the correct breakpoint is reported when we hit a
18 # thread-specific breakpoint inserted for several threads.
25 set testfile "thread-specific"
26 set srcfile ${testfile}.c
27 set binfile ${objdir}/${subdir}/${testfile}
29 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
33 # Return a list of the valid thread IDs, with the initial thread first.
34 proc get_thread_list { } {
40 gdb_test_multiple "info threads" "get threads list" {
41 -re "info threads\r\n" {
44 -re "New Thread \[^\n\]*\n" {
47 -re "^ *Id *Target Id\[^\n\]*\n" {
50 -re "^\\* *(\[0-9\]*) *Thread \[^\n\]*main\[^\n\]*\n" {
51 set thr_list "$expect_out(1,string) $thr_list"
54 -re "^ *(\[0-9\]*) *Thread \[^\n\]*\n" {
55 lappend thr_list $expect_out(1,string)
58 -re ".*$gdb_prompt $" {
59 if { [llength $thr_list] != 0 } {
60 pass "get threads list"
62 fail "get threads list (no threads)"
70 # Start with a fresh gdb.
74 gdb_reinitialize_dir $srcdir/$subdir
78 gdb_test_no_output "set print sevenbit-strings"
79 gdb_test_no_output "set width 0"
81 gdb_test {print $_thread} ".* = 0" "thread var when not running"
85 gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
86 gdb_continue_to_breakpoint "all threads started"
88 set line [gdb_get_line_number "thread-specific.exp: thread loop"]
89 set threads [get_thread_list]
91 if {[llength $threads] == 0} {
92 # We have already issued a FAIL above.
96 gdb_test {print $_thread} ".* = [lindex $threads 0]" "thread var in main"
98 gdb_test_multiple "break $line thread [lindex $threads 0]" \
99 "breakpoint $line main thread" {
100 -re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
101 set main_breakpoint $expect_out(1,string)
102 pass "breakpoint $line main thread"
106 foreach thread [lrange $threads 1 end] {
107 gdb_breakpoint "$line thread $thread"
110 gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
111 -re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
112 fail "continue to thread-specific breakpoint (wrong breakpoint)"
114 -re "Breakpoint (\[0-9\]*), .* at .*\r\n$gdb_prompt $" {
115 set this_breakpoint $expect_out(1,string)
116 pass "continue to thread-specific breakpoint"
120 gdb_test_multiple "info breakpoint $this_breakpoint" "info on bp" {
121 -re ".*stop only in thread (\[0-9\]*).*$gdb_prompt $" {
122 set this_thread $expect_out(1,string)
123 pass "found breakpoint for thread number"
127 gdb_test {print $_thread} ".* = $this_thread" "thread var at break"