Remove obsolete test from gdb.cp/var-tag.exp
[binutils-gdb.git] / gdb / testsuite / gdb.threads / thread-specific.exp
blob26bba8b9961c672df0c180ae38d32bc61285c982
1 # Copyright 2004-2024 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.
21 standard_testfile
23 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable debug] != "" } {
24     return -1
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   global tdlabel_re
33   set thr_list ""
35   gdb_test_multiple "info threads" "get threads list" {
36     -re "info threads\r\n" {
37       exp_continue
38     }
39     -re "New Thread \[^\n\]*\n" {
40       exp_continue
41     }
42     -re "^ *Id *Target Id\[^\n\]*\n" {
43       exp_continue
44     }
45     -re "^\\*  *(\[0-9\]*) *${tdlabel_re} \[^\n\]*main\[^\n\]*\n" {
46       set thr_list "$expect_out(1,string) $thr_list"
47       exp_continue
48     }
49     -re "^  *(\[0-9\]*) *${tdlabel_re} \[^\n\]*\n" {
50       lappend thr_list $expect_out(1,string)
51       exp_continue
52     }
53     -re ".*$gdb_prompt $" {
54       if { [llength $thr_list] != 0 } {
55         pass "get threads list"
56       } else {
57         fail "get threads list (no threads)"
58       }
59     }
60   }
62   return $thr_list
65 clean_restart ${binfile}
67 gdb_test_no_output "set print sevenbit-strings"
68 gdb_test_no_output "set width 0"
70 # As this test only runs a single inferior, $_thread and $_gthread
71 # should match throughout.
72 gdb_test {print $_thread} ".* = 0" "thread var when not running"
73 gdb_test {print $_gthread} ".* = 0" "gthread var when not running"
75 runto_main
77 gdb_breakpoint [gdb_get_line_number "thread-specific.exp: last thread start"]
78 gdb_continue_to_breakpoint "all threads started"
80 set line [gdb_get_line_number "thread-specific.exp: thread loop"]
81 set threads [get_thread_list]
83 if {[llength $threads] == 0} {
84   # We have already issued a FAIL above.
85   return 1
88 gdb_test {print $_thread} ".* = [lindex $threads 0]" "thread var in main"
89 gdb_test {print $_gthread} ".* = [lindex $threads 0]" "gthread var in main"
91 gdb_test_multiple "break $line thread [lindex $threads 0]" \
92   "breakpoint $line main thread" {
93     -re "Breakpoint (\[0-9\]*) at.* file .*$srcfile, line.*$gdb_prompt $" {
94       set main_breakpoint $expect_out(1,string)
95       pass "breakpoint $line main thread"
96     }
99 foreach thread [lrange $threads 1 end] {
100   gdb_breakpoint "$line thread $thread"
103 set this_breakpoint -1
104 gdb_test_multiple "continue" "continue to thread-specific breakpoint" {
105         -re "Breakpoint $main_breakpoint, .* at .*\r\n$gdb_prompt $" {
106             fail "continue to thread-specific breakpoint (wrong breakpoint)"
107         }
108         -re "Breakpoint (\[0-9\]*), .* at .*\r\n$gdb_prompt $" {
109             set this_breakpoint $expect_out(1,string)
110             pass "continue to thread-specific breakpoint"
111         }
114 set this_thread -1
115 if { $this_breakpoint != -1 } {
116     gdb_test_multiple "info breakpoint $this_breakpoint" "info on bp" {
117         -re ".*stop only in thread (\[0-9\]*).*$gdb_prompt $" {
118             set this_thread $expect_out(1,string)
119             pass "found breakpoint for thread number"
120         }
121     }
122 } else {
123     untested "info on bp"
126 if { $this_thread != -1 } {
127     gdb_test {print $_thread} ".* = $this_thread" "thread var at break"
128     gdb_test {print $_gthread} ".* = $this_thread" "gthread var at break"
129 } else {
130     untested "thread var at break"