Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Pedro Alves <palves@redhat.com>,
	gdb-patches@sourceware.org,
	Andrew Burgess <andrew.burgess@embecosm.com>
Subject: Re: [PATCH v2 18/24] Multi-target support
Date: Sun, 12 Jan 2020 20:17:00 -0000	[thread overview]
Message-ID: <113c6953-3621-c61b-e318-19806805e878@simark.ca> (raw)
In-Reply-To: <20191017225026.30496-19-palves@redhat.com>

On 2019-10-17 6:50 p.m., Pedro Alves wrote:
> This commit adds multi-target support to GDB.  What this means is that
> with this commit, GDB can now be connected to different targets at the
> same time.  E.g., you can debug a live native process and a core dump
> at the same time, connect to multiple gdbservers, etc.
>
> ...

remote-sim.c needs to be updated to.  The patch below makes it build, although
I have not tried it (I don't have time right now to re-figure out again how do
do it :)).

From 3342486f68499477f38d90c775f496846cb0d65e Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Sun, 12 Jan 2020 14:30:18 -0500
Subject: [PATCH] gdb: adjust remote-sim.c to multi-target

The remote-sim.c file doesn't build since the main multi-target patch
(5b6d1e4f, "Multi-target support"), this patch is an attempt to fix it.
I have only build-tested it, so I'm not sure it runs fine, but it should
get us close at least.

I made these functions methods of the gdbsim_target, because they need
to pass the target down to some GDB core functions, like
find_inferior_ptid:

 - get_sim_inferior_data_by_ptid (renamed to get_inferior_data_by_ptid)
 - gdbsim_resume_inferior (renamed to resume_one_inferior)
 - gdbsim_close_inferior (renamed to close_one_inferior)

In the last two, I changed iterate_over_inferiors to a range-based for,
since that gives simpler code (no need to pass data through the void
pointer).

The next_pid variable, INITIAL_PID macro and sim_inferior_data structure
are simply moved up in the file, above gdbsim_target.

gdb/ChangeLog:

	* remote-sim.c (next_pid, INITIAL_PID, sim_inferior_data): Move
	up.
	(gdbsim_target) <get_inferior_data_by_ptid, resume_one_inferior,
	close_one_inferior>: New methods.
	(get_sim_inferior_data_by_ptid): Move to gdbsim_target,
	pass down target to find_inferior_pid.
	(gdbsim_target::fetch_registers, gdbsim_target::store_registers):
	Pass down target to find_inferior_ptid.
	(gdbsim_target::create_inferior): Pass down target to
	add_thread_silent.
	(gdbsim_close_inferior): Move to gdbsim_close_inferior, pass
	target down to find_inferior_ptid and switch_to_thread.
	(gdbsim_target::close): Update to call close_one_inferior.
	(struct resume_data): Remove.
	(gdbsim_resume_inferior): Move to gdbsim_target.  Take arguments
	directly, rather than through a void pointer.
	(gdbsim_target::resume): Update to call resume_one_inferior.
---
 gdb/remote-sim.c | 146 +++++++++++++++++++++++------------------------
 1 file changed, 70 insertions(+), 76 deletions(-)

diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 582d206d60c7..533c0d6a9e12 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -74,6 +74,43 @@ static void gdb_os_error (host_callback *, const char *, ...)
    sim_* are the interface to the simulator (see remote-sim.h).
    gdbsim_* are stuff which is internal to gdb.  */

+/* Value of the next pid to allocate for an inferior.  As indicated
+   elsewhere, its initial value is somewhat arbitrary; it's critical
+   though that it's not zero or negative.  */
+static int next_pid;
+#define INITIAL_PID 42000
+
+/* Simulator-specific, per-inferior state.  */
+struct sim_inferior_data {
+  explicit sim_inferior_data (SIM_DESC desc)
+    : gdbsim_desc (desc),
+      remote_sim_ptid (next_pid, 0, next_pid)
+  {
+    ++next_pid;
+  }
+
+  ~sim_inferior_data ();
+
+  /* Flag which indicates whether or not the program has been loaded.  */
+  int program_loaded = 0;
+
+  /* Simulator descriptor for this inferior.  */
+  SIM_DESC gdbsim_desc;
+
+  /* This is the ptid we use for this particular simulator instance.  Its
+     value is somewhat arbitrary, as the simulator target don't have a
+     notion of tasks or threads, but we need something non-null to place
+     in inferior_ptid.  For simulators which permit multiple instances,
+     we also need a unique identifier to use for each inferior.  */
+  ptid_t remote_sim_ptid;
+
+  /* Signal with which to resume.  */
+  enum gdb_signal resume_siggnal = GDB_SIGNAL_0;
+
+  /* Flag which indicates whether resume should step or not.  */
+  int resume_step = 0;
+};
+
 static const target_info gdbsim_target_info = {
   "sim",
   N_("simulator"),
@@ -126,47 +163,16 @@ struct gdbsim_target final

   bool has_all_memory ()  override;
   bool has_memory ()  override;
+
+private:
+  sim_inferior_data *get_inferior_data_by_ptid (ptid_t ptid,
+						int sim_instance_needed);
+  void resume_one_inferior (inferior *inf, bool step, gdb_signal siggnal);
+  void close_one_inferior (inferior *inf);
 };

 static struct gdbsim_target gdbsim_ops;

-/* Value of the next pid to allocate for an inferior.  As indicated
-   elsewhere, its initial value is somewhat arbitrary; it's critical
-   though that it's not zero or negative.  */
-static int next_pid;
-#define INITIAL_PID 42000
-
-/* Simulator-specific, per-inferior state.  */
-struct sim_inferior_data {
-  explicit sim_inferior_data (SIM_DESC desc)
-    : gdbsim_desc (desc),
-      remote_sim_ptid (next_pid, 0, next_pid)
-  {
-    ++next_pid;
-  }
-
-  ~sim_inferior_data ();
-
-  /* Flag which indicates whether or not the program has been loaded.  */
-  int program_loaded = 0;
-
-  /* Simulator descriptor for this inferior.  */
-  SIM_DESC gdbsim_desc;
-
-  /* This is the ptid we use for this particular simulator instance.  Its
-     value is somewhat arbitrary, as the simulator target don't have a
-     notion of tasks or threads, but we need something non-null to place
-     in inferior_ptid.  For simulators which permit multiple instances,
-     we also need a unique identifier to use for each inferior.  */
-  ptid_t remote_sim_ptid;
-
-  /* Signal with which to resume.  */
-  enum gdb_signal resume_siggnal = GDB_SIGNAL_0;
-
-  /* Flag which indicates whether resume should step or not.  */
-  int resume_step = 0;
-};
-
 static inferior_key<sim_inferior_data> sim_inferior_data_key;

 /* Flag indicating the "open" status of this module.  It's set to 1
@@ -262,8 +268,9 @@ get_sim_inferior_data (struct inferior *inf, int sim_instance_needed)
    inferior in question.  Return NULL when no inferior is found or
    when ptid has a zero or negative pid component.  */

-static struct sim_inferior_data *
-get_sim_inferior_data_by_ptid (ptid_t ptid, int sim_instance_needed)
+sim_inferior_data *
+gdbsim_target::get_inferior_data_by_ptid (ptid_t ptid,
+					  int sim_instance_needed)
 {
   struct inferior *inf;
   int pid = ptid.pid ();
@@ -271,7 +278,7 @@ get_sim_inferior_data_by_ptid (ptid_t ptid, int sim_instance_needed)
   if (pid <= 0)
     return NULL;

-  inf = find_inferior_pid (pid);
+  inf = find_inferior_pid (this, pid);

   if (inf)
     return get_sim_inferior_data (inf, sim_instance_needed);
@@ -441,7 +448,7 @@ void
 gdbsim_target::fetch_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct inferior *inf = find_inferior_ptid (regcache->ptid ());
+  struct inferior *inf = find_inferior_ptid (this, regcache->ptid ());
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (inf, SIM_INSTANCE_NEEDED);

@@ -510,7 +517,7 @@ void
 gdbsim_target::store_registers (struct regcache *regcache, int regno)
 {
   struct gdbarch *gdbarch = regcache->arch ();
-  struct inferior *inf = find_inferior_ptid (regcache->ptid ());
+  struct inferior *inf = find_inferior_ptid (this, regcache->ptid ());
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (inf, SIM_INSTANCE_NEEDED);

@@ -656,7 +663,7 @@ gdbsim_target::create_inferior (const char *exec_file,

   inferior_ptid = sim_data->remote_sim_ptid;
   inferior_appeared (current_inferior (), inferior_ptid.pid ());
-  add_thread_silent (inferior_ptid);
+  add_thread_silent (this, inferior_ptid);

   insert_breakpoints ();	/* Needed to get correct instruction
 				   in cache.  */
@@ -770,8 +777,8 @@ gdbsim_target_open (const char *args, int from_tty)
 /* Callback for iterate_over_inferiors.  Called (indirectly) by
    gdbsim_close().  */

-static int
-gdbsim_close_inferior (struct inferior *inf, void *arg)
+void
+gdbsim_target::close_one_inferior (inferior *inf)
 {
   struct sim_inferior_data *sim_data = sim_inferior_data_key.get (inf);
   if (sim_data != NULL)
@@ -785,14 +792,12 @@ gdbsim_close_inferior (struct inferior *inf, void *arg)
 	 Thus we need to verify the existence of an inferior using the
 	 pid in question before setting inferior_ptid via
 	 switch_to_thread() or mourning the inferior.  */
-      if (find_inferior_ptid (ptid) != NULL)
+      if (find_inferior_ptid (this, ptid) != NULL)
 	{
-	  switch_to_thread (ptid);
+	  switch_to_thread (this, ptid);
 	  generic_mourn_inferior ();
 	}
     }
-
-  return 0;
 }

 /* Close out all files and local state before this target loses control.  */
@@ -803,7 +808,8 @@ gdbsim_target::close ()
   if (remote_debug)
     fprintf_unfiltered (gdb_stdlog, "gdbsim_close\n");

-  iterate_over_inferiors (gdbsim_close_inferior, NULL);
+  for (inferior *inf : all_inferiors (this))
+    close_one_inferior (inf);

   if (sim_argv != NULL)
     {
@@ -839,45 +845,30 @@ gdbsim_target::detach (inferior *inf, int from_tty)
    or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given
    to the target, or zero for no signal.  */

-struct resume_data
-{
-  enum gdb_signal siggnal;
-  int step;
-};
-
-static int
-gdbsim_resume_inferior (struct inferior *inf, void *arg)
+void
+gdbsim_target::resume_one_inferior (inferior *inf, bool step,
+				    gdb_signal siggnal)
 {
   struct sim_inferior_data *sim_data
     = get_sim_inferior_data (inf, SIM_INSTANCE_NOT_NEEDED);
-  struct resume_data *rd = (struct resume_data *) arg;

   if (sim_data)
     {
-      sim_data->resume_siggnal = rd->siggnal;
-      sim_data->resume_step = rd->step;
+      sim_data->resume_siggnal = siggnal;
+      sim_data->resume_step = step;

       if (remote_debug)
 	fprintf_unfiltered (gdb_stdlog,
 			    _("gdbsim_resume: pid %d, step %d, signal %d\n"),
-			    inf->pid, rd->step, rd->siggnal);
+			    inf->pid, step, siggnal);
     }
-
-  /* When called from iterate_over_inferiors, a zero return causes the
-     iteration process to proceed until there are no more inferiors to
-     consider.  */
-  return 0;
 }

 void
 gdbsim_target::resume (ptid_t ptid, int step, enum gdb_signal siggnal)
 {
-  struct resume_data rd;
   struct sim_inferior_data *sim_data
-    = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NOT_NEEDED);
-
-  rd.siggnal = siggnal;
-  rd.step = step;
+    = get_inferior_data_by_ptid (ptid, SIM_INSTANCE_NOT_NEEDED);

   /* We don't access any sim_data members within this function.
      What's of interest is whether or not the call to
@@ -887,9 +878,12 @@ gdbsim_target::resume (ptid_t ptid, int step, enum gdb_signal siggnal)
      either have multiple inferiors to resume or an error condition.  */

   if (sim_data)
-    gdbsim_resume_inferior (find_inferior_ptid (ptid), &rd);
+    resume_one_inferior (find_inferior_ptid (this, ptid), step, siggnal);
   else if (ptid == minus_one_ptid)
-    iterate_over_inferiors (gdbsim_resume_inferior, &rd);
+    {
+      for (inferior *inf : all_inferiors (this))
+	resume_one_inferior (inf, step, siggnal);
+    }
   else
     error (_("The program is not being run."));
 }
@@ -969,7 +963,7 @@ gdbsim_target::wait (ptid_t ptid, struct target_waitstatus *status, int options)
 				      SIM_INSTANCE_NEEDED);
   else
     {
-      sim_data = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NEEDED);
+      sim_data = get_inferior_data_by_ptid (ptid, SIM_INSTANCE_NEEDED);
       if (sim_data == NULL)
 	error (_("Unable to wait for pid %d.  Inferior not found."),
 	       ptid.pid ());
@@ -1248,7 +1242,7 @@ bool
 gdbsim_target::thread_alive (ptid_t ptid)
 {
   struct sim_inferior_data *sim_data
-    = get_sim_inferior_data_by_ptid (ptid, SIM_INSTANCE_NOT_NEEDED);
+    = get_inferior_data_by_ptid (ptid, SIM_INSTANCE_NOT_NEEDED);

   if (sim_data == NULL)
     return false;
-- 
2.24.1




  parent reply	other threads:[~2020-01-12 19:57 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 22:50 [PATCH v2 00/24] " Pedro Alves
2019-10-17 22:50 ` [PATCH v2 17/24] Fix reconnecting to a gdbserver already debugging multiple processes, II Pedro Alves
2019-10-17 22:50 ` [PATCH v2 01/24] Preserve selected thread in all-stop w/ background execution Pedro Alves
2019-11-01 13:20   ` Tom Tromey
2019-12-20 17:22     ` Pedro Alves
2019-12-20 18:54       ` Tom Tromey
2019-12-20 18:57         ` Pedro Alves
2019-12-20 18:57           ` Tom Tromey
2019-10-17 22:50 ` [PATCH v2 16/24] Fix reconnecting to a gdbserver already debugging multiple processes, I Pedro Alves
2019-10-17 22:50 ` [PATCH v2 06/24] Don't check target is running in remote_target::mourn_inferior Pedro Alves
2019-10-17 22:50 ` [PATCH v2 21/24] Revert 'Remove unused struct serial::name field' Pedro Alves
2019-10-17 22:50 ` [PATCH v2 12/24] Use all_non_exited_inferiors in infrun.c Pedro Alves
2019-10-17 22:50 ` [PATCH v2 09/24] switch inferior/thread before calling target methods Pedro Alves
2019-10-17 22:50 ` [PATCH v2 02/24] Don't rely on inferior_ptid in record_full_wait Pedro Alves
2019-11-01 14:54   ` Tom Tromey
2019-12-20 17:49     ` Pedro Alves
2019-12-20 18:57       ` Tom Tromey
2019-10-17 22:50 ` [PATCH v2 03/24] Make "show remote exec-file" inferior-aware Pedro Alves
2019-10-17 22:50 ` [PATCH v2 10/24] Some get_last_target_status tweaks Pedro Alves
2019-10-17 22:50 ` [PATCH v2 15/24] Avoid another inferior_ptid reference in gdb/remote.c Pedro Alves
2019-10-17 22:50 ` [PATCH v2 11/24] tfile_target::close: trace_fd can't be -1 Pedro Alves
2019-10-17 22:51 ` [PATCH v2 19/24] Add multi-target tests Pedro Alves
2019-10-17 22:51 ` [PATCH v2 04/24] exceptions.c:print_flush: Remove obsolete check Pedro Alves
2019-10-17 22:51 ` [PATCH v2 22/24] Add "info connections" command, "info inferiors" connection number/string Pedro Alves
2019-10-17 22:51 ` [PATCH v2 18/24] Multi-target support Pedro Alves
2020-01-11  3:12   ` Simon Marchi
2020-01-12  1:58     ` [pushed] Remove last traces of discard_all_inferiors (Re: [PATCH v2 18/24] Multi-target support) Pedro Alves
2020-01-12 20:17   ` Simon Marchi [this message]
2020-01-13 15:19     ` [PATCH v2 18/24] Multi-target support Pedro Alves
2020-01-13 16:37       ` Simon Marchi
2020-01-12 22:30   ` Simon Marchi
2020-01-13 15:59     ` Pedro Alves
2020-01-17  4:03   ` Simon Marchi
2020-01-17 16:19     ` Simon Marchi
2020-01-17 15:18   ` Simon Marchi
2020-05-16  8:16   ` Andreas Schwab
2020-05-16 11:33     ` Fix IA-64 GNU/Linux build (Re: [PATCH v2 18/24] Multi-target support) Pedro Alves
2019-10-17 22:57 ` [PATCH v2 07/24] Delete unnecessary code from kill_command Pedro Alves
2019-10-17 22:57 ` [PATCH v2 05/24] Make target_ops::has_execution take an 'inferior *' instead of a ptid_t Pedro Alves
2019-10-17 22:57 ` [PATCH v2 23/24] Require always-non-stop for multi-target resumptions Pedro Alves
2019-11-01 14:51   ` Tom Tromey
2019-12-30 18:30     ` Pedro Alves
2019-12-31 20:06       ` Tom Tromey
2019-10-17 22:59 ` [PATCH v2 13/24] Delete exit_inferior_silent(int pid) Pedro Alves
2019-10-17 22:59 ` [PATCH v2 20/24] gdbarch-selftests.c: No longer error out if debugging something Pedro Alves
2019-10-17 22:59 ` [PATCH v2 24/24] Multi-target: NEWS and user manual Pedro Alves
2019-10-17 22:59 ` [PATCH v2 08/24] Introduce switch_to_inferior_no_thread Pedro Alves
2019-11-07  9:14   ` Paunovic, Aleksandar
2019-12-20 18:50     ` Pedro Alves
2019-12-23 19:30       ` [PATCH] Switch the inferior too in switch_to_program_space_and_thread (Re: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread) Pedro Alves
2020-01-08 15:48         ` Aktemur, Tankut Baris
2020-01-10  2:03           ` Pedro Alves
     [not found]             ` <BYAPR11MB30305218B921F31040FE4C1EC4380@BYAPR11MB3030.namprd11.prod.outlook.com>
2020-01-10 12:18               ` Pedro Alves
2020-01-10 14:41             ` Tom Tromey
2020-01-10 20:03               ` Pedro Alves
2019-10-17 23:00 ` [PATCH v2 14/24] Tweak handling of remote errors in response to resumption packet Pedro Alves
2019-10-18 20:23 ` [PATCH v2 00/24] Multi-target support John Baldwin
2019-10-29 19:13   ` Pedro Alves
2020-01-09 19:32     ` John Baldwin
2020-01-09 19:50       ` Pedro Alves
2020-01-10 13:49         ` Aktemur, Tankut Baris
2020-01-10 15:40           ` [PATCH] Switch the inferior before outputting its id in "info inferiors" (Re: [PATCH v2 00/24] Multi-target support) Pedro Alves
2019-10-20 11:41 ` [PATCH v2 00/24] Multi-target support Philippe Waroquiers
2019-10-29 19:56   ` Pedro Alves
2019-11-01 14:56 ` Tom Tromey
2020-01-10 20:13 ` Pedro Alves
2020-08-04  3:30   ` Kevin Buettner
2020-08-06 15:16     ` Pedro Alves
2020-08-06 17:49       ` Tom Tromey
2020-08-07 22:43       ` Kevin Buettner
2020-08-12 18:45         ` Pedro Alves

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=113c6953-3621-c61b-e318-19806805e878@simark.ca \
    --to=simark@simark.ca \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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