gdb+gdbserver/Linux: avoid reading registers while going through shell

For every stop, Linux GDB and GDBserver save the stopped thread's PC,
in lwp->stop_pc.  This is done in save_stop_reason, in both
gdb/linux-nat.c and gdbserver/linux-low.cc.  However, while we're
going through the shell after "run", in startup_inferior, we shouldn't
be reading registers, as we haven't yet determined the target's
architecture -- the shell's architecture may not even be the same as
the final inferior's.

In gdb/linux-nat.c, lwp->stop_pc is only needed when the thread has
stopped for a breakpoint, and since when going through the shell, no
breakpoint is going to hit, we could simply teach save_stop_reason to
only record the stop pc when the thread stopped for a breakpoint.

However, in gdbserver/linux-low.cc, lwp->stop_pc is used in more cases
than breakpoint hits (e.g., it's used in tracepoints & the
"while-stepping" feature).

So to avoid GDB vs GDBserver divergence, we apply the same approach to
both implementations.

We set a flag in the inferior (process in GDBserver) whenever it is
being nursed through the shell, and when that flag is set,
save_stop_reason bails out early.  While going through the shell,
we'll only ever get process exits (normal or signalled), random
signals, and exec events, so nothing is lost.

Change-Id: If0f01831514d3a74d17efd102875de7d2c6401ad
This commit is contained in:
Pedro Alves
2022-06-27 20:41:50 +01:00
parent 9117c7b452
commit a9deee17d3
6 changed files with 38 additions and 4 deletions

View File

@@ -18,6 +18,7 @@
#include "server.h"
#include "gdbsupport/job-control.h"
#include "gdbsupport/scoped_restore.h"
#include "nat/fork-inferior.h"
#ifdef HAVE_SIGNAL_H
#include <signal.h>
@@ -103,6 +104,10 @@ post_fork_inferior (int pid, const char *program)
atexit (restore_old_foreground_pgrp);
#endif
process_info *proc = find_process_pid (pid);
scoped_restore save_starting_up
= make_scoped_restore (&proc->starting_up, true);
startup_inferior (the_target, pid,
START_INFERIOR_TRAPS_EXPECTED,
&cs.last_status, &cs.last_ptid);