binutils-gdb modified for the FreeChainXenon project
Find a file
Pedro Alves e0c01ce66d Don't stop all threads prematurely after first step of "step N"
In all-stop mode, when the target is itself in non-stop mode (like
GNU/Linux), if you use the "step N" (or "stepi/next/nexti N") to step
a thread a number of times:

 (gdb) help step
 step, s
 Step program until it reaches a different source line.
 Usage: step [N]
 Argument N means step N times (or till program stops for another reason).

... GDB prematurely stops all threads after the first step, and
doesn't re-resume them for the subsequent N-1 steps.  It's as if for
the 2nd and subsequent steps, the command was running with
scheduler-locking enabled.

This can be observed with the testcase added by this commit, which
looks like this:

 static pthread_barrier_t barrier;

 static void *
 thread_func (void *arg)
 {
   pthread_barrier_wait (&barrier);
   return NULL;
 }

 int
 main ()
 {
   pthread_t thread;
   int ret;

   pthread_barrier_init (&barrier, NULL, 2);

   /* We run to this line below, and then issue "next 3".  That should
      step over the 3 lines below and land on the return statement.  If
      GDB prematurely stops the thread_func thread after the first of
      the 3 nexts (and never resumes it again), then the join won't
      ever return.  */
   pthread_create (&thread, NULL, thread_func, NULL); /* set break here */
   pthread_barrier_wait (&barrier);
   pthread_join (thread, NULL);

   return 0;
 }

The test hangs and times out without the GDB fix:

 (gdb) next 3
 [New Thread 0x7ffff7d89700 (LWP 525772)]
 FAIL: gdb.threads/step-N-all-progress.exp: non-stop=off: target-non-stop=on: next 3 (timeout)

The problem is a core gdb bug.

When you do "step/stepi/next/nexti N", GDB internally creates a
thread_fsm object and associates it with the stepping thread.  For the
stepping commands, the FSM's class is step_command_fsm.  That object
is what keeps track of how many steps are left to make.  When one step
finishes, handle_inferior_event calls stop_waiting and returns, and
then fetch_inferior_event calls the "should_stop" method of the event
thread's FSM.  The implementation of that method decrements the
steps-left counter.  If the counter is 0, it returns true and we
proceed to presenting the stop to the user.  If it isn't 0 yet, then
the method returns false, indicating to fetch_inferior_event to "keep
going".

Focusing now on when the first step finishes -- we're in "all-stop"
mode, with the target in non-stop mode.  When a step finishes,
handle_inferior_event calls stop_waiting, which itself calls
stop_all_threads to stop everything.  I.e., after the first step
completes, all threads are stopped, before handle_inferior_event
returns.  And after that, now in fetch_inferior_event, we consult the
thread's thread_fsm::should_stop, which as we've seen, for the first
step returns false -- i.e., we need to keep_going for another step.
However, since the target is in non-stop mode, keep_going resumes
_only_ the current thread.  All the other threads remain stopped,
inadvertently.

If the target is in non-stop mode, we don't actually need to stop all
threads right after each step finishes, and then re-resume them again.
We can instead defer stopping all threads until all the steps are
completed.

So fix this by delaying the stopping of all threads until after we
called the FSM's "should_stop" method.  I.e., move it from
stop_waiting, to handle_inferior_events's callers,
fetch_inferior_event and wait_for_inferior.

New test included.  Tested on x86-64 GNU/Linux native and gdbserver.

Change-Id: Iaad50dcfea4464c84bdbac853a89df92ade6ae01
2022-07-20 15:10:24 +01:00
bfd Automatic date update in version.in 2022-07-20 00:00:20 +00:00
binutils [AArch64] Support AArch64 MTE memory tag dumps in core files 2022-07-19 15:24:27 +01:00
config Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
contrib Import mklog.py from gcc repo 2020-09-25 10:24:44 -04:00
cpu Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
elfcpp Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
etc Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
gas gas/symbols: introduce md_resolve_symbol 2022-07-20 12:20:14 +09:30
gdb Don't stop all threads prematurely after first step of "step N" 2022-07-20 15:10:24 +01:00
gdbserver gdbserver: remove unused variable 2022-07-13 20:10:18 +08:00
gdbsupport [gdbsupport] Improve thread scheduling in parallel_for_each 2022-07-18 08:34:06 +02:00
gnulib gnulib: update to bd11400942d6 2022-05-02 10:54:19 -04:00
gold Update version to 2.39.50 and regenerate files 2022-07-08 11:19:44 +01:00
gprof Regenerate with automake-1.15.1 2022-07-09 20:10:47 +09:30
gprofng gprofng: link libgprofng.so against -lpthread 2022-07-18 10:42:02 -07:00
include [AArch64] Support AArch64 MTE memory tag dumps in core files 2022-07-19 15:24:27 +01:00
intl Regenerate a couple of files 2021-11-15 12:20:12 +10:30
ld x86: Disallow invalid relocations against protected symbols 2022-07-19 08:41:52 -07:00
libbacktrace libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case 2022-03-25 12:02:35 +00:00
libctf Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
libdecnumber Merge config/ changes from GCC, to enable DFP on AArch64 2022-05-24 10:47:29 +01:00
libiberty Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
opcodes Re: opcodes/arc: Implement style support in the disassembler 2022-07-20 12:47:38 +09:30
readline gdb/readline: fix extra 'quit' message problem 2022-05-07 10:49:27 +01:00
sim sim: fix BFD_VMA format arguments on 32-bit hosts [PR gdb/29184] 2022-06-15 23:12:56 +01:00
texinfo
zlib Regenerate with automake-1.15.1 2022-07-09 20:10:47 +09:30
.cvsignore
.editorconfig Add top-level .editorconfig file 2022-01-28 08:25:42 -05:00
.gitattributes
.gitignore Add gnu global outputs to .gitignore 2020-12-02 10:00:27 -05:00
ar-lib Bump to autoconf 2.69 and automake 1.15.1 2018-06-19 16:55:06 -04:00
ChangeLog Add markers for 2.39 branch 2022-07-08 10:41:07 +01:00
compile
config-ml.in Update top level configure files by synchronizing them with gcc. 2018-01-10 15:29:21 +00:00
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 [gdb/build] Fix build breaker with --enable-shared 2022-06-27 15:36:19 +02:00
configure.ac [gdb/build] Fix build breaker with --enable-shared 2022-06-27 15:36:19 +02:00
COPYING
COPYING.LIB
COPYING.LIBGLOSS
COPYING.NEWLIB
COPYING3
COPYING3.LIB
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
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS MAINTAINERS: Update path to readline config.{sub,guess} files 2021-05-24 18:11:49 +02:00
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 Merge autoconf / automake update changes from GCC. 2018-10-31 17:10:56 +00:00
README
README-maintainer-mode Bump to autoconf 2.69 and automake 1.15.1 2018-06-19 16:55:06 -04:00
setup.com
src-release.sh gprofng: a new GNU profiler 2022-03-11 08:58:31 +00:00
symlink-tree
test-driver Bump to autoconf 2.69 and automake 1.15.1 2018-06-19 16:55:06 -04:00
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.