2
0
mirror of https://sourceware.org/git/binutils-gdb.git synced 2025-03-13 13:49:00 +08:00
binutils-gdb/gdb/testsuite/gdb.multi/stop-all-on-exit.exp
Tankut Baris Aktemur 53cccef118 gdb/infrun: stop all threads if there exists a non-stop target
Stop all threads not only if the current target is non-stop, but also
if there exists a non-stop target.

The multi-target patch (5b6d1e4fa4 "Multi-target support") made the
following change to gdb/inf-child.c:

void
 inf_child_target::maybe_unpush_target ()
 {
-  if (!inf_child_explicitly_opened && !have_inferiors ())
+  if (!inf_child_explicitly_opened)
     unpush_target (this);
 }

If we are in all-stop mode with multiple inferiors, and an exit event
is received from an inferior, target_mourn_inferior() gets to this
point and without the have_inferiors() check, the target is unpushed.
This leads to having exec_ops as the top target.

Here is a test scenario.  Two executables, ./a.out returns
immediately; ./sleepy just sleeps.

  $ gdb ./sleepy
  (gdb) start
  ...
  (gdb) add-inferior -exec ./a.out
  ...
  (gdb) inferior 2
  [Switching to inferior 2..
  (gdb) start
  ...
  (gdb) set schedule-multiple on
  (gdb) set debug infrun 1
  (gdb) continue

At this point, the exit event is received from ./a.out.  Normally,
this would lead to stop_all_threads() to also stop ./sleepy, but this
doesn't happen, because target_is_non_stop_p() returns false.  And it
returns false because the top target is no longer the process target;
it is the exec_ops.

This patch modifies 'stop_waiting' to call 'stop_all_threads' if there
exists a non-stop target, not just when the current top target is
non-stop.

Tested on X86_64 Linux.

gdb/ChangeLog:
2020-04-01  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* infrun.c (stop_all_threads): Update assertion, plus when
	stopping threads, take into account that we might be trying
	to stop an all-stop target.
	(stop_waiting): Call 'stop_all_threads' if there exists a
	non-stop target.

gdb/testsuite/ChangeLog:
2020-04-01  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.multi/stop-all-on-exit.c: New test.
	* gdb.multi/stop-all-on-exit.exp: New file.
2020-04-01 21:33:06 +02:00

65 lines
2.0 KiB
Plaintext

# This testcase is part of GDB, the GNU debugger.
# Copyright 2020 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/>.
# Test that in all-stop mode with multiple inferiors, GDB stops all
# threads upon receiving an exit event from one of the inferiors.
standard_testfile
if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} {
return -1
}
if {![runto_main]} {
fail "starting inferior 1"
return -1
}
# This is a test specific for a native target, where we use the
# "-exec" argument to "add-inferior" and we explicitly don't do
# "maint set target-non-stop on".
if {![gdb_is_target_native]} {
untested "the test is aimed at a native target"
return 0
}
# Add a second inferior that will sleep longer.
gdb_test "add-inferior -exec $binfile" "Added inferior 2.*" \
"add the second inferior"
gdb_test "inferior 2" ".*Switching to inferior 2.*"
if {![runto_main]} {
fail "starting inferior 2"
return -1
}
gdb_test "print duration=10" "= 10"
# Now continue both processes. We should get the exit event from the
# first inferior.
gdb_test_no_output "set schedule-multiple on"
gdb_continue_to_end
# GDB is expected to have stopped the other inferior. Switch to the
# slow inferior's thread. It should not be running.
gdb_test_multiple "thread 2.1" "check thread 2.1 is not running" {
-re "\\(running\\)\[\r\n\]+$gdb_prompt" {
fail $gdb_test_name
}
-re "$gdb_prompt" {
pass $gdb_test_name
}
}