mirror of
https://github.com/go-delve/delve.git
synced 2025-11-01 12:01:35 +08:00
DRY code duplicated across OSes
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user