mirror of
				https://github.com/go-delve/delve.git
				synced 2025-11-04 06:32:16 +08:00 
			
		
		
		
	Use correct tgid for kill in timeoutWait
This commit is contained in:
		@ -537,9 +537,10 @@ func (err TimeoutError) Error() string {
 | 
				
			|||||||
// The purpose is to detect whether a thread is sleeping. However, this is
 | 
					// The purpose is to detect whether a thread is sleeping. However, this is
 | 
				
			||||||
// tricky because a thread can be sleeping due to being a blocked M in the
 | 
					// tricky because a thread can be sleeping due to being a blocked M in the
 | 
				
			||||||
// scheduler or sleeping due to a user calling sleep.
 | 
					// scheduler or sleeping due to a user calling sleep.
 | 
				
			||||||
func timeoutWait(pid int, options int) (int, *syscall.WaitStatus, error) {
 | 
					func timeoutWait(thread *ThreadContext, options int) (int, *syscall.WaitStatus, error) {
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		status   syscall.WaitStatus
 | 
							status   syscall.WaitStatus
 | 
				
			||||||
 | 
							pid      = thread.Id
 | 
				
			||||||
		statchan = make(chan *waitstats)
 | 
							statchan = make(chan *waitstats)
 | 
				
			||||||
		errchan  = make(chan error)
 | 
							errchan  = make(chan error)
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
@ -556,25 +557,20 @@ func timeoutWait(pid int, options int) (int, *syscall.WaitStatus, error) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	go func(pid int) {
 | 
						go func(pid int) {
 | 
				
			||||||
		pid, err := syscall.Wait4(pid, &status, syscall.WALL|options, nil)
 | 
							wpid, err := syscall.Wait4(pid, &status, syscall.WALL|options, nil)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			errchan <- fmt.Errorf("wait err %s %d", err, pid)
 | 
								errchan <- fmt.Errorf("wait err %s %d", err, pid)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		statchan <- &waitstats{pid: pid, status: &status}
 | 
							statchan <- &waitstats{pid: wpid, status: &status}
 | 
				
			||||||
	}(pid)
 | 
						}(pid)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	select {
 | 
						select {
 | 
				
			||||||
	case s := <-statchan:
 | 
						case s := <-statchan:
 | 
				
			||||||
		return s.pid, s.status, nil
 | 
							return s.pid, s.status, nil
 | 
				
			||||||
	case <-time.After(2 * time.Second):
 | 
						case <-time.After(2 * time.Second):
 | 
				
			||||||
		if pid > 0 {
 | 
							syscall.Tgkill(thread.Process.Pid, pid, syscall.SIGSTOP)
 | 
				
			||||||
			ps, err := parseProcessStatus(pid)
 | 
							<-statchan
 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return -1, nil, err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			syscall.Tgkill(ps.ppid, ps.pid, syscall.SIGSTOP)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return 0, nil, TimeoutError{pid}
 | 
							return 0, nil, TimeoutError{pid}
 | 
				
			||||||
	case err := <-errchan:
 | 
						case err := <-errchan:
 | 
				
			||||||
 | 
				
			|||||||
@ -192,7 +192,7 @@ func (thread *ThreadContext) Step() (err error) {
 | 
				
			|||||||
		return fmt.Errorf("step failed: %s", err.Error())
 | 
							return fmt.Errorf("step failed: %s", err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_, _, err = timeoutWait(thread.Id, 0)
 | 
						_, _, err = timeoutWait(thread, 0)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		if _, ok := err.(TimeoutError); ok {
 | 
							if _, ok := err.(TimeoutError); ok {
 | 
				
			||||||
			return nil
 | 
								return nil
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user