binutils-gdb/gdb/testsuite/gdb.threads/multiple-successive-infcall.exp
Andrew Burgess 9516f85aea gdb: Mark async event handler when event is already pending
In PR22882 inferior functions are called on different threads while
scheduler-locking is turned on.  This results in a hang.  This was
discussed in this mailing list thread:

    https://sourceware.org/ml/gdb/2017-10/msg00032.html

The problem is that when the thread is set running in order to execute
the inferior call, a call to target_async is made.  If the target is
not already registered as 'target_async' then this will install the
async event handler, AND unconditionally mark the handler as having an
event pending.

However, if the target is already registered as target_async then the
event handler is not installed (its already installed) and the
handler is NOT marked as having an event pending.

If we try to set running a thread that already has a pending event,
then we do want to set target_async, however, there will not be an
external event incoming (the thread is already stopped) so we rely on
manually marking the event handler as having a pending event in order
to see the threads pending stop event.  This is fine, if, at the point
where we call target_async, the target is not already marked as async.
But, if it is, then the event handler will not be marked as ready, and
the threads pending stop event will never be processed.

A similar pattern of code can be seen in linux_nat_target::resume,
where, when a thread has a pending event, the call to target_async is
followed by a call to async_file_mark to ensure that the pending
thread event will be processed, even if target_async was already set.

gdb/ChangeLog:

	PR gdb/22882
	* infrun.c (resume_1): Add call to mark_async_event_handler.

gdb/testsuite/ChangeLog:

	* gdb.threads/multiple-successive-infcall.exp: Remove kfail case,
	rewrite test to describe action performed, rather than possible
	failure.
2018-06-12 21:15:33 +01:00

62 lines
2.0 KiB
Plaintext

# Copyright (C) 2018 Free Software Foundation, Inc.
# 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/>. */
# multiple-successive-infcall.exp -- Test if GDB can invoke functions on
# multiple inferiors, one after the other.
standard_testfile
if [get_compiler_info] {
return -1
}
if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
executable {debug}] != "" } {
return -1
}
clean_restart "${binfile}"
if ![runto_main] then {
fail "can't run to main"
return 0
}
# Ensure that each new thread is detected by GDB in the order that the
# test case creates them, so the thread identifiers match between
# test and test case.
gdb_breakpoint [gdb_get_line_number "prethreadcreationmarker"]
gdb_continue_to_breakpoint "prethreadcreationmarker"
set after_new_thread_message "created new thread"
foreach_with_prefix thread {5 4 3} {
gdb_test_multiple "continue" "${after_new_thread_message}" {
-re "\\\[New Thread ${hex} \\\(LWP \[0-9\]+\\\)\\\].*${gdb_prompt}" {
pass "${after_new_thread_message}"
}
}
}
gdb_breakpoint [gdb_get_line_number "testmarker01"]
gdb_continue_to_breakpoint "testmarker01"
gdb_test_no_output "set scheduler-locking on"
gdb_test "show scheduler-locking" \
"Mode for locking scheduler during execution is \"on\"."
foreach_with_prefix thread {5 4 3 2 1} {
gdb_test "thread ${thread}" "Switching to .*"
gdb_test "call get_value()" "= ${thread}" \
"call inferior function"
}