Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 4/7] Pass down ptid in bsd_uthread_ops layer
Date: Wed, 08 Mar 2017 16:42:00 -0000	[thread overview]
Message-ID: <20170308164140.7281-5-simon.marchi@ericsson.com> (raw)
In-Reply-To: <20170308164140.7281-1-simon.marchi@ericsson.com>

The following patches will add a ptid_t parameter to
target_fetch_registers and target_store_registers.  In the bsd uthread
implementations, there's another indirection layer in the form of
bsd_uthread_ops.  This patch adds the same ptid_t parameter to this
layer, so that the implementations of bsd_uthread_ops don't rely on the
current value of inferior_ptid.

From what I understand, the register values of the userspace threads
(uthreads) are stored in the memory of the "real" thread to which those
userspace threads are mapped.  Therefore, the implementation of these
register fetching/storing functions consists of reading/writing memory.
Since the memory read/write functions still rely on the value of
inferior_ptid to know which thread to read/write memory from/to, it is
necessary to set and restore inferior_ptid in those functions (e.g.
amd64fbsd_supply_uthread).  Eventually, when we add a ptid_t parameter
to the memory functions, this should go away as we'll simply pass down
the ptid parameter.

I was not able to test this patch, so it would be appreciated if some
*bsd user was able to give it a quick go.

gdb/ChangeLog:

	* amd64-fbsd-tdep.c (amd64fbsd_supply_uthread,
	amd64fbsd_collect_uthread): Add ptid parameter, set and restore
	inferior_ptid.
	* amd64-obsd.tdep.c (amd64fbsd_collect_uthread,
	amd64obsd_supply_uthread): Likewise.
	* bsd-uthread.c (bsd_uthread_fetch_registers): Pass ptid value
	to supply_uthread.
	(bsd_uthread_store_registers): Pass ptid value to
	collect_uthread.
	* bsd-uthread.h (bsd_uthread_supply_register_ftype,
	bsd_uthread_collect_register_ftype): Add ptid parameter.
	* i386-fbsd-tdep.c (i386fbsd_supply_uthread,
	i386fbsd_collect_uthread): Add ptid parameter, set and restore
	inferior_ptid.
	* i386-obsd-tdep.c (i386obsd_supply_uthread,
	i386obsd_collect_uthread): Add ptid parameter, set and restore
	inferior_ptid.
	* sparc-obsd-tdep.c (sparc32obsd_supply_uthread,
	sparc32obsd_collect_uthread): Add ptid parameter, set and restore
	inferior_ptid.
	* sparc-obsd-tdep.c (sparc64obsd_supply_uthread,
	sparc64obsd_collect_uthread): Add ptid parameter, set and restore
	inferior_ptid.
---
 gdb/amd64-fbsd-tdep.c   | 13 +++++++++++--
 gdb/amd64-obsd-tdep.c   | 13 +++++++++++--
 gdb/bsd-uthread.c       | 10 ++++++----
 gdb/bsd-uthread.h       |  6 +++---
 gdb/i386-fbsd-tdep.c    | 13 +++++++++++--
 gdb/i386-obsd-tdep.c    | 13 +++++++++++--
 gdb/sparc-obsd-tdep.c   | 13 +++++++++++--
 gdb/sparc64-obsd-tdep.c | 13 +++++++++++--
 8 files changed, 75 insertions(+), 19 deletions(-)

diff --git a/gdb/amd64-fbsd-tdep.c b/gdb/amd64-fbsd-tdep.c
index b8ef25821b..d4c81de26e 100644
--- a/gdb/amd64-fbsd-tdep.c
+++ b/gdb/amd64-fbsd-tdep.c
@@ -31,6 +31,7 @@
 #include "bsd-uthread.h"
 #include "fbsd-tdep.h"
 #include "solib-svr4.h"
+#include "inferior.h"
 
 /* Support for signal handlers.  */
 
@@ -226,11 +227,13 @@ amd64fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 }
 
 static void
-amd64fbsd_supply_uthread (struct regcache *regcache,
+amd64fbsd_supply_uthread (struct regcache *regcache, ptid_t ptid,
 			  int regnum, CORE_ADDR addr)
 {
   gdb_byte buf[8];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -243,14 +246,18 @@ amd64fbsd_supply_uthread (struct regcache *regcache,
 	  regcache_raw_supply (regcache, i, buf);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 
 static void
-amd64fbsd_collect_uthread (const struct regcache *regcache,
+amd64fbsd_collect_uthread (const struct regcache *regcache, ptid_t ptid,
 			   int regnum, CORE_ADDR addr)
 {
   gdb_byte buf[8];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -263,6 +270,8 @@ amd64fbsd_collect_uthread (const struct regcache *regcache,
 	  write_memory (addr + amd64fbsd_jmp_buf_reg_offset[i], buf, 8);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 
 static void
diff --git a/gdb/amd64-obsd-tdep.c b/gdb/amd64-obsd-tdep.c
index 72895b6fc6..ac39c51b3f 100644
--- a/gdb/amd64-obsd-tdep.c
+++ b/gdb/amd64-obsd-tdep.c
@@ -34,6 +34,7 @@
 #include "i387-tdep.h"
 #include "solib-svr4.h"
 #include "bsd-uthread.h"
+#include "inferior.h"
 
 /* Support for signal handlers.  */
 
@@ -217,7 +218,7 @@ static int amd64obsd_uthread_reg_offset[] =
 #define AMD64OBSD_UTHREAD_RSP_OFFSET	400
 
 static void
-amd64obsd_supply_uthread (struct regcache *regcache,
+amd64obsd_supply_uthread (struct regcache *regcache, ptid_t ptid,
 			  int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
@@ -226,6 +227,8 @@ amd64obsd_supply_uthread (struct regcache *regcache,
   CORE_ADDR sp = 0;
   gdb_byte buf[8];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -258,10 +261,12 @@ amd64obsd_supply_uthread (struct regcache *regcache,
 	  regcache_raw_supply (regcache, i, buf);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 
 static void
-amd64obsd_collect_uthread (const struct regcache *regcache,
+amd64obsd_collect_uthread (const struct regcache *regcache, ptid_t ptid,
 			   int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
@@ -270,6 +275,8 @@ amd64obsd_collect_uthread (const struct regcache *regcache,
   CORE_ADDR sp = 0;
   gdb_byte buf[8];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -306,6 +313,8 @@ amd64obsd_collect_uthread (const struct regcache *regcache,
 	  write_memory (sp + amd64obsd_uthread_reg_offset[i], buf, 8);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 /* Kernel debugging support.  */
 
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 09a9de28ae..2111128f21 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -286,7 +286,8 @@ bsd_uthread_fetch_registers (struct target_ops *ops,
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   struct bsd_uthread_ops *uthread_ops
     = (struct bsd_uthread_ops *) gdbarch_data (gdbarch, bsd_uthread_data);
-  CORE_ADDR addr = ptid_get_tid (inferior_ptid);
+  ptid_t ptid = inferior_ptid;
+  CORE_ADDR addr = ptid_get_tid (ptid);
   struct target_ops *beneath = find_target_beneath (ops);
   CORE_ADDR active_addr;
 
@@ -302,7 +303,7 @@ bsd_uthread_fetch_registers (struct target_ops *ops,
   if (addr != 0 && addr != active_addr)
     {
       bsd_uthread_check_magic (addr);
-      uthread_ops->supply_uthread (regcache, regnum,
+      uthread_ops->supply_uthread (regcache, ptid, regnum,
 				   addr + bsd_uthread_thread_ctx_offset);
     }
 }
@@ -315,14 +316,15 @@ bsd_uthread_store_registers (struct target_ops *ops,
   struct bsd_uthread_ops *uthread_ops
     = (struct bsd_uthread_ops *) gdbarch_data (gdbarch, bsd_uthread_data);
   struct target_ops *beneath = find_target_beneath (ops);
-  CORE_ADDR addr = ptid_get_tid (inferior_ptid);
+  ptid_t ptid = inferior_ptid;
+  CORE_ADDR addr = ptid_get_tid (ptid);
   CORE_ADDR active_addr;
 
   active_addr = bsd_uthread_read_memory_address (bsd_uthread_thread_run_addr);
   if (addr != 0 && addr != active_addr)
     {
       bsd_uthread_check_magic (addr);
-      uthread_ops->collect_uthread (regcache, regnum,
+      uthread_ops->collect_uthread (regcache, ptid, regnum,
 				    addr + bsd_uthread_thread_ctx_offset);
     }
   else
diff --git a/gdb/bsd-uthread.h b/gdb/bsd-uthread.h
index 4802d019ae..b61415331d 100644
--- a/gdb/bsd-uthread.h
+++ b/gdb/bsd-uthread.h
@@ -20,10 +20,10 @@
 #ifndef BSD_UTHREAD_H
 #define BSD_UTHREAD_H 1
 
-typedef void (*bsd_uthread_supply_register_ftype) (struct regcache *, int,
-						   CORE_ADDR);
+typedef void (*bsd_uthread_supply_register_ftype) (struct regcache *, ptid_t,
+						   int, CORE_ADDR);
 typedef void (*bsd_uthread_collect_register_ftype) (const struct regcache *,
-						    int, CORE_ADDR);
+						    ptid_t ptid, int, CORE_ADDR);
 
 /* Set the function that supplies registers for an inactive thread for
    architecture GDBARCH to FUNC.  */
diff --git a/gdb/i386-fbsd-tdep.c b/gdb/i386-fbsd-tdep.c
index b0bf7270bb..6d8f213489 100644
--- a/gdb/i386-fbsd-tdep.c
+++ b/gdb/i386-fbsd-tdep.c
@@ -31,6 +31,7 @@
 #include "bsd-uthread.h"
 #include "fbsd-tdep.h"
 #include "solib-svr4.h"
+#include "inferior.h"
 
 /* Support for signal handlers.  */
 
@@ -333,11 +334,13 @@ i386fbsd_iterate_over_regset_sections (struct gdbarch *gdbarch,
 }
 
 static void
-i386fbsd_supply_uthread (struct regcache *regcache,
+i386fbsd_supply_uthread (struct regcache *regcache, ptid_t ptid,
 			 int regnum, CORE_ADDR addr)
 {
   gdb_byte buf[4];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -350,14 +353,18 @@ i386fbsd_supply_uthread (struct regcache *regcache,
 	  regcache_raw_supply (regcache, i, buf);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 
 static void
-i386fbsd_collect_uthread (const struct regcache *regcache,
+i386fbsd_collect_uthread (const struct regcache *regcache, ptid_t ptid,
 			  int regnum, CORE_ADDR addr)
 {
   gdb_byte buf[4];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -370,6 +377,8 @@ i386fbsd_collect_uthread (const struct regcache *regcache,
 	  write_memory (addr + i386fbsd_jmp_buf_reg_offset[i], buf, 4);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 
 static void
diff --git a/gdb/i386-obsd-tdep.c b/gdb/i386-obsd-tdep.c
index 22375c5b75..6d675da59f 100644
--- a/gdb/i386-obsd-tdep.c
+++ b/gdb/i386-obsd-tdep.c
@@ -35,6 +35,7 @@
 #include "i387-tdep.h"
 #include "solib-svr4.h"
 #include "bsd-uthread.h"
+#include "inferior.h"
 
 /* Support for signal handlers.  */
 
@@ -187,7 +188,7 @@ static int i386obsd_uthread_reg_offset[] =
 #define I386OBSD_UTHREAD_ESP_OFFSET	176
 
 static void
-i386obsd_supply_uthread (struct regcache *regcache,
+i386obsd_supply_uthread (struct regcache *regcache, ptid_t ptid,
 			 int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
@@ -196,6 +197,8 @@ i386obsd_supply_uthread (struct regcache *regcache,
   CORE_ADDR sp = 0;
   gdb_byte buf[4];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -228,10 +231,12 @@ i386obsd_supply_uthread (struct regcache *regcache,
 	  regcache_raw_supply (regcache, i, buf);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 
 static void
-i386obsd_collect_uthread (const struct regcache *regcache,
+i386obsd_collect_uthread (const struct regcache *regcache, ptid_t ptid,
 			  int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
@@ -240,6 +245,8 @@ i386obsd_collect_uthread (const struct regcache *regcache,
   CORE_ADDR sp = 0;
   gdb_byte buf[4];
   int i;
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -276,6 +283,8 @@ i386obsd_collect_uthread (const struct regcache *regcache,
 	  write_memory (sp + i386obsd_uthread_reg_offset[i], buf, 4);
 	}
     }
+
+  do_cleanups (cleanup);
 }
 \f
 /* Kernel debugging support.  */
diff --git a/gdb/sparc-obsd-tdep.c b/gdb/sparc-obsd-tdep.c
index b7d3d3cf47..1bfcd64c6f 100644
--- a/gdb/sparc-obsd-tdep.c
+++ b/gdb/sparc-obsd-tdep.c
@@ -31,6 +31,7 @@
 #include "sparc-tdep.h"
 #include "solib-svr4.h"
 #include "bsd-uthread.h"
+#include "inferior.h"
 
 /* Signal trampolines.  */
 
@@ -150,13 +151,15 @@ static const struct frame_unwind sparc32obsd_sigtramp_frame_unwind =
 #define SPARC32OBSD_UTHREAD_PC_OFFSET	132
 
 static void
-sparc32obsd_supply_uthread (struct regcache *regcache,
+sparc32obsd_supply_uthread (struct regcache *regcache, ptid_t ptid,
 			    int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR fp, fp_addr = addr + SPARC32OBSD_UTHREAD_FP_OFFSET;
   gdb_byte buf[4];
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -192,16 +195,20 @@ sparc32obsd_supply_uthread (struct regcache *regcache,
     }
 
   sparc_supply_rwindow (regcache, fp, regnum);
+
+  do_cleanups (cleanup);
 }
 
 static void
-sparc32obsd_collect_uthread(const struct regcache *regcache,
+sparc32obsd_collect_uthread(const struct regcache *regcache, ptid_t ptid,
 			    int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR sp;
   gdb_byte buf[4];
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -228,6 +235,8 @@ sparc32obsd_collect_uthread(const struct regcache *regcache,
   regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
   sp = extract_unsigned_integer (buf, 4, byte_order);
   sparc_collect_rwindow (regcache, sp, regnum);
+
+  do_cleanups (cleanup);
 }
 \f
 
diff --git a/gdb/sparc64-obsd-tdep.c b/gdb/sparc64-obsd-tdep.c
index 0da50b1dc7..49ca460d03 100644
--- a/gdb/sparc64-obsd-tdep.c
+++ b/gdb/sparc64-obsd-tdep.c
@@ -32,6 +32,7 @@
 #include "sparc64-tdep.h"
 #include "solib-svr4.h"
 #include "bsd-uthread.h"
+#include "inferior.h"
 
 /* Older OpenBSD versions used the traditional NetBSD core file
    format, even for ports that use ELF.  These core files don't use
@@ -320,13 +321,15 @@ static const struct frame_unwind sparc64obsd_trapframe_unwind =
 #define SPARC64OBSD_UTHREAD_PC_OFFSET	240
 
 static void
-sparc64obsd_supply_uthread (struct regcache *regcache,
+sparc64obsd_supply_uthread (struct regcache *regcache, ptid_t ptid,
 			    int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR fp, fp_addr = addr + SPARC64OBSD_UTHREAD_FP_OFFSET;
   gdb_byte buf[8];
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -362,16 +365,20 @@ sparc64obsd_supply_uthread (struct regcache *regcache,
     }
 
   sparc_supply_rwindow (regcache, fp, regnum);
+
+  do_cleanups (cleanup);
 }
 
 static void
-sparc64obsd_collect_uthread(const struct regcache *regcache,
+sparc64obsd_collect_uthread(const struct regcache *regcache, ptid_t ptid,
 			    int regnum, CORE_ADDR addr)
 {
   struct gdbarch *gdbarch = get_regcache_arch (regcache);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   CORE_ADDR sp;
   gdb_byte buf[8];
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = ptid;
 
   gdb_assert (regnum >= -1);
 
@@ -398,6 +405,8 @@ sparc64obsd_collect_uthread(const struct regcache *regcache,
   regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
   sp = extract_unsigned_integer (buf, 8, byte_order);
   sparc_collect_rwindow (regcache, sp, regnum);
+
+  do_cleanups (cleanup);
 }
 \f
 
-- 
2.11.0


  parent reply	other threads:[~2017-03-08 16:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-08 16:42 [PATCH 0/7] Pass ptid to target_ops register methods Simon Marchi
2017-03-08 16:42 ` [PATCH 3/7] Define and use typedefs for bsd_uthread_ops fields Simon Marchi
2017-03-08 16:42 ` [PATCH 1/7] windows: Don't use current_thread for register fetch/store Simon Marchi
2017-03-08 16:42 ` [PATCH 6/7] Pass ptid to target_store_registers Simon Marchi
2017-03-08 16:42 ` Simon Marchi [this message]
2017-03-08 16:42 ` [PATCH 2/7] Add overload of s390_inferior_tid with a parameter Simon Marchi
2017-03-08 16:42 ` [PATCH 7/7] Pass ptid to to_prepare_to_store Simon Marchi
2017-03-08 16:42 ` [PATCH 5/7] Pass ptid to target_fetch_registers Simon Marchi
2017-03-08 21:08   ` Simon Marchi
2017-03-08 17:03 ` [PATCH 0/7] Pass ptid to target_ops register methods Simon Marchi
2017-03-08 23:31 ` Pedro Alves
2017-03-10 16:06   ` Simon Marchi
2017-03-10 17:12     ` Ulrich Weigand
2017-03-10 17:51       ` 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=20170308164140.7281-5-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --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