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