Misc fixes for test problems (#2751)

* service/dap: remove deadlock in TestLaunchDebugRequest

Fixes #2746

* terminal: fix TestScopePrefix flakiness

When there are more than 10 frames api.PrintStack will prefix the
output with spaces to right justify the frame number, which confuses
TestScopePrefix.

* _scripts: pass -buildvcs for Go 1.18 and later on TeamCity

Go 1.18 will try to stamp builds with the VCS version, this doesn't
work on TeamCity because the checkout isn't a valid repository (but
looks like it).
Pass -buildvcs=false to disable this feature.

* proc: switch to goroutine stack if first frame's func can not be found

If the first frame on the system stack can not be resolved to a
function switch directly to the goroutine stack.
This commit is contained in:
Alessandro Arzilli 2021-10-18 22:17:47 +02:00 committed by GitHub
parent b99d5f5971
commit 8ebd2d83ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 4 deletions

@ -53,4 +53,12 @@ echo "$GOROOT"
echo "$GOPATH"
cd delve
# Starting with go1.18 'go build' and 'go run' will try to stamp the build
# with the current VCS revision, which does not work with TeamCity
if [ "$version" = "gotip" ]; then
export GOFLAGS=-buildvcs=false
elif [ ${version:4} -gt 17 ]; then
export GOFLAGS=-buildvcs=false
fi
make test

@ -131,6 +131,10 @@ const amd64cgocallSPOffsetSaveSlot = 0x28
func amd64SwitchStack(it *stackIterator, _ *op.DwarfRegisters) bool {
if it.frame.Current.Fn == nil {
if it.systemstack && it.g != nil && it.top {
it.switchToGoroutineStack()
return true
}
return false
}
switch it.frame.Current.Fn.Name {

@ -132,6 +132,10 @@ const arm64cgocallSPOffsetSaveSlot = 0x8
const prevG0schedSPOffsetSaveSlot = 0x10
func arm64SwitchStack(it *stackIterator, callFrameRegs *op.DwarfRegisters) bool {
if it.frame.Current.Fn == nil && it.systemstack && it.g != nil && it.top {
it.switchToGoroutineStack()
return true
}
if it.frame.Current.Fn != nil {
switch it.frame.Current.Fn.Name {
case "runtime.asmcgocall", "runtime.cgocallback_gofunc", "runtime.sigpanic", "runtime.cgocallback":

@ -117,6 +117,10 @@ func i386FixFrameUnwindContext(fctxt *frame.FrameContext, pc uint64, bi *BinaryI
// SwitchStack will use the current frame to determine if it's time to
func i386SwitchStack(it *stackIterator, _ *op.DwarfRegisters) bool {
if it.frame.Current.Fn == nil {
if it.systemstack && it.g != nil && it.top {
it.switchToGoroutineStack()
return true
}
return false
}
switch it.frame.Current.Fn.Name {

@ -5408,7 +5408,7 @@ func TestWatchpointsBasic(t *testing.T) {
t.Fatal("breakpoint not set")
}
p.ClearBreakpoint(bp.Addr)
assertNoError(p.ClearBreakpoint(bp.Addr), t, "ClearBreakpoint")
assertNoError(p.Continue(), t, "Continue 2")
assertLineNumber(p, t, 21, "Continue 2") // Position 2

@ -402,6 +402,7 @@ func TestScopePrefix(t *testing.T) {
stackOut := strings.Split(term.MustExec(fmt.Sprintf("goroutine %d stack", gid)), "\n")
fid := -1
for _, line := range stackOut {
line = strings.TrimLeft(line, " ")
space := strings.Index(line, " ")
if space < 0 {
continue
@ -417,7 +418,7 @@ func TestScopePrefix(t *testing.T) {
}
}
if fid < 0 {
t.Fatalf("Could not find frame for goroutine %d: %v", gid, stackOut)
t.Fatalf("Could not find frame for goroutine %d: %q", gid, stackOut)
}
term.AssertExec(fmt.Sprintf("goroutine %d frame %d locals", gid, fid), "(no locals)\n")
argsOut := strings.Split(term.MustExec(fmt.Sprintf("goroutine %d frame %d args", gid, fid)), "\n")

@ -4734,6 +4734,15 @@ func TestLaunchDebugRequest(t *testing.T) {
rescueStderr := os.Stderr
r, w, _ := os.Pipe()
os.Stderr = w
done := make(chan struct{})
var err []byte
go func() {
err, _ = ioutil.ReadAll(r)
t.Log(string(err))
close(done)
}()
tmpBin := "__tmpBin"
runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) {
@ -4748,8 +4757,7 @@ func TestLaunchDebugRequest(t *testing.T) {
time.Sleep(100 * time.Millisecond)
w.Close()
err, _ := ioutil.ReadAll(r)
t.Log(string(err))
<-done
os.Stderr = rescueStderr
rmErrRe, _ := regexp.Compile(`could not remove .*\n`)