[IA64] Synchronize RBS on PTRACE_ATTACH
authorPetr Tesarik <ptesarik@suse.cz>
Wed, 12 Dec 2007 14:24:25 +0000 (15:24 +0100)
committerTony Luck <tony.luck@intel.com>
Fri, 8 Feb 2008 20:01:29 +0000 (12:01 -0800)
When attaching to a stopped process, the RSE must be explicitly
synced to user-space, so the debugger can read the correct values.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
CC: Roland McGrath <roland@redhat.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
arch/ia64/kernel/ptrace.c
include/asm-ia64/ptrace.h

index 2de5a524a0ee463037d165d3a8df295f47029ed6..331d6768b5d50f7257cb6c389929fdfb989800c9 100644 (file)
@@ -613,6 +613,63 @@ void ia64_sync_krbs(void)
        unw_init_running(do_sync_rbs, ia64_sync_kernel_rbs);
 }
 
+/*
+ * After PTRACE_ATTACH, a thread's register backing store area in user
+ * space is assumed to contain correct data whenever the thread is
+ * stopped.  arch_ptrace_stop takes care of this on tracing stops.
+ * But if the child was already stopped for job control when we attach
+ * to it, then it might not ever get into ptrace_stop by the time we
+ * want to examine the user memory containing the RBS.
+ */
+void
+ptrace_attach_sync_user_rbs (struct task_struct *child)
+{
+       int stopped = 0;
+       struct unw_frame_info info;
+
+       /*
+        * If the child is in TASK_STOPPED, we need to change that to
+        * TASK_TRACED momentarily while we operate on it.  This ensures
+        * that the child won't be woken up and return to user mode while
+        * we are doing the sync.  (It can only be woken up for SIGKILL.)
+        */
+
+       read_lock(&tasklist_lock);
+       if (child->signal) {
+               spin_lock_irq(&child->sighand->siglock);
+               if (child->state == TASK_STOPPED &&
+                   !test_and_set_tsk_thread_flag(child, TIF_RESTORE_RSE)) {
+                       tsk_set_notify_resume(child);
+
+                       child->state = TASK_TRACED;
+                       stopped = 1;
+               }
+               spin_unlock_irq(&child->sighand->siglock);
+       }
+       read_unlock(&tasklist_lock);
+
+       if (!stopped)
+               return;
+
+       unw_init_from_blocked_task(&info, child);
+       do_sync_rbs(&info, ia64_sync_user_rbs);
+
+       /*
+        * Now move the child back into TASK_STOPPED if it should be in a
+        * job control stop, so that SIGCONT can be used to wake it up.
+        */
+       read_lock(&tasklist_lock);
+       if (child->signal) {
+               spin_lock_irq(&child->sighand->siglock);
+               if (child->state == TASK_TRACED &&
+                   (child->signal->flags & SIGNAL_STOP_STOPPED)) {
+                       child->state = TASK_STOPPED;
+               }
+               spin_unlock_irq(&child->sighand->siglock);
+       }
+       read_unlock(&tasklist_lock);
+}
+
 static inline int
 thread_matches (struct task_struct *thread, unsigned long addr)
 {
index 13435f778b0c28755bd184fc24266988bd4b5256..0bdce7dde1b01b6f75067447b10d2a4b6d2c036a 100644 (file)
@@ -310,6 +310,10 @@ struct switch_stack {
   #define arch_ptrace_stop_needed(code, info) \
        (!test_thread_flag(TIF_RESTORE_RSE))
 
+  extern void ptrace_attach_sync_user_rbs (struct task_struct *);
+  #define arch_ptrace_attach(child) \
+       ptrace_attach_sync_user_rbs(child)
+
 #endif /* !__KERNEL__ */
 
 /* pt_all_user_regs is used for PTRACE_GETREGS PTRACE_SETREGS */