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
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]
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"
42 if { [gdb_compile_pthreads $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
43 untested "failed to compile"
47 # Start with a fresh gdb.
48 if {[mi_clean_restart $binfile]} {
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" \
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\""\
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"\
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" \
86 -pending "${libfile1}.c:pendfunc2" \
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" \
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"
142 -re "\\*stopped,reason=\"breakpoint-hit\",disp=\"keep\",bkptno=\"4\",frame=\{addr=\"$hex\",func=\"pendfunc3\".*thread-id=\"2\".*" {
147 fail "$testname (timeout)"