提交 047a91af 编写于 作者: D Derek Parker

Improve 'next' algorithm

上级 16064ce6
...@@ -240,9 +240,6 @@ func (dbp *DebuggedProcess) Status() *sys.WaitStatus { ...@@ -240,9 +240,6 @@ func (dbp *DebuggedProcess) Status() *sys.WaitStatus {
// Step over function calls. // Step over function calls.
func (dbp *DebuggedProcess) Next() error { func (dbp *DebuggedProcess) Next() error {
if err := dbp.setChanRecvBreakpoints(); err != nil {
return err
}
return dbp.run(dbp.next) return dbp.run(dbp.next)
} }
...@@ -250,12 +247,18 @@ func (dbp *DebuggedProcess) next() error { ...@@ -250,12 +247,18 @@ func (dbp *DebuggedProcess) next() error {
// Make sure we clean up the temp breakpoints created by thread.Next // Make sure we clean up the temp breakpoints created by thread.Next
defer dbp.clearTempBreakpoints() defer dbp.clearTempBreakpoints()
chanRecvCount, err := dbp.setChanRecvBreakpoints()
if err != nil {
return err
}
curg, err := dbp.CurrentThread.curG() curg, err := dbp.CurrentThread.curG()
if err != nil { if err != nil {
return err return err
} }
var goroutineExiting bool var goroutineExiting bool
var waitCount int
for _, th := range dbp.Threads { for _, th := range dbp.Threads {
if th.blocked() { // Continue threads that aren't running go code. if th.blocked() { // Continue threads that aren't running go code.
if err = th.Continue(); err != nil { if err = th.Continue(); err != nil {
...@@ -263,8 +266,10 @@ func (dbp *DebuggedProcess) next() error { ...@@ -263,8 +266,10 @@ func (dbp *DebuggedProcess) next() error {
} }
continue continue
} }
waitCount++
if err = th.Next(); err != nil { if err = th.Next(); err != nil {
if err, ok := err.(GoroutineExitingError); ok { if err, ok := err.(GoroutineExitingError); ok {
waitCount = waitCount - 1 + chanRecvCount
if err.goid == curg.Id { if err.goid == curg.Id {
goroutineExiting = true goroutineExiting = true
} }
...@@ -277,7 +282,7 @@ func (dbp *DebuggedProcess) next() error { ...@@ -277,7 +282,7 @@ func (dbp *DebuggedProcess) next() error {
} }
} }
for { for waitCount > 0 {
thread, err := dbp.trapWait(-1) thread, err := dbp.trapWait(-1)
if err != nil { if err != nil {
return err return err
...@@ -291,32 +296,31 @@ func (dbp *DebuggedProcess) next() error { ...@@ -291,32 +296,31 @@ func (dbp *DebuggedProcess) next() error {
if dbp.CurrentThread != thread { if dbp.CurrentThread != thread {
dbp.SwitchThread(thread.Id) dbp.SwitchThread(thread.Id)
} }
if err = dbp.Halt(); err != nil {
return err
}
break
} }
waitCount--
} }
return nil return dbp.Halt()
} }
func (dbp *DebuggedProcess) setChanRecvBreakpoints() error { func (dbp *DebuggedProcess) setChanRecvBreakpoints() (int, error) {
var count int
allg, err := dbp.GoroutinesInfo() allg, err := dbp.GoroutinesInfo()
if err != nil { if err != nil {
return err return 0, err
} }
for _, g := range allg { for _, g := range allg {
if g.ChanRecvBlocked() { if g.ChanRecvBlocked() {
ret, err := g.chanRecvReturnAddr(dbp) ret, err := g.chanRecvReturnAddr(dbp)
if err != nil { if err != nil {
return err return 0, err
} }
if _, err = dbp.TempBreak(ret); err != nil { if _, err = dbp.TempBreak(ret); err != nil {
return err return 0, err
} }
count++
} }
} }
return nil return count, nil
} }
// Resume process. // Resume process.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册