Only clear and reset breakpoint for current thread

This commit is contained in:
aarzilli
2015-06-26 15:59:11 +02:00
committed by Derek Parker
parent 9d1711d376
commit 71fae8f5c6
2 changed files with 11 additions and 7 deletions

View File

@ -123,7 +123,7 @@ func (dbp *Process) setBreakpoint(tid int, addr uint64, temp bool) (*Breakpoint,
if _, err := readMemory(thread, uintptr(addr), originalData); err != nil {
return nil, err
}
if _, err := writeMemory(thread, uintptr(addr), dbp.arch.BreakpointInstruction()); err != nil {
if err := dbp.writeSoftwareBreakpoint(thread, addr); err != nil {
return nil, err
}
dbp.Breakpoints[addr] = &Breakpoint{
@ -139,6 +139,11 @@ func (dbp *Process) setBreakpoint(tid int, addr uint64, temp bool) (*Breakpoint,
return dbp.Breakpoints[addr], nil
}
func (dbp *Process) writeSoftwareBreakpoint(thread *Thread, addr uint64) error {
_, err := writeMemory(thread, uintptr(addr), dbp.arch.BreakpointInstruction())
return err
}
// Error thrown when trying to clear a breakpoint that does not exist.
type NoBreakpointError struct {
addr uint64

View File

@ -78,19 +78,18 @@ func (thread *Thread) Step() (err error) {
bp, ok := thread.dbp.Breakpoints[pc]
if ok {
// Clear the breakpoint so that we can continue execution.
_, err = thread.dbp.ClearBreakpoint(bp.Addr)
_, err = bp.Clear(thread)
if err != nil {
return err
}
// Restore breakpoint now that we have passed it.
defer func() {
var nbp *Breakpoint
nbp, err = thread.dbp.setBreakpoint(thread.Id, bp.Addr, bp.Temp)
if err != nil {
return
if bp.hardware {
err = thread.dbp.setHardwareBreakpoint(bp.reg, thread.Id, bp.Addr)
} else {
err = thread.dbp.writeSoftwareBreakpoint(thread, bp.Addr)
}
nbp.Temp = bp.Temp
}()
}