Skip to content
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

Go Lang debugging not working in VSCode using sam cli #1376

Closed
KarthickEmis opened this issue Aug 27, 2019 · 4 comments
Closed

Go Lang debugging not working in VSCode using sam cli #1376

KarthickEmis opened this issue Aug 27, 2019 · 4 comments

Comments

@KarthickEmis
Copy link

i tried the same in visual studio code for go lang .. I am getting the below error

{
"errorMessage": "fork/exec /tmp/lambci_debug_files/dlv: exec format error",
"errorType": "PathError"
}?[0m
2019-08-27 17:42:43 Function returned an invalid response (must include one of: body, headers, multiValueHeaders or statusCode in the response object).

Note:

I modifed Handler name to main in template.yaml

I created the project through sam init --runtime go1.x

Installed docker ...

in my docker images i have lambci/lambdaimage only.

Below command are used :

set GOARCH=amd64
set GOOS=linux
mkdir debugger
go build -gcflags "all=-N -l" -o ./debugger/dlv github.com/go-delve/delve/cmd/dlv
go build -gcflags "all=-N -l" -o hello-world/hello-world ./hello-world
sam local start-api -d 5987 --debugger-path ./debugger --debug-args="-delveAPI=2"

PFA my template.yaml file and launch.json file.
template.txt

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "",
"port": 5988,
"host": "127.0.0.1"
// "program": "${fileDirname}",
// "env": {},
// "args": []
}
]
}

whether i need to run dlv in my container and need to point out in build command ? If so kindly give some example.
template.txt

@KarthickEmis
Copy link
Author

I just tried the below steps
sam init --runtime go1.x
cd sam-app
code . # to launch VSCode
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
go get -u github.com/aws/aws-lambda-go/...
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"

debugger is not attaching in VS code .. but code is working

@KarthickEmis
Copy link
Author

C:\go-work\src\sam-app1\sam-app>sam local start-api -d 5989 --debugger-path . --debug-args="-delveAPI=2"
2019-08-27 19:57:59 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2019-08-27 19:57:59 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-08-27 19:57:59 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2019-08-27 19:58:18 Invoking hello-world (go1.x)
2019-08-27 19:58:18 Found credentials in environment variables.

Fetching lambci/lambda:go1.x Docker container image......
2019-08-27 19:58:22 Mounting C:\go-work\src\sam-app1\sam-app\hello-world as /var/task:ro,delegated inside runtime container
Could not create config directory: mkdir .config: read-only file system.API server listening at: [::]:5989
2019-08-27T14:28:22Z info layer=debugger launching process with args: [/var/task/hello-world]

It get strucked after this .

@sriram-mv
Copy link
Contributor

Closing #1379 and this issue. This issue is referenced in #1310

@ssgao
Copy link

ssgao commented Apr 2, 2021

If anyone run into this, the issue here is that the dlv that you've built is not compatible with the OS that your code runs on.
For example, if you are on windows, or macos, and you try to use dlv to debug linux go code, it will result in this error.
The fix is two fold.

Step 1

Install a dlv binary that's compatible with the OS that your code is going to run on. For me, my native OS is macOS, and I need to run go code in linux. With go 1.16, I did

GOARCH=amd64 GOOS=linux go install github.com/go-delve/delve/cmd/dlv@latest

This installed a dlv in my $GOPATH/bin/linux_amd64 folder.

Step 2

Set your DLV_BIN to the new executable folder:

export DLV_BIN=$GOPATH/bin/linux_amd64

Now run the sam command again with --debugger-path $DLV_BIN. It should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants