Imported Upstream version 7.9
[platform/upstream/gdb.git] / gdb / testsuite / gdb.threads / thread-specific.exp
1 # Copyright 2004-2015 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
21 standard_testfile
22
23 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } {
24     return -1
25 }
26
27 # Return a list of the valid thread IDs, with the initial thread first.
28 proc get_thread_list { } {
29   global gdb_prompt
30   global expect_out
31
32   set thr_list ""
33
34   gdb_test_multiple "info threads" "get threads list" {
35     -re "info threads\r\n" {
36       exp_continue
37     }
38     -re "New Thread \[^\n\]*\n" {
39       exp_continue
40     }
41     -re "^ *Id *Target Id\[^\n\]*\n" {
42       exp_continue
43     }
44     -re "^\\*  *(\[0-9\]*) *Thread \[^\n\]*main\[^\n\]*\n" {
45       set thr_list "$expect_out(1,string) $thr_list"
46       exp_continue
47     }
48     -re "^  *(\[0-9\]*) *Thread \[^\n\]*\n" {
49       lappend thr_list $expect_out(1,string)
50       exp_continue
51     }
52     -re ".*$gdb_prompt $" {
53       if { [llength $thr_list] != 0 } {
54         pass "get threads list"
55       } else {
56         fail "get threads list (no threads)"
57       }
58     }
59   }
60
61   return $thr_list
62 }
63
64 clean_restart ${binfile}
65
66 gdb_test_no_output "set print sevenbit-strings"
67 gdb_test_no_output "set width 0"
68
69 gdb_test {print $_thread} ".* = 0" "thread var when not running"
70
71 runto_main
72
73 gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
74 gdb_continue_to_breakpoint "all threads started"
75
76 set line [gdb_get_line_number "thread-specific.exp: thread loop"]
77 set threads [get_thread_list]
78
79 if {[llength $threads] == 0} {
80   # We have already issued a FAIL above.
81   return 1
82 }
83
84 gdb_test {print $_thread} ".* = [lindex $threads 0]" "thread var in main"
85
86 gdb_test_multiple "break $line thread [lindex $threads 0]" \
87   "breakpoint $line main thread" {
88     -re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
89       set main_breakpoint $expect_out(1,string)
90       pass "breakpoint $line main thread"
91     }
92 }
93
94 foreach thread [lrange $threads 1 end] {
95   gdb_breakpoint "$line thread $thread"
96 }
97
98 set this_breakpoint -1
99 gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
100         -re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
101             fail "continue to thread-specific breakpoint (wrong breakpoint)"
102         }
103         -re "Breakpoint (\[0-9\]*), .* at .*\r\n$gdb_prompt $" {
104             set this_breakpoint $expect_out(1,string)
105             pass "continue to thread-specific breakpoint"
106         }
107 }
108
109 set this_thread -1
110 if { $this_breakpoint != -1 } {
111     gdb_test_multiple "info breakpoint $this_breakpoint" "info on bp" {
112         -re ".*stop only in thread (\[0-9\]*).*$gdb_prompt $" {
113             set this_thread $expect_out(1,string)
114             pass "found breakpoint for thread number"
115         }
116     }
117 } else {
118     untested "info on bp"
119 }
120
121 if { $this_thread != -1 } {
122     gdb_test {print $_thread} ".* = $this_thread" "thread var at break"
123 } else {
124     untested "thread var at break"
125 }
126
127 return 0