gpt4 book ai didi

debugging - 如何在VSCode中调试AWS SAM制作的应用程序?

转载 作者:行者123 更新时间:2023-12-01 20:27:26 25 4
gpt4 key购买 nike

概括

我通过AWS SAM制作了Go应用程序。现在,我尝试在VSCode中调试此示例应用程序,但是它失败了,所以我想知道如何正确调试它。

试过了

toggl-slack
├── Makefile
├── README.md
├── dlv
├── samconfig.toml
├── hello-world
│ ├── main.go
│ └── main_test.go
└── template.yaml

我将以下命令放在控制台上进行调试。
cd toggl-slack
go get -u github.com/go-delve/delve/cmd/dlv
GOARCH=amd64 GOOS=linux go build -o ./dlv github.com/go-delve/delve/cmd/dlv
GOARCH=amd64 GOOS=linux go build -gcflags='-N -l' -o hello-world/hello-world ./hello-world
sam local start-api -d 5986 --debugger-path . --debug-args="-delveAPI=2"
curl http://127.0.0.1:3000/hello

结果,调试不起作用,并且控制台显示错误消息。
Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2019-12-28 21:23:17 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
Invoking hello-world (go1.x)

Fetching lambci/lambda:go1.x Docker container image......
Mounting /Users/jpskgc/toggl-slack/hello-world as /var/task:ro,delegated inside runtime container
Could not create config directory: mkdir /home/sbx_user1051: permission denied.API server listening at: [::]:5986
2019-12-28T12:23:46Z info layer=debugger launching process with args: [/var/task/hello-world]
2019-12-28T12:23:47Z warning layer=debugger reading debug_info: could not find abstract origin (0x13ed31) of inlined call at 0xfab50

代号

launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to Lambda container",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath": "",
"port": 5986,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
}
]
}

其他代码与AWS SAM的默认示例应用程序相同。

完整的源代码在这里:
https://github.com/jpskgc/toggl-slack/tree/0db02109685ce89f17ed64fdaadd5261e5f61512

最佳答案

reading debug_info: could not find abstract origin行告诉我们,编译标志已被打乱,并且调试信息实际上并未包括在内。我们需要的是:

GOOS=linux GOARCH=amd64 go build -gcflags "all=-N -l" -o hello-world/hello-world ./hello-world

其次,VSCode应该告诉您这一点,但是在 launch.json中, "request": "launch",现在是 "request": "attach",模式的 remote,它给出了:
{
"version": "0.2.0",
"configurations": [
{
"name": "Connect to SAM local",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "",
"port": 5986,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
}
]
}

通过上述更改,您应该能够使用VSCode(或GoLand/Vim/CLI)连接到调试服务器。

最后, Could not create config directory: mkdir /home/sbx_user1051: permission denied.行可以忽略。

I am contributing this on behalf of my employer, Amazon. My contribution is licensed under the MIT license. See here for a more detailed explanation.

关于debugging - 如何在VSCode中调试AWS SAM制作的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59512329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com