mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 21:40:22 +08:00
DRY code duplicated across OSes
This commit is contained in:
@ -471,6 +471,27 @@ func (dbp *DebuggedProcess) clearTempBreakpoints() error {
|
|||||||
}
|
}
|
||||||
return nil
|
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 {
|
func (dbp *DebuggedProcess) run(fn func() error) error {
|
||||||
if dbp.exited {
|
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
|
// Since we cannot be notified of new threads on OS X
|
||||||
// this is as good a time as any to check for them.
|
// this is as good a time as any to check for them.
|
||||||
dbp.updateThreadList()
|
dbp.updateThreadList()
|
||||||
thread, ok := dbp.Threads[int(port)]
|
return dbp.handleBreakpointOnThread(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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func wait(pid, options int) (int, *sys.WaitStatus, error) {
|
func wait(pid, options int) (int, *sys.WaitStatus, error) {
|
||||||
|
|||||||
@ -258,25 +258,7 @@ func trapWait(dbp *DebuggedProcess, pid int) (*ThreadContext, *BreakPoint, error
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if status.StopSignal() == sys.SIGTRAP {
|
if status.StopSignal() == sys.SIGTRAP {
|
||||||
thread, ok := dbp.Threads[wpid]
|
return dbp.handleBreakpointOnThread(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
|
|
||||||
}
|
}
|
||||||
if status.StopSignal() == sys.SIGSTOP && dbp.halt {
|
if status.StopSignal() == sys.SIGSTOP && dbp.halt {
|
||||||
return nil, nil, ManualStopError{}
|
return nil, nil, ManualStopError{}
|
||||||
|
|||||||
Reference in New Issue
Block a user