This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/3] spu: Use ptid from regcache instead of inferior_ptid


The implementations of to_fetch_regiters/to_store_registers in the spu
code use some functions that rely on inferior_ptid.  It's simpler for
now to set/restore inferior_ptid.

	* spu-linux-nat.c (spu_fetch_inferior_registers,
	spu_store_inferior_registers): Use ptid from regcache, set and
	restore inferior_ptid.
	* spu-multiarch.c (spu_fetch_registers, spu_store_registers):
	Likewise.
---
 gdb/spu-linux-nat.c | 24 ++++++++++++++++++++++--
 gdb/spu-multiarch.c | 26 ++++++++++++++++++++++++--
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/gdb/spu-linux-nat.c b/gdb/spu-linux-nat.c
index c5b91222c1..5ec7b65ad9 100644
--- a/gdb/spu-linux-nat.c
+++ b/gdb/spu-linux-nat.c
@@ -492,9 +492,17 @@ spu_fetch_inferior_registers (struct target_ops *ops,
   int fd;
   ULONGEST addr;
 
+  /* Since we use functions that rely on inferior_ptid, we need to set and
+     restore it.  */
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = regcache_get_ptid (regcache);
+
   /* We must be stopped on a spu_run system call.  */
   if (!parse_spufs_run (&fd, &addr))
-    return;
+    {
+      do_cleanups (cleanup);
+      return;
+    }
 
   /* The ID register holds the spufs file handle.  */
   if (regno == -1 || regno == SPU_ID_REGNUM)
@@ -529,6 +537,8 @@ spu_fetch_inferior_registers (struct target_ops *ops,
 	for (i = 0; i < SPU_NUM_GPRS; i++)
 	  regcache_raw_supply (regcache, i, buf + i*16);
     }
+
+  do_cleanups (cleanup);
 }
 
 /* Override the store_inferior_register routine.  */
@@ -539,9 +549,17 @@ spu_store_inferior_registers (struct target_ops *ops,
   int fd;
   ULONGEST addr;
 
+  /* Since we use functions that rely on inferior_ptid, we need to set and
+     restore it.  */
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = regcache_get_ptid (regcache);
+
   /* We must be stopped on a spu_run system call.  */
   if (!parse_spufs_run (&fd, &addr))
-    return;
+    {
+      do_cleanups (cleanup);
+      return;
+    }
 
   /* The NPC register is found at ADDR.  */
   if (regno == -1 || regno == SPU_PC_REGNUM)
@@ -565,6 +583,8 @@ spu_store_inferior_registers (struct target_ops *ops,
       xsnprintf (annex, sizeof annex, "%d/regs", fd);
       spu_proc_xfer_spu (annex, NULL, buf, 0, sizeof buf, &len);
     }
+
+  do_cleanups (cleanup);
 }
 
 /* Override the to_xfer_partial routine.  */
diff --git a/gdb/spu-multiarch.c b/gdb/spu-multiarch.c
index b99a1a3de3..220464ad27 100644
--- a/gdb/spu-multiarch.c
+++ b/gdb/spu-multiarch.c
@@ -149,16 +149,25 @@ spu_fetch_registers (struct target_ops *ops,
   int spufs_fd;
   CORE_ADDR spufs_addr;
 
+  /* Since we use functions that rely on inferior_ptid, we need to set and
+     restore it.  */
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = regcache_get_ptid (regcache);
+
   /* This version applies only if we're currently in spu_run.  */
   if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
     {
       ops_beneath->to_fetch_registers (ops_beneath, regcache, regno);
+      do_cleanups (cleanup);
       return;
     }
 
   /* We must be stopped on a spu_run system call.  */
   if (!parse_spufs_run (inferior_ptid, &spufs_fd, &spufs_addr))
-    return;
+    {
+      do_cleanups (cleanup);
+      return;
+    }
 
   /* The ID register holds the spufs file handle.  */
   if (regno == -1 || regno == SPU_ID_REGNUM)
@@ -191,6 +200,8 @@ spu_fetch_registers (struct target_ops *ops,
 	for (i = 0; i < SPU_NUM_GPRS; i++)
 	  regcache_raw_supply (regcache, i, buf + i*16);
     }
+
+  do_cleanups (cleanup);
 }
 
 /* Override the to_store_registers routine.  */
@@ -203,16 +214,25 @@ spu_store_registers (struct target_ops *ops,
   int spufs_fd;
   CORE_ADDR spufs_addr;
 
+  /* Since we use functions that rely on inferior_ptid, we need to set and
+     restore it.  */
+  struct cleanup *cleanup = save_inferior_ptid ();
+  inferior_ptid = regcache_get_ptid (regcache);
+
   /* This version applies only if we're currently in spu_run.  */
   if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
     {
       ops_beneath->to_store_registers (ops_beneath, regcache, regno);
+      do_cleanups (cleanup);
       return;
     }
 
   /* We must be stopped on a spu_run system call.  */
   if (!parse_spufs_run (inferior_ptid, &spufs_fd, &spufs_addr))
-    return;
+    {
+      do_cleanups (cleanup);
+      return;
+    }
 
   /* The NPC register is found in PPC memory at SPUFS_ADDR.  */
   if (regno == -1 || regno == SPU_PC_REGNUM)
@@ -238,6 +258,8 @@ spu_store_registers (struct target_ops *ops,
       target_write (ops_beneath, TARGET_OBJECT_SPU, annex,
 		    buf, 0, sizeof buf);
     }
+
+  do_cleanups (cleanup);
 }
 
 /* Override the to_xfer_partial routine.  */
-- 
2.12.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]