return(1);
 }
 
+static int ptrace_dump_regs(int pid)
+{
+        unsigned long regs[MAX_REG_NR];
+        int i;
+
+        if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
+                return -errno;
+        else {
+                printk("Stub registers -\n");
+                for(i = 0; i < ARRAY_SIZE(regs); i++)
+                        printk("\t%d - %lx\n", i, regs[i]);
+        }
+
+        return 0;
+}
+
 void wait_stub_done(int pid, int sig, char * fname)
 {
        int n, status, err;
 
        if((n < 0) || !WIFSTOPPED(status) ||
           (WSTOPSIG(status) != SIGUSR1 && WSTOPSIG(status) != SIGTRAP)){
-               unsigned long regs[MAX_REG_NR];
-
-               if(ptrace(PTRACE_GETREGS, pid, 0, regs) < 0)
+               err = ptrace_dump_regs(pid);
+               if(err)
                        printk("Failed to get registers from stub, "
-                              "errno = %d\n", errno);
-               else {
-                       int i;
-
-                       printk("Stub registers -\n");
-                       for(i = 0; i < ARRAY_SIZE(regs); i++)
-                               printk("\t%d - %lx\n", i, regs[i]);
-               }
+                              "errno = %d\n", -err);
                panic("%s : failed to wait for SIGUSR1/SIGTRAP, "
                      "pid = %d, n = %d, errno = %d, status = 0x%x\n",
                      fname, pid, n, errno, status);
 
                CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED));
                if((err < 0) || !WIFSTOPPED(status) ||
-                  (WSTOPSIG(status) != SIGTRAP + 0x80))
+                  (WSTOPSIG(status) != SIGTRAP + 0x80)){
+                        err = ptrace_dump_regs(pid);
+                        if(err)
+                                printk("Failed to get registers from process, "
+                                       "errno = %d\n", -err);
                        panic("handle_trap - failed to wait at end of syscall, "
                              "errno = %d, status = %d\n", errno, status);
+                }
        }
 
        handle_syscall(regs);