- unsigned long value;
-
- value = i386_linux_dr_get (ptid, DR_STATUS);
- value &= ~mask;
- i386_linux_dr_set (ptid, DR_STATUS, value);
+ struct i386_debug_reg_state *state = i386_debug_reg_state ();
+ int i;
+
+ /* See amd64_linux_prepare_to_resume for Linux kernel note on
+ i386_linux_dr_set calls ordering. */
+
+ for (i = DR_FIRSTADDR; i <= DR_LASTADDR; i++)
+ if (state->dr_ref_count[i] > 0)
+ {
+ i386_linux_dr_set (lwp->ptid, i, state->dr_mirror[i]);
+
+ /* If we're setting a watchpoint, any change the inferior
+ had done itself to the debug registers needs to be
+ discarded, otherwise, i386_stopped_data_address can get
+ confused. */
+ clear_status = 1;
+ }
+
+ i386_linux_dr_set (lwp->ptid, DR_CONTROL, state->dr_control_mirror);
+
+ lwp->arch_private->debug_registers_changed = 0;