Go to file
Simon Marchi 152a174956 gdb: prune inferiors at end of fetch_inferior_event, fix intermittent failure of gdb.threads/fork-plus-threads.exp
This test sometimes fail like this:

    info threads^M
      Id   Target Id         Frame ^M
      11.12 process 2270719   Couldn't get registers: No such process.^M
    (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: no threads left
    [Inferior 11 (process 2270719) exited normally]^M
    info inferiors^M
      Num  Description       Connection           Executable        ^M
    * 1    <null>                                 /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M
      11   <null>                                 /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.threads/fork-plus-threads/fork-plus-threads ^M
    (gdb) FAIL: gdb.threads/fork-plus-threads.exp: detach-on-fork=off: only inferior 1 left (the program exited)

I can get it to fail quite reliably by pinning it to a core:

  $ taskset -c 5 make check TESTS="gdb.threads/fork-plus-threads.exp"

The previous attempt at fixing this was:

  https://sourceware.org/pipermail/gdb-patches/2021-October/182846.html

What we see is part due to a possible unfortunate ordering of events
given by the kernel, and what could be considered a bug in GDB.

The test program makes a number of forks, waits them all, then exits.
Most of the time, GDB will get and process the exit event for inferior 1
after the exit events of all the children.  But this is not guaranteed.
After the last child exits and is waited by the parent, the parent can
exit quickly, such that GDB collects from the kernel the exit events for
the parent and that child at the same time.  It then chooses one event
at random, which can be the event for the parent.  This will result in
the parent appearing to exit before its child.  There's not much we can
do about it, so I think we have to adjust the test to cope.

After expect has seen the "exited normally" notification for inferior 1,
it immediately does an "info thread" that it expects to come back empty.
But at this point, GDB might not have processed inferior 11's (the last
child) exit event, so it will look like there is still a thread.  Of
course that thread is dead, we just don't know it yet.  But that makes
the "no thread" test fail.  If the test waited just a bit more for the
"exited normally" notification for inferior 11, then the list of threads
would be empty.

So, first change, make the test collect all the "exited normally"
notifications for all inferiors before proceeding, that should ensure we
see an empty thread list.  That would fix the first FAIL above.

However, we would still have the second FAIL, as we expect inferior 11
to not be there, it should have been deleted automatically.  Inferior 11
is normally deleted when prune_inferiors is called.  That is called by
normal_stop, which is only called by fetch_inferior_event only if the
event thread completed an execution command FSM (thread_fsm).  But the
FSM for the continue command completed when inferior 1 exited.  At that
point inferior 11 was not prunable, as it still had a thread.  When
inferior 11 exits, prune_inferiors is not called.

I think that can be considered a GDB bug.  From the user point of view,
there's no reason why in one case inferior 11 would be deleted and not
in the other case.

This patch makes the somewhat naive change to call prune_inferiors in
fetch_inferior_event, so that it is called in this case.  It is placed
at this particular point in the function so that it is called after the
user inferior / thread selection is restored.  If it was called before
that, inferior 11 wouldn't be pruned, because it would still be the
current inferior.

Change-Id: I48a15d118f30b1c72c528a9f805ed4974170484a
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=26272
2022-04-22 13:40:57 -04:00
bfd Automatic date update in version.in 2022-04-22 00:00:20 +00:00
binutils prune .note.GNU-stack warning from testsuite 2022-04-21 15:31:39 +09:30
config Add markers for 2.38 branch 2022-01-22 12:08:55 +00:00
contrib
cpu Add markers for 2.38 branch 2022-01-22 12:08:55 +00:00
elfcpp Add markers for 2.38 branch 2022-01-22 12:08:55 +00:00
etc
gas Delete unused COFF gas macro 2022-04-21 11:31:45 +09:30
gdb gdb: prune inferiors at end of fetch_inferior_event, fix intermittent failure of gdb.threads/fork-plus-threads.exp 2022-04-22 13:40:57 -04:00
gdbserver gdbsupport: make gdb_abspath return an std::string 2022-04-18 15:48:03 -04:00
gdbsupport gdbsupport: add path_join function 2022-04-21 11:11:21 -04:00
gnulib Update gnulib 2022-04-18 10:14:04 -06:00
gold Updated Serbian translations for the bfd, gold, ld and opcodes directories 2022-02-17 15:18:59 +00:00
gprof libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
gprofng gprofng doesn't build with gcc 5.5 2022-04-11 18:07:26 -07:00
include RISC-V: Add missing DECLARE_INSNs for Zicbo{m,p,z} 2022-04-22 09:31:02 +08:00
intl
ld prune .note.GNU-stack warning from testsuite 2022-04-21 15:31:39 +09:30
libbacktrace libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
libctf libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
libdecnumber
libiberty gdb: rename floatformats_ia64_quad to floatformats_ieee_quad 2022-04-02 08:36:33 +08:00
opcodes x86: VCMPSH is Evex.LLIG 2022-04-19 09:25:25 +02:00
readline
sim Fix for v850e divq instruction 2022-04-06 11:10:40 -04:00
texinfo
zlib Rebase the zlib sources to the 1.2.12 release 2022-04-12 16:24:10 +01:00
.cvsignore
.editorconfig Add top-level .editorconfig file 2022-01-28 08:25:42 -05:00
.gitattributes
.gitignore
ar-lib
ChangeLog Rebase the zlib sources to the 1.2.12 release 2022-04-12 16:24:10 +01:00
compile
config-ml.in
config.guess Update the config.guess and config.sub files from the master repository and regenerate files. 2022-01-17 16:21:22 +00:00
config.rpath
config.sub Update the config.guess and config.sub files from the master repository and regenerate files. 2022-01-17 16:21:22 +00:00
configure Pass PKG_CONFIG_PATH down from top-level Makefile 2022-04-08 10:56:41 -04:00
configure.ac Pass PKG_CONFIG_PATH down from top-level Makefile 2022-04-08 10:56:41 -04:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.LIBGLOSS
COPYING.NEWLIB
depcomp
djunpack.bat
install-sh
libtool.m4 libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS
Makefile.def gprofng: a new GNU profiler 2022-03-11 08:58:31 +00:00
Makefile.in Pass PKG_CONFIG_PATH down from top-level Makefile 2022-04-08 10:56:41 -04:00
Makefile.tpl Pass PKG_CONFIG_PATH down from top-level Makefile 2022-04-08 10:56:41 -04:00
makefile.vms
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
README-maintainer-mode
setup.com
src-release.sh gprofng: a new GNU profiler 2022-03-11 08:58:31 +00:00
symlink-tree
test-driver
ylwrap

		   README for GNU development tools

This directory contains various GNU compilers, assemblers, linkers, 
debuggers, etc., plus their support routines, definitions, and documentation.

If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README;  if with a libg++ release,
see libg++/README, etc.  That'll give you info about this
package -- supported targets, how to use it, how to report bugs, etc.

It is now possible to automatically configure and build a variety of
tools with one command.  To build all of the tools contained herein,
run the ``configure'' script here, e.g.:

	./configure 
	make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
	make install

(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''.  You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)

If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make.  For example (assuming sh/bash/ksh):

	CC=gcc ./configure
	make

A similar example using csh:

	setenv CC gcc
	./configure
	make

Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc.  See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.

REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.