public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>, Pedro Alves <pedro@palves.net>
Subject: [PATCH 2/7] gdb: add inferior_forked observable
Date: Mon,  3 Apr 2023 14:52:03 -0400	[thread overview]
Message-ID: <20230403185208.197965-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230403185208.197965-1-simon.marchi@efficios.com>

In the upcoming patch to support fork in the amd-dbgapi target, the
amd-dbgapi target will need to be notified of fork events through an
observer, to attach itself (attach in the amd-dbgapi sense, not ptrace
sense) to the new inferior / process.

The reason that this can't be done through target_ops::follow_fork is
that the amd-dbgapi target isn't pushed on the inferior's target stack
right away.  It attaches itself to the process and only pushes itself on
its target stack if and when the inferior initializes the ROCm runtime.

If an inferior that is not using the ROCm runtime forks, we want to be
notified of it, so we can attach to the child, and catch if the child
starts using the ROCm runtime.

So, add a new observable and notify it in follow_fork_inferior.  It will
be used later in this series.

Change-Id: I67fced5a9cba6d5da72b9c7ea1c8397644ca1d54
Reviewed-By: Pedro Alves <pedro@palves.net>
---
 gdb/infrun.c     | 2 ++
 gdb/observable.c | 1 +
 gdb/observable.h | 9 +++++++++
 3 files changed, 12 insertions(+)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index c95a8e7ee1da..11a788467a8a 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -624,6 +624,8 @@ holding the child stopped.  Try \"set detach-on-fork\" or \
   target_follow_fork (child_inf, child_ptid, fork_kind, follow_child,
 		      detach_fork);
 
+  gdb::observers::inferior_forked.notify (parent_inf, child_inf, fork_kind);
+
   /* target_follow_fork must leave the parent as the current inferior.  If we
      want to follow the child, we make it the current one below.  */
   gdb_assert (current_inferior () == parent_inf);
diff --git a/gdb/observable.c b/gdb/observable.c
index 28249a5ad015..49de89c25e04 100644
--- a/gdb/observable.c
+++ b/gdb/observable.c
@@ -44,6 +44,7 @@ DEFINE_OBSERVABLE (target_changed);
 DEFINE_OBSERVABLE (executable_changed);
 DEFINE_OBSERVABLE (inferior_created);
 DEFINE_OBSERVABLE (inferior_execd);
+DEFINE_OBSERVABLE (inferior_forked);
 DEFINE_OBSERVABLE (record_changed);
 DEFINE_OBSERVABLE (solib_loaded);
 DEFINE_OBSERVABLE (solib_unloaded);
diff --git a/gdb/observable.h b/gdb/observable.h
index 00955cbc876b..3066cf68f314 100644
--- a/gdb/observable.h
+++ b/gdb/observable.h
@@ -21,6 +21,7 @@
 #define OBSERVABLE_H
 
 #include "gdbsupport/observable.h"
+#include "target/waitstatus.h"
 
 struct bpstat;
 struct so_list;
@@ -97,6 +98,14 @@ extern observable<inferior */* inferior */> inferior_created;
 extern observable<inferior */* exec_inf */, inferior */* follow_inf */>
     inferior_execd;
 
+/* The inferior PARENT_INF has forked.  If we are setting up an inferior for
+   the child (because we follow only the child or we follow both), CHILD_INF
+   is the child inferior.  Otherwise, CHILD_INF is nullptr.
+
+   FORK_KIND is TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED.  */
+extern observable<inferior */* parent_inf */, inferior */* child_inf */,
+		  target_waitkind /* fork_kind */> inferior_forked;
+
 /* The status of process record for inferior inferior in gdb has
    changed.  The process record is started if STARTED is true, and
    the process record is stopped if STARTED is false.
-- 
2.40.0


  parent reply	other threads:[~2023-04-03 18:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-03 18:52 [PATCH 0/7] amdgpu: handle fork and exec Simon Marchi
2023-04-03 18:52 ` [PATCH 1/7] gdb: pass execing and following inferior to inferior_execd observers Simon Marchi
2023-04-03 18:52 ` Simon Marchi [this message]
2023-04-03 18:52 ` [PATCH 3/7] gdb: remove regcache::target Simon Marchi
2023-04-03 18:52 ` [PATCH 4/7] gdb: add maybe_switch_inferior function Simon Marchi
2023-04-03 18:52 ` [PATCH 5/7] gdb: make regcache::raw_update switch to right inferior Simon Marchi
2023-04-03 18:52 ` [PATCH 6/7] gdb: switch to right inferior in fetch_inferior_event Simon Marchi
2023-04-03 18:52 ` [PATCH 7/7] gdb/amdgpu: add follow fork and exec support Simon Marchi
2023-04-13 15:54 ` [PATCH 0/7] amdgpu: handle fork and exec Simon Marchi
2023-04-17 17:57   ` 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=20230403185208.197965-3-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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).