diff --git a/server/mach.c b/server/mach.c
index 3690b29004d0753050e23dd4f241284838236c8e..69f3ee22a91b29c34ba478ddbfc9ac4303cf676c 100644
--- a/server/mach.c
+++ b/server/mach.c
@@ -283,18 +283,7 @@ void set_thread_context( struct thread *thread, const context_t *context, unsign
         state.uds.ds32.dr7 = dr7;
 #endif
     }
-    if (!thread_set_state( port, x86_DEBUG_STATE, (thread_state_t)&state, count ))
-    {
-        if (thread->context)  /* update the cached values */
-        {
-#ifdef __x86_64__
-            if (thread->process->cpu == CPU_x86_64)
-                thread->context->debug.x86_64_regs = context->debug.x86_64_regs;
-            else
-#endif
-                thread->context->debug.i386_regs = context->debug.i386_regs;
-        }
-    }
+    thread_set_state( port, x86_DEBUG_STATE, (thread_state_t)&state, count );
     mach_port_deallocate( mach_task_self(), port );
 #endif
 }
diff --git a/server/ptrace.c b/server/ptrace.c
index 6be1591d54300fca7bea962359829a5533a0bbeb..49347791d8c1e2f7ef665eef2fd3634adcaea007 100644
--- a/server/ptrace.c
+++ b/server/ptrace.c
@@ -637,36 +637,24 @@ void set_thread_context( struct thread *thread, const context_t *context, unsign
         /* Linux 2.6.33+ does DR0-DR3 alignment validation, so it has to know LEN bits first */
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.i386_regs.dr7 & 0xffff0000 ) == -1) goto error;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(0), context->debug.i386_regs.dr0 ) == -1) goto error;
-        if (thread->context) thread->context->debug.i386_regs.dr0 = context->debug.i386_regs.dr0;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(1), context->debug.i386_regs.dr1 ) == -1) goto error;
-        if (thread->context) thread->context->debug.i386_regs.dr1 = context->debug.i386_regs.dr1;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(2), context->debug.i386_regs.dr2 ) == -1) goto error;
-        if (thread->context) thread->context->debug.i386_regs.dr2 = context->debug.i386_regs.dr2;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(3), context->debug.i386_regs.dr3 ) == -1) goto error;
-        if (thread->context) thread->context->debug.i386_regs.dr3 = context->debug.i386_regs.dr3;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(6), context->debug.i386_regs.dr6 ) == -1) goto error;
-        if (thread->context) thread->context->debug.i386_regs.dr6 = context->debug.i386_regs.dr6;
         /* Linux 2.6.33+ needs enable bits set briefly to update value returned by PEEKUSER later */
         ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.i386_regs.dr7 | 0x55 );
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.i386_regs.dr7 ) == -1) goto error;
-        if (thread->context) thread->context->debug.i386_regs.dr7 = context->debug.i386_regs.dr7;
         thread->system_regs |= SERVER_CTX_DEBUG_REGISTERS;
         break;
     case CPU_x86_64:
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.x86_64_regs.dr7 & 0xffff0000 ) == -1) goto error;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(0), context->debug.x86_64_regs.dr0 ) == -1) goto error;
-        if (thread->context) thread->context->debug.x86_64_regs.dr0 = context->debug.x86_64_regs.dr0;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(1), context->debug.x86_64_regs.dr1 ) == -1) goto error;
-        if (thread->context) thread->context->debug.x86_64_regs.dr1 = context->debug.x86_64_regs.dr1;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(2), context->debug.x86_64_regs.dr2 ) == -1) goto error;
-        if (thread->context) thread->context->debug.x86_64_regs.dr2 = context->debug.x86_64_regs.dr2;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(3), context->debug.x86_64_regs.dr3 ) == -1) goto error;
-        if (thread->context) thread->context->debug.x86_64_regs.dr3 = context->debug.x86_64_regs.dr3;
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(6), context->debug.x86_64_regs.dr6 ) == -1) goto error;
-        if (thread->context) thread->context->debug.x86_64_regs.dr6 = context->debug.x86_64_regs.dr6;
         ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.x86_64_regs.dr7 | 0x55 );
         if (ptrace( PTRACE_POKEUSER, pid, DR_OFFSET(7), context->debug.x86_64_regs.dr7 ) == -1) goto error;
-        if (thread->context) thread->context->debug.x86_64_regs.dr7 = context->debug.x86_64_regs.dr7;
         thread->system_regs |= SERVER_CTX_DEBUG_REGISTERS;
         break;
     default:
@@ -785,8 +773,6 @@ void set_thread_context( struct thread *thread, const context_t *context, unsign
 #endif
     if (ptrace( PTRACE_SETDBREGS, pid, (caddr_t)&dbregs, 0 ) != -1)
     {
-        if (thread->context)
-            thread->context->debug.i386_regs = context->debug.i386_regs;  /* update the cached values */
         thread->system_regs |= SERVER_CTX_DEBUG_REGISTERS;
     }
     else file_set_error();
diff --git a/server/thread.c b/server/thread.c
index 0d3cb28f5ce8b08638e40c63770b7c5eb45b87f0..534fab6597f9be802641621b55aa950d3a23ff5b 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -1823,7 +1823,7 @@ DECL_HANDLER(set_thread_context)
         if (system_flags) set_thread_context( thread, context, system_flags );
         if (thread->context && !get_error())
         {
-            copy_context( thread->context, context, client_flags );
+            copy_context( thread->context, context, context->flags );
             thread->context->flags |= client_flags;
         }
     }