From 2d6d016bf1decd21c9808cfcc8e3ed348cde6588 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Mon, 3 Jun 2019 19:41:33 +0200 Subject: [PATCH] proc: fix panic when calling Ancestors on a parked goroutine (#1570) Fixes #1568 --- pkg/proc/proc_test.go | 2 +- pkg/proc/variables.go | 4 ++-- service/debugger/debugger.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 2a73f8fe..9f41d2bb 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -4280,7 +4280,7 @@ func TestAncestors(t *testing.T) { _, err := setFunctionBreakpoint(p, "main.testgoroutine") assertNoError(err, t, "setFunctionBreakpoint()") assertNoError(proc.Continue(p), t, "Continue()") - as, err := p.SelectedGoroutine().Ancestors(1000) + as, err := proc.Ancestors(p, p.SelectedGoroutine(), 1000) assertNoError(err, t, "Ancestors") t.Logf("ancestors: %#v\n", as) if len(as) != 1 { diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index b87bf73e..1b4e1bab 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -659,8 +659,8 @@ func (g *G) StartLoc() Location { var errTracebackAncestorsDisabled = errors.New("tracebackancestors is disabled") // Ancestors returns the list of ancestors for g. -func (g *G) Ancestors(n int) ([]Ancestor, error) { - scope := globalScope(g.Thread.BinInfo(), g.Thread.BinInfo().Images[0], g.Thread) +func Ancestors(p Process, g *G, n int) ([]Ancestor, error) { + scope := globalScope(p.BinInfo(), p.BinInfo().Images[0], p.CurrentThread()) tbav, err := scope.EvalExpression("runtime.debug.tracebackancestors", loadSingleValue) if err == nil && tbav.Unreadable == nil && tbav.Kind == reflect.Int { tba, _ := constant.Int64Val(tbav.Value) diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 33020237..0e44ae5f 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -991,7 +991,7 @@ func (d *Debugger) Ancestors(goroutineID, numAncestors, depth int) ([]api.Ancest return nil, errors.New("no selected goroutine") } - ancestors, err := g.Ancestors(numAncestors) + ancestors, err := proc.Ancestors(d.target, g, numAncestors) if err != nil { return nil, err }