* lib/gdb.exp (skip_hw_breakpoint_tests): New procedure.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / thread-specific.exp
CommitLineData
7b6bb8da 1# Copyright 2004, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
c47cebdb
DJ
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c47cebdb 6# (at your option) any later version.
e22f8b7c 7#
c47cebdb
DJ
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.
e22f8b7c 12#
c47cebdb 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c47cebdb 15
c47cebdb
DJ
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.
19
20if $tracelevel then {
21 strace $tracelevel
22}
23
c47cebdb
DJ
24
25set testfile "thread-specific"
26set srcfile ${testfile}.c
27set binfile ${objdir}/${subdir}/${testfile}
28
29if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
30 return -1
31}
32
33# Return a list of the valid thread IDs, with the initial thread first.
34proc get_thread_list { } {
35 global gdb_prompt
36 global expect_out
37
38 set thr_list ""
39
40 gdb_test_multiple "info threads" "get threads list" {
41 -re "info threads\r\n" {
42 exp_continue
43 }
b32306ca
UW
44 -re "New Thread \[^\n\]*\n" {
45 exp_continue
46 }
a283af87
AS
47 -re "^ *Id *Target Id\[^\n\]*\n" {
48 exp_continue
49 }
50 -re "^\\* *(\[0-9\]*) *Thread \[^\n\]*main\[^\n\]*\n" {
c47cebdb
DJ
51 set thr_list "$expect_out(1,string) $thr_list"
52 exp_continue
53 }
a283af87 54 -re "^ *(\[0-9\]*) *Thread \[^\n\]*\n" {
c47cebdb
DJ
55 lappend thr_list $expect_out(1,string)
56 exp_continue
57 }
58 -re ".*$gdb_prompt $" {
59 if { [llength $thr_list] != 0 } {
60 pass "get threads list"
61 } else {
62 fail "get threads list (no threads)"
63 }
64 }
65 }
66
67 return $thr_list
68}
69
70# Start with a fresh gdb.
71
72gdb_exit
73gdb_start
74gdb_reinitialize_dir $srcdir/$subdir
75
76gdb_load ${binfile}
77
12b5d08a
MS
78gdb_test_no_output "set print sevenbit-strings"
79gdb_test_no_output "set width 0"
c47cebdb 80
6aed2dbc
SS
81gdb_test {print $_thread} ".* = 0" "thread var when not running"
82
c47cebdb
DJ
83runto_main
84
85gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
86gdb_continue_to_breakpoint "all threads started"
87
88set line [gdb_get_line_number "thread-specific.exp: thread loop"]
89set threads [get_thread_list]
90
9cf689d7
DJ
91if {[llength $threads] == 0} {
92 # We have already issued a FAIL above.
93 return 1
94}
95
6aed2dbc
SS
96gdb_test {print $_thread} ".* = [lindex $threads 0]" "thread var in main"
97
c47cebdb
DJ
98gdb_test_multiple "break $line thread [lindex $threads 0]" \
99 "breakpoint $line main thread" {
44c75849 100 -re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
c47cebdb
DJ
101 set main_breakpoint $expect_out(1,string)
102 pass "breakpoint $line main thread"
103 }
104}
105
106foreach thread [lrange $threads 1 end] {
107 gdb_breakpoint "$line thread $thread"
108}
109
110gdb_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)"
113 }
6aed2dbc
SS
114 -re "Breakpoint (\[0-9\]*), .* at .*\r\n$gdb_prompt $" {
115 set this_breakpoint $expect_out(1,string)
c47cebdb
DJ
116 pass "continue to thread-specific breakpoint"
117 }
118}
119
6aed2dbc
SS
120gdb_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"
124 }
125}
126
127gdb_test {print $_thread} ".* = $this_thread" "thread var at break"
128
c47cebdb 129return 0
This page took 0.671376 seconds and 4 git commands to generate.