GDBserver
|
00001 /* Debug register code for the i386. 00002 00003 Copyright (C) 2009-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "server.h" 00021 #include "target.h" 00022 #include "i386-low.h" 00023 #include "break-common.h" 00024 00025 /* Support for 8-byte wide hw watchpoints. */ 00026 #ifndef TARGET_HAS_DR_LEN_8 00027 /* NOTE: sizeof (long) == 4 on win64. */ 00028 #define TARGET_HAS_DR_LEN_8 (sizeof (void *) == 8) 00029 #endif 00030 00031 /* DR7 Debug Control register fields. */ 00032 00033 /* How many bits to skip in DR7 to get to R/W and LEN fields. */ 00034 #define DR_CONTROL_SHIFT 16 00035 /* How many bits in DR7 per R/W and LEN field for each watchpoint. */ 00036 #define DR_CONTROL_SIZE 4 00037 00038 /* Watchpoint/breakpoint read/write fields in DR7. */ 00039 #define DR_RW_EXECUTE (0x0) /* Break on instruction execution. */ 00040 #define DR_RW_WRITE (0x1) /* Break on data writes. */ 00041 #define DR_RW_READ (0x3) /* Break on data reads or writes. */ 00042 00043 /* This is here for completeness. No platform supports this 00044 functionality yet (as of March 2001). Note that the DE flag in the 00045 CR4 register needs to be set to support this. */ 00046 #ifndef DR_RW_IORW 00047 #define DR_RW_IORW (0x2) /* Break on I/O reads or writes. */ 00048 #endif 00049 00050 /* Watchpoint/breakpoint length fields in DR7. The 2-bit left shift 00051 is so we could OR this with the read/write field defined above. */ 00052 #define DR_LEN_1 (0x0 << 2) /* 1-byte region watch or breakpoint. */ 00053 #define DR_LEN_2 (0x1 << 2) /* 2-byte region watch. */ 00054 #define DR_LEN_4 (0x3 << 2) /* 4-byte region watch. */ 00055 #define DR_LEN_8 (0x2 << 2) /* 8-byte region watch (AMD64). */ 00056 00057 /* Local and Global Enable flags in DR7. 00058 00059 When the Local Enable flag is set, the breakpoint/watchpoint is 00060 enabled only for the current task; the processor automatically 00061 clears this flag on every task switch. When the Global Enable flag 00062 is set, the breakpoint/watchpoint is enabled for all tasks; the 00063 processor never clears this flag. 00064 00065 Currently, all watchpoint are locally enabled. If you need to 00066 enable them globally, read the comment which pertains to this in 00067 i386_insert_aligned_watchpoint below. */ 00068 #define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit. */ 00069 #define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit. */ 00070 #define DR_ENABLE_SIZE 2 /* Two enable bits per debug register. */ 00071 00072 /* Local and global exact breakpoint enable flags (a.k.a. slowdown 00073 flags). These are only required on i386, to allow detection of the 00074 exact instruction which caused a watchpoint to break; i486 and 00075 later processors do that automatically. We set these flags for 00076 backwards compatibility. */ 00077 #define DR_LOCAL_SLOWDOWN (0x100) 00078 #define DR_GLOBAL_SLOWDOWN (0x200) 00079 00080 /* Fields reserved by Intel. This includes the GD (General Detect 00081 Enable) flag, which causes a debug exception to be generated when a 00082 MOV instruction accesses one of the debug registers. 00083 00084 FIXME: My Intel manual says we should use 0xF800, not 0xFC00. */ 00085 #define DR_CONTROL_RESERVED (0xFC00) 00086 00087 /* Auxiliary helper macros. */ 00088 00089 /* A value that masks all fields in DR7 that are reserved by Intel. */ 00090 #define I386_DR_CONTROL_MASK (~DR_CONTROL_RESERVED) 00091 00092 /* The I'th debug register is vacant if its Local and Global Enable 00093 bits are reset in the Debug Control register. */ 00094 #define I386_DR_VACANT(state, i) \ 00095 (((state)->dr_control_mirror & (3 << (DR_ENABLE_SIZE * (i)))) == 0) 00096 00097 /* Locally enable the break/watchpoint in the I'th debug register. */ 00098 #define I386_DR_LOCAL_ENABLE(state, i) \ 00099 do { \ 00100 (state)->dr_control_mirror |= \ 00101 (1 << (DR_LOCAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ 00102 } while (0) 00103 00104 /* Globally enable the break/watchpoint in the I'th debug register. */ 00105 #define I386_DR_GLOBAL_ENABLE(state, i) \ 00106 do { \ 00107 (state)->dr_control_mirror |= \ 00108 (1 << (DR_GLOBAL_ENABLE_SHIFT + DR_ENABLE_SIZE * (i))); \ 00109 } while (0) 00110 00111 /* Disable the break/watchpoint in the I'th debug register. */ 00112 #define I386_DR_DISABLE(state, i) \ 00113 do { \ 00114 (state)->dr_control_mirror &= \ 00115 ~(3 << (DR_ENABLE_SIZE * (i))); \ 00116 } while (0) 00117 00118 /* Set in DR7 the RW and LEN fields for the I'th debug register. */ 00119 #define I386_DR_SET_RW_LEN(state, i,rwlen) \ 00120 do { \ 00121 (state)->dr_control_mirror &= \ 00122 ~(0x0f << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \ 00123 (state)->dr_control_mirror |= \ 00124 ((rwlen) << (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))); \ 00125 } while (0) 00126 00127 /* Get from DR7 the RW and LEN fields for the I'th debug register. */ 00128 #define I386_DR_GET_RW_LEN(dr7, i) \ 00129 (((dr7) \ 00130 >> (DR_CONTROL_SHIFT + DR_CONTROL_SIZE * (i))) & 0x0f) 00131 00132 /* Did the watchpoint whose address is in the I'th register break? */ 00133 #define I386_DR_WATCH_HIT(dr6, i) ((dr6) & (1 << (i))) 00134 00135 /* A macro to loop over all debug registers. */ 00136 #define ALL_DEBUG_REGISTERS(i) for (i = 0; i < DR_NADDR; i++) 00137 00138 /* Types of operations supported by i386_handle_nonaligned_watchpoint. */ 00139 typedef enum { WP_INSERT, WP_REMOVE, WP_COUNT } i386_wp_op_t; 00140 00141 /* Implementation. */ 00142 00143 /* Clear the reference counts and forget everything we knew about the 00144 debug registers. */ 00145 00146 void 00147 i386_low_init_dregs (struct i386_debug_reg_state *state) 00148 { 00149 int i; 00150 00151 ALL_DEBUG_REGISTERS (i) 00152 { 00153 state->dr_mirror[i] = 0; 00154 state->dr_ref_count[i] = 0; 00155 } 00156 state->dr_control_mirror = 0; 00157 state->dr_status_mirror = 0; 00158 } 00159 00160 /* Print the values of the mirrored debug registers. This is enabled via 00161 the "set debug-hw-points 1" monitor command. */ 00162 00163 static void 00164 i386_show_dr (struct i386_debug_reg_state *state, 00165 const char *func, CORE_ADDR addr, 00166 int len, enum target_hw_bp_type type) 00167 { 00168 int i; 00169 00170 fprintf (stderr, "%s", func); 00171 if (addr || len) 00172 fprintf (stderr, " (addr=%lx, len=%d, type=%s)", 00173 (unsigned long) addr, len, 00174 type == hw_write ? "data-write" 00175 : (type == hw_read ? "data-read" 00176 : (type == hw_access ? "data-read/write" 00177 : (type == hw_execute ? "instruction-execute" 00178 /* FIXME: if/when I/O read/write 00179 watchpoints are supported, add them 00180 here. */ 00181 : "??unknown??")))); 00182 fprintf (stderr, ":\n"); 00183 fprintf (stderr, "\tCONTROL (DR7): %08x STATUS (DR6): %08x\n", 00184 state->dr_control_mirror, state->dr_status_mirror); 00185 ALL_DEBUG_REGISTERS (i) 00186 { 00187 fprintf (stderr, "\ 00188 \tDR%d: addr=0x%s, ref.count=%d DR%d: addr=0x%s, ref.count=%d\n", 00189 i, paddress (state->dr_mirror[i]), 00190 state->dr_ref_count[i], 00191 i + 1, paddress (state->dr_mirror[i + 1]), 00192 state->dr_ref_count[i + 1]); 00193 i++; 00194 } 00195 } 00196 00197 /* Return the value of a 4-bit field for DR7 suitable for watching a 00198 region of LEN bytes for accesses of type TYPE. LEN is assumed to 00199 have the value of 1, 2, or 4. */ 00200 00201 static unsigned 00202 i386_length_and_rw_bits (int len, enum target_hw_bp_type type) 00203 { 00204 unsigned rw; 00205 00206 switch (type) 00207 { 00208 case hw_execute: 00209 rw = DR_RW_EXECUTE; 00210 break; 00211 case hw_write: 00212 rw = DR_RW_WRITE; 00213 break; 00214 case hw_read: 00215 fatal ("The i386 doesn't support data-read watchpoints.\n"); 00216 case hw_access: 00217 rw = DR_RW_READ; 00218 break; 00219 #if 0 00220 /* Not yet supported. */ 00221 case hw_io_access: 00222 rw = DR_RW_IORW; 00223 break; 00224 #endif 00225 default: 00226 error ("\ 00227 Invalid hardware breakpoint type %d in i386_length_and_rw_bits.\n", 00228 (int) type); 00229 } 00230 00231 switch (len) 00232 { 00233 case 1: 00234 return (DR_LEN_1 | rw); 00235 case 2: 00236 return (DR_LEN_2 | rw); 00237 case 4: 00238 return (DR_LEN_4 | rw); 00239 case 8: 00240 if (TARGET_HAS_DR_LEN_8) 00241 return (DR_LEN_8 | rw); 00242 /* ELSE FALL THROUGH */ 00243 default: 00244 error ("\ 00245 Invalid hardware breakpoint length %d in i386_length_and_rw_bits.\n", len); 00246 } 00247 } 00248 00249 /* Insert a watchpoint at address ADDR, which is assumed to be aligned 00250 according to the length of the region to watch. LEN_RW_BITS is the 00251 value of the bits from DR7 which describes the length and access 00252 type of the region to be watched by this watchpoint. Return 0 on 00253 success, -1 on failure. */ 00254 00255 static int 00256 i386_insert_aligned_watchpoint (struct i386_debug_reg_state *state, 00257 CORE_ADDR addr, unsigned len_rw_bits) 00258 { 00259 int i; 00260 00261 /* First, look for an occupied debug register with the same address 00262 and the same RW and LEN definitions. If we find one, we can 00263 reuse it for this watchpoint as well (and save a register). */ 00264 ALL_DEBUG_REGISTERS (i) 00265 { 00266 if (!I386_DR_VACANT (state, i) 00267 && state->dr_mirror[i] == addr 00268 && I386_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits) 00269 { 00270 state->dr_ref_count[i]++; 00271 return 0; 00272 } 00273 } 00274 00275 /* Next, look for a vacant debug register. */ 00276 ALL_DEBUG_REGISTERS (i) 00277 { 00278 if (I386_DR_VACANT (state, i)) 00279 break; 00280 } 00281 00282 /* No more debug registers! */ 00283 if (i >= DR_NADDR) 00284 return -1; 00285 00286 /* Now set up the register I to watch our region. */ 00287 00288 /* Record the info in our local mirrored array. */ 00289 state->dr_mirror[i] = addr; 00290 state->dr_ref_count[i] = 1; 00291 I386_DR_SET_RW_LEN (state, i, len_rw_bits); 00292 /* Note: we only enable the watchpoint locally, i.e. in the current 00293 task. Currently, no i386 target allows or supports global 00294 watchpoints; however, if any target would want that in the 00295 future, GDB should probably provide a command to control whether 00296 to enable watchpoints globally or locally, and the code below 00297 should use global or local enable and slow-down flags as 00298 appropriate. */ 00299 I386_DR_LOCAL_ENABLE (state, i); 00300 state->dr_control_mirror |= DR_LOCAL_SLOWDOWN; 00301 state->dr_control_mirror &= I386_DR_CONTROL_MASK; 00302 00303 return 0; 00304 } 00305 00306 /* Remove a watchpoint at address ADDR, which is assumed to be aligned 00307 according to the length of the region to watch. LEN_RW_BITS is the 00308 value of the bits from DR7 which describes the length and access 00309 type of the region watched by this watchpoint. Return 0 on 00310 success, -1 on failure. */ 00311 00312 static int 00313 i386_remove_aligned_watchpoint (struct i386_debug_reg_state *state, 00314 CORE_ADDR addr, unsigned len_rw_bits) 00315 { 00316 int i, retval = -1; 00317 00318 ALL_DEBUG_REGISTERS (i) 00319 { 00320 if (!I386_DR_VACANT (state, i) 00321 && state->dr_mirror[i] == addr 00322 && I386_DR_GET_RW_LEN (state->dr_control_mirror, i) == len_rw_bits) 00323 { 00324 if (--state->dr_ref_count[i] == 0) /* No longer in use? */ 00325 { 00326 /* Reset our mirror. */ 00327 state->dr_mirror[i] = 0; 00328 I386_DR_DISABLE (state, i); 00329 } 00330 retval = 0; 00331 } 00332 } 00333 00334 return retval; 00335 } 00336 00337 /* Insert or remove a (possibly non-aligned) watchpoint, or count the 00338 number of debug registers required to watch a region at address 00339 ADDR whose length is LEN for accesses of type TYPE. Return 0 on 00340 successful insertion or removal, a positive number when queried 00341 about the number of registers, or -1 on failure. If WHAT is not a 00342 valid value, bombs through internal_error. */ 00343 00344 static int 00345 i386_handle_nonaligned_watchpoint (struct i386_debug_reg_state *state, 00346 i386_wp_op_t what, CORE_ADDR addr, int len, 00347 enum target_hw_bp_type type) 00348 { 00349 int retval = 0; 00350 int max_wp_len = TARGET_HAS_DR_LEN_8 ? 8 : 4; 00351 00352 static const int size_try_array[8][8] = 00353 { 00354 {1, 1, 1, 1, 1, 1, 1, 1}, /* Trying size one. */ 00355 {2, 1, 2, 1, 2, 1, 2, 1}, /* Trying size two. */ 00356 {2, 1, 2, 1, 2, 1, 2, 1}, /* Trying size three. */ 00357 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size four. */ 00358 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size five. */ 00359 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size six. */ 00360 {4, 1, 2, 1, 4, 1, 2, 1}, /* Trying size seven. */ 00361 {8, 1, 2, 1, 4, 1, 2, 1}, /* Trying size eight. */ 00362 }; 00363 00364 while (len > 0) 00365 { 00366 int align = addr % max_wp_len; 00367 /* Four (eight on AMD64) is the maximum length a debug register 00368 can watch. */ 00369 int try = (len > max_wp_len ? (max_wp_len - 1) : len - 1); 00370 int size = size_try_array[try][align]; 00371 00372 if (what == WP_COUNT) 00373 { 00374 /* size_try_array[] is defined such that each iteration 00375 through the loop is guaranteed to produce an address and a 00376 size that can be watched with a single debug register. 00377 Thus, for counting the registers required to watch a 00378 region, we simply need to increment the count on each 00379 iteration. */ 00380 retval++; 00381 } 00382 else 00383 { 00384 unsigned len_rw = i386_length_and_rw_bits (size, type); 00385 00386 if (what == WP_INSERT) 00387 retval = i386_insert_aligned_watchpoint (state, addr, len_rw); 00388 else if (what == WP_REMOVE) 00389 retval = i386_remove_aligned_watchpoint (state, addr, len_rw); 00390 else 00391 fatal ("\ 00392 Invalid value %d of operation in i386_handle_nonaligned_watchpoint.\n", 00393 (int) what); 00394 00395 if (retval) 00396 break; 00397 } 00398 00399 addr += size; 00400 len -= size; 00401 } 00402 00403 return retval; 00404 } 00405 00406 #define Z_PACKET_HW_BP '1' 00407 #define Z_PACKET_WRITE_WP '2' 00408 #define Z_PACKET_READ_WP '3' 00409 #define Z_PACKET_ACCESS_WP '4' 00410 00411 /* Map the protocol watchpoint type TYPE to enum target_hw_bp_type. */ 00412 00413 static enum target_hw_bp_type 00414 Z_packet_to_hw_type (char type) 00415 { 00416 switch (type) 00417 { 00418 case Z_PACKET_HW_BP: 00419 return hw_execute; 00420 case Z_PACKET_WRITE_WP: 00421 return hw_write; 00422 case Z_PACKET_READ_WP: 00423 return hw_read; 00424 case Z_PACKET_ACCESS_WP: 00425 return hw_access; 00426 default: 00427 fatal ("Z_packet_to_hw_type: bad watchpoint type %c", type); 00428 } 00429 } 00430 00431 /* Update the inferior debug registers state, in INF_STATE, with the 00432 new debug registers state, in NEW_STATE. */ 00433 00434 static void 00435 i386_update_inferior_debug_regs (struct i386_debug_reg_state *inf_state, 00436 struct i386_debug_reg_state *new_state) 00437 { 00438 int i; 00439 00440 ALL_DEBUG_REGISTERS (i) 00441 { 00442 if (I386_DR_VACANT (new_state, i) != I386_DR_VACANT (inf_state, i)) 00443 i386_dr_low_set_addr (new_state, i); 00444 else 00445 gdb_assert (new_state->dr_mirror[i] == inf_state->dr_mirror[i]); 00446 } 00447 00448 if (new_state->dr_control_mirror != inf_state->dr_control_mirror) 00449 i386_dr_low_set_control (new_state); 00450 00451 *inf_state = *new_state; 00452 } 00453 00454 /* Insert a watchpoint to watch a memory region which starts at 00455 address ADDR and whose length is LEN bytes. Watch memory accesses 00456 of the type TYPE_FROM_PACKET. Return 0 on success, -1 on failure. */ 00457 00458 int 00459 i386_low_insert_watchpoint (struct i386_debug_reg_state *state, 00460 char type_from_packet, CORE_ADDR addr, int len) 00461 { 00462 int retval; 00463 enum target_hw_bp_type type = Z_packet_to_hw_type (type_from_packet); 00464 /* Work on a local copy of the debug registers, and on success, 00465 commit the change back to the inferior. */ 00466 struct i386_debug_reg_state local_state = *state; 00467 00468 if (type == hw_read) 00469 return 1; /* unsupported */ 00470 00471 if (((len != 1 && len != 2 && len != 4) 00472 && !(TARGET_HAS_DR_LEN_8 && len == 8)) 00473 || addr % len != 0) 00474 { 00475 retval = i386_handle_nonaligned_watchpoint (&local_state, WP_INSERT, 00476 addr, len, type); 00477 } 00478 else 00479 { 00480 unsigned len_rw = i386_length_and_rw_bits (len, type); 00481 00482 retval = i386_insert_aligned_watchpoint (&local_state, addr, len_rw); 00483 } 00484 00485 if (retval == 0) 00486 i386_update_inferior_debug_regs (state, &local_state); 00487 00488 if (debug_hw_points) 00489 i386_show_dr (state, "insert_watchpoint", addr, len, type); 00490 00491 return retval; 00492 } 00493 00494 /* Remove a watchpoint that watched the memory region which starts at 00495 address ADDR, whose length is LEN bytes, and for accesses of the 00496 type TYPE_FROM_PACKET. Return 0 on success, -1 on failure. */ 00497 00498 int 00499 i386_low_remove_watchpoint (struct i386_debug_reg_state *state, 00500 char type_from_packet, CORE_ADDR addr, int len) 00501 { 00502 int retval; 00503 enum target_hw_bp_type type = Z_packet_to_hw_type (type_from_packet); 00504 /* Work on a local copy of the debug registers, and on success, 00505 commit the change back to the inferior. */ 00506 struct i386_debug_reg_state local_state = *state; 00507 00508 if (((len != 1 && len != 2 && len != 4) 00509 && !(TARGET_HAS_DR_LEN_8 && len == 8)) 00510 || addr % len != 0) 00511 { 00512 retval = i386_handle_nonaligned_watchpoint (&local_state, WP_REMOVE, 00513 addr, len, type); 00514 } 00515 else 00516 { 00517 unsigned len_rw = i386_length_and_rw_bits (len, type); 00518 00519 retval = i386_remove_aligned_watchpoint (&local_state, addr, len_rw); 00520 } 00521 00522 if (retval == 0) 00523 i386_update_inferior_debug_regs (state, &local_state); 00524 00525 if (debug_hw_points) 00526 i386_show_dr (state, "remove_watchpoint", addr, len, type); 00527 00528 return retval; 00529 } 00530 00531 /* Return non-zero if we can watch a memory region that starts at 00532 address ADDR and whose length is LEN bytes. */ 00533 00534 int 00535 i386_low_region_ok_for_watchpoint (struct i386_debug_reg_state *state, 00536 CORE_ADDR addr, int len) 00537 { 00538 int nregs; 00539 00540 /* Compute how many aligned watchpoints we would need to cover this 00541 region. */ 00542 nregs = i386_handle_nonaligned_watchpoint (state, WP_COUNT, 00543 addr, len, hw_write); 00544 return nregs <= DR_NADDR ? 1 : 0; 00545 } 00546 00547 /* If the inferior has some break/watchpoint that triggered, set the 00548 address associated with that break/watchpoint and return true. 00549 Otherwise, return false. */ 00550 00551 int 00552 i386_low_stopped_data_address (struct i386_debug_reg_state *state, 00553 CORE_ADDR *addr_p) 00554 { 00555 CORE_ADDR addr = 0; 00556 int i; 00557 int rc = 0; 00558 /* The current thread's DR_STATUS. We always need to read this to 00559 check whether some watchpoint caused the trap. */ 00560 unsigned status; 00561 /* We need DR_CONTROL as well, but only iff DR_STATUS indicates a 00562 data breakpoint trap. Only fetch it when necessary, to avoid an 00563 unnecessary extra syscall when no watchpoint triggered. */ 00564 int control_p = 0; 00565 unsigned control = 0; 00566 00567 /* In non-stop/async, threads can be running while we change the 00568 global dr_mirror (and friends). Say, we set a watchpoint, and 00569 let threads resume. Now, say you delete the watchpoint, or 00570 add/remove watchpoints such that dr_mirror changes while threads 00571 are running. On targets that support non-stop, 00572 inserting/deleting watchpoints updates the global dr_mirror only. 00573 It does not update the real thread's debug registers; that's only 00574 done prior to resume. Instead, if threads are running when the 00575 mirror changes, a temporary and transparent stop on all threads 00576 is forced so they can get their copy of the debug registers 00577 updated on re-resume. Now, say, a thread hit a watchpoint before 00578 having been updated with the new dr_mirror contents, and we 00579 haven't yet handled the corresponding SIGTRAP. If we trusted 00580 dr_mirror below, we'd mistake the real trapped address (from the 00581 last time we had updated debug registers in the thread) with 00582 whatever was currently in dr_mirror. So to fix this, dr_mirror 00583 always represents intention, what we _want_ threads to have in 00584 debug registers. To get at the address and cause of the trap, we 00585 need to read the state the thread still has in its debug 00586 registers. 00587 00588 In sum, always get the current debug register values the current 00589 thread has, instead of trusting the global mirror. If the thread 00590 was running when we last changed watchpoints, the mirror no 00591 longer represents what was set in this thread's debug 00592 registers. */ 00593 status = i386_dr_low_get_status (); 00594 00595 ALL_DEBUG_REGISTERS (i) 00596 { 00597 if (!I386_DR_WATCH_HIT (status, i)) 00598 continue; 00599 00600 if (!control_p) 00601 { 00602 control = i386_dr_low_get_control (); 00603 control_p = 1; 00604 } 00605 00606 /* This second condition makes sure DRi is set up for a data 00607 watchpoint, not a hardware breakpoint. The reason is that 00608 GDB doesn't call the target_stopped_data_address method 00609 except for data watchpoints. In other words, I'm being 00610 paranoiac. */ 00611 if (I386_DR_GET_RW_LEN (control, i) != 0) 00612 { 00613 addr = i386_dr_low_get_addr (i); 00614 rc = 1; 00615 if (debug_hw_points) 00616 i386_show_dr (state, "watchpoint_hit", addr, -1, hw_write); 00617 } 00618 } 00619 00620 if (debug_hw_points && addr == 0) 00621 i386_show_dr (state, "stopped_data_addr", 0, 0, hw_write); 00622 00623 if (rc) 00624 *addr_p = addr; 00625 return rc; 00626 } 00627 00628 /* Return true if the inferior has some watchpoint that triggered. 00629 Otherwise return false. */ 00630 00631 int 00632 i386_low_stopped_by_watchpoint (struct i386_debug_reg_state *state) 00633 { 00634 CORE_ADDR addr = 0; 00635 return i386_low_stopped_data_address (state, &addr); 00636 }