mirror of
				https://github.com/go-delve/delve.git
				synced 2025-10-31 18:57:18 +08:00 
			
		
		
		
	Do not ask to kill process we spawned
This commit is contained in:
		| @ -69,4 +69,7 @@ type Client interface { | |||||||
|  |  | ||||||
| 	// Returns stacktrace | 	// Returns stacktrace | ||||||
| 	Stacktrace(goroutineId, depth int) ([]api.Location, error) | 	Stacktrace(goroutineId, depth int) ([]api.Location, error) | ||||||
|  |  | ||||||
|  | 	// Returns whether we attached to a running process or not | ||||||
|  | 	AttachedToExistingProcess() bool | ||||||
| } | } | ||||||
|  | |||||||
| @ -205,6 +205,12 @@ func (c *RPCClient) Stacktrace(goroutineId, depth int) ([]api.Location, error) { | |||||||
| 	return locations, err | 	return locations, err | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (c *RPCClient) AttachedToExistingProcess() bool { | ||||||
|  | 	var answer bool | ||||||
|  | 	c.call("AttachedToRunningProcess", nil, &answer) | ||||||
|  | 	return answer | ||||||
|  | } | ||||||
|  |  | ||||||
| func (c *RPCClient) url(path string) string { | func (c *RPCClient) url(path string) string { | ||||||
| 	return fmt.Sprintf("http://%s%s", c.addr, path) | 	return fmt.Sprintf("http://%s%s", c.addr, path) | ||||||
| } | } | ||||||
|  | |||||||
| @ -302,3 +302,10 @@ func (s *RPCServer) ListGoroutines(arg interface{}, goroutines *[]*api.Goroutine | |||||||
| 	*goroutines = gs | 	*goroutines = gs | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (c *RPCServer) AttachedToExistingProcess(arg interface{}, answer *bool) error { | ||||||
|  | 	if c.config.AttachPid != 0 { | ||||||
|  | 		*answer = true | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  | |||||||
| @ -132,13 +132,18 @@ func handleExit(client service.Client, t *Term) (error, int) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	var kill bool | ||||||
|  | 	if client.AttachedToExistingProcess() { | ||||||
| 		answer, err := t.line.Prompt("Would you like to kill the process? [Y/n] ") | 		answer, err := t.line.Prompt("Would you like to kill the process? [Y/n] ") | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return io.EOF, 2 | 			return io.EOF, 2 | ||||||
| 		} | 		} | ||||||
| 		answer = strings.ToLower(strings.TrimSpace(answer)) | 		answer = strings.ToLower(strings.TrimSpace(answer)) | ||||||
|  |  | ||||||
| 	kill := (answer != "n" && answer != "no") | 		kill = (answer != "n" && answer != "no") | ||||||
|  | 	} else { | ||||||
|  | 		kill = true | ||||||
|  | 	} | ||||||
| 	err = client.Detach(kill) | 	err = client.Detach(kill) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err, 1 | 		return err, 1 | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Derek Parker
					Derek Parker