delve: Cannot debug go plugins on mac
- What version of Delve are you using (
dlv version
)?
Delve Debugger
Version: 1.2.0
Build: cb658772972d74042ba75f006ac14023e552c7cd
- What version of Go are you using? (
go version
)?
go version go1.12.6 darwin/amd64
- What operating system and processor architecture are you using?
darwin/amd64
- What did you do?
I’m trying to debug a simple go plugin from https://github.com/vladimirvivien/go-plugin-example.
I’ve build plugins using the command:
go build -gcflags "all=-N -l" -x -v -buildmode=plugin -o eng/eng.so eng/greeter.go
I’m debugging the code calling the plugin (https://github.com/vladimirvivien/go-plugin-example/blob/master/greeter.go).
Once debugger reaches the breakpoint on line 58, I’m adding a breakpoint at eng/greeter.go:8 and continue or trying to step into the call.
- What did you expect to see?
Adding a breakpoint inside the plugin succeeds. If I continue, debugger hits the breakpoint inside the plugin. Step into the call in plugin also works.
- What did you see instead?
Create breakpoint call fails with the “could not find file /Users/nd/go/src/github.com/vladimirvivien/go-plugin-example/eng/greeter.go” error. Step into plugin call also fails.
Debug log: https://gist.github.com/nd/feb71212f6ef9dcfbb33c4293e18f146
Debug works fine on linux.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 17
- Comments: 27 (13 by maintainers)
Debugging plugin on mac is really needed for Golang developers. Hope delve supports it 😃
Yes.
If
--staticLinking
is NOT specified when building a plugin, it is still a perfect plugin, which is not debuggable on Mac.hotswap
helps me debug the code in a plugin. It is a problem solver, not a curer:)--staticLinking
is a per build choice.FYI Sonoma (or rather the version of xcode that ships with sonoma) still has an old version of dsymutil.
I checked out the latest version of macOS (13.4) and it still has a bugged version of dsymutil.
Delve’s side of this needs to be implemented. At the moment I don’t have access to a working VM (and none of the builders have a version of macos that will receive the updated version of xcode) so I’m not going to do it any time soon, if someone else wants to do it: it should be fairly simple, just add a call to getLoadedDynamicLibraries at the end of ContinueOnce and call bi.AddImage for all the dynamic libraries.
I discovered that the fix for https://github.com/golang/go/issues/27502 is present in
go1.14beta1
, so I installed that version:Then I rebuilt the binaries from the example project:
I then used
otool -l
to validate that theeng.so
binary had the DWARF debug sections.So I got my hopes up, but when I tried debugging the
greeter
binary I hit the same problem.This is a major obstacle for me as I am working on same code base that uses plugins and I often switch between Linux and Mac while working on this.
Meantime I believe lack of debugging symbols in plugins on Darwin is still an issue in Go https://github.com/golang/go/issues/27502
@aarzilli : I’ve put in a comment on that issue. But frankly I’m too ignorant about this topic to understand what the issues are here, and how exactly golang/go#25841 is blocking this issue.
e.g., I don’t understand how you obtained the output that you cite, they look like they came from running
readelf
, but the ticket is about Mac. So I’m guessing maybe you targetedGOOS=linux
in the build. And if so then I’m not seeing how that relates to this issue.Furthermore, I seem to be seeing at least 2 different problems in my example above, but I’m not sure if they are symptoms of one underlying cause.
cannot set the breakpoint
On Mac, where it fails in this scenario, it looks like this:
On linux where it works it looks like this:
cannot step into the plugin code
On Mac. where it fails in this scenario, it looks like this:
On linux where it works it looks like this: