Bry*_*ock 22 google-app-engine go visual-studio-code delve
Hello World教程,演示如何使用Visual Studio(又名VScode)设置VS Code来调试Golang App Engine代码
这是使用AppEngine文档中的Helloworld代码:
go get -u -d github.com/directmeasure/VScodeDebugGoAppEngine.git
Run Code Online (Sandbox Code Playgroud)
在运行osX 10.13.3的Mac上运行.
我测试了代码,服务器在本地工作.我正在试图弄清楚如何使用调试器输入代码,以便我可以学习如何在其他项目中使用调试器.
这些是我能找到的使用VScode与GAE最好的说明,但他们似乎是过时的基础上更新Golang(如开关Gcloud,-go_debugging标志和目录结构的变化):
https://medium.com/@dbenque /调试-golang-应用服务引擎模块与-视觉工作室码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 .
Run Code Online (Sandbox Code Playgroud)我是如何尝试运行调试器的:
dev_appserver.py --go_debugging=true app.yaml
Run Code Online (Sandbox Code Playgroud)
ps aux | grep _go_app
dlv attach <#using the PID from the server binary>
Run Code Online (Sandbox Code Playgroud)
Delve成功附加到二进制文件.
当我启动调试会话时,蓝色进度条永远不会停止水平扫描.
VARIABLE侧栏永远不会填充hello.go中的变量
断点设置为hello.go:第21行
Debug 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
Run Code Online (Sandbox Code Playgroud)
这是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,
}
]
}
Run Code Online (Sandbox Code Playgroud)
以下是我安装的版本:
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
Run Code Online (Sandbox Code Playgroud)
编辑###########################
$ 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
Run Code Online (Sandbox Code Playgroud)
当我启动调试器时,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
Run Code Online (Sandbox Code Playgroud)
Tyl*_*ich 13
VS Code永远不会附加到Delve,因为它正在等待连接到远程Delve服务器127.0.0.1:2345.如果你dlv attach处于无头模式,听正确的地址,你应该能够连接.
以下步骤描述了如何调试运行的Go App Engine应用程序,dev_appserver.py而不是其他工具/帮助程序.但是,当您对Go代码进行更改,dev_appserver.py重新编译并重新启动应用程序时,更改PID Delve需要进行调试.http://github.com/dbenque/delveAppengine可以帮助Delve保持正确的流程.请参阅此处获取教程.
go get -u -d github.com/directmeasure/VScodeDebugGoAppEngine.gitcd $GOPATH/src/src/github.com/GoogleCloudPlatform/golang-samples/appengine/helloworld
注意:如果您的GOPATH有多个条目,cd则go get下载到目录.
启动App Engine开发服务器:
dev_appserver.py --go_debugging=true app.yaml
找到Go过程的PID:
ps aux | grep _go_app
启动Delve服务器(选择系统上可用的任何端口):
dlv --headless -l "localhost:2345" attach $GO_APP_PID
创建"Go:连接到服务器"条目:
注意:这只是一个模板 - 您可以稍后进行编辑.
自定义配置以指向启动Delve时指定的端口.这是我的完整配置:
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": [],
"showLog": true
}
有关在VS Code中调试Go代码(不使用App Engine运行)的一般帮助,请参阅https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code.
| 归档时间: |
|
| 查看次数: |
2486 次 |
| 最近记录: |