-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Cannot debug go plugins on mac #1628
Comments
Debugging plugin on mac is really needed for Golang developers. Hope delve supports it :) |
I didn't try implementing this because it would be affected by golang/go#25841 at least. I also vaguely remembering some versions of go not producing any dwarf at all for macOS. What's the output of |
It returns an error:
|
Right, of course, because they aren't elfs. My bad. I guess the right one would be |
otool -l output:
|
As you can see, no debug sections. Now that I think about it I knew this because I noticed when I changed the linker to make it able to emit debug symbols for plugins. |
First of all, I don't know how debugger works well. But It seems that it's impossible to debug golang plugin at this moment. Because as you said, the built plugin doesn't contain debugging symbols at all. |
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 golang/go#27502 |
@aarzilli : Thanks for your diligence in pushing this support forward. It's nice that golang/go#27502 has now been fixed, but it seems like the ability to debug go plugins on Mac will still be blocked by golang/go#25841, according to:
Given this, perhaps you can revisit your comment in golang/go#25841, where you responded that it was not important? Seems that @heschik was willing to dig into that issue before. |
I discovered that the fix for golang/go#27502 is present in
Then I rebuilt the binaries from the example project:
I then used
So I got my hopes up, but when I tried debugging the
|
I think it would behoove you to comment yourself on that thread, your first hand account of why you need it would be more persuasive than my second hand perception that some people might need it. |
@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 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 breakpointOn 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 codeOn Mac. where it fails in this scenario, it looks like this:
On linux where it works it looks like this:
|
they are from |
Thanks for the response. Hmm, for some reason
Whereas when I crosscompile the binary for being run on linux (again from Mac),
|
It's probably because of dwarf compression, you probably have to disable it with |
@aarzilli : woot! That was it. Thanks for teaching me something.
|
After a long waiting, I walked around the problem by adding a static-linking mode to my plugin builder. With https://github.com/edwingeng/hotswap, you can switch freely between the dynamic-linking mode and the static-linking mode. Debugging a plugin under Mac is no longer a trouble to me. P.S. Don't miss the |
@edwingeng debugging a go plugin should still be a issue for you. When i read trough your project you generate some wrapper code to compile code that was written as go plugin into the main binary ? |
Yes.
If
|
@FloThinksPi golang/go#25841 seems to be fixed, should it be working now? I still get errors trying to debug a plugin in macos with delve. |
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 guess I'll give it a try since no one more experienced with delve and go is available. @aarzilli Please give me a hand with this. I just tried your suggestion:
There must be something I'm missing. Edit: I'm trying to use delve with dap. Edit 2: Looks like AddImage is returning an error:
(The code I'm using to test this is just the example in the official docs https://pkg.go.dev/plugin) |
@rstcruzo presumably it's coming from loadBinaryInfoMacho, you should check that it can actually load the plugin binary. Could be something in go's standard library. |
I checked out the latest version of macOS (13.4) and it still has a bugged version of dsymutil. |
@aarzilli I updated my macbook to macOS Sonoma. Is there a command I can run to check if dsymutil was updated? |
No, build something and check that the debug_frame section is correct (you could probably find out from the version of llvm but I don't know which version has the fix). |
FYI Sonoma (or rather the version of xcode that ships with sonoma) still has an old version of dsymutil. |
Still not able to debug plugins, is there any workaround for this ? |
dlv version
)?go version
)?I'm trying to debug a simple go plugin from https://github.com/vladimirvivien/go-plugin-example.
I've build plugins using the command:
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.
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.
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.
The text was updated successfully, but these errors were encountered: