old-cross-binutils/gdb/testsuite/gdb.mi/mi-condbreak-call-thr-state.exp

117 lines
3.2 KiB
Text
Raw Normal View History

# Copyright (C) 2013-2016 Free Software Foundation, Inc.
PR15693 - Fix spurious *running events, thread state, dprintf-style call If one sets a breakpoint with a condition that involves calling a function in the inferior, and then the condition evaluates false, GDB outputs one *running event for each time the program hits the breakpoint. E.g., $ gdb return-false -i=mi (gdb) start ... (gdb) b 14 if return_false () &"b 14 if return_false ()\n" ~"Breakpoint 2 at 0x4004eb: file return-false.c, line 14.\n" ... ^done (gdb) c &"c\n" ~"Continuing.\n" ^running *running,thread-id=(...) (gdb) *running,thread-id=(...) *running,thread-id=(...) *running,thread-id=(...) *running,thread-id=(...) *running,thread-id=(...) ... repeat forever ... An easy way a user can trip on this is with a dprintf with "set dprintf-style call". In that case, a dprintf is just a breakpoint that when hit GDB calls the printf function in the inferior, and then resumes it, just like the case above. If the breakpoint/dprintf is set in a loop, then these spurious events can potentially slow down a frontend much, if it decides to refresh its GUI whenever it sees this event (Eclipse is one such case). When we run an infcall, we pretend we don't actually run the inferior. This is already handled for the usual case of calling a function directly from the CLI: (gdb) p return_false () &"p return_false ()\n" ~"$1 = 0" ~"\n" ^done (gdb) Note no *running, nor *stopped events. That's handled by: static void mi_on_resume (ptid_t ptid) { ... /* Suppress output while calling an inferior function. */ if (tp->control.in_infcall) return; and equivalent code on normal_stop. However, in the cases of the PR, after finishing the infcall there's one more resume, and mi_on_resume doesn't know that it should suppress output then too, somehow. The "running/stopped" state is a high level user/frontend state. Internal stops are invisible to the frontend. If follows from that that we should be setting the thread to running at a higher level where we still know the set of threads the user _intends_ to resume. Currently we mark a thread as running from within target_resume, a low level target operation. As consequence, today, if we resume a multi-threaded program while stopped at a breakpoint, we see this: -exec-continue ^running *running,thread-id="1" (gdb) *running,thread-id="all" The first *running was GDB stepping over the breakpoint, and the second is GDB finally resuming everything. Between those two *running's, threads other than "1" still have their state set to stopped. That's bogus -- in async mode, this opens a tiny window between both resumes where the user might try to run another execution command to threads other than thread 1, and very much confuse GDB. That is, the "step" below should fail the "step", complaining that the thread is running: (gdb) c -a & (gdb) thread 2 (gdb) step IOW, threads that GDB happens to not resume immediately (say, because it needs to step over a breakpoint) shall still be marked as running. Then, if we move marking threads as running to a higher layer, decoupled from target_resume, plus skip marking threads as running when running an infcall, the spurious *running events disappear, because there will be no state transitions at all. I think we might end up adding a new thread state -- THREAD_INFCALL or some such, however since infcalls are always synchronous today, I didn't find a need. There's no way to execute a CLI/MI command directly from the prompt if some thread is running an infcall. Tested on x86_64 Fedora 20. gdb/ 2014-05-29 Pedro Alves <palves@redhat.com> PR PR15693 * infrun.c (resume): Determine how much to resume depending on whether the caller wanted a step, not whether we can hardware step the target. Mark all threads that we intend to run as running, unless we're calling an inferior function. (normal_stop): If the thread is running an infcall, don't finish thread state. * target.c (target_resume): Don't mark threads as running here. gdb/testsuite/ 2014-05-29 Pedro Alves <palves@redhat.com> Hui Zhu <hui@codesourcery.com> PR PR15693 * gdb.mi/mi-condbreak-call-thr-state-mt.c: New file. * gdb.mi/mi-condbreak-call-thr-state-st.c: New file. * gdb.mi/mi-condbreak-call-thr-state.c: New file. * gdb.mi/mi-condbreak-call-thr-state.exp: New file.
2014-05-29 11:27:01 +00:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Regression test for PR15693. A breakpoint with a condition that
# calls a function that evaluates false would result in a spurious
# *running event sent to the frontend each time the breakpoint is hit
# (and the target re-resumed). Like:
#
# -exec-continue
# ^running
# *running,thread-id="all"
# (gdb)
# *running,thread-id="all"
# *running,thread-id="all"
# *running,thread-id="all"
# *running,thread-id="all"
# *running,thread-id="all"
# ...
load_lib mi-support.exp
set MIFLAGS "-i=mi"
# Run either the multi-threaded or the single-threaded variant of the
# test, as determined by VARIANT.
proc test { variant } {
global gdb_test_file_name
global testfile srcdir subdir srcfile srcfile2 binfile
global mi_gdb_prompt async
with_test_prefix "$variant" {
gdb_exit
if [mi_gdb_start] {
continue
}
set options {debug}
if {$variant == "mt" } {
lappend options "pthreads"
}
# Don't use standard_testfile as we need a different binary
# for each variant.
set testfile $gdb_test_file_name-$variant
set binfile [standard_output_file ${testfile}]
set srcfile $testfile.c
set srcfile2 $gdb_test_file_name.c
if {[build_executable "failed to prepare" \
$testfile \
"${srcfile} ${srcfile2}" \
$options] == -1} {
return -1
}
mi_delete_breakpoints
mi_gdb_reinitialize_dir $srcdir/$subdir
mi_gdb_reinitialize_dir $srcdir/$subdir
mi_gdb_load ${binfile}
mi_runto test
# Leave the breakpoint at 'test' set, on purpose. The next
# resume shall emit a single '*running,thread-id="all"', even
# if GDB needs to step over a breakpoint (that is, even if GDB
# needs to run only one thread for a little bit).
set bp_location [gdb_get_line_number "set breakpoint here" $srcfile2]
set bp_location_end [gdb_get_line_number "set end breakpoint here" $srcfile2]
mi_gdb_test "-break-insert -c return_false() $srcfile2:$bp_location" ".*" \
"insert conditional breakpoint"
mi_gdb_test "-break-insert $srcfile2:$bp_location_end" ".*" \
"insert end breakpoint"
set msg "no spurious *running notifications"
send_gdb "-exec-continue\n"
gdb_expect {
-re "\\*running.*\\*running.*\\*stopped" {
fail $msg
}
-re "\\^running\r\n\\*running,thread-id=\"all\"\r\n${mi_gdb_prompt}.*\\*stopped" {
pass $msg
}
timeout {
fail "$msg (timeout)"
}
}
# In sync mode, there's an extra prompt after *stopped. Consume it.
if {!$async} {
gdb_expect {
-re "$mi_gdb_prompt" {
}
}
}
}
}
# Single-threaded.
test "st"
# Multi-threaded.
test "mt"