public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 03/14] gdb: restore displaced step buffer bytes when another thread forks
Date: Wed,  2 Dec 2020 10:47:54 -0500	[thread overview]
Message-ID: <20201202154805.1484317-4-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20201202154805.1484317-1-simon.marchi@polymtl.ca>

In handle_inferior_event, where we handle forks, we make sure to restore
the bytes of the displaced stepping buffer in the child's address
space.  However, we only do it when the forking thread was the one
doing a displaced step.  It could happen that a thread forks while
another one is doing a displaced step.  In this case, we also need to
restore the bytes in the child.

Move the byte-restoring code outside of the condition that checks
whether the event thread was displaced stepping.

gdb/ChangeLog:

	* infrun.c (handle_inferior_event): Restore displaced step
	buffer bytes in child process when handling fork, even if fork
	happened in another thread than the displaced-stepping one.

Change-Id: Ibb0daaeb123aba03f4fb4b4d820754eb2436bc69
---
 gdb/infrun.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 0e0a7a691c43..5c383b4d8a12 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -5302,25 +5302,27 @@ handle_inferior_event (struct execution_control_state *ecs)
       {
 	struct regcache *regcache = get_thread_regcache (ecs->event_thread);
 	struct gdbarch *gdbarch = regcache->arch ();
+	inferior *parent_inf = find_inferior_ptid (ecs->target, ecs->ptid);
 
-	/* If checking displaced stepping is supported, and thread
-	   ecs->ptid is displaced stepping.  */
+	/* If this is a fork (child gets its own address space copy) and the
+	   displaced step buffer was in use at the time of the fork, restore
+	   displaced step buffer bytes in the child process.  */
+	if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
+	  {
+	    displaced_step_inferior_state *displaced
+	      = get_displaced_stepping_state (parent_inf);
+
+	    if (displaced->step_thread != nullptr)
+	      displaced_step_restore (displaced, ecs->ws.value.related_pid);
+	  }
+
+	/* If displaced stepping is supported, and thread ecs->ptid is
+	   displaced stepping.  */
 	if (displaced_step_in_progress_thread (ecs->event_thread))
 	  {
-	    struct inferior *parent_inf
-	      = find_inferior_ptid (ecs->target, ecs->ptid);
 	    struct regcache *child_regcache;
 	    CORE_ADDR parent_pc;
 
-	    if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
-	      {
-		struct displaced_step_inferior_state *displaced
-		  = get_displaced_stepping_state (parent_inf);
-
-		/* Restore scratch pad for child process.  */
-		displaced_step_restore (displaced, ecs->ws.value.related_pid);
-	      }
-
 	    /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
 	       indicating that the displaced stepping of syscall instruction
 	       has been done.  Perform cleanup for parent process here.  Note
-- 
2.29.2


  parent reply	other threads:[~2020-12-02 15:48 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 15:47 [PATCH v2 00/14] Concurrent displaced stepping Simon Marchi
2020-12-02 15:47 ` [PATCH v2 01/14] gdb: add inferior_execd observable Simon Marchi
2020-12-04  1:45   ` Pedro Alves
2020-12-02 15:47 ` [PATCH v2 02/14] gdb: clear inferior displaced stepping state and in-line step-over info on exec Simon Marchi
2020-12-02 17:16   ` Simon Marchi
2020-12-04  1:54     ` Pedro Alves
2020-12-04 20:49       ` Simon Marchi
2020-12-04  1:48   ` Pedro Alves
2020-12-04 21:03     ` Simon Marchi
2020-12-02 15:47 ` Simon Marchi [this message]
2020-12-04  1:48   ` [PATCH v2 03/14] gdb: restore displaced step buffer bytes when another thread forks Pedro Alves
2020-12-02 15:47 ` [PATCH v2 04/14] gdb: get rid of get_displaced_stepping_state Simon Marchi
2020-12-04  1:48   ` Pedro Alves
2020-12-04 21:06     ` Simon Marchi
2020-12-02 15:47 ` [PATCH v2 05/14] gdb: rename things related to step over chains Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-04 21:04     ` Simon Marchi
2020-12-02 15:47 ` [PATCH v2 06/14] gdb: rename displaced_step_closure to displaced_step_copy_insn_closure Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-02 15:47 ` [PATCH v2 07/14] gdb: rename displaced_step_fixup to displaced_step_finish Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-02 15:47 ` [PATCH v2 08/14] gdb: introduce status enum for displaced step prepare/finish Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-04 21:08     ` Simon Marchi
2020-12-02 15:48 ` [PATCH v2 09/14] gdb: pass inferior to get_linux_inferior_data Simon Marchi
2020-12-04  1:50   ` Pedro Alves
2020-12-02 15:48 ` [PATCH v2 10/14] gdb: move displaced stepping types to displaced-stepping.{h, c} Simon Marchi
2020-12-04  1:50   ` Pedro Alves
2020-12-02 15:48 ` [PATCH v2 11/14] gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced steps Simon Marchi
2020-12-04  1:50   ` Pedro Alves
2020-12-04 21:11     ` Simon Marchi
2020-12-02 15:48 ` [PATCH v2 12/14] gdb: change linux gdbarch data from post to pre-init Simon Marchi
2020-12-04  1:50   ` Pedro Alves
2020-12-02 15:48 ` [PATCH v2 13/14] gdb: make displaced stepping implementation capable of managing multiple buffers Simon Marchi
2020-12-04  1:51   ` Pedro Alves
2020-12-04 21:14     ` Simon Marchi
2020-12-02 15:48 ` [PATCH v2 14/14] gdb: use two displaced step buffers on amd64/Linux Simon Marchi
2020-12-04  1:51   ` Pedro Alves
2020-12-04  1:56 ` [PATCH v2 00/14] Concurrent displaced stepping Pedro Alves
2020-12-04 21:52   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201202154805.1484317-4-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).