Skip to content

Commit

Permalink
cmd/dlv: address comments - made the --connect unhidden
Browse files Browse the repository at this point in the history
  • Loading branch information
hyangah committed Jul 6, 2021
1 parent e6f72d2 commit 6538d62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Documentation/usage/dlv_dap.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ The server does not yet accept multiple client connections (--accept-multiclient
While --continue is not supported, stopOnEntry launch/attach attribute can be used to control if
execution is resumed at the start of the debug session.

The --connect flag is a special flag that makes the server operate in reverse mode.
In this mode, Delve connects to a DAP client listening on host:port,
instead of listening for connections.

```
dlv dap
```

### Options

```
--connect string host:port of the DAP client when running in reverse mode.
```

### Options inherited from parent commands
Expand Down
13 changes: 8 additions & 5 deletions cmd/dlv/cmds/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ var (
// disableASLR is used to disable ASLR
disableASLR bool

// dapConnect is dap subcommand's hidden flag that sets the rendezvous point address.
// dapConnect is dap subcommand's flag that specifies the address of a DAP client.
// If it is specified, the dap server operates in reverse mode and
// communicate only through the proxy dap server at the rendezvous point.
// and dials into the client waiting there.
dapConnect string

// backend selection
Expand Down Expand Up @@ -190,11 +190,14 @@ to be launched or process to be attached to. The following modes are supported:
- attach + local (attaches to a running process, like 'dlv attach')
The server does not yet accept multiple client connections (--accept-multiclient).
While --continue is not supported, stopOnEntry launch/attach attribute can be used to control if
execution is resumed at the start of the debug session.`,
execution is resumed at the start of the debug session.
The --connect flag is a special flag that makes the server operate in reverse mode.
In this mode, Delve connects to a DAP client listening on host:port,
instead of listening for connections.`,
Run: dapCmd,
}
dapCommand.Flags().StringVar(&dapConnect, "connect", "", "host:port of the proxy DAP server. If set, the command starts a DAP server in reverse mode")
dapCommand.Flags().MarkHidden("connect")
dapCommand.Flags().StringVar(&dapConnect, "connect", "", "host:port of the DAP client when running in reverse mode.")

rootCommand.AddCommand(dapCommand)

Expand Down
23 changes: 10 additions & 13 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,15 @@ import (
// when halt is issued while stopping. At that point these goroutines
// wrap-up and exit.
//
// The DAP server set up using NewReverseDAPServer is a special
// DAP server, that is bound to a single net.Conn. Once the connection
// is closed, the server is stopped. Its Run is never called, but
// the NewReverseDAPServer immediately starts serveDAPCodec on the
// net.Conn.
// The DAP server set up using NewReverseServer is a special DAP server,
// that is bound to a single net.Conn. Once the connection is closed,
// the server stops.
type Server struct {
// config is all the information necessary to start the debugger and server.
config *service.Config
// listener is used to accept the client connection.
// In reverse mode, this is nil.
listener net.Listener
// inReverseMode is true if this server operates in reverse mode
// where listener is nil.
inReverseMode bool
// stopTriggered is closed when the server is Stop()-ed.
stopTriggered chan struct{}
// reader is used to read requests from the connection.
Expand Down Expand Up @@ -219,11 +215,13 @@ func NewReverseServer(config *service.Config, conn net.Conn) *Server {

func newServer(config *service.Config, conn net.Conn, inReverseMode bool) *Server {
logger := logflags.DAPLogger()
if !inReverseMode {
if config.Listener != nil {
logflags.WriteDAPListeningMessage(config.Listener.Addr().String())
logger.Debug("DAP server pid = ", os.Getpid())
} else {
} else if conn != nil {
logger.Debug("Reverse DAP server pid = ", os.Getpid())
} else {
logger.Fatal("Cannot set up a DAP server without network configuration")
}

return &Server{
Expand All @@ -235,7 +233,6 @@ func newServer(config *service.Config, conn net.Conn, inReverseMode bool) *Serve
variableHandles: newVariablesHandlesMap(),
args: defaultArgs,
exceptionErr: nil,
inReverseMode: inReverseMode,
conn: conn,
}
}
Expand Down Expand Up @@ -294,7 +291,7 @@ func (s *Server) Stop() {
s.log.Debug("DAP server stopping...")
close(s.stopTriggered)

if !s.inReverseMode {
if s.listener != nil {
_ = s.listener.Close()
}

Expand Down Expand Up @@ -357,7 +354,7 @@ func (s *Server) triggerServerStop() {
// TODO(polina): allow new client connections for new debug sessions,
// so the editor needs to launch delve only once?
func (s *Server) Run() {
if s.inReverseMode {
if s.listener == nil {
go s.serveDAPCodec()
return
}
Expand Down

0 comments on commit 6538d62

Please sign in to comment.