proc: use file:line at entry point in skipAutogeneratedWrappersOut (#2089)

The file:line information for the entrypoint is more acccurate than the
file:line information at a return point, which could be affected by a
compiler bug.

Fixes #2086
This commit is contained in:
Alessandro Arzilli 2020-07-21 22:44:04 +02:00 committed by GitHub
parent 9e1b6541c1
commit 54664c54db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

18
_fixtures/issue2086.go Normal file

@ -0,0 +1,18 @@
package main
import (
"runtime"
)
var i int
type T struct{}
func (t T) m() { stop() }
func stop() {
runtime.Breakpoint()
i++
}
func main() { T{}.m() }

@ -4839,5 +4839,21 @@ func TestRefreshCurThreadSelGAfterContinueOnceError(t *testing.T) {
t.Fatalf("wrong current location %s:%d (expected :9)", g.CurrentLoc.File, g.CurrentLoc.Line)
}
})
}
func TestStepoutOneliner(t *testing.T) {
// The heuristic detecting autogenerated wrappers when stepping out should
// not skip oneliner functions.
withTestProcess("issue2086", t, func(p *proc.Target, fixture protest.Fixture) {
assertNoError(p.Continue(), t, "Continue()")
assertLineNumber(p, t, 15, "after first continue")
assertNoError(p.StepOut(), t, "StepOut()")
if fn := p.BinInfo().PCToFunc(currentPC(p, t)); fn == nil || fn.Name != "main.T.m" {
t.Fatalf("wrong function after stepout %#v", fn)
}
assertNoError(p.StepOut(), t, "second StepOut()")
if fn := p.BinInfo().PCToFunc(currentPC(p, t)); fn == nil || fn.Name != "main.main" {
t.Fatalf("wrong fnuction after second stepout %#v", fn)
}
})
}

@ -888,7 +888,8 @@ func skipAutogeneratedWrappersOut(g *G, thread Thread, startTopframe, startRetfr
if frame.Current.Fn == nil {
return
}
if !isAutogenerated(frame.Current) {
file, line := frame.Current.Fn.cu.lineInfo.PCToLine(frame.Current.Fn.Entry, frame.Current.Fn.Entry)
if !isAutogenerated(Location{File: file, Line: line, Fn: frame.Current.Fn}) {
return &frames[i-1], &frames[i]
}
}