* thread.c (thread_id_make_value): Make a value representing the
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / thread-specific.exp
1 # Copyright 2004, 2007, 2008, 2009, 2010 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 # 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
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24
25 set testfile "thread-specific"
26 set srcfile ${testfile}.c
27 set binfile ${objdir}/${subdir}/${testfile}
28
29 if {[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.
34 proc 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 }
44 -re "New Thread \[^\n\]*\n" {
45 exp_continue
46 }
47 -re "^\\* *(\[0-9\]*) Thread \[^\n\]*main\[^\n\]*\n" {
48 set thr_list "$expect_out(1,string) $thr_list"
49 exp_continue
50 }
51 -re "^ *(\[0-9\]*) Thread \[^\n\]*\n" {
52 lappend thr_list $expect_out(1,string)
53 exp_continue
54 }
55 -re ".*$gdb_prompt $" {
56 if { [llength $thr_list] != 0 } {
57 pass "get threads list"
58 } else {
59 fail "get threads list (no threads)"
60 }
61 }
62 }
63
64 return $thr_list
65 }
66
67 # Start with a fresh gdb.
68
69 gdb_exit
70 gdb_start
71 gdb_reinitialize_dir $srcdir/$subdir
72
73 gdb_load ${binfile}
74
75 gdb_test_no_output "set print sevenbit-strings"
76 gdb_test_no_output "set width 0"
77
78 gdb_test {print $_thread} ".* = 0" "thread var when not running"
79
80 runto_main
81
82 gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
83 gdb_continue_to_breakpoint "all threads started"
84
85 set line [gdb_get_line_number "thread-specific.exp: thread loop"]
86 set threads [get_thread_list]
87
88 if {[llength $threads] == 0} {
89 # We have already issued a FAIL above.
90 return 1
91 }
92
93 gdb_test {print $_thread} ".* = [lindex $threads 0]" "thread var in main"
94
95 gdb_test_multiple "break $line thread [lindex $threads 0]" \
96 "breakpoint $line main thread" {
97 -re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
98 set main_breakpoint $expect_out(1,string)
99 pass "breakpoint $line main thread"
100 }
101 }
102
103 foreach thread [lrange $threads 1 end] {
104 gdb_breakpoint "$line thread $thread"
105 }
106
107 gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
108 -re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
109 fail "continue to thread-specific breakpoint (wrong breakpoint)"
110 }
111 -re "Breakpoint (\[0-9\]*), .* at .*\r\n$gdb_prompt $" {
112 set this_breakpoint $expect_out(1,string)
113 pass "continue to thread-specific breakpoint"
114 }
115 }
116
117 gdb_test_multiple "info breakpoint $this_breakpoint" "info on bp" {
118 -re ".*stop only in thread (\[0-9\]*).*$gdb_prompt $" {
119 set this_thread $expect_out(1,string)
120 pass "found breakpoint for thread number"
121 }
122 }
123
124 gdb_test {print $_thread} ".* = $this_thread" "thread var at break"
125
126 return 0
This page took 0.035388 seconds and 4 git commands to generate.