1# Copyright 2004, 2007 Free Software Foundation, Inc.
2
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.
7#
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.
12#
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/>.
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19# This file was written by Daniel Jacobowitz <drow@mvista.com>.
20# It tests that the correct breakpoint is reported when we hit a
21# thread-specific breakpoint inserted for several threads.
22
23if $tracelevel then {
24	strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30set testfile "thread-specific"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33
34if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
35    return -1
36}
37
38# Return a list of the valid thread IDs, with the initial thread first.
39proc get_thread_list { } {
40  global gdb_prompt
41  global expect_out
42
43  set thr_list ""
44
45  gdb_test_multiple "info threads" "get threads list" {
46    -re "info threads\r\n" {
47      exp_continue
48    }
49    -re "^\\*  *(\[0-9\]*) Thread \[^\n\]*main\[^\n\]*\n" {
50      set thr_list "$expect_out(1,string) $thr_list"
51      exp_continue
52    }
53    -re "^  *(\[0-9\]*) Thread \[^\n\]*\n" {
54      lappend thr_list $expect_out(1,string)
55      exp_continue
56    }
57    -re ".*$gdb_prompt $" {
58      if { [llength $thr_list] != 0 } {
59	pass "get threads list"
60      } else {
61	fail "get threads list (no threads)"
62      }
63    }
64  }
65
66  return $thr_list
67}
68
69# Start with a fresh gdb.
70
71gdb_exit
72gdb_start
73gdb_reinitialize_dir $srcdir/$subdir
74
75gdb_load ${binfile}
76
77gdb_test "set print sevenbit-strings" ""
78gdb_test "set width 0" ""
79
80runto_main
81
82gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
83gdb_continue_to_breakpoint "all threads started"
84
85set line [gdb_get_line_number "thread-specific.exp: thread loop"]
86set threads [get_thread_list]
87
88if {[llength $threads] == 0} {
89  # We have already issued a FAIL above.
90  return 1
91}
92
93gdb_test_multiple "break $line thread [lindex $threads 0]" \
94  "breakpoint $line main thread" {
95    -re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
96      set main_breakpoint $expect_out(1,string)
97      pass "breakpoint $line main thread"
98    }
99}
100
101foreach thread [lrange $threads 1 end] {
102  gdb_breakpoint "$line thread $thread"
103}
104
105gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
106	-re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
107	    fail "continue to thread-specific breakpoint (wrong breakpoint)"
108	}
109	-re "Breakpoint .* at .*\r\n$gdb_prompt $" {
110	    pass "continue to thread-specific breakpoint"
111	}
112}
113
114return 0
115