gdb: LoongArch: Improve the handling of atomic sequence
[binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-pending.exp
blob4358c181509de048d0cf6cc3e5b98ac7b809791e
1 # Copyright 2007-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 load_lib mi-support.exp
17 set MIFLAGS "-i=mi"
20 # test running programs
23 require allow_shlib_tests
25 standard_testfile mi-pending.c
27 set libfile1 "mi-pendshr"
28 set libfile2 "mi-pendshr2"
29 set libsrc1  $srcdir/$subdir/$libfile1.c
30 set libsrc2  $srcdir/$subdir/$libfile2.c
31 set lib_sl1  [standard_output_file $libfile1.sl]
32 set lib_sl2  [standard_output_file $libfile2.sl]
33 set lib_opts debug
34 set exec_opts [list debug shlib=$lib_sl1 shlib_load]
36 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
37      || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
38     untested "failed to compile shared library"
39     return -1
42 if { [gdb_compile_pthreads $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
43     untested "failed to compile"
44     return -1
47 # Start with a fresh gdb.
48 if {[mi_clean_restart $binfile]} {
49     return
51 mi_load_shlibs $lib_sl1
52 mi_load_shlibs $lib_sl2
54 # Set pending breakpoint via MI.
55 mi_create_breakpoint_pending "-f pendfunc1" \
56     "MI pending breakpoint on pendfunc1" \
57     -number "1" \
58     -type "breakpoint" \
59     -disp "keep" \
60     -enabled "y" \
61     -pending "pendfunc1" \
62     -original-location "pendfunc1"
64 # Add some commands to the pending breakpoint, use -break-info to
65 # check that the commands show up, then clear the commands again.
66 mi_gdb_test "-break-commands 1 \"print 1\" \"print 2\" \"print 3\""\
67     "\\^done" \
68     "set breakpoint commands on pending breakpoint"
69 set bp [mi_make_breakpoint_pending -number 1 -disp keep \
70             -enabled y -original-location pendfunc1 \
71             -script {\["print 1","print 2","print 3"\]}]
72 mi_gdb_test "-break-info 1" \
73     "\\^done,[mi_make_breakpoint_table [list $bp]]" \
74     "breakpoint commands: check that commands are set"
75 mi_gdb_test "-break-commands 1"\
76     "\\^done" \
77     "clear breakpoint commands on pending breakpoint"
79 # Set pending breakpoint with a condition via MI.
80 mi_create_breakpoint_pending "-f -c x==4 ${libfile1}.c:pendfunc2" \
81     "MI pending breakpoint on ${libfile1}.c:pendfunc2 if x==4" \
82     -number "2" \
83     -type "breakpoint" \
84     -disp "keep" \
85     -enabled "y" \
86     -pending "${libfile1}.c:pendfunc2" \
87     -cond "x==4" \
88     -original-location "${libfile1}.c:pendfunc2"
90 # Set breakpoint so that we can stop when the thread is created
91 mi_create_breakpoint "-f thread_func" \
92     "MI breakpoint on thread_func" \
93     -number "3" \
94     -type "breakpoint" \
95     -disp "keep" \
96     -enabled "y" \
97     -addr "$hex" \
98     -func "thread_func"
100 mi_run_cmd
102 mi_expect_stop "breakpoint-hit" "pendfunc1" ".*" ".*" ".*" \
103     { "" "disp=\"keep\"" } \
104     "Run till MI pending breakpoint on pendfunc1"
106 mi_send_resuming_command "exec-continue" "continuing execution to skip conditional bp"
108 # We should not stop on the conditional breakpoint yet, but we stop on the original bp. 
109 mi_expect_stop "breakpoint-hit" "pendfunc1" ".*" ".*" ".*" \
110     { "" "disp=\"keep\"" } \
111     "Run till MI pending breakpoint on pendfunc1 a second time"
113 mi_send_resuming_command "exec-continue" "continuing execution to conditional bp"
115 # Now we should stop on the conditional breakpoint.
116 mi_expect_stop "breakpoint-hit" "pendfunc2" "\{name=\"x\",value=\"4\"\}" ".*" ".*" \
117     { "" "disp=\"keep\"" } \
118     "Run till MI pending breakpoint on pendfunc2 with x==4"
120 mi_send_resuming_command "exec-continue" "continuing execution to thread creation"
122 # Stop on thread creation so we can set a pending breakpoint with a thread cond.
123 mi_expect_stop "breakpoint-hit" "thread_func" ".*" ".*" ".*" \
124     { "" "disp=\"keep\"" } \
125     "Run till MI pending breakpoint on thread_func"
127 # Delete thread creation breakpoint to enable more than 1 thread to be created.
128 mi_gdb_test "-break-delete 3" "\\^done" "delete breakpoint 3"
130 # Set pending breakpoint with a thread via MI.
131 set bp [mi_make_breakpoint_pending -number "4" -type "breakpoint" \
132             -disp "keep" -enabled "y" -pending "pendfunc3" -thread "2" \
133             -times "0" -original-location "pendfunc3"]
134 mi_gdb_test "-break-insert -p 2 -f pendfunc3" ".*\\^done,$bp"\
135     "MI pending breakpoint on pendfunc3"
137 mi_send_resuming_command "exec-continue" "continuing execution to thread condition"
139 # Check if we stopped in thread 2 like we should.
140 set testname "run till MI pending breakpoint on pendfunc3 on thread 2"
141 gdb_expect {
142     -re "\\*stopped,reason=\"breakpoint-hit\",disp=\"keep\",bkptno=\"4\",frame=\{addr=\"$hex\",func=\"pendfunc3\".*thread-id=\"2\".*" {
143         pass $testname
144         return 0
145     }
146     timeout {
147         fail "$testname (timeout)"
148         return -1
149     }