delve/pkg/proc/variable_test.go
Sergio Lopez 11accd4d71 proc/proc: Extend GoroutinesInfo to allow specifying a range
Instead of unconditionally returning all present goroutines,
GoroutinesInfo now allows specifying a range (start and count). In
addition to the array of goroutines and the error, it now also returns
the next goroutine to be processed, to be used as 'start' argument on
the next call, or 0 if all present goroutines have already been
processed.

This way clients can avoid eating large amounts of RAM while debugging
core dumps and processes with a exceptionally high amount of goroutines.

Fixes #1403
2018-11-19 10:06:38 -08:00

46 lines
1.3 KiB
Go

package proc_test
import (
"path/filepath"
"testing"
"github.com/derekparker/delve/pkg/proc"
protest "github.com/derekparker/delve/pkg/proc/test"
)
func TestGoroutineCreationLocation(t *testing.T) {
protest.AllowRecording(t)
withTestProcess("goroutinestackprog", t, func(p proc.Process, fixture protest.Fixture) {
bp, err := setFunctionBreakpoint(p, "main.agoroutine")
assertNoError(err, t, "BreakByLocation()")
assertNoError(proc.Continue(p), t, "Continue()")
gs, _, err := proc.GoroutinesInfo(p, 0, 0)
assertNoError(err, t, "GoroutinesInfo")
for _, g := range gs {
currentLocation := g.UserCurrent()
currentFn := currentLocation.Fn
if currentFn != nil && currentFn.BaseName() == "agoroutine" {
createdLocation := g.Go()
if createdLocation.Fn == nil {
t.Fatalf("goroutine creation function is nil")
}
if createdLocation.Fn.BaseName() != "main" {
t.Fatalf("goroutine creation function has wrong name: %s", createdLocation.Fn.BaseName())
}
if filepath.Base(createdLocation.File) != "goroutinestackprog.go" {
t.Fatalf("goroutine creation file incorrect: %s", filepath.Base(createdLocation.File))
}
if createdLocation.Line != 23 {
t.Fatalf("goroutine creation line incorrect: %v", createdLocation.Line)
}
}
}
p.ClearBreakpoint(bp.Addr)
proc.Continue(p)
})
}