]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Pass down ptid in bsd_uthread_ops layer
authorSimon Marchi <simon.marchi@ericsson.com>
Tue, 7 Feb 2017 22:04:38 +0000 (17:04 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Tue, 7 Mar 2017 15:56:40 +0000 (10:56 -0500)
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.

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
gdb/amd64-obsd-tdep.c
gdb/bsd-uthread.c
gdb/bsd-uthread.h
gdb/i386-fbsd-tdep.c
gdb/i386-obsd-tdep.c
gdb/sparc-obsd-tdep.c
gdb/sparc64-obsd-tdep.c

index b8ef25821b281c094b1c5c0a8faf54ae1550cf37..d4c81de26ecb741be07fa994ecec0443ef8de733 100644 (file)
@@ -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
index 72895b6fc6e91f7c930efa33f8654d37d957d19a..ac39c51b3f9d6b5c740cd98f75c5f6cf98e7cd35 100644 (file)
@@ -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.  */
 
index 09a9de28aee560656221e5b89765419401db1f90..2111128f21969f54bb494d3ac407e221b77b491d 100644 (file)
@@ -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
index 4802d019ae7d39bd0c2213cb98f271f52fe3c6df..b61415331d3631d1d2b95e8c251f80cbd4572239 100644 (file)
 #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.  */
index b0bf7270bbe1f15cb9413955d3a25da58c2a9397..6d8f213489aecfd4f9a0be9a1f49d12fd674ea42 100644 (file)
@@ -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
index 22375c5b7508a0ba6327b63a276da6ba58ab67b8..6d675da59f6f6721866ca0883ffccfbf8a5b4355 100644 (file)
@@ -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.  */
index b7d3d3cf47a143cf1e253ca85fcc3a2577f92c8b..1bfcd64c6fae257ddc48f6815d088c2f3749608b 100644 (file)
@@ -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
 
index 0da50b1dc76f05cb19e21d1980060a09f659bade..49ca460d03771e1cc885c6573b0e5060dc3d5314 100644 (file)
@@ -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