public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Subject: [PATCH v2] Conditionally restore displaced stepping state after fork.
Date: Tue,  1 Jun 2021 14:11:37 -0700	[thread overview]
Message-ID: <20210601211137.83647-1-jhb@FreeBSD.org> (raw)
In-Reply-To: <20210531161558.10600-1-jhb@FreeBSD.org>

There is no default method for
gdbarch_displaced_step_restore_all_in_ptid, so calling it
unconditionally for fork events triggered an assertion failure on
platforms that do not support displaced stepping.  To fix, only invoke
the method if the gdbarch supports displaced stepping.

Note that not all gdbarches support both displaced stepping and fork
events, so gdbarch validation does not require
gdbarch_displaced_step_restore_all_in_ptid for any gdbarch supporting
displaced stepping.  However, the internal assertion in
gdbarch_displaced_step_restore_all_in_ptid should catch any gdbarches
which do support both but fail to provide this method.

gdb/ChangeLog:

	* infrun.c (handle_inferior_event): Only call
	gdbarch_displaced_step_restore_all_in_ptid if
	gdbarch_supports_displaced_stepping is true.
---
 gdb/ChangeLog |  6 ++++++
 gdb/infrun.c  | 16 ++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 03910c0634..b0f448a35e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2021-05-30  John Baldwin  <jhb@FreeBSD.org>
+
+	* infrun.c (handle_inferior_event): Only call
+	gdbarch_displaced_step_restore_all_in_ptid if
+	gdbarch_supports_displaced_stepping is true.
+
 2021-05-27  Simon Marchi  <simon.marchi@polymtl.ca>
 
 	* Fix tab after space indentation issues throughout.
diff --git a/gdb/infrun.c b/gdb/infrun.c
index e9624d2a9b..488bcc1e10 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -5493,10 +5493,18 @@ handle_inferior_event (struct execution_control_state *ecs)
 	struct gdbarch *gdbarch = regcache->arch ();
 	inferior *parent_inf = find_inferior_ptid (ecs->target, ecs->ptid);
 
-	/* If this is a fork (child gets its own address space copy) and some
-	   displaced step buffers were in use at the time of the fork, restore
-	   the displaced step buffer bytes in the child process.  */
-	if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
+	/* If this is a fork (child gets its own address space copy)
+	   and some displaced step buffers were in use at the time of
+	   the fork, restore the displaced step buffer bytes in the
+	   child process.
+
+	   Architectures which support displaced stepping and fork
+	   events must supply an implementation of
+	   gdbarch_displaced_step_restore_all_in_ptid.  This is not
+	   enforced during gdbarch validation to support architectures
+	   which support displaced stepping but not forks.  */
+	if (ecs->ws.kind == TARGET_WAITKIND_FORKED
+	    && gdbarch_supports_displaced_stepping (gdbarch))
 	  gdbarch_displaced_step_restore_all_in_ptid
 	    (gdbarch, parent_inf, ecs->ws.value.related_pid);
 
-- 
2.31.1


  parent reply	other threads:[~2021-06-01 21:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-31 16:15 [PATCH] " John Baldwin
2021-05-31 16:32 ` John Baldwin
2021-06-01  0:59 ` Simon Marchi
2021-06-01 17:25   ` John Baldwin
2021-06-01 21:11 ` John Baldwin [this message]
2021-06-01 21:18   ` [PATCH v2] " 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=20210601211137.83647-1-jhb@FreeBSD.org \
    --to=jhb@freebsd.org \
    --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).