Add translations for various sub-directories
[binutils-gdb.git] / gdb / nat / x86-dregs.c
blob7ea9f49eb680955ffffc9132d67b2aebd773f941
1 /* Debug register code for x86 (i386 and x86-64).
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "x86-dregs.h"
21 #include "gdbsupport/break-common.h"
23 /* Support for hardware watchpoints and breakpoints using the x86
24 debug registers.
26 This provides several functions for inserting and removing
27 hardware-assisted breakpoints and watchpoints, testing if one or
28 more of the watchpoints triggered and at what address, checking
29 whether a given region can be watched, etc.
31 The functions below implement debug registers sharing by reference
32 counts, and allow to watch regions up to 16 bytes long. */
34 /* Accessor macros for low-level function vector. */
36 /* Can we update the inferior's debug registers? */
38 static bool
39 x86_dr_low_can_set_addr ()
41 return x86_dr_low.set_addr != nullptr;
44 /* Update the inferior's debug register REGNUM from STATE. */
46 static void
47 x86_dr_low_set_addr (struct x86_debug_reg_state *new_state, int i)
49 x86_dr_low.set_addr (i, new_state->dr_mirror[i]);
52 /* Return the inferior's debug register REGNUM. */
54 static CORE_ADDR
55 x86_dr_low_get_addr (int i)
57 return x86_dr_low.get_addr (i);
60 /* Can we update the inferior's DR7 control register? */
62 static bool
63 x86_dr_low_can_set_control ()
65 return x86_dr_low.set_control != nullptr;
68 /* Update the inferior's DR7 debug control register from STATE. */
70 static void
71 x86_dr_low_set_control (struct x86_debug_reg_state *new_state)
73 x86_dr_low.set_control (new_state->dr_control_mirror);
76 /* Return the value of the inferior's DR7 debug control register. */
78 static unsigned long
79 x86_dr_low_get_control ()
81 return x86_dr_low.get_control ();
84 /* Return the value of the inferior's DR6 debug status register. */
86 static unsigned long
87 x86_dr_low_get_status ()
89 return x86_dr_low.get_status ();
92 /* Return the debug register size, in bytes. */
94 static int
95 x86_get_debug_register_length ()
97 return x86_dr_low.debug_register_length;
100 /* Support for 8-byte wide hw watchpoints. */
101 #define TARGET_HAS_DR_LEN_8 (x86_get_debug_register_length () == 8)
103 /* DR7 Debug Control register fields. */
105 /* How many bits to skip in DR7 to get to R/W and LEN fields. */
106 #define DR_CONTROL_SHIFT 16
107 /* How many bits in DR7 per R/W and LEN field for each watchpoint. */
108 #define DR_CONTROL_SIZE 4
110 /* Watchpoint/breakpoint read/write fields in DR7. */
111 #define DR_RW_EXECUTE (0x0) /* Break on instruction execution. */
112 #define DR_RW_WRITE (0x1) /* Break on data writes. */
113 #define DR_RW_READ (0x3) /* Break on data reads or writes. */
115 /* This is here for completeness. No platform supports this
116 functionality yet (as of March 2001). Note that the DE flag in the
117 CR4 register needs to be set to support this. */
118 #ifndef DR_RW_IORW
119 #define DR_RW_IORW (0x2) /* Break on I/O reads or writes. */
120 #endif
122 /* Watchpoint/breakpoint length fields in DR7. The 2-bit left shift
123 is so we could OR this with the read/write field defined above. */
124 #define DR_LEN_1 (0x0 << 2) /* 1-byte region watch or breakpoint. */
125 #define DR_LEN_2 (0x1 << 2) /* 2-byte region watch. */
126 #define DR_LEN_4 (0x3 << 2) /* 4-byte region watch. */
127 #define DR_LEN_8 (0x2 << 2) /* 8-byte region watch (AMD64). */
129 /* Local and Global Enable flags in DR7.
131 When the Local Enable flag is set, the breakpoint/watchpoint is
132 enabled only for the current task; the processor automatically
133 clears this flag on every task switch. When the Global Enable flag
134 is set, the breakpoint/watchpoint is enabled for all tasks; the
135 processor never clears this flag.
137 Currently, all watchpoint are locally enabled. If you need to
138 enable them globally, read the comment which pertains to this in
139 x86_insert_aligned_watchpoint below. */
140 #define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */
141 #define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */
142 #define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */
144 /* Local and global exact breakpoint enable flags (a.k.a. slowdown
145 flags). These are only required on i386, to allow detection of the
146 exact instruction which caused a watchpoint to break; i486 and
147 later processors do that automatically. We set these flags for
148 backwards compatibility. */
149 #define DR_LOCAL_SLOWDOWN (0x100)
150 #define DR_GLOBAL_SLOWDOWN (0x200)
152 /* Fields reserved by Intel. This includes the GD (General Detect
153 Enable) flag, which causes a debug exception to be generated when a
154 MOV instruction accesses one of the debug registers.
156 FIXME: My Intel manual says we should use 0xF800, not 0xFC00. */
157 #define DR_CONTROL_RESERVED (0xFC00)
159 /* Auxiliary helper macros. */
161 /* A value that masks all fields in DR7 that are reserved by Intel. */
162 #define X86_DR_CONTROL_MASK (~DR_CONTROL_RESERVED)
164 /* The I'th debug register is vacant if its Local and Global Enable
165 bits are reset in the Debug Control register. */
166 #define X86_DR_VACANT(state, i) \
167 (((state)->dr_control_mirror & (3 << (DR_ENABLE_SIZE * (i)))) == 0)
169 /* Locally enable the break/watchpoint in the I'th debug register. */
170 #define X86_DR_LOCAL_ENABLE(state, i) \
171 do { \
172 (state)->dr_control_mirror |= \
173 (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \
174 } while (0)
176 /* Globally enable the break/watchpoint in the I'th debug register. */
177 #define X86_DR_GLOBAL_ENABLE(state, i) \
178 do { \
179 (state)->dr_control_mirror |= \
180 (1 << (DR_GLOBAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \
181 } while (0)
183 /* Disable the break/watchpoint in the I'th debug register. */
184 #define X86_DR_DISABLE(state, i) \
185 do { \
186 (state)->dr_control_mirror &= \
187 ~(3 << (DR_ENABLE_SIZE * (i))); \
188 } while (0)
190 /* Set in DR7 the RW and LEN fields for the I'th debug register. */
191 #define X86_DR_SET_RW_LEN(state, i, rwlen) \
192 do { \
193 (state)->dr_control_mirror &= \
194 ~(0x0f << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \
195 (state)->dr_control_mirror |= \
196 ((rwlen) << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \
197 } while (0)
199 /* Get from DR7 the RW and LEN fields for the I'th debug register. */
200 #define X86_DR_GET_RW_LEN(dr7, i) \
201 (((dr7) \
202 >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f)
204 /* Did the watchpoint whose address is in the I'th register break? */
205 #define X86_DR_WATCH_HIT(dr6, i) ((dr6) & (1 << (i)))
207 /* Types of operations supported by x86_handle_nonaligned_watchpoint. */
208 enum x86_wp_op_t { WP_INSERT, WP_REMOVE, WP_COUNT };
210 /* Print the values of the mirrored debug registers. */
212 static void
213 x86_show_dr (struct x86_debug_reg_state *state,
214 const char *func, CORE_ADDR addr,
215 int len, enum target_hw_bp_type type)
217 int i;
219 debug_printf ("%s", func);
220 if (addr || len)
221 debug_printf (" (addr=%s, len=%d, type=%s)",
222 phex (addr, 8), len,
223 type == hw_write ? "data-write"
224 : (type == hw_read ? "data-read"
225 : (type == hw_access ? "data-read/write"
226 : (type == hw_execute ? "instruction-execute"
227 /* FIXME: if/when I/O read/write
228 watchpoints are supported, add them
229 here. */
230 : "??unknown??"))));
231 debug_printf (":\n");
233 debug_printf ("\tCONTROL (DR7): 0x%s\n", phex (state->dr_control_mirror, 8));
234 debug_printf ("\tSTATUS (DR6): 0x%s\n", phex (state->dr_status_mirror, 8));
236 ALL_DEBUG_ADDRESS_REGISTERS (i)
238 debug_printf ("\tDR%d: addr=0x%s, ref.count=%d\n",
239 i, phex (state->dr_mirror[i],
240 x86_get_debug_register_length ()),
241 state->dr_ref_count[i]);
245 /* Return the value of a 4-bit field for DR7 suitable for watching a
246 region of LEN bytes for accesses of type TYPE. LEN is assumed to
247 have the value of 1, 2, or 4. */
249 static unsigned
250 x86_length_and_rw_bits (int len, enum target_hw_bp_type type)
252 unsigned rw;
254 switch (type)
256 case hw_execute:
257 rw = DR_RW_EXECUTE;
258 break;
259 case hw_write:
260 rw = DR_RW_WRITE;
261 break;
262 case hw_read:
263 internal_error (_("The i386 doesn't support "
264 "data-read watchpoints.\n"));
265 case hw_access:
266 rw = DR_RW_READ;
267 break;
268 #if 0
269 /* Not yet supported. */
270 case hw_io_access:
271 rw = DR_RW_IORW;
272 break;
273 #endif
274 default:
275 internal_error (_("\
276 Invalid hardware breakpoint type %d in x86_length_and_rw_bits.\n"),
277 (int) type);
280 switch (len)
282 case 1:
283 return (DR_LEN_1 | rw);
284 case 2:
285 return (DR_LEN_2 | rw);
286 case 4:
287 return (DR_LEN_4 | rw);
288 case 8:
289 if (TARGET_HAS_DR_LEN_8)
290 return (DR_LEN_8 | rw);
291 [[fallthrough]];
292 default:
293 internal_error (_("\
294 Invalid hardware breakpoint length %d in x86_length_and_rw_bits.\n"), len);
298 /* Insert a watchpoint at address ADDR, which is assumed to be aligned
299 according to the length of the region to watch. LEN_RW_BITS is the
300 value of the bits from DR7 which describes the length and access
301 type of the region to be watched by this watchpoint. Return 0 on
302 success, -1 on failure. */
304 static int
305 x86_insert_aligned_watchpoint (struct x86_debug_reg_state *state,
306 CORE_ADDR addr, unsigned len_rw_bits)
308 int i;
310 if (!x86_dr_low_can_set_addr () || !x86_dr_low_can_set_control ())
311 return -1;
313 /* First, look for an occupied debug register with the same address
314 and the same RW and LEN definitions. If we find one, we can
315 reuse it for this watchpoint as well (and save a register). */
316 ALL_DEBUG_ADDRESS_REGISTERS (i)
318 if (!X86_DR_VACANT (state, i)
319 && state->dr_mirror[i] == addr
320 && X86_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits)
322 state->dr_ref_count[i]++;
323 return 0;
327 /* Next, look for a vacant debug register. */
328 ALL_DEBUG_ADDRESS_REGISTERS (i)
330 if (X86_DR_VACANT (state, i))
331 break;
334 /* No more debug registers! */
335 if (i >= DR_NADDR)
336 return -1;
338 /* Now set up the register I to watch our region. */
340 /* Record the info in our local mirrored array. */
341 state->dr_mirror[i] = addr;
342 state->dr_ref_count[i] = 1;
343 X86_DR_SET_RW_LEN (state, i, len_rw_bits);
344 /* Note: we only enable the watchpoint locally, i.e. in the current
345 task. Currently, no x86 target allows or supports global
346 watchpoints; however, if any target would want that in the
347 future, GDB should probably provide a command to control whether
348 to enable watchpoints globally or locally, and the code below
349 should use global or local enable and slow-down flags as
350 appropriate. */
351 X86_DR_LOCAL_ENABLE (state, i);
352 state->dr_control_mirror |= DR_LOCAL_SLOWDOWN;
353 state->dr_control_mirror &= X86_DR_CONTROL_MASK;
355 return 0;
358 /* Remove a watchpoint at address ADDR, which is assumed to be aligned
359 according to the length of the region to watch. LEN_RW_BITS is the
360 value of the bits from DR7 which describes the length and access
361 type of the region watched by this watchpoint. Return 0 on
362 success, -1 on failure. */
364 static int
365 x86_remove_aligned_watchpoint (struct x86_debug_reg_state *state,
366 CORE_ADDR addr, unsigned len_rw_bits)
368 int i, retval = -1;
369 int all_vacant = 1;
371 ALL_DEBUG_ADDRESS_REGISTERS (i)
373 if (!X86_DR_VACANT (state, i)
374 && state->dr_mirror[i] == addr
375 && X86_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits)
377 if (--state->dr_ref_count[i] == 0) /* No longer in use? */
379 /* Reset our mirror. */
380 state->dr_mirror[i] = 0;
381 X86_DR_DISABLE (state, i);
382 /* Even though not strictly necessary, clear out all
383 bits in DR_CONTROL related to this debug register.
384 Debug output is clearer when we don't have stale bits
385 in place. This also allows the assertion below. */
386 X86_DR_SET_RW_LEN (state, i, 0);
388 retval = 0;
391 if (!X86_DR_VACANT (state, i))
392 all_vacant = 0;
395 if (all_vacant)
397 /* Even though not strictly necessary, clear out all of
398 DR_CONTROL, so that when we have no debug registers in use,
399 we end up with DR_CONTROL == 0. The Linux support relies on
400 this for an optimization. Plus, it makes for clearer debug
401 output. */
402 state->dr_control_mirror &= ~DR_LOCAL_SLOWDOWN;
404 gdb_assert (state->dr_control_mirror == 0);
406 return retval;
409 /* Insert or remove a (possibly non-aligned) watchpoint, or count the
410 number of debug registers required to watch a region at address
411 ADDR whose length is LEN for accesses of type TYPE. Return 0 on
412 successful insertion or removal, a positive number when queried
413 about the number of registers, or -1 on failure. If WHAT is not a
414 valid value, bombs through internal_error. */
416 static int
417 x86_handle_nonaligned_watchpoint (struct x86_debug_reg_state *state,
418 x86_wp_op_t what, CORE_ADDR addr, int len,
419 enum target_hw_bp_type type)
421 int retval = 0;
422 int max_wp_len = TARGET_HAS_DR_LEN_8 ? 8 : 4;
424 static const int size_try_array[8][8] =
426 {1, 1, 1, 1, 1, 1, 1, 1}, /* Trying size one. */
427 {2, 1, 2, 1, 2, 1, 2, 1}, /* Trying size two. */
428 {2, 1, 2, 1, 2, 1, 2, 1}, /* Trying size three. */
429 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size four. */
430 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size five. */
431 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size six. */
432 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size seven. */
433 {8, 1, 2, 1, 4, 1, 2, 1}, /* Trying size eight. */
436 while (len > 0)
438 int align = addr % max_wp_len;
439 /* Four (eight on AMD64) is the maximum length a debug register
440 can watch. */
441 int attempt = (len > max_wp_len ? (max_wp_len - 1) : len - 1);
442 int size = size_try_array[attempt][align];
444 if (what == WP_COUNT)
446 /* size_try_array[] is defined such that each iteration
447 through the loop is guaranteed to produce an address and a
448 size that can be watched with a single debug register.
449 Thus, for counting the registers required to watch a
450 region, we simply need to increment the count on each
451 iteration. */
452 retval++;
454 else
456 unsigned len_rw = x86_length_and_rw_bits (size, type);
458 if (what == WP_INSERT)
459 retval = x86_insert_aligned_watchpoint (state, addr, len_rw);
460 else if (what == WP_REMOVE)
461 retval = x86_remove_aligned_watchpoint (state, addr, len_rw);
462 else
463 internal_error (_("\
464 Invalid value %d of operation in x86_handle_nonaligned_watchpoint.\n"),
465 (int) what);
466 if (retval)
467 break;
470 addr += size;
471 len -= size;
474 return retval;
477 /* Update the inferior debug registers state, in STATE, with the
478 new debug registers state, in NEW_STATE. */
480 static void
481 x86_update_inferior_debug_regs (struct x86_debug_reg_state *state,
482 struct x86_debug_reg_state *new_state)
484 int i;
486 ALL_DEBUG_ADDRESS_REGISTERS (i)
488 if (X86_DR_VACANT (new_state, i) != X86_DR_VACANT (state, i))
489 x86_dr_low_set_addr (new_state, i);
490 else
491 gdb_assert (new_state->dr_mirror[i] == state->dr_mirror[i]);
494 if (new_state->dr_control_mirror != state->dr_control_mirror)
495 x86_dr_low_set_control (new_state);
497 *state = *new_state;
500 /* Insert a watchpoint to watch a memory region which starts at
501 address ADDR and whose length is LEN bytes. Watch memory accesses
502 of the type TYPE. Return 0 on success, -1 on failure. */
505 x86_dr_insert_watchpoint (struct x86_debug_reg_state *state,
506 enum target_hw_bp_type type,
507 CORE_ADDR addr, int len)
509 int retval;
510 /* Work on a local copy of the debug registers, and on success,
511 commit the change back to the inferior. */
512 struct x86_debug_reg_state local_state = *state;
514 if (type == hw_read)
515 return 1; /* unsupported */
517 if (((len != 1 && len != 2 && len != 4)
518 && !(TARGET_HAS_DR_LEN_8 && len == 8))
519 || addr % len != 0)
521 retval = x86_handle_nonaligned_watchpoint (&local_state,
522 WP_INSERT,
523 addr, len, type);
525 else
527 unsigned len_rw = x86_length_and_rw_bits (len, type);
529 retval = x86_insert_aligned_watchpoint (&local_state,
530 addr, len_rw);
533 if (retval == 0)
534 x86_update_inferior_debug_regs (state, &local_state);
536 if (show_debug_regs)
537 x86_show_dr (state, "insert_watchpoint", addr, len, type);
539 return retval;
542 /* Remove a watchpoint that watched the memory region which starts at
543 address ADDR, whose length is LEN bytes, and for accesses of the
544 type TYPE. Return 0 on success, -1 on failure. */
547 x86_dr_remove_watchpoint (struct x86_debug_reg_state *state,
548 enum target_hw_bp_type type,
549 CORE_ADDR addr, int len)
551 int retval;
552 /* Work on a local copy of the debug registers, and on success,
553 commit the change back to the inferior. */
554 struct x86_debug_reg_state local_state = *state;
556 if (((len != 1 && len != 2 && len != 4)
557 && !(TARGET_HAS_DR_LEN_8 && len == 8))
558 || addr % len != 0)
560 retval = x86_handle_nonaligned_watchpoint (&local_state,
561 WP_REMOVE,
562 addr, len, type);
564 else
566 unsigned len_rw = x86_length_and_rw_bits (len, type);
568 retval = x86_remove_aligned_watchpoint (&local_state,
569 addr, len_rw);
572 if (retval == 0)
573 x86_update_inferior_debug_regs (state, &local_state);
575 if (show_debug_regs)
576 x86_show_dr (state, "remove_watchpoint", addr, len, type);
578 return retval;
581 /* Return non-zero if we can watch a memory region that starts at
582 address ADDR and whose length is LEN bytes. */
585 x86_dr_region_ok_for_watchpoint (struct x86_debug_reg_state *state,
586 CORE_ADDR addr, int len)
588 int nregs;
590 /* Compute how many aligned watchpoints we would need to cover this
591 region. */
592 nregs = x86_handle_nonaligned_watchpoint (state, WP_COUNT,
593 addr, len, hw_write);
594 return nregs <= DR_NADDR ? 1 : 0;
597 /* If the inferior has some break/watchpoint that triggered, set the
598 address associated with that break/watchpoint and return non-zero.
599 Otherwise, return zero. */
602 x86_dr_stopped_data_address (struct x86_debug_reg_state *state,
603 CORE_ADDR *addr_p)
605 CORE_ADDR addr = 0;
606 int i;
607 int rc = 0;
608 /* The current thread's DR_STATUS. We always need to read this to
609 check whether some watchpoint caused the trap. */
610 unsigned status;
611 /* We need DR_CONTROL as well, but only iff DR_STATUS indicates a
612 data breakpoint trap. Only fetch it when necessary, to avoid an
613 unnecessary extra syscall when no watchpoint triggered. */
614 int control_p = 0;
615 unsigned control = 0;
617 /* In non-stop/async, threads can be running while we change the
618 global dr_mirror (and friends). Say, we set a watchpoint, and
619 let threads resume. Now, say you delete the watchpoint, or
620 add/remove watchpoints such that dr_mirror changes while threads
621 are running. On targets that support non-stop,
622 inserting/deleting watchpoints updates the global dr_mirror only.
623 It does not update the real thread's debug registers; that's only
624 done prior to resume. Instead, if threads are running when the
625 mirror changes, a temporary and transparent stop on all threads
626 is forced so they can get their copy of the debug registers
627 updated on re-resume. Now, say, a thread hit a watchpoint before
628 having been updated with the new dr_mirror contents, and we
629 haven't yet handled the corresponding SIGTRAP. If we trusted
630 dr_mirror below, we'd mistake the real trapped address (from the
631 last time we had updated debug registers in the thread) with
632 whatever was currently in dr_mirror. So to fix this, dr_mirror
633 always represents intention, what we _want_ threads to have in
634 debug registers. To get at the address and cause of the trap, we
635 need to read the state the thread still has in its debug
636 registers.
638 In sum, always get the current debug register values the current
639 thread has, instead of trusting the global mirror. If the thread
640 was running when we last changed watchpoints, the mirror no
641 longer represents what was set in this thread's debug
642 registers. */
643 status = x86_dr_low_get_status ();
645 ALL_DEBUG_ADDRESS_REGISTERS (i)
647 if (!X86_DR_WATCH_HIT (status, i))
648 continue;
650 if (!control_p)
652 control = x86_dr_low_get_control ();
653 control_p = 1;
656 /* This second condition makes sure DRi is set up for a data
657 watchpoint, not a hardware breakpoint. The reason is that
658 GDB doesn't call the target_stopped_data_address method
659 except for data watchpoints. In other words, I'm being
660 paranoiac. */
661 if (X86_DR_GET_RW_LEN (control, i) != 0)
663 addr = x86_dr_low_get_addr (i);
664 rc = 1;
665 if (show_debug_regs)
666 x86_show_dr (state, "watchpoint_hit", addr, -1, hw_write);
670 if (show_debug_regs && addr == 0)
671 x86_show_dr (state, "stopped_data_addr", 0, 0, hw_write);
673 if (rc)
674 *addr_p = addr;
675 return rc;
678 /* Return non-zero if the inferior has some watchpoint that triggered.
679 Otherwise return zero. */
682 x86_dr_stopped_by_watchpoint (struct x86_debug_reg_state *state)
684 CORE_ADDR addr = 0;
685 return x86_dr_stopped_data_address (state, &addr);
688 /* Return non-zero if the inferior has some hardware breakpoint that
689 triggered. Otherwise return zero. */
692 x86_dr_stopped_by_hw_breakpoint (struct x86_debug_reg_state *state)
694 CORE_ADDR addr = 0;
695 int i;
696 int rc = 0;
697 /* The current thread's DR_STATUS. We always need to read this to
698 check whether some watchpoint caused the trap. */
699 unsigned status;
700 /* We need DR_CONTROL as well, but only iff DR_STATUS indicates a
701 breakpoint trap. Only fetch it when necessary, to avoid an
702 unnecessary extra syscall when no watchpoint triggered. */
703 int control_p = 0;
704 unsigned control = 0;
706 /* As above, always read the current thread's debug registers rather
707 than trusting dr_mirror. */
708 status = x86_dr_low_get_status ();
710 ALL_DEBUG_ADDRESS_REGISTERS (i)
712 if (!X86_DR_WATCH_HIT (status, i))
713 continue;
715 if (!control_p)
717 control = x86_dr_low_get_control ();
718 control_p = 1;
721 if (X86_DR_GET_RW_LEN (control, i) == 0)
723 addr = x86_dr_low_get_addr (i);
724 rc = 1;
725 if (show_debug_regs)
726 x86_show_dr (state, "watchpoint_hit", addr, -1, hw_execute);
730 return rc;