VScodeDebugGoAppEngine
Hello World 教程展示了如何设置 VS Code 以使用 Visual Studio(又名 VScode)调试 Golang App Engine 代码
这是使用 AppEngine 文档中的 Helloworld 代码:
go get -u -d github.com/directmeasure/VScodeDebugGoAppEngine.git
在运行 osX 10.13.3 的 Mac 上。
我已经测试了代码并且服务器在本地工作。我试图弄清楚如何使用调试器输入代码,以便我可以学习如何在其他项目中使用调试器。
这些是我能找到的在 GAE 中使用 VScode 的最佳说明,但它们似乎已经过时,基于对 Golang 的更新(例如切换到 Gcloud、-go_debugging 标志和更改目录结构):
https ://medium.com/@dbenque /debugging-golang-appengine-module-with-visual-studio-code-85b3aa59e0f
以下是我采取的步骤:
设置环境
添加到 .bash_profile
export BASEFOLDER="/Users/Bryan/google-cloud-sdk/" . export GOROOT="/usr/local/go" # this shoudln't have to be set with current Version, doing it to follow the tutorial .
我如何尝试让调试器运行:
启动本地服务器。
dev_appserver.py --go_debugging=true app.yaml
将本地二进制文件附加到 Delve
ps aux | grep _go_app
dlv attach <#using the PID from the server binary>
Delve 成功附加到二进制文件。
当我启动调试会话时,蓝色进度条永远不会停止水平扫描。
VARIABLE 侧边栏永远不会填充 hello.go 中的变量
断点设置在 hello.go:第 21 行
调试 REPL 终端显示:
Verbose logs are written to:
/var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/vscode-go-debug.txt
16:02:31, 2018-4-5
InitializeRequest
InitializeResponse
Using GOPATH: /Users/Bryan/go
fmt.Print(u)
Please start a debug session to evaluate
这是 launch.json 配置:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
//"port": 1234,
"port": 2345 // docs say port should match assigned port headless server, https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code#remote-debugging
// this creates bind error
"host": "127.0.0.1",
"program": "${workspaceFolder}/hello.go",
"env": {},
"args": [],
"showLog": true,
"trace": true,
}
]
}
以下是我安装的版本:
go version go1.10 darwin/amd64
$ gcloud version .
Google Cloud SDK 197.0.0
app-engine-go
app-engine-python 1.9.68
bq 2.0.31
core 2018.04.06
gsutil 4.30
VS code extension:
Go 0.6.78
编辑###########################
$ lsof -n -i :8080
Bryan@Bryans-MacBook-Pro Thu Apr 12 17:02:04 ~
$ lsof -n -i :2345
Bryan@Bryans-MacBook-Pro Thu Apr 12 17:03:34 ~
$ ps aux | grep _go_app
Bryan 7433 0.0 0.0 2434840 800 s000 S+ 5:03PM 0:00.00 grep _go_app
Bryan 7426 0.0 0.0 556603172 3896 s002 S+ 5:02PM 0:00.01 /var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/tmp8GWk1gappengine-go-bin/_go_app
Bryan@Bryans-MacBook-Pro Thu Apr 12 17:03:52 ~
$ dlv attach --headless -l "localhost:2345" 7426 /var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/tmp8GWk1gappengine-go-bin/_go_app
API server listening at: 127.0.0.1:2345
当我启动调试器时,REPL 显示:
Verbose logs are written to:
/var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/vscode-go-debug.txt
couldn't start listener: listen tcp 127.0.0.1:2345: bind: address already in use
Process exiting with code: 1