daveleroy / SublimeDebugger

Graphical Debugger for Sublime Text for debuggers that support the debug adapter protocol
MIT License
369 stars 42 forks source link

Golang Delve - Env not parsed and cannot connect to remote server #213

Closed ViBiOh closed 1 year ago

ViBiOh commented 1 year ago

Hi 👋

Thank you for adapting the Debug Adapter Protocol into Sublime Text, it helps a lot to have almost an IDE in the text editor =)

I try to use it with Golang and Delve, but I have two issues. In both cases, if I run the same configuration in VsCode (adapting the env variable name), it works as expected. Is there something I did wrong?

Environment

I'm running the latest plugin version (installed today), v0.9.3. Sublime Text version is Dev Channel Build 4148, on macOS 13.2.1 and with delve 1.20.1 and golang 1.20.2.

Env file not parsed

I'm trying to run the main of my app with a given .env file. The environment contains the following content (configuration for turning JSON logging instead of plain text) and is at the root of my project.

API_LOGGER_JSON=true

It seems not taken in account when launching (the log are not in JSON) with this configuration:

{
  "name": "Launch file",
  "type": "go",
  "request": "launch",
  "mode": "debug",
  "cwd": "${folder}", // This is required, unless the project won't start
  "envFile": ["${folder}/.env"],
  "program": "${folder}/cmd/goweb"
}

The protocol debug are the following

-- platform: osx-x64
-- theme: Adaptive.sublime-theme
-- color_scheme: Mariana.sublime-color-scheme
-- font_face: Menlo
-- font_size: 12

-- adapter: type=go version=0.38.0
-- socket transport process: ['/Users/macbook/opt/gopath/bin/dlv', 'dap', '--listen', 'localhost:58324']
-- socket transport: localhost:58324
-- socket transport: localhost:58324
-- begin transport protocol
<- initialize(1) :: {"seq": 1, "type": "request", "command": "initialize", "arguments": {"clientID": "sublime", "clientName": "Sublime Text", "adapterID": "go", "pathFormat": "path", "linesStartAt1": true, "columnsStartAt1": true, "supportsVariableType": true, "supportsVariablePaging": false, "supportsRunInTerminalRequest": true, "supportsMemoryReferences": true, "locale": "en-us"}}
-> initialize(1) :: {"seq": 0, "type": "response", "request_seq": 1, "success": true, "command": "initialize", "body": {"supportsConfigurationDoneRequest": true, "supportsFunctionBreakpoints": true, "supportsConditionalBreakpoints": true, "supportsEvaluateForHovers": true, "supportsSetVariable": true, "supportsExceptionInfoRequest": true, "supportsDelayedStackTraceLoading": true, "supportsLogPoints": true, "supportsDisassembleRequest": true, "supportsClipboardContext": true, "supportsSteppingGranularity": true, "supportsInstructionBreakpoints": true}}
<- launch(2) :: {"seq": 2, "type": "request", "command": "launch", "arguments": {"cwd": "/Users/macbook/code/goweb", "envFile": ["/Users/macbook/code/goweb/.env"], "mode": "debug", "name": "Launch file", "program": "/Users/macbook/code/goweb/cmd/goweb", "request": "launch", "type": "go"}}
-> initialized .. {"seq": 0, "type": "event", "event": "initialized"}
-> launch(2) :: {"seq": 0, "type": "response", "request_seq": 2, "success": true, "command": "launch"}
<- setExceptionBreakpoints(3) :: {"seq": 3, "type": "request", "command": "setExceptionBreakpoints", "arguments": {"filters": [], "filterOptions": []}}
<- setFunctionBreakpoints(4) :: {"seq": 4, "type": "request", "command": "setFunctionBreakpoints", "arguments": {"breakpoints": []}}
<- threads(5) :: {"seq": 5, "type": "request", "command": "threads", "arguments": {}}
-> setExceptionBreakpoints(3) :: {"seq": 0, "type": "response", "request_seq": 3, "success": true, "command": "setExceptionBreakpoints", "body": {}}
-> setFunctionBreakpoints(4) :: {"seq": 0, "type": "response", "request_seq": 4, "success": true, "command": "setFunctionBreakpoints", "body": {"breakpoints": []}}
-> threads(5) :: {"seq": 0, "type": "response", "request_seq": 5, "success": true, "command": "threads", "body": {"threads": [{"id": 1, "name": "Dummy"}]}}
<- configurationDone(6) :: {"seq": 6, "type": "request", "command": "configurationDone", "arguments": {}}
-> output .. {"seq": 0, "type": "event", "event": "output", "body": {"category": "console", "output": "Type 'dlv help' for list of commands.\n", "source": {}}}
-> configurationDone(6) :: {"seq": 0, "type": "response", "request_seq": 6, "success": true, "command": "configurationDone"}
<- disconnect(7) :: {"seq": 7, "type": "request", "command": "disconnect", "arguments": {"restart": false, "terminateDebuggee": true}}
-> stopped .. {"seq": 0, "type": "event", "event": "stopped", "body": {"reason": "pause", "allThreadsStopped": true}}
-> output .. {"seq": 0, "type": "event", "event": "output", "body": {"category": "console", "output": "Detaching and terminating target process\n", "source": {}}}
<- threads(8) :: {"seq": 8, "type": "request", "command": "threads", "arguments": {}}
<- stackTrace(9) :: {"seq": 9, "type": "request", "command": "stackTrace", "arguments": {"threadId": 1}}
-> disconnect(7) :: {"seq": 0, "type": "response", "request_seq": 7, "success": true, "command": "disconnect"}
-> terminated .. {"seq": 0, "type": "event", "event": "terminated", "body": {}}
-- end transport protocol: [Errno 54] Connection reset by peer

Connect to remote not working

I've tried to run my app from a Makefile, that read my .env with the following command

dlv debug ./cmd/goweb --headless --listen 127.0.0.1:2345 --accept-multiclient --continue --

and the following config

{
  "name": "Connect to server",
  "type": "go",
  "request": "attach",
  "mode": "remote",
  "remotePath": "${folder}",
  "port": 2345,
  "host": "127.0.0.1"
}

I got this error

-- platform: osx-x64
-- theme: Adaptive.sublime-theme
-- color_scheme: Mariana.sublime-color-scheme
-- font_face: Menlo
-- font_size: 12

-- adapter: type=go version=0.38.0
-- socket transport process: ['/Users/macbook/opt/gopath/bin/dlv', 'dap', '--listen', 'localhost:58287']
-- socket transport: localhost:58287
-- socket transport: localhost:58287
-- begin transport protocol
<- initialize(1) :: {"seq": 1, "type": "request", "command": "initialize", "arguments": {"clientID": "sublime", "clientName": "Sublime Text", "adapterID": "go", "pathFormat": "path", "linesStartAt1": true, "columnsStartAt1": true, "supportsVariableType": true, "supportsVariablePaging": false, "supportsRunInTerminalRequest": true, "supportsMemoryReferences": true, "locale": "en-us"}}
-> initialize(1) :: {"seq": 0, "type": "response", "request_seq": 1, "success": true, "command": "initialize", "body": {"supportsConfigurationDoneRequest": true, "supportsFunctionBreakpoints": true, "supportsConditionalBreakpoints": true, "supportsEvaluateForHovers": true, "supportsSetVariable": true, "supportsExceptionInfoRequest": true, "supportsDelayedStackTraceLoading": true, "supportsLogPoints": true, "supportsDisassembleRequest": true, "supportsClipboardContext": true, "supportsSteppingGranularity": true, "supportsInstructionBreakpoints": true}}
<- attach(2) :: {"seq": 2, "type": "request", "command": "attach", "arguments": {"host": "127.0.0.1", "mode": "remote", "name": "Connect to server", "port": 2345, "remotePath": "/Users/macbook/code/goweb", "request": "attach", "type": "go"}}
-> attach(2) !! {"seq": 0, "type": "response", "request_seq": 2, "success": false, "command": "attach", "message": "Failed to attach", "body": {"error": {"id": 3001, "format": "Failed to attach: no debugger found", "showUser": true}}}
-- end transport protocol: eof
daveleroy commented 1 year ago

I don't think any of that stuff works since its not part of delve and they implemented it inside their vscode extension.

https://github.com/golang/vscode-go/blob/fa820d45d7b9217e949c21ffd13268e20c7e0ee4/src/debugAdapter/goDebug.ts#L491

daveleroy commented 1 year ago

If you wanted to implement more of the vscode-go side it would go in here https://github.com/daveleroy/sublime_debugger/blob/a933215da8101d7496e68868a692845673c3983d/modules/adapters/go.py#L27

daveleroy commented 1 year ago

This is how they handle mode: "remote" https://github.com/golang/vscode-go/blob/fa820d45d7b9217e949c21ffd13268e20c7e0ee4/src/debugAdapter/goDebug.ts#L453 which again is implemented outside of delve

ViBiOh commented 1 year ago

Thanks, I'll take a look, I'm not familiar with Python, but worth give it a try ;)

daveleroy commented 1 year ago

I implemented part of this so the env configuration option works but not the envFile option. If you want to add support for envFile you would need to parse the file and add its contents to the env variable.

https://github.com/daveleroy/sublime_debugger/commit/b3e0218fe022ef70b089053124db2cda57941b78