internal/pkgbits: cleanup pre-Go 1.17 workaround Now that golang/go#44505 is resolved, we can simplify frames_go1*.go. This was already done in GOROOT in https://go.dev/cl/420903. Change-Id: Ia7f2a123794fad62532bae2da267b0c8034917bc Reviewed-on: https://go-review.googlesource.com/c/tools/+/609955 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/internal/pkgbits/frames_go1.go b/internal/pkgbits/frames_go1.go deleted file mode 100644 index 5294f6a..0000000 --- a/internal/pkgbits/frames_go1.go +++ /dev/null
@@ -1,21 +0,0 @@ -// Copyright 2021 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !go1.7 -// +build !go1.7 - -// TODO(mdempsky): Remove after #44505 is resolved - -package pkgbits - -import "runtime" - -func walkFrames(pcs []uintptr, visit frameVisitor) { - for _, pc := range pcs { - fn := runtime.FuncForPC(pc) - file, line := fn.FileLine(pc) - - visit(file, line, fn.Name(), pc-fn.Entry()) - } -}
diff --git a/internal/pkgbits/frames_go17.go b/internal/pkgbits/frames_go17.go deleted file mode 100644 index 2324ae7..0000000 --- a/internal/pkgbits/frames_go17.go +++ /dev/null
@@ -1,28 +0,0 @@ -// Copyright 2021 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.7 -// +build go1.7 - -package pkgbits - -import "runtime" - -// walkFrames calls visit for each call frame represented by pcs. -// -// pcs should be a slice of PCs, as returned by runtime.Callers. -func walkFrames(pcs []uintptr, visit frameVisitor) { - if len(pcs) == 0 { - return - } - - frames := runtime.CallersFrames(pcs) - for { - frame, more := frames.Next() - visit(frame.File, frame.Line, frame.Function, frame.PC-frame.Entry) - if !more { - return - } - } -}
diff --git a/internal/pkgbits/sync.go b/internal/pkgbits/sync.go index a17a008..1520b73 100644 --- a/internal/pkgbits/sync.go +++ b/internal/pkgbits/sync.go
@@ -6,6 +6,7 @@ import ( "fmt" + "runtime" "strings" ) @@ -23,6 +24,24 @@ type frameVisitor func(file string, line int, name string, offset uintptr) +// walkFrames calls visit for each call frame represented by pcs. +// +// pcs should be a slice of PCs, as returned by runtime.Callers. +func walkFrames(pcs []uintptr, visit frameVisitor) { + if len(pcs) == 0 { + return + } + + frames := runtime.CallersFrames(pcs) + for { + frame, more := frames.Next() + visit(frame.File, frame.Line, frame.Function, frame.PC-frame.Entry) + if !more { + return + } + } +} + // SyncMarker is an enum type that represents markers that may be // written to export data to ensure the reader and writer stay // synchronized.