proc: skip autogenerated functions correctly (#2959)

Adjust heuristic used to skip autogenerated functions so that it works
correctly with the new naming scheme in go1.18.

Fixes #2948
This commit is contained in:
Alessandro Arzilli 2022-04-14 00:28:56 +02:00 committed by GitHub
parent a5532eb985
commit 3138157826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

14
_fixtures/stepintobug.go Normal file

@ -0,0 +1,14 @@
package main
type T struct {
}
func main() {
t := T{}
f1 := t.m1
println(f1(1)) //break
}
func (t T) m1(x int) int {
return x + 1
}

@ -5841,3 +5841,14 @@ func TestNilPtrDerefInBreakInstr(t *testing.T) {
}
})
}
func TestStepIntoAutogeneratedSkip(t *testing.T) {
// Tests that autogenerated functions are skipped with the new naming
// scheme for autogenerated functions (issue #2948).
withTestProcess("stepintobug", t, func(p *proc.Target, fixture protest.Fixture) {
setFileBreakpoint(p, t, fixture.Source, 9)
assertNoError(p.Continue(), t, "Continue()")
assertNoError(p.Step(), t, "Step")
assertLineNumber(p, t, 12, "After step")
})
}

@ -839,7 +839,7 @@ func skipAutogeneratedWrappersIn(p Process, startfn *Function, startpc uint64) (
}
tgtfn := tgtfns[0]
if tgtfn.BaseName() != fn.BaseName() {
if strings.TrimSuffix(tgtfn.BaseName(), "-fm") != strings.TrimSuffix(fn.BaseName(), "-fm") {
return startfn, startpc
}
fn = tgtfn