1 # Copyright 2007-2019 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 if {[skip_shlib_tests]} {
27 standard_testfile mi-pending.c
29 set libfile1 "mi-pendshr"
30 set libfile2 "mi-pendshr2"
31 set libsrc1 $srcdir/$subdir/$libfile1.c
32 set libsrc2 $srcdir/$subdir/$libfile2.c
33 set lib_sl1 [standard_output_file $libfile1.sl]
34 set lib_sl2 [standard_output_file $libfile2.sl]
36 set exec_opts [list debug shlib=$lib_sl1 shlib_load]
38 if [get_compiler_info] {
42 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
43 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
44 untested "failed to compile shared library"
48 if { [gdb_compile_pthreads $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
49 untested "failed to compile"
53 # Start with a fresh gdb.
56 mi_gdb_reinitialize_dir $srcdir/$subdir
57 mi_gdb_load ${binfile}
58 mi_load_shlibs $lib_sl1
59 mi_load_shlibs $lib_sl2
61 # Set pending breakpoint via MI.
62 mi_gdb_test "-break-insert -f pendfunc1" \
63 ".*\\^done,bkpt=\{number=\"1\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"<PENDING>\",pending=\"pendfunc1\",times=\"0\",original-location=\"pendfunc1\"\}"\
64 "MI pending breakpoint on pendfunc1"
66 # Set pending breakpoint with a condition via MI.
67 mi_gdb_test "-break-insert -f -c x==4 ${libfile1}.c:pendfunc2" \
68 ".*\\^done,bkpt=\{number=\"2\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"<PENDING>\",pending=\"${libfile1}.c:pendfunc2\",cond=\"x==4\",times=\"0\",original-location=\"${libfile1}.c:pendfunc2\"\}"\
69 "MI pending breakpoint on ${libfile1}.c:pendfunc2 if x==4"
71 # Set breakpoint so that we can stop when the thread is created
72 mi_gdb_test "-break-insert -f thread_func" \
73 ".*\\^done,bkpt=\{number=\"3\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"${hex}\",func=\"thread_func\".*\}"\
74 "MI pending breakpoint on thread_func"
78 mi_expect_stop "breakpoint-hit" "pendfunc1" ".*" ".*" ".*" \
79 { "" "disp=\"keep\"" } \
80 "Run till MI pending breakpoint on pendfunc1"
82 mi_send_resuming_command "exec-continue" "continuing execution to skip conditional bp"
84 # We should not stop on the conditional breakpoint yet, but we stop on the original bp.
85 mi_expect_stop "breakpoint-hit" "pendfunc1" ".*" ".*" ".*" \
86 { "" "disp=\"keep\"" } \
87 "Run till MI pending breakpoint on pendfunc1 a second time"
89 mi_send_resuming_command "exec-continue" "continuing execution to conditional bp"
91 # Now we should stop on the conditional breakpoint.
92 mi_expect_stop "breakpoint-hit" "pendfunc2" "\{name=\"x\",value=\"4\"\}" ".*" ".*" \
93 { "" "disp=\"keep\"" } \
94 "Run till MI pending breakpoint on pendfunc2 with x==4"
96 mi_send_resuming_command "exec-continue" "continuing execution to thread creation"
98 # Stop on thread creation so we can set a pending breakpoint with a thread cond.
99 mi_expect_stop "breakpoint-hit" "thread_func" ".*" ".*" ".*" \
100 { "" "disp=\"keep\"" } \
101 "Run till MI pending breakpoint on thread_func"
103 # Delete thread creation breakpoint to enable more than 1 thread to be created.
104 mi_gdb_test "-break-delete 3" "\\^done" "delete breakpoint 3"
106 # Set pending breakpoint with a thread via MI.
107 mi_gdb_test "-break-insert -p 2 -f pendfunc3" \
108 ".*\\^done,bkpt=\{number=\"4\",type=\"breakpoint\",disp=\"keep\",enabled=\"y\",addr=\"<PENDING>\",pending=\"pendfunc3\",thread=\"2\",thread=\"2\",times=\"0\",original-location=\"pendfunc3\"\}"\
109 "MI pending breakpoint on pendfunc3"
111 mi_send_resuming_command "exec-continue" "continuing execution to thread condition"
113 # Check if we stopped in thread 2 like we should.
114 set testname "run till MI pending breakpoint on pendfunc3 on thread 2"
116 -re "\\*stopped,reason=\"breakpoint-hit\",disp=\"keep\",bkptno=\"4\",frame=\{addr=\"$hex\",func=\"pendfunc3\".*thread-id=\"2\".*" {
121 fail "$testname (timeout)"