Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright (C) 2013-2014 Free Software Foundation, Inc. |
49fa26b0 PA |
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 | clean_restart ${binfile} | |
28 | ||
29 | # Extract and return the thread ID of the thread stopped at function | |
30 | # FUNC. | |
31 | ||
32 | proc get_thread_id {func} { | |
33 | global gdb_prompt | |
34 | ||
35 | set thre -1 | |
36 | set test "get $func thread id" | |
37 | gdb_test_multiple "info threads" $test { | |
38 | -re "(\[0-9\]+)\[^\n\r\]*Thread\[^\n\r\]*$func.*$gdb_prompt $" { | |
39 | # Get the thread's id. | |
40 | set thre $expect_out(1,string) | |
41 | pass $test | |
42 | } | |
43 | } | |
44 | ||
45 | return $thre | |
46 | } | |
47 | ||
48 | proc check_thread_specific_breakpoint {mode} { | |
49 | with_test_prefix "$mode" { | |
50 | global gdb_prompt | |
51 | ||
52 | if ![runto_main] { | |
53 | untested "could not run to main" | |
54 | return -1 | |
55 | } | |
56 | ||
57 | set main_thre [get_thread_id "main"] | |
58 | if { $main_thre < 0 } { | |
59 | return -1 | |
60 | } | |
61 | ||
62 | gdb_breakpoint "start" | |
63 | gdb_continue_to_breakpoint "start" | |
64 | ||
65 | set start_thre [get_thread_id "start"] | |
66 | if { $start_thre < 0 } { | |
67 | return -1 | |
68 | } | |
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 reacheable 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 { $mode == "non-stop" } { | |
86 | set cmd "continue -a" | |
87 | } else { | |
88 | set cmd "continue" | |
89 | } | |
90 | gdb_test "$cmd" \ | |
91 | "Breakpoint .* end .* at .*" \ | |
92 | "continue to end" | |
93 | ||
94 | # Force GDB to update the thread list. Otherwise, depending | |
95 | # on target, GDB may not realize that the start thread has | |
96 | # exited and thus not remove the thread specific breakpoint. | |
97 | set test "thread start is gone" | |
98 | gdb_test_multiple "info threads" $test { | |
99 | -re "\[0-9\]+.*start.*$gdb_prompt $" { | |
100 | fail $test | |
101 | } | |
102 | -re "$gdb_prompt $" { | |
103 | pass $test | |
104 | } | |
105 | } | |
106 | ||
107 | set test "thread-specific breakpoint was deleted" | |
108 | gdb_test_multiple "info breakpoint" $test { | |
109 | -re "thread $start_thre\n$gdb_prompt $" { | |
110 | fail $test | |
111 | } | |
112 | -re "$gdb_prompt $" { | |
113 | pass $test | |
114 | } | |
115 | } | |
116 | } | |
117 | } | |
118 | ||
119 | # Test all-stop mode. | |
120 | check_thread_specific_breakpoint "all-stop" | |
121 | ||
122 | clean_restart ${binfile} | |
123 | ||
124 | # Test non-stop mode. | |
49fa26b0 PA |
125 | gdb_test_no_output "set non-stop on" "set non-stop mode" |
126 | check_thread_specific_breakpoint "non-stop" |