Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes for go 1.22 #3455

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ func TestStaticcheck(t *testing.T) {
if err != nil {
t.Skip("staticcheck not installed")
}
if goversion.VersionAfterOrEqual(runtime.Version(), 1, 22) {
t.Skip("broken with staticcheck@2023.1")
}
// default checks minus SA1019 which complains about deprecated identifiers, which change between versions of Go.
args := []string{"-tests=false", "-checks=all,-SA1019,-ST1000,-ST1003,-ST1016,-S1021,-ST1023", "github.com/go-delve/delve/..."}
// * SA1019 is disabled because new deprecations get added on every version
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
github.com/spf13/pflag v1.0.5
go.starlark.net v0.0.0-20220816155156-cfacd8902214
golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4
golang.org/x/sys v0.6.0
golang.org/x/tools v0.2.0
golang.org/x/sys v0.12.0
golang.org/x/tools v0.13.0
gopkg.in/yaml.v2 v2.4.0
)

Expand All @@ -32,5 +32,5 @@ require (
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/mod v0.12.0 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -312,6 +314,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down Expand Up @@ -345,6 +349,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
5 changes: 5 additions & 0 deletions pkg/proc/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ func (scope *EvalScope) setValue(dstv, srcv *Variable, srcExpr string) error {
if err := allocString(scope, srcv); err != nil {
return err
}
if cm, ok := dstv.mem.(*compositeMemory); ok {
// allocString can change the current thread, recover it so that the
// registers are set on the correct thread.
cm.regs.ChangeFunc = scope.callCtx.p.CurrentThread().SetReg
}
return dstv.writeString(uint64(srcv.Len), uint64(srcv.Base))
}

Expand Down
47 changes: 33 additions & 14 deletions pkg/proc/fncall.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,19 @@ type funcCallArg struct {

// funcCallEvalArgs evaluates the arguments of the function call, copying
// them into the argument frame starting at argFrameAddr.
func funcCallEvalArgs(scope *EvalScope, fncall *functionCallState, formalScope *EvalScope) error {
if scope.g == nil {
func funcCallEvalArgs(callScope *EvalScope, fncall *functionCallState, thread Thread) error {
if callScope.g == nil {
// this should never happen
return errNoGoroutine
}

formalScope, err := GoroutineScope(callScope.target, thread)
if err != nil {
return err
}

if fncall.receiver != nil {
err := funcCallCopyOneArg(scope, fncall, fncall.receiver, &fncall.formalArgs[0], formalScope)
err := funcCallCopyOneArg(callScope, fncall, fncall.receiver, &fncall.formalArgs[0], formalScope)
if err != nil {
return err
}
Expand All @@ -588,7 +593,7 @@ func funcCallEvalArgs(scope *EvalScope, fncall *functionCallState, formalScope *
for i := range fncall.formalArgs {
formalArg := &fncall.formalArgs[i]

actualArg, err := scope.evalAST(fncall.expr.Args[i])
actualArg, err := callScope.evalAST(fncall.expr.Args[i])
if err != nil {
if _, ispanic := err.(fncallPanicErr); ispanic {
return err
Expand All @@ -597,7 +602,14 @@ func funcCallEvalArgs(scope *EvalScope, fncall *functionCallState, formalScope *
}
actualArg.Name = exprToString(fncall.expr.Args[i])

err = funcCallCopyOneArg(scope, fncall, actualArg, formalArg, formalScope)
// evalAST can cause the current thread to change, recover it
thread = callScope.callCtx.p.CurrentThread()
formalScope, err = GoroutineScope(callScope.target, thread)
if err != nil {
return err
}

err = funcCallCopyOneArg(callScope, fncall, actualArg, formalArg, formalScope)
if err != nil {
return err
}
Expand Down Expand Up @@ -842,7 +854,7 @@ func funcCallStep(callScope *EvalScope, fncall *functionCallState, thread Thread
fnname = loc.Fn.Name
}
}
fncallLog("function call interrupt gid=%d (original) thread=%d regval=%#x (PC=%#x in %s)", callScope.g.ID, thread.ThreadID(), regval, pc, fnname)
fncallLog("function call interrupt gid=%d (original) thread=%d regval=%#x (PC=%#x in %s %s:%d)", callScope.g.ID, thread.ThreadID(), regval, pc, fnname, loc.File, loc.Line)
}

switch regval {
Expand Down Expand Up @@ -880,6 +892,10 @@ func funcCallStep(callScope *EvalScope, fncall *functionCallState, thread Thread
break
}
//TODO: double check that function call size isn't too big

// funcCallEvalFuncExpr can start a function call injection itself, we
// need to recover the correct thread here.
thread = p.CurrentThread()
}

// instead of evaluating the arguments we start first by pushing the call
Expand All @@ -898,14 +914,8 @@ func funcCallStep(callScope *EvalScope, fncall *functionCallState, thread Thread
oldlr = regs.LR()
}
callOP(bi, thread, regs, fncall.fn.Entry)
formalScope, err := GoroutineScope(callScope.target, thread)
if formalScope != nil && formalScope.Regs.CFA != int64(cfa) {
// This should never happen, checking just to avoid hard to figure out disasters.
err = fmt.Errorf("mismatch in CFA %#x (calculated) %#x (expected)", formalScope.Regs.CFA, int64(cfa))
}
if err == nil {
err = funcCallEvalArgs(callScope, fncall, formalScope)
}
err = funcCallEvalArgs(callScope, fncall, thread)
thread = p.CurrentThread() // call evaluation in funcCallEvalArgs can cause the current thread to change

if err != nil {
// rolling back the call, note: this works because we called regs.Copy() above
Expand Down Expand Up @@ -937,6 +947,7 @@ func funcCallStep(callScope *EvalScope, fncall *functionCallState, thread Thread
if err := setSP(thread, sp); err != nil {
fncall.err = fmt.Errorf("could not restore SP: %v", err)
}
fncallLog("stepping thread %d", thread.ThreadID())
if err := stepInstructionOut(p, thread, debugCallName, debugCallName); err != nil {
fncall.err = fmt.Errorf("could not step out of %s: %v", debugCallName, err)
}
Expand Down Expand Up @@ -1141,6 +1152,10 @@ func callInjectionProtocol(t *Target, threads []Thread) (done bool, err error) {
// we aren't injecting any calls, no need to check the threads.
return false, nil
}
currentThread := t.currentThread
defer func() {
t.currentThread = currentThread
}()
for _, thread := range threads {
loc, err := thread.Location()
if err != nil {
Expand All @@ -1150,6 +1165,9 @@ func callInjectionProtocol(t *Target, threads []Thread) (done bool, err error) {
continue
}

regs, _ := thread.Registers()
fncallLog("call injection found thread=%d %s %s:%d PC=%#x SP=%#x", thread.ThreadID(), loc.Fn.Name, loc.File, loc.Line, regs.PC(), regs.SP())

g, callinj, err := findCallInjectionStateForThread(t, thread)
if err != nil {
return false, err
Expand All @@ -1161,6 +1179,7 @@ func callInjectionProtocol(t *Target, threads []Thread) (done bool, err error) {
}

fncallLog("step for injection on goroutine %d (current) thread=%d (location %s)", g.ID, thread.ThreadID(), loc.Fn.Name)
t.currentThread = thread
callinj.continueCompleted <- g
contReq, ok := <-callinj.continueRequest
if !contReq.cont {
Expand Down
10 changes: 10 additions & 0 deletions pkg/proc/target_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/go-delve/delve/pkg/astutil"
"github.com/go-delve/delve/pkg/dwarf/reader"
"github.com/go-delve/delve/pkg/logflags"
)

const maxSkipAutogeneratedWrappers = 5 // maximum recursion depth for skipAutogeneratedWrappers
Expand Down Expand Up @@ -81,6 +82,7 @@ func (grp *TargetGroup) Continue() error {
for _, dbp := range grp.targets {
dbp.ClearCaches()
}
logflags.DebuggerLogger().Debugf("ContinueOnce")
trapthread, stopReason, contOnceErr := grp.procgrp.ContinueOnce(grp.cctx)
var traptgt *Target
if trapthread != nil {
Expand Down Expand Up @@ -127,6 +129,14 @@ func (grp *TargetGroup) Continue() error {
for it.Next() {
dbp := it.Target
threads := dbp.ThreadList()
if logflags.Debugger() {
log := logflags.DebuggerLogger()
log.Debugf("callInjection protocol on:")
for _, th := range threads {
regs, _ := th.Registers()
log.Debugf("\t%d PC=%#x", th.ThreadID(), regs.PC())
}
}
callInjectionDoneThis, callErrThis := callInjectionProtocol(dbp, threads)
callInjectionDone = callInjectionDone || callInjectionDoneThis
if callInjectionDoneThis {
Expand Down
6 changes: 5 additions & 1 deletion pkg/proc/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,11 @@ func testCallFunction(t *testing.T, grp *proc.TargetGroup, p *proc.Target, tc te
}

if len(retvals) != len(tc.outs) {
t.Fatalf("call %q: wrong number of return parameters (%#v)", tc.expr, retvals)
t.Logf("call %q: wrong number of return parameters (%#v)", tc.expr, retvals)
for i := range retvals {
t.Logf("%d: %#v", i, retvals[i])
}
t.Fatal("previous errors")
}

for i := range retvals {
Expand Down
6 changes: 3 additions & 3 deletions vendor/golang.org/x/mod/semver/semver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions vendor/golang.org/x/sys/unix/ioctl_signed.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions vendor/golang.org/x/sys/unix/ioctl_zos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading