![](https://csdnimg.cn/release/download_crawler_static/2192878/bg13.jpg)
Chapter 3: Algorithms 12
i386_region_ok_for_watchpoint (addr, len )
The macro TARGET_REGION_OK_FOR_HW_WATCHPOINT is set to call this function.
It counts the number of debug registers required to watch a given region, and
returns a non-zero value if that number is less than 4, the number of debug
registers available to x86 processors.
i386_stopped_data_address (addr_p )
The target function target_stopped_data_address is set to call this function.
This function examines the breakpoint condition bits in the DR6 Debug Status
register, as returned by the I386_DR_LOW_GET_STATUS macro, and returns the
address associated with the first bit that is set in DR6.
i386_stopped_by_watchpoint (void)
The m acro STOPPED_BY_WATCHPOINT is set to call this function. The argu-
ment passed to STOPPED_BY_WATCHPOINT is ignored. This function examines
the breakpoint condition bits in the DR6 Debug Status register, as returned
by the I386_DR_LOW_GET_STATUS macro, and returns true if any bit is set.
Otherwise, false is returned.
i386_insert_watchpoint (addr, len, type )
i386_remove_watchpoint (addr, len, type )
Insert or remove a watchpoint. The macros target_insert_watchpoint and
target_remove_watchpoint are set to call these functions. i386_insert_
watchpoint first looks for a debug register which is already set to watch the
same region for the same access types; if found, it just increments the reference
count of that debug register, thus implementing debug register sharing between
watchpoints. If no such register is found, the function looks for a vacant de-
bug register, sets its mirrored value to addr, sets the mirrored value of DR7
Debug Control register as appropriate for the len and type parameters, and
then passes the new values of the debug register and DR7 to the inferior by
calling I386_DR_LOW_SET_ADDR and I386_DR_LOW_SET_CONTROL. If more than
one debug register is required to cover the given region, the above process is
repeated for each debug register.
i386_remove_watchpoint does the opposite: it resets the address in the mir-
rored value of the debug register and its read/write and length bits in the
mirrored value of DR7, then passes these new values to the inferior via I386_
DR_LOW_RESET_ADDR and I386_DR_LOW_SET_CONTROL. If a register is shared by
several watchpoints, each time a i386_remove_watchpoint is called, it decre-
ments the reference count, and only calls I386_DR_LOW_RESET_ADDR and I386_
DR_LOW_SET_CONTROL when the count goes to zero.
i386_insert_hw_breakpoint (bp_tgt )
i386_remove_hw_breakpoint (bp_tgt )
These functions insert and remove hardware-assisted breakpoints. The macros
target_insert_hw_breakpoint and target_remove_hw_breakpoint are set
to call these functions. The argument is a struct bp_target_info *, as de-
scribed in the documentation for target_insert_breakpoint. These func-
tions work like i386_insert_watchpoint and i386_remove_watchpoint, re-
spective ly, except that they set up the debug registers to watch instruction