gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced...
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 21 Jan 2020 21:08:01 +0000 (16:08 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 8 Jul 2020 18:19:09 +0000 (14:19 -0400)
commit9844051a443863782539114ecf8da690fe8a96c4
treee1341a6b68dbab1433484165cbf2e7efe6baf29f
parent7ccba087914c008843d1ac6078581d97f71c1ef4
gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced steps

Move displaced step logic to gdbarch
====================================

Currently, the task of preparing for a thread to execute a displaced
step is driven by the displaced_step_prepare_throw function.  It does
obviously some calls to the gdbarch to do the specific operations but
the high-level logic is in displaced_step_prepare_throw.  The steps are
roughly:

- Ask the gdbarch for the displaced step buffer location
- Save the existing bytes in the displaced step buffer
- Ask the gdbarch to copy the instruction into the displaced step buffer
- Set the pc of the thread to the beginning of the displaced step buffer

Similarly, the "fixup" phase, executed after the instruction was
successfully single-stepped, is driven by the infrun code (function
displaced_step_fixup).  The steps are roughly:

- Restore the original bytes in the displaced stepping buffer
- Ask the gdbarch to fixup the instruction result (adjust the target's
  registers or memory to do as if the instruction had been executed in
  its original location)

In order to allow some architectures to change how this is done (in
particular to allow using multiple displaced step buffers or sharing
displaced step buffers between threads), this patch makes the whole task
of preparing and finishing a displaced step gdbarch operations.

Two new gdbarch methods are added, with the following sematics:

  - gdbarch_displaced_step_prepare: Prepare for the given thread to
    execute a displaced step.  Upon return, everything should be ready
    for GDB to single step it.
  - gdbarch_displaced_step_finish: Apply any fixup required to
    compensate for the fact that the instruction was executed at
    different place than its original pc. Release any resources that was
    allocated for this displaced step.

The displaced_step_prepare_throw function now pretty much just offloads
to gdbarch_displaced_step_prepare and the displaced_step_finish function
(renamed from displaced_step_fixup) offloads to
gdbarch_displaced_step_finish.

To keep the existing behavior, the logic that was previously implemented
in infrun.c is moved to a new displaced-stepping.c file.  Architectures
currently using displaced stepping are modified to use that new file to
implement the gdbarch methods.

Allow starting concurrent displaced steps
=========================================

Currently, there can only be a single displaced step in progress for
each inferior.  This is enforced in start_step_over:

      /* If this inferior already has a displaced step in process,
 don't start a new one.  */
      if (displaced_step_in_progress (tp->inf))
continue;

Since we want to allow concurrent displaced steps, we need to remove
this constraint.  The core part of GDB handling displaced steps, in
infrun.c, now tries to start as many step-overs as possible.  The
implementation provided by the gdbarch is responsible to decide whether
a given can do a displaced step at this time, and if it is, prepare it.
15 files changed:
gdb/Makefile.in
gdb/amd64-linux-tdep.c
gdb/amd64-tdep.c
gdb/displaced-stepping.c [new file with mode: 0644]
gdb/displaced-stepping.h [new file with mode: 0644]
gdb/gdbarch.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/gdbthread.h
gdb/i386-linux-tdep.c
gdb/infrun.c
gdb/infrun.h
gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
gdb/testsuite/gdb.threads/forking-threads-plus-breakpoint.exp
gdb/thread.c
This page took 0.025844 seconds and 4 git commands to generate.