]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/thread-specific-bp.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / thread-specific-bp.exp
1 # Copyright (C) 2013-2024 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 # Verify that a thread-specific breakpoint is deleted when the
17 # corresponding thread is gone.
18
19 standard_testfile
20
21 if {[gdb_compile_pthreads \
22 "${srcdir}/${subdir}/${srcfile}" \
23 "${binfile}" executable {debug} ] != "" } {
24 return -1
25 }
26
27 # Extract and return the thread ID of the thread stopped at function
28 # FUNC.
29
30 proc get_thread_id {func} {
31 global gdb_prompt
32
33 set thre -1
34 set test "get $func thread id"
35 gdb_test_multiple "info threads" $test {
36 -re "(\[0-9\]+)\[^\n\r\]*Thread\[^\n\r\]*$func.*$gdb_prompt $" {
37 # Get the thread's id.
38 set thre $expect_out(1,string)
39 pass $test
40 }
41 }
42
43 return $thre
44 }
45
46 proc check_thread_specific_breakpoint {non_stop} {
47 global gdb_prompt
48
49 if { ![runto_main] } {
50 return -1
51 }
52
53 set main_thre [get_thread_id "main"]
54 if { $main_thre < 0 } {
55 return -1
56 }
57
58 gdb_breakpoint "start"
59 gdb_continue_to_breakpoint "start"
60
61 set start_thre [get_thread_id "start"]
62 if { $start_thre < 0 } {
63 return -1
64 }
65
66 # Check that multiple uses of 'thread' keyword give an error.
67 gdb_test "break main thread $start_thre thread $main_thre" \
68 "You can specify only one thread\\."
69
70 # Set a thread-specific breakpoint at "main". This can't ever
71 # be hit, but that's OK.
72 gdb_breakpoint "main thread $start_thre"
73 gdb_test "info break" ".*breakpoint.*thread $start_thre" "breakpoint set"
74
75 # Set breakpoint at a place only reachable after the "start"
76 # thread exits.
77 gdb_breakpoint "end"
78
79 # Switch back to the main thread, and resume all threads. The
80 # "start" thread exits, and the main thread reaches "end".
81 gdb_test "thread $main_thre" \
82 "Switching to thread $main_thre.*" \
83 "thread $main_thre selected"
84
85 if { $non_stop } {
86 set cmd "continue -a"
87 } else {
88 set cmd "continue"
89 }
90 set msg_re \
91 [join \
92 [list \
93 "Thread-specific breakpoint 3 deleted" \
94 "-" \
95 "thread 2 no longer in the thread list\\."]]
96
97 gdb_test_multiple "$cmd" "continue to end" {
98 -re "$\r\n${gdb_prompt} .*${msg_re}\r\n" {
99 pass $gdb_test_name
100 }
101 -re "\r\n${msg_re}\r\n.*$gdb_prompt " {
102 pass $gdb_test_name
103 }
104 }
105
106 set test "thread-specific breakpoint was deleted"
107 gdb_test_multiple "info breakpoint" $test {
108 -re "thread $start_thre\n$gdb_prompt $" {
109 fail $test
110 }
111 -re "$gdb_prompt $" {
112 pass $test
113 }
114 }
115 }
116
117 foreach_with_prefix non_stop {on off} {
118 save_vars { GDBFLAGS } {
119 append GDBFLAGS " -ex \"set non-stop $non_stop\""
120 clean_restart $binfile
121 }
122
123 check_thread_specific_breakpoint $non_stop
124 }