golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.89k stars 755 forks source link

decoding dwarf section - dlv problem to start app #3547

Closed tzookb closed 1 month ago

tzookb commented 1 month ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - go version go1.21.0 darwin/arm64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. ``` Build info ---------- golang.org/x/tools/gopls v0.16.2 golang.org/x/tools/gopls@v0.16.2 h1:K1z03MlikHfaMTtG01cUeL5FAOTJnITuNe0TWOcg8tM= github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y= golang.org/x/mod@v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= golang.org/x/sync@v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/telemetry@v0.0.0-20240829154258-f29ab539cc98 h1:Wm3cG5X6sZ0RSVRc/H1/sciC4AT6HAKgLCSH2lbpR/c= golang.org/x/text@v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/tools@v0.22.1-0.20240829175637-39126e24d653 h1:6bJEg2w2kUHWlfdJaESYsmNfI1LKAZQi6zCa7LUn7eI= golang.org/x/vuln@v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I= honnef.co/go/tools@v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo= mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8= go: go1.21.0 ``` * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. ``` 1.93.1 38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40 arm64 ``` * Check your installed extensions to get the version of the VS Code Go extension - * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. ``` # Tools Configuration ## Environment GOBIN: /xxxx/build-support/go/bin toolsGopath: gopath: /xxxx/build-support/go GOROOT: /xxxx/build-support/go/go1.21.0/ PATH: /xxxxx/build-support/go/go1.21.0/bin:/Users/tzookb/.pyenv/shims:/usr/local/Cellar/postgresql@13/13.12/bin/:/Users/tzookb/.jenv/shims:/xxxx/build-support/go/bin:/Users/tzookb/.compass/bin:/xxxxx/build-support/go/sdk/bin:/Users/tzookb/.nvm/versions/node/v20.16.0/bin:/Applications/Banyan.app/Contents/Resources/bin/:/Users/tzookb/.my-exec:/usr/local/sbin:/usr/local/opt/openssl@1.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/tzookb/.cargo/bin:/Users/tzookb/Library/Python/3.9/bin:/Users/tzookb/.pyenv/shims:/usr/local/Cellar/postgresql@13/13.12/bin/:/Users/tzookb/.jenv/shims:/xxxxx/build-support/go/bin:/Users/tzookb/.compass/bin:/xxxxxx/build-support/go/sdk/bin:/Users/tzookb/.nvm/versions/node/v20.16.0/bin:/Applications/Banyan.app/Contents/Resources/bin/:/Users/tzookb/.my-exec:/usr/local/sbin:/usr/local/opt/openssl@1.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/tzookb/.cargo/bin PATH (vscode launched with): /Users/tzookb/.pyenv/shims:/usr/local/Cellar/postgresql@13/13.12/bin/:/Users/tzookb/.jenv/shims:/xxxx/build-support/go/bin:/Users/tzookb/.compass/bin:/xxxxx/build-support/go/sdk/bin:/Users/tzookb/.nvm/versions/node/v20.16.0/bin:/Applications/Banyan.app/Contents/Resources/bin/:/Users/tzookb/.my-exec:/usr/local/sbin:/usr/local/opt/openssl@1.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/tzookb/.cargo/bin:/Users/tzookb/Library/Python/3.9/bin:/Users/tzookb/.pyenv/shims:/usr/local/Cellar/postgresql@13/13.12/bin/:/Users/tzookb/.jenv/shims:/xxxxxxxx/build-support/go/bin:/Users/tzookb/.compass/bin:/xxxxx/build-support/go/sdk/bin:/Users/tzookb/.nvm/versions/node/v20.16.0/bin:/Applications/Banyan.app/Contents/Resources/bin/:/Users/tzookb/.my-exec:/usr/local/sbin:/usr/local/opt/openssl@1.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/tzookb/.cargo/bin ## Tools go: xxxxxx/build-support/go/go1.21.0/bin/go: go version go1.21.0 darwin/arm64 gopls: xxxxx/build-support/go/bin/gopls (version: v0.16.2 built with go: go1.21.0) gotests: not installed gomodifytags: not installed impl: not installed goplay: not installed dlv: /xxxxxxx/build-support/go/bin/dlv (version: v1.23.1 built with go: go1.21.0) staticcheck: not installed ## Go env Workspace Folder (connected_accounts): /xxxxxxx/src/go/compass.com/connected_accounts GO111MODULE='on' GOARCH='arm64' GOBIN='/xxxxxx/build-support/go/bin' GOCACHE='/Users/tzookb/Library/Caches/go-build' GOENV='/Users/tzookb/Library/Application Support/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='-modcacherw' GOHOSTARCH='arm64' GOHOSTOS='darwin' GOINSECURE='' GOMODCACHE='/xxxxx/build-support/go/pkg/mod' GONOPROXY='' GONOSUMDB='*' GOOS='darwin' GOPATH='/xxxxx/build-support/go' GOPRIVATE='' GOPROXY='https://xxxxxxxx@artifacts.compass-tech.net/repository/go' GOROOT='/xxxxxx/build-support/go/go1.21.0/' GOSUMDB='off' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/xxxxx/build-support/go/go1.21.0/pkg/tool/darwin_arm64' GOVCS='' GOVERSION='go1.21.0' GCCGO='gccgo' AR='ar' CC='clang' CXX='clang++' CGO_ENABLED='1' GOMOD='/xxxxx/src/go/compass.com/go.mod' GOWORK='/xxxx/go.work' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/4c/tz1ybdq90bngpx087gtbgy7r0000gq/T/go-build1172643733=/tmp/go-build -gno-record-gcc-switches -fno-common' ```

Share the Go related settings you have added/edited

launch.json:

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "staging",
        "type": "go",
        "mode": "auto",
        "request": "launch",
        "program": "/xxxxxxx/connected_accounts/cmd/connected_accountsd/main.go",
        "debugAdapter": "dlv-dap",
        "args": [
            "--log-level=debug",
            "--env=staging",
            "--opty-service=grpc://opty.grpc.dev.na.xxxxx.com:31337",
            "--pg-connected-accounts-api-port=25434",
            "--people-service=grpc://peopleserver.grpc.dev.na.xxxxx.com:31337",
            "--aws-profile=crm"
        ],
        "trace": "verbose",
      }
    ]
  }

Describe the bug

running the app like always, but now I get: (attached screenshot)

Failed to launch: could not launch process: could not read debug info (decoding dwarf section info at offset 0x0: too short) and could not read go symbol table (could not find rodata struct member

Screenshots or recordings

Screenshot 2024-09-24 at 10 09 59
dunglas commented 1 month ago

Same issue on my side, but only on projects using cgo. This works as expected on non-cgo projects.

tzookb commented 1 month ago

I would say that I made it "work" by downgrading dlv to 1.21.2

rm -f $(which dlv)

./build-support/go/go1.21.0/bin/go install github.com/go-delve/delve/cmd/dlv@v1.21.2

but now breakpoint are not stopping, as it says:

could not find file /xxxxx/src/go/example.com/contacts_interactions/server/contacts_interactions.go
hyangah commented 1 month ago

Can you try to run dlv command directly and see if it works? I think something like

cd /xxxxxxx/connected_accounts/cmd/connected_accountsd
dlv debug ./main.go

cc @derekparker @aarzilli

tzookb commented 1 month ago

not sure if it worked or not :|

#:/ dlv debug ./main.go
Warning: no debug info found, some functionality will be missing such as stack traces and variable evaluation.
Type 'help' for list of commands.

(dlv)
Screenshot 2024-09-24 at 18 23 45
derekparker commented 1 month ago

@tzookb was this using the latest version of Delve? This error message is unusual especially considering Delve is building the binary. The binary seems to be created without any debug information.

A few questions:

tzookb commented 1 month ago

I just installed latest vscode-go, that installed latest dlv, as I don't want to jump hoops around versioning.

I tried to see what I can do here: https://github.com/golang/vscode-go/blob/master/docs/debugging.md#starting-a-debug-session-fails-with

but I get the original error of the issue:

Failed to launch: could not launch process: could not read debug info (decoding dwarf section info at offset 0x0: too short) and could not read go symbol table (could not find rodata struct member

dlv (latest 1.23.1) debug errors now:

➜  connected_accountsd git:(master) ✗ dlv debug ./main.go

Warning: no debug info found, some functionality will be missing such as stack traces and variable evaluation.
could not launch process: could not read debug info (decoding dwarf section info at offset 0x0: too short) and could not read go symbol table (could not find rodata struct member)

we are using a this go version: go version go1.21.0 darwin/arm64

aarzilli commented 1 month ago

Could be a duplicate of https://github.com/go-delve/delve/issues/3701, knowing whether you are using CGO would be important.

What's the output of clang --version, ld -v and dsymutil -v?

tzookb commented 1 month ago

clang --version

Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

ld -v

@(#)PROGRAM:ld PROJECT:ld-1115.7.3
BUILD 13:29:00 Aug  9 2024
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
will use ld-classic for: armv6 armv7 armv7s i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 16.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 16.0.0 (tapi-1600.0.11.8)

dsymutil -v

Apple LLVM version 16.0.0
   (clang-1600.0.26.3)Optimized build.

xcode version: /usr/bin/xcodebuild -version

Xcode 16.0
Build version 16A242d

I couldn't replicate the other pr solution :|

aarzilli commented 1 month ago

What about cgo? Does it use it? Also can you post the binary executable built with go build -gcflags='all=-N -l' ... somewhere?

dunglas commented 1 month ago

In my case, cgo is heavily used (and I haven't the problem on non-cgo projects) and I've the same problem when using the command line:

CGO_CFLAGS="$(/usr/local/bin/php-config --includes) -I/opt/homebrew/include/" CGO_LDFLAGS="$(/usr/local/bin/
php-config --ldflags) $(/usr/local/bin/php-config --libs) -L/opt/homebrew/lib/" dlv debug main.go 
WARN[0000] CGO_CFLAGS already set, Cgo code could be optimized.  layer=dlv
# command-line-arguments
ld: warning: ignoring duplicate libraries: '-lcrypto', '-liconv', '-lpthread', '-lresolv', '-lsqlite3', '-lssl', '-lxml2'
Warning: no debug info found, some functionality will be missing such as stack traces and variable evaluation.
could not launch process: could not read debug info (decoding dwarf section info at offset 0x0: too short) and could not read go symbol table (could not find rodata struct member)
go version
go version go1.22.0 darwin/arm64
clang --version
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin24.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ld -v
@(#)PROGRAM:ld PROJECT:ld-1115.7.3
BUILD 13:29:00 Aug  9 2024
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
will use ld-classic for: armv6 armv7 armv7s i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 16.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 16.0.0 (tapi-1600.0.11.8)
dsymutil -v
Apple LLVM version 16.0.0
   (clang-1600.0.26.3)Optimized build.
/usr/bin/xcodebuild -version
Xcode 16.0
Build version 16A242d
dunglas commented 1 month ago

This looks to be the same issue as: https://github.com/go-delve/delve/issues/1138#issuecomment-2361176952 However, I tried to upgrade delve and the other workaround and nothing fixes the issue in my case.

aarzilli commented 1 month ago

cc @cherrymui it could be that the problem that existed with custom clang toolchains now also affects the xcode toolchain.

dunglas commented 1 month ago

I also notified a weird issue that may, or may not be related.

Starting the program with go run main.go works, but building it with go build and then executing it fails with this error:

terminated by signal SIGKILL (Forced quit)

However, executing the binary that is killed through LLDB (lldb ./mybinary) surprisingly works.

dunglas commented 1 month ago

I figured out the issue on my side: it is because the project has toolchain go1.22.0 in its go.mod. Setting the environment variable GOTOOLCHAIN to auto to force using the system installation fixes both Delve and go build. Thanks for your time and sorry for the noise.

Edit: the root of the issue was that ~/Library/Application\ Support/go/env was containing a GOTOOLCHAIN variable (I've no idea why, I probably messed it up at some point). Removing this file definitely fixed the issue.

tzookb commented 1 month ago

at least for me I noticed that for an app that include packages that needs "CGO_ENABLED" it fails with the mentioned error.

it depends on https://github.com/confluentinc/confluent-kafka-go

aarzilli commented 1 month ago

@tzookb can you upgrade to go1.23 and see if the problem still reproduces?

tzookb commented 1 month ago

checked with 1.23 and Im able to run and debug 😮‍💨

aarzilli commented 1 month ago

I think this can be closed.

tzookb commented 1 month ago

do we have a suggestion for go 1.21?

findleyr commented 1 month ago

Thanks @aarzilli @dunglas and @derekparker for your help investigating.

do we have a suggestion for go 1.21?

@tzookb as Go 1.21 is not supported by the Go release policy, I don't think we'll be able to help. If you must use 1.21, your solution above (downgrading delve) may be necessary.

matschaffer-roblox commented 1 day ago

I ran into this for a 1.22 golang project on my M1 mac (14.7.1) with latest xcode (16.0). Switching the project to 1.23 got debugging working again.