xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.mi/mi-pending.exp (revision 345cf9fb81bd0411c53e25d62cd93bdcaa865312)
1# Copyright 2007-2020 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
16load_lib mi-support.exp
17set MIFLAGS "-i=mi"
18
19#
20# test running programs
21#
22
23if {[skip_shlib_tests]} {
24    return 0
25}
26
27standard_testfile mi-pending.c
28
29set libfile1 "mi-pendshr"
30set libfile2 "mi-pendshr2"
31set libsrc1  $srcdir/$subdir/$libfile1.c
32set libsrc2  $srcdir/$subdir/$libfile2.c
33set lib_sl1  [standard_output_file $libfile1.sl]
34set lib_sl2  [standard_output_file $libfile2.sl]
35set lib_opts debug
36set exec_opts [list debug shlib=$lib_sl1 shlib_load]
37
38if [get_compiler_info] {
39    return -1
40}
41
42if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
43     || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
44    untested "failed to compile shared library"
45    return -1
46}
47
48if { [gdb_compile_pthreads $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
49    untested "failed to compile"
50    return -1
51}
52
53# Start with a fresh gdb.
54gdb_exit
55mi_gdb_start
56mi_gdb_reinitialize_dir $srcdir/$subdir
57mi_gdb_load ${binfile}
58mi_load_shlibs $lib_sl1
59mi_load_shlibs $lib_sl2
60
61# Set pending breakpoint via MI.
62mi_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"
65
66# Set pending breakpoint with a condition via MI.
67mi_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"
70
71# Set breakpoint so that we can stop when the thread is created
72mi_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"
75
76mi_run_cmd
77
78mi_expect_stop "breakpoint-hit" "pendfunc1" ".*" ".*" ".*" \
79    { "" "disp=\"keep\"" } \
80    "Run till MI pending breakpoint on pendfunc1"
81
82mi_send_resuming_command "exec-continue" "continuing execution to skip conditional bp"
83
84# We should not stop on the conditional breakpoint yet, but we stop on the original bp.
85mi_expect_stop "breakpoint-hit" "pendfunc1" ".*" ".*" ".*" \
86    { "" "disp=\"keep\"" } \
87    "Run till MI pending breakpoint on pendfunc1 a second time"
88
89mi_send_resuming_command "exec-continue" "continuing execution to conditional bp"
90
91# Now we should stop on the conditional breakpoint.
92mi_expect_stop "breakpoint-hit" "pendfunc2" "\{name=\"x\",value=\"4\"\}" ".*" ".*" \
93    { "" "disp=\"keep\"" } \
94    "Run till MI pending breakpoint on pendfunc2 with x==4"
95
96mi_send_resuming_command "exec-continue" "continuing execution to thread creation"
97
98# Stop on thread creation so we can set a pending breakpoint with a thread cond.
99mi_expect_stop "breakpoint-hit" "thread_func" ".*" ".*" ".*" \
100    { "" "disp=\"keep\"" } \
101    "Run till MI pending breakpoint on thread_func"
102
103# Delete thread creation breakpoint to enable more than 1 thread to be created.
104mi_gdb_test "-break-delete 3" "\\^done" "delete breakpoint 3"
105
106# Set pending breakpoint with a thread via MI.
107mi_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"
110
111mi_send_resuming_command "exec-continue" "continuing execution to thread condition"
112
113# Check if we stopped in thread 2 like we should.
114set testname "run till MI pending breakpoint on pendfunc3 on thread 2"
115gdb_expect {
116    -re "\\*stopped,reason=\"breakpoint-hit\",disp=\"keep\",bkptno=\"4\",frame=\{addr=\"$hex\",func=\"pendfunc3\".*thread-id=\"2\".*" {
117	pass $testname
118	return 0
119    }
120    timeout {
121	fail "$testname (timeout)"
122	return -1
123    }
124}
125