Skip to content

Commit c751c1a

Browse files
committed
proc: extend macOS workaround to amd64
Go change 064f34f (which exists in Go 1.19.2 and following) removed the pagezero_size option from linker calls (because it is deprecated). This expanded the problem that exists on darwin/arm64 as well as PIE builds on darwin/amd64 to all darwin/amd64 builds. This problem is described on: golang/go#25841. This commit extends the darwin/arm64 workaround to darwin/amd64. Fixes go-delve#3194
1 parent a185d0e commit c751c1a

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

_fixtures/issue3194.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
/*
4+
#cgo LDFLAGS: -framework CoreFoundation
5+
#cgo LDFLAGS: -framework CFNetwork
6+
#include <CFNetwork/CFProxySupport.h>
7+
*/
8+
import "C"
9+
import "fmt"
10+
11+
func main() {
12+
f() // break here
13+
}
14+
15+
func f() {
16+
fmt.Println("ok")
17+
}

pkg/proc/bininfo.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,8 +1804,7 @@ func (bi *BinaryInfo) parseDebugFrameMacho(image *Image, exe *macho.File, debugI
18041804
//
18051805
// [golang/go#25841]: https://github.com/golang/go/issues/25841
18061806
func (bi *BinaryInfo) macOSDebugFrameBugWorkaround() {
1807-
//TODO: log extensively because of bugs in the field
1808-
if bi.GOOS != "darwin" || bi.Arch.Name != "arm64" {
1807+
if bi.GOOS != "darwin" {
18091808
return
18101809
}
18111810
if len(bi.Images) > 1 {
@@ -1818,9 +1817,28 @@ func (bi *BinaryInfo) macOSDebugFrameBugWorkaround() {
18181817
if !ok {
18191818
return
18201819
}
1821-
if exe.Flags&macho.FlagPIE == 0 {
1822-
bi.logger.Infof("debug_frame workaround not needed: not a PIE (%#x)", exe.Flags)
1823-
return
1820+
if bi.Arch.Name == "arm64" {
1821+
if exe.Flags&macho.FlagPIE == 0 {
1822+
bi.logger.Infof("debug_frame workaround not needed: not a PIE (%#x)", exe.Flags)
1823+
return
1824+
}
1825+
} else {
1826+
prod := goversion.ParseProducer(bi.Producer())
1827+
if !prod.AfterOrEqual(goversion.GoVersion{1, 19, 3, 0, 0, ""}) {
1828+
bi.logger.Infof("debug_frame workaround not needed (version %q on %s)", bi.Producer(), bi.Arch.Name)
1829+
return
1830+
}
1831+
found := false
1832+
for i := range bi.frameEntries {
1833+
if bi.frameEntries[i].CIE.CIE_id == ^uint32(0) && bi.frameEntries[i].Begin() < 0x4000000 {
1834+
found = true
1835+
break
1836+
}
1837+
}
1838+
if !found {
1839+
bi.logger.Infof("debug_frame workaround not needed (all FDEs above 0x4000000)")
1840+
return
1841+
}
18241842
}
18251843

18261844
// Find first Go function (first = lowest entry point)

pkg/proc/proc_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6009,3 +6009,18 @@ func TestGnuDebuglink(t *testing.T) {
60096009
}
60106010
}
60116011
}
6012+
6013+
func TestStacktraceExtlink(t *testing.T) {
6014+
// Tests stacktrace for programs built using external linker.
6015+
// See issue #3194
6016+
withTestProcess("issue3194", t, func(p *proc.Target, fixture protest.Fixture) {
6017+
setFunctionBreakpoint(p, t, "main.main")
6018+
assertNoError(p.Continue(), t, "First Continue()")
6019+
frames, err := proc.ThreadStacktrace(p.CurrentThread(), 10)
6020+
assertNoError(err, t, "ThreadStacktrace")
6021+
logStacktrace(t, p, frames)
6022+
if len(frames) < 2 || frames[0].Call.Fn.Name != "main.main" || frames[1].Call.Fn.Name != "runtime.main" {
6023+
t.Fatalf("bad stacktrace")
6024+
}
6025+
})
6026+
}

0 commit comments

Comments
 (0)