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]

[try 2nd 3/8] Refactor copy_svc_os


copy_svc is a little bit different from other copy helpers, OS stuff is
involved.  arm_linux_copy_svc itself has nothing to do with ARM/Thumb
mode.  It should work well under two modes.  However, one of the
parameters INSN make it hard to be called from both modes.  Fortunately,
INSN is *not* used inside arm_linux_copy_svc except printing debug
message.  We can remove parameter INSN and TO, so it can be called from
two modes respectively.

-- 
Yao (éå)
2011-03-24  Yao Qi  <yao@codesourcery.com>

	* gdb/arm-linux-tdep.c (arm_linux_copy_svc): Remove parameters INSN
	and TO.
	* gdb/arm-tdep.c (cleanup_svc): Handle variable instruction size.
	(arm_copy_svc): Remove parameters INSN and TO.
	(decode_svc_copro): Update caller.
	* gdb/arm-tdep.h (struct displaced_step_closure): Remove parameters
	from function pointer `copy_svc_os'.

---
 gdb/arm-linux-tdep.c |   10 ++--------
 gdb/arm-tdep.c       |   20 ++++++++++++--------
 gdb/arm-tdep.h       |    3 +--
 3 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index 2f3109c..e44ba25 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -798,19 +798,14 @@ arm_linux_cleanup_svc (struct gdbarch *gdbarch,
 }
 
 static int
-arm_linux_copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to,
-		    struct regcache *regs, struct displaced_step_closure *dsc)
+arm_linux_copy_svc (struct gdbarch *gdbarch, struct regcache *regs,
+		    struct displaced_step_closure *dsc)
 {
   CORE_ADDR return_to = 0;
 
   struct frame_info *frame;
   unsigned int svc_number = displaced_read_reg (regs, dsc, 7);
   int is_sigreturn = 0;
-
-  if (debug_displaced)
-    fprintf_unfiltered (gdb_stdlog, "displaced: copying Linux svc insn %.8lx\n",
-			(unsigned long) insn);
-
   frame = get_current_frame ();
 
   is_sigreturn = arm_linux_sigreturn_return_addr(frame, svc_number,
@@ -864,7 +859,6 @@ arm_linux_copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to,
      Cleanup: if pc lands in scratch space, pc <- insn_addr + 4
               else leave pc alone.  */
 
-  dsc->modinsn[0] = insn;
 
   dsc->cleanup = &arm_linux_cleanup_svc;
   /* Pretend we wrote to the PC, so cleanup doesn't set PC to the next
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index af81b1e..3348dcb 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -6412,7 +6412,7 @@ static void
 cleanup_svc (struct gdbarch *gdbarch, struct regcache *regs,
 	     struct displaced_step_closure *dsc)
 {
-  CORE_ADDR resume_addr = dsc->insn_addr + 4;
+  CORE_ADDR resume_addr = dsc->insn_addr + dsc->insn_size;
 
   if (debug_displaced)
     fprintf_unfiltered (gdb_stdlog, "displaced: cleanup for svc, resume at "
@@ -6422,12 +6422,9 @@ cleanup_svc (struct gdbarch *gdbarch, struct regcache *regs,
 }
 
 static int
-arm_copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to,
+arm_copy_svc (struct gdbarch *gdbarch, uint32_t insn,
 	      struct regcache *regs, struct displaced_step_closure *dsc)
 {
-  /* Allow OS-specific code to override SVC handling.  */
-  if (dsc->u.svc.copy_svc_os)
-    return dsc->u.svc.copy_svc_os (gdbarch, insn, to, regs, dsc);
 
   if (debug_displaced)
     fprintf_unfiltered (gdb_stdlog, "displaced: copying svc insn %.8lx\n",
@@ -6439,12 +6436,19 @@ arm_copy_svc (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to,
 
   dsc->modinsn[0] = insn;
 
-  dsc->cleanup = &cleanup_svc;
   /* Pretend we wrote to the PC, so cleanup doesn't set PC to the next
      instruction.  */
   dsc->wrote_to_pc = 1;
 
-  return 0;
+  /* Allow OS-specific code to override SVC handling.  */
+  if (dsc->u.svc.copy_svc_os)
+    return dsc->u.svc.copy_svc_os (gdbarch, regs, dsc);
+  else
+    {
+      dsc->cleanup = &cleanup_svc;
+      return 0;
+    }
+
 }
 
 /* Copy undefined instructions.  */
@@ -6898,7 +6902,7 @@ decode_svc_copro (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to,
   else if ((op1 & 0x31) == 0x21 && op && (coproc & 0xe) != 0xa)
     return arm_copy_unmodified (gdbarch, insn, "mrc/mrc2", dsc);
   else if ((op1 & 0x30) == 0x30)
-    return arm_copy_svc (gdbarch, insn, to, regs, dsc);
+    return arm_copy_svc (gdbarch, insn, regs, dsc);
   else
     return copy_undef (gdbarch, insn, dsc);  /* Possibly unreachable.  */
 }
diff --git a/gdb/arm-tdep.h b/gdb/arm-tdep.h
index 3b1fce9..3f5e7d6 100644
--- a/gdb/arm-tdep.h
+++ b/gdb/arm-tdep.h
@@ -271,8 +271,7 @@ struct displaced_step_closure
     {
       /* If non-NULL, override generic SVC handling (e.g. for a particular
          OS).  */
-      int (*copy_svc_os) (struct gdbarch *gdbarch, uint32_t insn, CORE_ADDR to,
-			  struct regcache *regs,
+      int (*copy_svc_os) (struct gdbarch *gdbarch, struct regcache *regs,
 			  struct displaced_step_closure *dsc);
     } svc;
   } u;
-- 
1.7.0.4


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