DRY code duplicated across OSes

This commit is contained in:
Derek Parker
2015-04-03 10:52:31 -05:00
parent e4426fa51f
commit ccad114ed1
3 changed files with 23 additions and 39 deletions

View File

@ -471,6 +471,27 @@ func (dbp *DebuggedProcess) clearTempBreakpoints() error {
}
return nil
}
func (dbp *DebuggedProcess) handleBreakpointOnThread(id int) (*ThreadContext, *BreakPoint, error) {
thread, ok := dbp.Threads[id]
if !ok {
return nil, nil, fmt.Errorf("could not find thread for %d", id)
}
pc, err := thread.CurrentPC()
if err != nil {
return nil, nil, err
}
// Check for hardware breakpoint
for _, bp := range dbp.HWBreakPoints {
if bp != nil && bp.Addr == pc {
return thread, bp, nil
}
}
// Check to see if we have hit a software breakpoint.
if bp, ok := dbp.BreakPoints[pc-1]; ok {
return thread, bp, nil
}
return thread, nil, nil
}
func (dbp *DebuggedProcess) run(fn func() error) error {
if dbp.exited {

View File

@ -197,26 +197,7 @@ func trapWait(dbp *DebuggedProcess, pid int) (*ThreadContext, *BreakPoint, error
// Since we cannot be notified of new threads on OS X
// this is as good a time as any to check for them.
dbp.updateThreadList()
thread, ok := dbp.Threads[int(port)]
if !ok {
return nil, nil, fmt.Errorf("could not find thread for %d", port)
}
pc, err := thread.CurrentPC()
if err != nil {
return nil, nil, err
}
// Check for hardware breakpoint
for _, bp := range dbp.HWBreakPoints {
if bp != nil && bp.Addr == pc {
return thread, bp, nil
}
}
// Check to see if we have hit a software breakpoint.
if bp, ok := dbp.BreakPoints[pc-1]; ok {
return thread, bp, nil
}
return thread, nil, nil
return dbp.handleBreakpointOnThread(int(port))
}
func wait(pid, options int) (int, *sys.WaitStatus, error) {

View File

@ -258,25 +258,7 @@ func trapWait(dbp *DebuggedProcess, pid int) (*ThreadContext, *BreakPoint, error
continue
}
if status.StopSignal() == sys.SIGTRAP {
thread, ok := dbp.Threads[wpid]
if !ok {
return nil, nil, fmt.Errorf("could not find thread for %d", wpid)
}
pc, err := thread.CurrentPC()
if err != nil {
return nil, nil, err
}
// Check for hardware breakpoint
for _, bp := range dbp.HWBreakPoints {
if bp != nil && bp.Addr == pc {
return thread, bp, nil
}
}
// Check to see if we have hit a software breakpoint.
if bp, ok := dbp.BreakPoints[pc-1]; ok {
return thread, bp, nil
}
return thread, nil, nil
return dbp.handleBreakpointOnThread(wpid)
}
if status.StopSignal() == sys.SIGSTOP && dbp.halt {
return nil, nil, ManualStopError{}