+ /* The current thread's DR_STATUS. We always need to read this to
+ check whether some watchpoint caused the trap. */
+ unsigned status;
+ /* We need DR_CONTROL as well, but only iff DR_STATUS indicates a
+ data breakpoint trap. Only fetch it when necessary, to avoid an
+ unnecessary extra syscall when no watchpoint triggered. */
+ int control_p = 0;
+ unsigned control = 0;
+
+ /* In non-stop/async, threads can be running while we change the
+ STATE (and friends). Say, we set a watchpoint, and let threads
+ resume. Now, say you delete the watchpoint, or add/remove
+ watchpoints such that STATE changes while threads are running.
+ On targets that support non-stop, inserting/deleting watchpoints
+ updates the STATE only. It does not update the real thread's
+ debug registers; that's only done prior to resume. Instead, if
+ threads are running when the mirror changes, a temporary and
+ transparent stop on all threads is forced so they can get their
+ copy of the debug registers updated on re-resume. Now, say,
+ a thread hit a watchpoint before having been updated with the new
+ STATE contents, and we haven't yet handled the corresponding
+ SIGTRAP. If we trusted STATE below, we'd mistake the real
+ trapped address (from the last time we had updated debug
+ registers in the thread) with whatever was currently in STATE.
+ So to fix this, STATE always represents intention, what we _want_
+ threads to have in debug registers. To get at the address and
+ cause of the trap, we need to read the state the thread still has
+ in its debug registers.
+
+ In sum, always get the current debug register values the current
+ thread has, instead of trusting the global mirror. If the thread
+ was running when we last changed watchpoints, the mirror no
+ longer represents what was set in this thread's debug
+ registers. */
+ status = i386_dr_low.get_status ();