Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2008-2020 Free Software Foundation, Inc. |
1c5cfe86 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 | ||
d5b4a7be YQ |
16 | if { ![support_displaced_stepping] } { |
17 | unsupported "displaced stepping" | |
18 | return -1 | |
19 | } | |
20 | ||
1c5cfe86 PA |
21 | load_lib mi-support.exp |
22 | set MIFLAGS "-i=mi" | |
23 | ||
24 | gdb_exit | |
25 | if {[mi_gdb_start]} { | |
26 | continue | |
27 | } | |
28 | ||
29 | # | |
30 | # Start here | |
31 | # | |
298a9cf0 | 32 | standard_testfile nsmoribund.c |
1c5cfe86 | 33 | |
298a9cf0 | 34 | set options [list debug] |
1c5cfe86 PA |
35 | if {[gdb_compile_pthreads "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } { |
36 | return -1 | |
37 | } | |
38 | ||
39 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
40 | mi_gdb_load $binfile | |
41 | ||
1c5cfe86 | 42 | mi_gdb_test "-gdb-set non-stop 1" ".*" |
329ea579 | 43 | mi_gdb_test "-gdb-set mi-async 1" ".*" |
fcdfa280 | 44 | mi_detect_async |
1c5cfe86 | 45 | |
56a8e183 | 46 | if { [mi_run_to_main] < 0 } { |
56a8e183 | 47 | continue |
1c5cfe86 | 48 | } |
1c5cfe86 | 49 | |
7a9dd1b2 | 50 | # Keep this in sync with THREADS in the $srcfile. |
1c5cfe86 PA |
51 | set nthreads 10 |
52 | ||
53 | # Set a breakpoint and let all threads hit it (except the main | |
54 | # thread). | |
55 | ||
56 | set bkpt_line [gdb_get_line_number "set breakpoint here"] | |
57 | ||
4b48d439 KS |
58 | mi_create_breakpoint "$srcfile:$bkpt_line" \ |
59 | "breakpoint at thread_function" \ | |
60 | -number 2 -function thread_function | |
1c5cfe86 PA |
61 | |
62 | mi_send_resuming_command "exec-continue --all" "resume all" | |
63 | for {set i 0} {$i < $nthreads} {incr i} { | |
64 | mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \ | |
65 | "\[0-9\]*" {"" "disp=\"keep\""} "stop $i" | |
66 | } | |
67 | ||
68 | # All but the main thread should have hit it. | |
69 | ||
70 | mi_check_thread_states \ | |
71 | {"running" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped" "stopped"} \ | |
72 | "thread state: all stopped except the main thread" | |
73 | ||
74 | # Select a stopped thread to make sure we're able to delete | |
75 | # breakpoints | |
76 | mi_gdb_test "-thread-select 5" "\\^done.*" "select thread 5" | |
77 | ||
78 | # Now that we know about all the threads, we can get rid of | |
79 | # breakpoint. | |
80 | mi_delete_breakpoints | |
81 | ||
82 | # Recreate the same breakpoint, but this time, specific to thread 5. | |
998580f1 MK |
83 | mi_gdb_test "234-break-insert -p 5 $srcfile:$bkpt_line" \ |
84 | "234\\^done,bkpt=\{number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\".*\",func=\"thread_function\",file=\".*\",fullname=\".*\",line=\".*\",thread-groups=\\\[\".*\"\\\],thread=\"5\",thread=\"5\",times=\"0\",original-location=\".*\"\}" \ | |
85 | "thread specific breakpoint at thread_function" | |
1c5cfe86 PA |
86 | |
87 | # Resume all threads. Only thread 5 should report a stop. | |
88 | ||
89 | set running_re "" | |
d0b1d624 | 90 | for {set i $nthreads} {$i > 1} {incr i -1} { |
1c5cfe86 PA |
91 | set running_re "$running_re\\*running,thread-id=\"$decimal\"\r\n" |
92 | } | |
d0b1d624 MP |
93 | # Don't append \r\n after last line. |
94 | set running_re "$running_re\\*running,thread-id=\"$decimal\"" | |
1c5cfe86 | 95 | |
d0b1d624 MP |
96 | mi_gdb_test "-exec-continue --all" "\[^\n\]*\r\n$running_re" \ |
97 | "resume all, thread specific breakpoint" | |
1c5cfe86 PA |
98 | |
99 | mi_expect_stop "breakpoint-hit" "thread_function" "\[^\n\]*" "$srcfile" \ | |
100 | "\[0-9\]*" {"" "disp=\"keep\""} "hit thread specific breakpoint" | |
101 | ||
102 | # All threads except both thread 5 (and the main thread) should now be | |
103 | # repeatedly hitting the thread specific breakpoint and stepping over | |
104 | # it transparently. These are internal events, so the frontend should | |
105 | # see those threads as running. | |
106 | ||
107 | mi_check_thread_states \ | |
108 | {"running" "running" "running" "running" "stopped" "running" "running" "running" "running"} \ | |
109 | "thread state: all running except the breakpoint thread" | |
110 | ||
111 | # Get rid of the breakpoint while the other threads are stepping over | |
112 | # it, and tell all threads to exit. The program should exit | |
113 | # gracefully shortly. Send all commands in a row, since if something | |
114 | # goes wrong with moribund locations support or displaced stepping (or | |
115 | # a target bug if it can step over breakpoints itself), a spurious | |
116 | # SIGTRAP/SIGSEGV can come at any time after deleting the breakpoint. | |
2ed91d1b PA |
117 | # Note that this causes multiple prompts to appear before the output |
118 | # we are interested in, so we can't use mi_gdb_test or | |
119 | # gdb_test_multiple (or an MI equivalent) | |
1c5cfe86 | 120 | |
e809353a JK |
121 | mi_gdb_test "102-break-delete" "102\\^done.*" |
122 | mi_gdb_test "print done = 1" { = 1"} | |
123 | mi_gdb_test "103-exec-continue --all" "\[^\n\]*\r\n$running_re" | |
2ed91d1b PA |
124 | |
125 | gdb_expect { | |
126 | -re "\\*stopped,reason=\"exited-normally\"" { | |
127 | pass "resume all, program exited normally" | |
1c5cfe86 | 128 | } |
2ed91d1b PA |
129 | timeout { |
130 | fail "resume all, waiting for program exit (timeout)" | |
131 | } | |
132 | } | |
1c5cfe86 PA |
133 | |
134 | mi_gdb_exit |