diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 46ece47c3..67b51e037 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -114,6 +114,8 @@ type BinaryInfo struct { debugPinnerFn *Function logger logflags.Logger + + appliedMacOSDebugFrameBugWorkaround bool } var ( @@ -2155,6 +2157,11 @@ func (bi *BinaryInfo) macOSDebugFrameBugWorkaround() { bi.frameEntries[i].Translate(delta) } } + bi.appliedMacOSDebugFrameBugWorkaround = true +} + +func (bi *BinaryInfo) IsMacOSDebugFrameBugWorkaroundApplied() bool { + return bi.appliedMacOSDebugFrameBugWorkaround } // macOSShortSectionNamesWorkaround works around a bug in Go 1.23 (and diff --git a/pkg/proc/gdbserial/gdbserver.go b/pkg/proc/gdbserial/gdbserver.go index 35d7091d6..6ba8a93bf 100644 --- a/pkg/proc/gdbserial/gdbserver.go +++ b/pkg/proc/gdbserial/gdbserver.go @@ -942,6 +942,16 @@ continueLoop: } } + if p.BinInfo().GOOS == "darwin" && !p.BinInfo().IsMacOSDebugFrameBugWorkaroundApplied() { + images, err := p.conn.getLoadedDynamicLibraries() + if err != nil { + return nil, stopReason, fmt.Errorf("could not load dynamic libraries %s", err) + } + for _, image := range images { + p.bi.AddImage(image.Pathname, image.LoadAddress) + } + } + if err := p.setCurrentBreakpoints(); err != nil { return nil, stopReason, err } diff --git a/pkg/proc/test/support.go b/pkg/proc/test/support.go index da8ba31a9..27705a60c 100644 --- a/pkg/proc/test/support.go +++ b/pkg/proc/test/support.go @@ -356,8 +356,8 @@ func WithPlugins(t *testing.T, flags BuildFlags, plugins ...string) []Fixture { if !goversion.VersionAfterOrEqual(runtime.Version(), 1, 12) { t.Skip("versions of Go before 1.12 do not include debug information in packages that import plugin (or they do but it's wrong)") } - if runtime.GOOS != "linux" { - t.Skip("only supported on linux") + if runtime.GOOS != "linux" && runtime.GOOS != "darwin" { + t.Skip("only supported on linux and darwin") } r := make([]Fixture, len(plugins))