-
Notifications
You must be signed in to change notification settings - Fork 2.2k
cmd/dlv: add --client-addr flag to run dap with a predefined client #2568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
cbfed32
e6f72d2
6538d62
d974e4d
596c5ba
fa0574a
4664030
d818a10
962ccae
104d76b
e58f24b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,11 @@ var ( | |
| // disableASLR is used to disable ASLR | ||
| disableASLR bool | ||
|
|
||
| // dapConnect is dap subcommand's hidden flag that sets the rendezvous point address. | ||
| // If it is specified, the dap server operates in reverse mode and | ||
| // communicate only through the proxy dap server at the rendezvous point. | ||
| dapConnect string | ||
|
|
||
| // backend selection | ||
| backend string | ||
|
|
||
|
|
@@ -188,6 +193,9 @@ While --continue is not supported, stopOnEntry launch/attach attribute can be us | |
| execution is resumed at the start of the debug session.`, | ||
| 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") | ||
|
|
||
| rootCommand.AddCommand(dapCommand) | ||
|
|
||
| // 'debug' subcommand. | ||
|
|
@@ -435,26 +443,47 @@ func dapCmd(cmd *cobra.Command, args []string) { | |
| fmt.Fprintf(os.Stderr, "Warning: program flags ignored with dap; specify via launch/attach request instead\n") | ||
| } | ||
|
|
||
| listener, err := net.Listen("tcp", addr) | ||
| if err != nil { | ||
| fmt.Printf("couldn't start listener: %s\n", err) | ||
| return 1 | ||
| } | ||
| var server *dap.Server | ||
| disconnectChan := make(chan struct{}) | ||
| server := dap.NewServer(&service.Config{ | ||
| Listener: listener, | ||
| DisconnectChan: disconnectChan, | ||
| Debugger: debugger.Config{ | ||
| Backend: backend, | ||
| Foreground: headless && tty == "", | ||
| DebugInfoDirectories: conf.DebugInfoDirectories, | ||
| CheckGoVersion: checkGoVersion, | ||
| TTY: tty, | ||
| }, | ||
| CheckLocalConnUser: checkLocalConnUser, | ||
| }) | ||
| defer server.Stop() | ||
|
|
||
| if dapConnect == "" { | ||
| listener, err := net.Listen("tcp", addr) | ||
| if err != nil { | ||
| fmt.Printf("couldn't start listener: %s\n", err) | ||
| return 1 | ||
| } | ||
| server = dap.NewServer(&service.Config{ | ||
| Listener: listener, | ||
| DisconnectChan: disconnectChan, | ||
| Debugger: debugger.Config{ | ||
|
polinasok marked this conversation as resolved.
Outdated
|
||
| Backend: backend, | ||
| Foreground: headless && tty == "", | ||
| DebugInfoDirectories: conf.DebugInfoDirectories, | ||
| CheckGoVersion: checkGoVersion, | ||
| TTY: tty, | ||
| }, | ||
| CheckLocalConnUser: checkLocalConnUser, | ||
| }) | ||
| } else { // reverse mode | ||
|
hyangah marked this conversation as resolved.
Outdated
|
||
| headless = true // TODO(github.com/go-delve/delve/issues/2552): consider the same for the normal mode. | ||
|
hyangah marked this conversation as resolved.
Outdated
|
||
|
|
||
| conn, err := net.Dial("tcp", dapConnect) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reminded me of the preconnected Listener used by the rpc server. In non-headless (basically with-client) mode, even though the client connection is predefined, the server code is reused as-is. Is something similar perhaps to consider here to arrive at a less nuanced common server denominator?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't understand what you mean. There is nothing special here beyond the standard basic tcp connection and I don't see much of commonality beyond that. preconnected Listener is used to arrange the dlv cli to connect to the server (possibly running in process). There, the client is still a client (the role in the rpc protocol) and the server is what uses service/debugger package. In this reverse mode, the entity that is dialing and plays the role of 'server' in the protocol, is what's using service/debugger package.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my understanding, the client is the entity that makes the debugging requests and the server is the entity that serves those requests. I don't think it matters which side connects to which side, client to server or server to client. Regardless of the specifics of that initial handshake, the rest of the traffic and meaning of the two sides don't change, do they? That's true for both rpc+terminal case and for dap+special-client case. In this new mode you are defining, you have a predefined client that you connect to before you call NewServer. I propose that we do the same here to move connection details outside of the server, keeping it general and consistent with the rpc server, which we ultimately want to merge with under a single command.
Then pass the result to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the proposed approach overcomplicates the code without clear use cases. When the use case that benefits from it is obvious, I am ok to rework this. Until then, I prefer simplicity and less channels and locks. |
||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Failed to connect to the DAP proxy server: %v\n", err) | ||
|
hyangah marked this conversation as resolved.
Outdated
|
||
| return 1 | ||
| } | ||
| server = dap.NewReverseServer(&service.Config{ | ||
| DisconnectChan: disconnectChan, | ||
| Debugger: debugger.Config{ | ||
| Backend: backend, | ||
| Foreground: headless && tty == "", | ||
| DebugInfoDirectories: conf.DebugInfoDirectories, | ||
| CheckGoVersion: checkGoVersion, | ||
| TTY: tty, | ||
| }, | ||
| }, conn) | ||
| } | ||
| defer server.Stop() | ||
| server.Run() | ||
| waitForDisconnectSignal(disconnectChan) | ||
| return 0 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.