xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.mi/mi-condbreak-call-thr-state.exp (revision b2c35e17b976cf7ccd7250c86c6f5e95090ed636)
1# Copyright (C) 2013-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
16# Regression test for PR15693.  A breakpoint with a condition that
17# calls a function that evaluates false would result in a spurious
18# *running event sent to the frontend each time the breakpoint is hit
19# (and the target re-resumed).  Like:
20#
21#  -exec-continue
22#  ^running
23#  *running,thread-id="all"
24#  (gdb)
25#  *running,thread-id="all"
26#  *running,thread-id="all"
27#  *running,thread-id="all"
28#  *running,thread-id="all"
29#  *running,thread-id="all"
30#  ...
31
32load_lib mi-support.exp
33set MIFLAGS "-i=mi"
34
35# Run either the multi-threaded or the single-threaded variant of the
36# test, as determined by VARIANT.
37proc test { variant } {
38    global gdb_test_file_name
39    global testfile srcdir subdir srcfile srcfile2 binfile
40    global mi_gdb_prompt async
41
42    with_test_prefix "$variant" {
43	gdb_exit
44	if [mi_gdb_start] {
45	    continue
46	}
47
48	set options {debug}
49	if {$variant == "mt" } {
50	    lappend options "pthreads"
51	}
52
53	# Don't use standard_testfile as we need a different binary
54	# for each variant.
55	set testfile $gdb_test_file_name-$variant
56	set binfile [standard_output_file ${testfile}]
57	set srcfile $testfile.c
58	set srcfile2 $gdb_test_file_name.c
59
60	if {[build_executable "failed to prepare" \
61		 $testfile \
62		 "${srcfile} ${srcfile2}" \
63		 $options] == -1} {
64	    return -1
65	}
66
67	mi_delete_breakpoints
68	mi_gdb_reinitialize_dir $srcdir/$subdir
69	mi_gdb_reinitialize_dir $srcdir/$subdir
70	mi_gdb_load ${binfile}
71
72	mi_runto test
73
74	# Leave the breakpoint at 'test' set, on purpose.  The next
75	# resume shall emit a single '*running,thread-id="all"', even
76	# if GDB needs to step over a breakpoint (that is, even if GDB
77	# needs to run only one thread for a little bit).
78
79	set bp_location [gdb_get_line_number "set breakpoint here" $srcfile2]
80	set bp_location_end [gdb_get_line_number "set end breakpoint here" $srcfile2]
81
82	mi_gdb_test "-break-insert -c return_false() $srcfile2:$bp_location" ".*" \
83	    "insert conditional breakpoint"
84
85	mi_gdb_test "-break-insert $srcfile2:$bp_location_end" ".*" \
86	    "insert end breakpoint"
87
88	set msg "no spurious *running notifications"
89	send_gdb "-exec-continue\n"
90	gdb_expect {
91	    -re "\\*running.*\\*running.*\\*stopped" {
92		fail $msg
93	    }
94	    -re "\\^running\r\n\\*running,thread-id=\"all\"\r\n${mi_gdb_prompt}.*\\*stopped" {
95		pass $msg
96	    }
97	    timeout {
98		fail "$msg (timeout)"
99	    }
100	}
101
102	# In sync mode, there's an extra prompt after *stopped.  Consume it.
103	if {!$async} {
104	    gdb_expect {
105		-re "$mi_gdb_prompt" {
106		}
107	    }
108	}
109    }
110}
111
112# Single-threaded.
113test "st"
114
115# Multi-threaded.
116test "mt"
117