mirror of
https://github.com/go-delve/delve.git
synced 2025-11-02 21:40:22 +08:00
service: Make Halt work during tracing (#469)
While tracing delve may spend most of its time outside of proc.(*Process).Continue, which renders service/rpc/client.(*Client).Halt ineffective. This commit changes the implementation of service/rpc/client.(*Client).Halt to make it capable of stopping traces.
This commit is contained in:
committed by
Derek Parker
parent
38127e5a00
commit
7820921b7e
@ -7,6 +7,7 @@ import (
|
||||
"net/rpc/jsonrpc"
|
||||
|
||||
"github.com/derekparker/delve/service/api"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Client is a RPC service.Client.
|
||||
@ -14,6 +15,8 @@ type RPCClient struct {
|
||||
addr string
|
||||
processPid int
|
||||
client *rpc.Client
|
||||
haltMu sync.Mutex
|
||||
haltReq bool
|
||||
}
|
||||
|
||||
// NewClient creates a new RPCClient.
|
||||
@ -50,8 +53,18 @@ func (c *RPCClient) GetState() (*api.DebuggerState, error) {
|
||||
|
||||
func (c *RPCClient) Continue() <-chan *api.DebuggerState {
|
||||
ch := make(chan *api.DebuggerState)
|
||||
c.haltMu.Lock()
|
||||
c.haltReq = false
|
||||
c.haltMu.Unlock()
|
||||
go func() {
|
||||
for {
|
||||
c.haltMu.Lock()
|
||||
if c.haltReq {
|
||||
c.haltMu.Unlock()
|
||||
close(ch)
|
||||
return
|
||||
}
|
||||
c.haltMu.Unlock()
|
||||
state := new(api.DebuggerState)
|
||||
err := c.call("Command", &api.DebuggerCommand{Name: api.Continue}, state)
|
||||
if err != nil {
|
||||
@ -125,6 +138,9 @@ func (c *RPCClient) SwitchGoroutine(goroutineID int) (*api.DebuggerState, error)
|
||||
|
||||
func (c *RPCClient) Halt() (*api.DebuggerState, error) {
|
||||
state := new(api.DebuggerState)
|
||||
c.haltMu.Lock()
|
||||
c.haltReq = true
|
||||
c.haltMu.Unlock()
|
||||
err := c.call("Command", &api.DebuggerCommand{Name: api.Halt}, state)
|
||||
return state, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user