From ad75f78c4e69c8c62c30e80aa9e47cf336534435 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Wed, 18 Mar 2020 09:25:32 -0700 Subject: [PATCH] *: Fix go vet complaints (#1935) * *: Fix go vet struct complaints * *: Fix struct vet issue on linux * *: Ignore proc/native in go vet check We have to do some unsafe pointer manipulation that will never make go vet happy within the proc/native package. Ignore it for runs of go vet. --- Makefile | 7 ++- cmd/dlv/cmds/commands.go | 2 +- pkg/dwarf/godwarf/type.go | 14 ++--- pkg/dwarf/util/buf.go | 2 +- pkg/gobuild/gobuild.go | 4 +- pkg/proc/core/core_test.go | 7 +-- pkg/proc/dwarf_expr_test.go | 8 +-- pkg/proc/native/registers_linux_amd64.go | 2 +- pkg/proc/proc_test.go | 42 +++++++-------- pkg/proc/scope_test.go | 4 +- pkg/proc/test/support.go | 4 +- pkg/terminal/command.go | 15 +++--- pkg/terminal/command_test.go | 8 +-- pkg/terminal/config.go | 2 +- pkg/terminal/starbind/conv.go | 4 +- pkg/terminal/starlark.go | 2 +- pkg/terminal/terminal.go | 2 +- service/api/conversions.go | 22 ++++---- service/debugger/debugger.go | 2 +- service/debugger/locations.go | 2 +- service/rpc1/server.go | 8 ++- service/rpc2/client.go | 2 +- service/rpc2/server.go | 4 +- service/test/common_test.go | 4 +- service/test/integration1_test.go | 38 ++++++------- service/test/integration2_test.go | 69 +++++++++++++----------- service/test/variables_test.go | 22 +++++--- 27 files changed, 166 insertions(+), 136 deletions(-) diff --git a/Makefile b/Makefile index 5b13a0a1..ae142f6d 100644 --- a/Makefile +++ b/Makefile @@ -12,9 +12,12 @@ install: uninstall: @go run scripts/make.go uninstall -test: +test: vet @go run scripts/make.go test +vet: + @go vet $$(go list ./... | grep -v scripts | grep -v native) + test-proc-run: @go run scripts/make.go test -s proc -r $(RUN) @@ -24,4 +27,4 @@ test-integration-run: vendor: @go run scripts/make.go vendor -.PHONY: vendor test-integration-run test-proc-run test check-cert install build +.PHONY: vendor test-integration-run test-proc-run test check-cert install build vet diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index 2a5e9b8c..f53007b9 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -90,7 +90,7 @@ func New(docCall bool) *cobra.Command { buildFlagsDefault := "" if runtime.GOOS == "windows" { ver, _ := goversion.Installed() - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { // Work-around for https://github.com/golang/go/issues/13154 buildFlagsDefault = "-ldflags='-linkmode internal'" } diff --git a/pkg/dwarf/godwarf/type.go b/pkg/dwarf/godwarf/type.go index 829d2782..c8d01ab7 100644 --- a/pkg/dwarf/godwarf/type.go +++ b/pkg/dwarf/godwarf/type.go @@ -545,7 +545,7 @@ func readType(d *dwarf.Data, name string, r *dwarf.Reader, off dwarf.Offset, typ } addressSize := r.AddressSize() if e == nil || e.Offset != off { - return nil, dwarf.DecodeError{name, off, "no type at offset"} + return nil, dwarf.DecodeError{Name: name, Offset: off, Err: "no type at offset"} } // If this is the root of the recursion, prepare to resolve typedef sizes @@ -613,7 +613,7 @@ func readType(d *dwarf.Data, name string, r *dwarf.Reader, off dwarf.Offset, typ return nil } case uint64: - err = dwarf.DecodeError{name, e.Offset, "DWARFv4 section debug_types unsupported"} + err = dwarf.DecodeError{Name: name, Offset: e.Offset, Err: "DWARFv4 section debug_types unsupported"} return nil default: // It appears that no Type means "void". @@ -677,7 +677,7 @@ func readType(d *dwarf.Data, name string, r *dwarf.Reader, off dwarf.Offset, typ } ndim++ case dwarf.TagEnumerationType: - err = dwarf.DecodeError{name, kid.Offset, "cannot handle enumeration type as array bound"} + err = dwarf.DecodeError{Name: name, Offset: kid.Offset, Err: "cannot handle enumeration type as array bound"} goto Error } } @@ -697,12 +697,12 @@ func readType(d *dwarf.Data, name string, r *dwarf.Reader, off dwarf.Offset, typ name, _ := e.Val(dwarf.AttrName).(string) enc, ok := e.Val(dwarf.AttrEncoding).(int64) if !ok { - err = dwarf.DecodeError{name, e.Offset, "missing encoding attribute for " + name} + err = dwarf.DecodeError{Name: name, Offset: e.Offset, Err: "missing encoding attribute for " + name} goto Error } switch enc { default: - err = dwarf.DecodeError{name, e.Offset, "unrecognized encoding attribute value"} + err = dwarf.DecodeError{Name: name, Offset: e.Offset, Err: "unrecognized encoding attribute value"} goto Error case encAddress: @@ -816,12 +816,12 @@ func readType(d *dwarf.Data, name string, r *dwarf.Reader, off dwarf.Offset, typ f.ByteOffset = b.Int() op_ = op.Opcode(b.Uint8()) if op_ != op.DW_OP_plus { - err = dwarf.DecodeError{name, kid.Offset, fmt.Sprintf("unexpected opcode 0x%x", op_)} + err = dwarf.DecodeError{Name: name, Offset: kid.Offset, Err: fmt.Sprintf("unexpected opcode 0x%x", op_)} goto Error } b.AssertEmpty() default: - err = dwarf.DecodeError{name, kid.Offset, fmt.Sprintf("unexpected opcode 0x%x", op_)} + err = dwarf.DecodeError{Name: name, Offset: kid.Offset, Err: fmt.Sprintf("unexpected opcode 0x%x", op_)} goto Error } if b.Err != nil { diff --git a/pkg/dwarf/util/buf.go b/pkg/dwarf/util/buf.go index 8aa1d614..52349fe0 100644 --- a/pkg/dwarf/util/buf.go +++ b/pkg/dwarf/util/buf.go @@ -146,6 +146,6 @@ func (b *buf) AssertEmpty() { func (b *buf) error(s string) { if b.Err == nil { b.data = nil - b.Err = dwarf.DecodeError{b.name, b.off, s} + b.Err = dwarf.DecodeError{Name: b.name, Offset: b.off, Err: s} } } diff --git a/pkg/gobuild/gobuild.go b/pkg/gobuild/gobuild.go index ed59d1ac..e8a04b7a 100644 --- a/pkg/gobuild/gobuild.go +++ b/pkg/gobuild/gobuild.go @@ -29,9 +29,9 @@ func optflags(args []string) []string { ver, _ := goversion.Installed() switch { - case ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}): + case ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}): args = append(args, "-gcflags", "all=-N -l") - case ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}): + case ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}): args = append(args, "-gcflags", "-N -l", "-a") default: args = append(args, "-gcflags", "-N -l") diff --git a/pkg/proc/core/core_test.go b/pkg/proc/core/core_test.go index 81ac81cf..97859694 100644 --- a/pkg/proc/core/core_test.go +++ b/pkg/proc/core/core_test.go @@ -263,7 +263,7 @@ func TestCoreFpRegisters(t *testing.T) { } // in go1.10 the crash is executed on a different thread and registers are // no longer available in the core dump. - if ver, _ := goversion.Parse(runtime.Version()); ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { t.Skip("not supported in go1.10 and later") } @@ -368,11 +368,12 @@ mainSearch: } scope := proc.FrameToScope(p.BinInfo(), p.CurrentThread(), nil, *mainFrame) - v1, err := scope.EvalVariable("t", proc.LoadConfig{true, 1, 64, 64, -1, 0}) + loadConfig := proc.LoadConfig{FollowPointers: true, MaxVariableRecurse: 1, MaxStringLen: 64, MaxArrayValues: 64, MaxStructFields: -1} + v1, err := scope.EvalVariable("t", loadConfig) assertNoError(err, t, "EvalVariable(t)") assertNoError(v1.Unreadable, t, "unreadable variable 't'") t.Logf("t = %#v\n", v1) - v2, err := scope.EvalVariable("s", proc.LoadConfig{true, 1, 64, 64, -1, 0}) + v2, err := scope.EvalVariable("s", loadConfig) assertNoError(err, t, "EvalVariable(s)") assertNoError(v2.Unreadable, t, "unreadable variable 's'") t.Logf("s = %#v\n", v2) diff --git a/pkg/proc/dwarf_expr_test.go b/pkg/proc/dwarf_expr_test.go index 6a236e26..cbfe812d 100644 --- a/pkg/proc/dwarf_expr_test.go +++ b/pkg/proc/dwarf_expr_test.go @@ -215,8 +215,8 @@ func TestDwarfExprLoclist(t *testing.T) { dwb.AddSubprogram("main.main", 0x40100, 0x41000) dwb.AddVariable("a", uint16off, []dwarfbuilder.LocEntry{ - {0x40100, 0x40700, dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa)}, - {0x40700, 0x41000, dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa, op.DW_OP_consts, int(2), op.DW_OP_plus)}, + {Lowpc: 0x40100, Highpc: 0x40700, Loc: dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa)}, + {Lowpc: 0x40700, Highpc: 0x41000, Loc: dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa, op.DW_OP_consts, int(2), op.DW_OP_plus)}, }) dwb.TagClose() @@ -288,8 +288,8 @@ func TestLocationCovers(t *testing.T) { dwb.AddCompileUnit("main", 0x0) dwb.AddSubprogram("main.main", 0x40100, 0x41000) aOff := dwb.AddVariable("a", uint16off, []dwarfbuilder.LocEntry{ - {0x40100, 0x40700, dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa)}, - {0x40700, 0x41000, dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa, op.DW_OP_consts, int(2), op.DW_OP_plus)}, + {Lowpc: 0x40100, Highpc: 0x40700, Loc: dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa)}, + {Lowpc: 0x40700, Highpc: 0x41000, Loc: dwarfbuilder.LocationBlock(op.DW_OP_call_frame_cfa, op.DW_OP_consts, int(2), op.DW_OP_plus)}, }) dwb.TagClose() dwb.TagClose() diff --git a/pkg/proc/native/registers_linux_amd64.go b/pkg/proc/native/registers_linux_amd64.go index 276d5994..21499701 100644 --- a/pkg/proc/native/registers_linux_amd64.go +++ b/pkg/proc/native/registers_linux_amd64.go @@ -55,7 +55,7 @@ func registers(thread *Thread, floatingPoint bool) (proc.Registers, error) { if err != nil { return nil, err } - r := &linutil.AMD64Registers{®s, nil, nil} + r := &linutil.AMD64Registers{Regs: ®s} if floatingPoint { var fpregset linutil.AMD64Xstate r.Fpregs, fpregset, err = thread.fpRegisters() diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 73b990c2..d9a77182 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -527,7 +527,7 @@ func TestNextGeneral(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 7, -1, 0, 0, ""}) { + if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 7, Rev: -1}) { testcases = []nextTest{ {17, 19}, {19, 20}, @@ -674,7 +674,7 @@ func TestNextFunctionReturnDefer(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { testcases = []nextTest{ {5, 6}, {6, 9}, @@ -1724,7 +1724,7 @@ func TestIssue384(t *testing.T) { // Crash related to reading uninitialized memory, introduced by the memory prefetching optimization ver, _ := goversion.Parse(runtime.Version()) - if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // go 1.10 emits DW_AT_decl_line and we won't be able to evaluate 'st' // which is declared after line 13. t.Skip("can not evaluate not-yet-declared variables with go 1.10") @@ -1856,7 +1856,7 @@ func TestPackageVariables(t *testing.T) { func TestIssue149(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 7, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 7, Rev: -1}) { return } // setting breakpoint on break statement @@ -2073,7 +2073,7 @@ func TestIssue509(t *testing.T) { func TestUnsupportedArch(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major < 0 || !ver.AfterOrEqual(goversion.GoVersion{1, 6, -1, 0, 0, ""}) || ver.AfterOrEqual(goversion.GoVersion{1, 7, -1, 0, 0, ""}) { + if ver.Major < 0 || !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 6, Rev: -1}) || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 7, Rev: -1}) { // cross compile (with -N?) works only on select versions of go return } @@ -2725,7 +2725,7 @@ func TestStacktraceWithBarriers(t *testing.T) { // struct. // In Go 1.9 stack barriers have been removed and this test must be disabled. - if ver, _ := goversion.Parse(runtime.Version()); ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { return } @@ -3074,7 +3074,7 @@ func TestIssue871(t *testing.T) { } func TestShadowedFlag(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { return } withTestProcess("testshadow", t, func(p *proc.Target, fixture protest.Fixture) { @@ -3285,13 +3285,13 @@ func frameInFile(frame proc.Stackframe, file string) bool { func TestCgoStacktrace(t *testing.T) { if runtime.GOOS == "windows" { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { t.Skip("disabled on windows with go before version 1.9") } } if runtime.GOOS == "darwin" { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 8, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 8, Rev: -1}) { t.Skip("disabled on macOS with go before version 1.8") } } @@ -3394,7 +3394,7 @@ func TestCgoStacktrace(t *testing.T) { func TestCgoSources(t *testing.T) { if runtime.GOOS == "windows" { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { t.Skip("disabled on windows with go before version 1.9") } } @@ -3516,7 +3516,7 @@ func TestIssue1008(t *testing.T) { func TestDeclLine(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { t.Skip("go 1.9 and prior versions do not emit DW_AT_decl_line") } @@ -3662,7 +3662,7 @@ func checkFrame(frame proc.Stackframe, fnname, file string, line int, inlined bo } func TestAllPCsForFileLines(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3683,7 +3683,7 @@ func TestAllPCsForFileLines(t *testing.T) { } func TestInlinedStacktraceAndVariables(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3802,7 +3802,7 @@ func TestInlinedStacktraceAndVariables(t *testing.T) { } func TestInlineStep(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3816,7 +3816,7 @@ func TestInlineStep(t *testing.T) { } func TestInlineNext(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3830,7 +3830,7 @@ func TestInlineNext(t *testing.T) { } func TestInlineStepOver(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3842,7 +3842,7 @@ func TestInlineStepOver(t *testing.T) { } func TestInlineStepOut(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3855,7 +3855,7 @@ func TestInlineStepOut(t *testing.T) { func TestInlineFunctionList(t *testing.T) { // We should be able to list all functions, even inlined ones. - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3875,7 +3875,7 @@ func TestInlineFunctionList(t *testing.T) { func TestInlineBreakpoint(t *testing.T) { // We should be able to set a breakpoint on the call site of an inlined function. - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Versions of go before 1.10 do not have DWARF information for inlined calls t.Skip("inlining not supported") } @@ -3898,7 +3898,7 @@ func TestInlineBreakpoint(t *testing.T) { } func TestIssue951(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { t.Skip("scopes not implemented in <=go1.8") } @@ -3975,7 +3975,7 @@ func TestMapLoadConfigWithReslice(t *testing.T) { func TestStepOutReturn(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { t.Skip("return variables aren't marked on 1.9 or earlier") } withTestProcess("stepoutret", t, func(p *proc.Target, fixture protest.Fixture) { diff --git a/pkg/proc/scope_test.go b/pkg/proc/scope_test.go index 392f04b8..b5ee6923 100644 --- a/pkg/proc/scope_test.go +++ b/pkg/proc/scope_test.go @@ -19,7 +19,7 @@ import ( ) func TestScopeWithEscapedVariable(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 3, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1, Beta: 3}) { return } @@ -63,7 +63,7 @@ func TestScopeWithEscapedVariable(t *testing.T) { // every variable except the last one should be marked as shadowed // 2. EvalExpression should return the last one. func TestScope(t *testing.T) { - if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { return } diff --git a/pkg/proc/test/support.go b/pkg/proc/test/support.go index b49c71ec..0eadefce 100644 --- a/pkg/proc/test/support.go +++ b/pkg/proc/test/support.go @@ -109,7 +109,7 @@ func BuildFixture(name string, flags BuildFlags) Fixture { buildFlags := []string{"build"} var ver goversion.GoVersion - if ver, _ = goversion.Parse(runtime.Version()); runtime.GOOS == "windows" && ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver, _ = goversion.Parse(runtime.Version()); runtime.GOOS == "windows" && ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { // Work-around for https://github.com/golang/go/issues/13154 buildFlags = append(buildFlags, "-ldflags=-linkmode internal") } @@ -139,7 +139,7 @@ func BuildFixture(name string, flags BuildFlags) Fixture { if flags&BuildModePlugin != 0 { buildFlags = append(buildFlags, "-buildmode=plugin") } - if ver.IsDevel() || ver.AfterOrEqual(goversion.GoVersion{1, 11, -1, 0, 0, ""}) { + if ver.IsDevel() || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 11, Rev: -1}) { if flags&EnableDWZCompression != 0 { buildFlags = append(buildFlags, "-ldflags=-compressdwarf=false") } diff --git a/pkg/terminal/command.go b/pkg/terminal/command.go index 4d1dc12b..3f310880 100644 --- a/pkg/terminal/command.go +++ b/pkg/terminal/command.go @@ -7,10 +7,6 @@ import ( "bytes" "errors" "fmt" - "github.com/cosiner/argv" - "github.com/go-delve/delve/service" - "github.com/go-delve/delve/service/api" - "github.com/go-delve/delve/service/debugger" "go/parser" "go/scanner" "io" @@ -24,6 +20,11 @@ import ( "strconv" "strings" "text/tabwriter" + + "github.com/cosiner/argv" + "github.com/go-delve/delve/service" + "github.com/go-delve/delve/service/api" + "github.com/go-delve/delve/service/debugger" ) const optimizedFunctionWarning = "Warning: debugging optimized function" @@ -88,10 +89,10 @@ var ( // * Follows pointers // * Loads more array values // * Does not limit struct fields - LongLoadConfig = api.LoadConfig{true, 1, 64, 64, -1} + LongLoadConfig = api.LoadConfig{FollowPointers: true, MaxVariableRecurse: 1, MaxStringLen: 64, MaxArrayValues: 64, MaxStructFields: -1} // ShortLoadConfig loads less information, not following pointers // and limiting struct fields loaded to 3. - ShortLoadConfig = api.LoadConfig{false, 0, 64, 0, 3} + ShortLoadConfig = api.LoadConfig{MaxStringLen: 64, MaxStructFields: 3} ) // ByFirstAlias will sort by the first @@ -415,7 +416,7 @@ The "note" is arbitrary text that can be used to identify the checkpoint, if it }) c.cmds = append(c.cmds, command{ aliases: []string{"rev"}, - group: runCmds, + group: runCmds, cmdFn: c.revCmd, helpMsg: `Reverses the execution of the target program for the command specified. Currently, only the rev step-instruction command is supported.`, diff --git a/pkg/terminal/command_test.go b/pkg/terminal/command_test.go index 93692bf1..d7a9fd1f 100644 --- a/pkg/terminal/command_test.go +++ b/pkg/terminal/command_test.go @@ -245,7 +245,9 @@ func TestExecuteFile(t *testing.T) { func TestIssue354(t *testing.T) { printStack([]api.Stackframe{}, "", false) - printStack([]api.Stackframe{{api.Location{PC: 0, File: "irrelevant.go", Line: 10, Function: nil}, nil, nil, 0, 0, nil, true, ""}}, "", false) + printStack([]api.Stackframe{ + {Location: api.Location{PC: 0, File: "irrelevant.go", Line: 10, Function: nil}, + Bottom: true}}, "", false) } func TestIssue411(t *testing.T) { @@ -778,7 +780,7 @@ func TestConfig(t *testing.T) { if err != nil { t.Fatalf("error executing configureCmd(substitute-path a b): %v", err) } - if len(term.conf.SubstitutePath) != 1 || (term.conf.SubstitutePath[0] != config.SubstitutePathRule{"a", "b"}) { + if len(term.conf.SubstitutePath) != 1 || (term.conf.SubstitutePath[0] != config.SubstitutePathRule{From: "a", To: "b"}) { t.Fatalf("unexpected SubstitutePathRules after insert %v", term.conf.SubstitutePath) } @@ -884,7 +886,7 @@ func TestPrintContextParkedGoroutine(t *testing.T) { func TestStepOutReturn(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { t.Skip("return variables aren't marked on 1.9 or earlier") } withTestTerminal("stepoutret", t, func(term *FakeTerminal) { diff --git a/pkg/terminal/config.go b/pkg/terminal/config.go index 1c91c08b..f5bae369 100644 --- a/pkg/terminal/config.go +++ b/pkg/terminal/config.go @@ -170,7 +170,7 @@ func configureSetSubstitutePath(t *Term, rest string) error { return nil } } - t.conf.SubstitutePath = append(t.conf.SubstitutePath, config.SubstitutePathRule{argv[0], argv[1]}) + t.conf.SubstitutePath = append(t.conf.SubstitutePath, config.SubstitutePathRule{From: argv[0], To: argv[1]}) default: return fmt.Errorf("too many arguments to \"config substitute-path\"") } diff --git a/pkg/terminal/starbind/conv.go b/pkg/terminal/starbind/conv.go index 8385ae66..1046cb07 100644 --- a/pkg/terminal/starbind/conv.go +++ b/pkg/terminal/starbind/conv.go @@ -13,7 +13,7 @@ import ( ) // autoLoadConfig is the load configuration used to automatically load more from a variable -var autoLoadConfig = api.LoadConfig{false, 1, 1024, 64, -1} +var autoLoadConfig = api.LoadConfig{MaxVariableRecurse: 1, MaxStringLen: 1024, MaxArrayValues: 64, MaxStructFields: -1} // interfaceToStarlarkValue converts an interface{} variable (produced by // decoding JSON) into a starlark.Value. @@ -253,7 +253,7 @@ func (env *Env) variableValueToStarlarkValue(v *api.Variable, top bool) (starlar } func (env *Env) autoLoad(expr string) *api.Variable { - v, err := env.ctx.Client().EvalVariable(api.EvalScope{-1, 0, 0}, expr, autoLoadConfig) + v, err := env.ctx.Client().EvalVariable(api.EvalScope{GoroutineID: -1}, expr, autoLoadConfig) if err != nil { return &api.Variable{Unreadable: err.Error()} } diff --git a/pkg/terminal/starlark.go b/pkg/terminal/starlark.go index 85a1ab98..9134a276 100644 --- a/pkg/terminal/starlark.go +++ b/pkg/terminal/starlark.go @@ -51,7 +51,7 @@ func (ctx starlarkContext) CallCommand(cmdstr string) error { } func (ctx starlarkContext) Scope() api.EvalScope { - return api.EvalScope{-1, ctx.term.cmds.frame, 0} + return api.EvalScope{GoroutineID: -1, Frame: ctx.term.cmds.frame} } func (ctx starlarkContext) LoadConfig() api.LoadConfig { diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index 716bf67e..d802cdd8 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -417,7 +417,7 @@ func (t *Term) handleExit() (int, error) { // loadConfig returns an api.LoadConfig with the parameterss specified in // the configuration file. func (t *Term) loadConfig() api.LoadConfig { - r := api.LoadConfig{true, 1, 64, 64, -1} + r := api.LoadConfig{FollowPointers: true, MaxVariableRecurse: 1, MaxStringLen: 64, MaxArrayValues: 64, MaxStructFields: -1} if t.conf != nil && t.conf.MaxStringLen != nil { r.MaxStringLen = *t.conf.MaxStringLen diff --git a/service/api/conversions.go b/service/api/conversions.go index 9aa1488c..8756500c 100644 --- a/service/api/conversions.go +++ b/service/api/conversions.go @@ -305,12 +305,12 @@ func LoadConfigToProc(cfg *LoadConfig) *proc.LoadConfig { return nil } return &proc.LoadConfig{ - cfg.FollowPointers, - cfg.MaxVariableRecurse, - cfg.MaxStringLen, - cfg.MaxArrayValues, - cfg.MaxStructFields, - 0, // MaxMapBuckets is set internally by pkg/proc, read its documentation for an explanation. + FollowPointers: cfg.FollowPointers, + MaxVariableRecurse: cfg.MaxVariableRecurse, + MaxStringLen: cfg.MaxStringLen, + MaxArrayValues: cfg.MaxArrayValues, + MaxStructFields: cfg.MaxStructFields, + MaxMapBuckets: 0, // MaxMapBuckets is set internally by pkg/proc, read its documentation for an explanation. } } @@ -320,11 +320,11 @@ func LoadConfigFromProc(cfg *proc.LoadConfig) *LoadConfig { return nil } return &LoadConfig{ - cfg.FollowPointers, - cfg.MaxVariableRecurse, - cfg.MaxStringLen, - cfg.MaxArrayValues, - cfg.MaxStructFields, + FollowPointers: cfg.FollowPointers, + MaxVariableRecurse: cfg.MaxVariableRecurse, + MaxStringLen: cfg.MaxStringLen, + MaxArrayValues: cfg.MaxArrayValues, + MaxStructFields: cfg.MaxStructFields, } } diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 07e62cc8..8ab0fcf2 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -1482,7 +1482,7 @@ func go11DecodeErrorCheck(err error) error { } gover, ok := goversion.Installed() - if !ok || !gover.AfterOrEqual(goversion.GoVersion{1, 11, -1, 0, 0, ""}) || goversion.VersionAfterOrEqual(runtime.Version(), 1, 11) { + if !ok || !gover.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 11, Rev: -1}) || goversion.VersionAfterOrEqual(runtime.Version(), 1, 11) { return err } diff --git a/service/debugger/locations.go b/service/debugger/locations.go index 355b0fa8..f29deee9 100644 --- a/service/debugger/locations.go +++ b/service/debugger/locations.go @@ -275,7 +275,7 @@ func (loc *AddrLocationSpec) Find(d *Debugger, scope *proc.EvalScope, locStr str } return []api.Location{{PC: uint64(addr)}}, nil } else { - v, err := scope.EvalExpression(loc.AddrExpr, proc.LoadConfig{true, 0, 0, 0, 0, 0}) + v, err := scope.EvalExpression(loc.AddrExpr, proc.LoadConfig{FollowPointers: true}) if err != nil { return nil, err } diff --git a/service/rpc1/server.go b/service/rpc1/server.go index eb71e3ee..d2435034 100644 --- a/service/rpc1/server.go +++ b/service/rpc1/server.go @@ -10,7 +10,13 @@ import ( "github.com/go-delve/delve/service/debugger" ) -var defaultLoadConfig = proc.LoadConfig{true, 1, 64, 64, -1, 0} +var defaultLoadConfig = proc.LoadConfig{ + FollowPointers: true, + MaxVariableRecurse: 1, + MaxStringLen: 64, + MaxArrayValues: 64, + MaxStructFields: -1, +} type RPCServer struct { // config is all the information necessary to start the debugger and server. diff --git a/service/rpc2/client.go b/service/rpc2/client.go index ea58fec5..8af72c1d 100644 --- a/service/rpc2/client.go +++ b/service/rpc2/client.go @@ -33,7 +33,7 @@ func NewClient(addr string) *RPCClient { func newFromRPCClient(client *rpc.Client) *RPCClient { c := &RPCClient{client: client} - c.call("SetApiVersion", api.SetAPIVersionIn{2}, &api.SetAPIVersionOut{}) + c.call("SetApiVersion", api.SetAPIVersionIn{APIVersion: 2}, &api.SetAPIVersionOut{}) return c } diff --git a/service/rpc2/server.go b/service/rpc2/server.go index d684d20d..843e8584 100644 --- a/service/rpc2/server.go +++ b/service/rpc2/server.go @@ -174,7 +174,7 @@ type StacktraceOut struct { func (s *RPCServer) Stacktrace(arg StacktraceIn, out *StacktraceOut) error { cfg := arg.Cfg if cfg == nil && arg.Full { - cfg = &api.LoadConfig{true, 1, 64, 64, -1} + cfg = &api.LoadConfig{FollowPointers: true, MaxVariableRecurse: 1, MaxStringLen: 64, MaxArrayValues: 64, MaxStructFields: -1} } if arg.Defers { arg.Opts |= api.StacktraceReadDefers @@ -453,7 +453,7 @@ type EvalOut struct { func (s *RPCServer) Eval(arg EvalIn, out *EvalOut) error { cfg := arg.Cfg if cfg == nil { - cfg = &api.LoadConfig{true, 1, 64, 64, -1} + cfg = &api.LoadConfig{FollowPointers: true, MaxVariableRecurse: 1, MaxStringLen: 64, MaxArrayValues: 64, MaxStructFields: -1} } v, err := s.debugger.EvalVariableInScope(arg.Scope, arg.Expr, *api.LoadConfigToProc(cfg)) if err != nil { diff --git a/service/test/common_test.go b/service/test/common_test.go index c6e7f885..1e217e1e 100644 --- a/service/test/common_test.go +++ b/service/test/common_test.go @@ -89,9 +89,9 @@ func findLocationHelper(t *testing.T, c interface{}, loc string, shouldErr bool, switch c := c.(type) { case locationFinder1: - locs, err = c.FindLocation(api.EvalScope{-1, 0, 0}, loc) + locs, err = c.FindLocation(api.EvalScope{GoroutineID: -1}, loc) case locationFinder2: - locs, err = c.FindLocation(api.EvalScope{-1, 0, 0}, loc, false) + locs, err = c.FindLocation(api.EvalScope{GoroutineID: -1}, loc, false) default: t.Errorf("unexpected type %T passed to findLocationHelper", c) } diff --git a/service/test/integration1_test.go b/service/test/integration1_test.go index 980f0cb6..423c9411 100644 --- a/service/test/integration1_test.go +++ b/service/test/integration1_test.go @@ -253,7 +253,7 @@ func Test1NextGeneral(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 7, -1, 0, 0, ""}) { + if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 7, Rev: -1}) { testcases = []nextTest{ {17, 19}, {19, 20}, @@ -433,7 +433,7 @@ func Test1ClientServer_infoLocals(t *testing.T) { if state.Err != nil { t.Fatalf("Unexpected error: %v, state: %#v", state.Err, state) } - locals, err := c.ListLocalVariables(api.EvalScope{-1, 0, 0}) + locals, err := c.ListLocalVariables(api.EvalScope{GoroutineID: -1}) if err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -461,7 +461,7 @@ func Test1ClientServer_infoArgs(t *testing.T) { if regs == "" { t.Fatal("Expected string showing registers values, got empty string") } - locals, err := c.ListFunctionArgs(api.EvalScope{-1, 0, 0}) + locals, err := c.ListFunctionArgs(api.EvalScope{GoroutineID: -1}) if err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -687,7 +687,7 @@ func Test1ClientServer_EvalVariable(t *testing.T) { t.Fatalf("Continue(): %v\n", state.Err) } - var1, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "a1") + var1, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "a1") assertNoError(err, t, "EvalVariable") t.Logf("var1: %s", var1.SinglelineString()) @@ -706,9 +706,9 @@ func Test1ClientServer_SetVariable(t *testing.T) { t.Fatalf("Continue(): %v\n", state.Err) } - assertNoError(c.SetVariable(api.EvalScope{-1, 0, 0}, "a2", "8"), t, "SetVariable()") + assertNoError(c.SetVariable(api.EvalScope{GoroutineID: -1}, "a2", "8"), t, "SetVariable()") - a2, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "a2") + a2, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "a2") if err != nil { t.Fatalf("Could not evaluate variable: %v", err) } @@ -835,10 +835,10 @@ func Test1Issue355(t *testing.T) { assertError(err, t, "ListThreads()") _, err = c.GetThread(tid) assertError(err, t, "GetThread()") - assertError(c.SetVariable(api.EvalScope{gid, 0, 0}, "a", "10"), t, "SetVariable()") - _, err = c.ListLocalVariables(api.EvalScope{gid, 0, 0}) + assertError(c.SetVariable(api.EvalScope{GoroutineID: gid}, "a", "10"), t, "SetVariable()") + _, err = c.ListLocalVariables(api.EvalScope{GoroutineID: gid}) assertError(err, t, "ListLocalVariables()") - _, err = c.ListFunctionArgs(api.EvalScope{gid, 0, 0}) + _, err = c.ListFunctionArgs(api.EvalScope{GoroutineID: gid}) assertError(err, t, "ListFunctionArgs()") _, err = c.ListRegisters() assertError(err, t, "ListRegisters()") @@ -846,9 +846,9 @@ func Test1Issue355(t *testing.T) { assertError(err, t, "ListGoroutines()") _, err = c.Stacktrace(gid, 10, false) assertError(err, t, "Stacktrace()") - _, err = c.FindLocation(api.EvalScope{gid, 0, 0}, "+1") + _, err = c.FindLocation(api.EvalScope{GoroutineID: gid}, "+1") assertError(err, t, "FindLocation()") - _, err = c.DisassemblePC(api.EvalScope{-1, 0, 0}, 0x40100, api.IntelFlavour) + _, err = c.DisassemblePC(api.EvalScope{GoroutineID: -1}, 0x40100, api.IntelFlavour) assertError(err, t, "DisassemblePC()") }) } @@ -863,12 +863,12 @@ func Test1Disasm(t *testing.T) { state := <-ch assertNoError(state.Err, t, "Continue()") - locs, err := c.FindLocation(api.EvalScope{-1, 0, 0}, "main.main") + locs, err := c.FindLocation(api.EvalScope{GoroutineID: -1}, "main.main") assertNoError(err, t, "FindLocation()") if len(locs) != 1 { t.Fatalf("wrong number of locations for main.main: %d", len(locs)) } - d1, err := c.DisassemblePC(api.EvalScope{-1, 0, 0}, locs[0].PC, api.IntelFlavour) + d1, err := c.DisassemblePC(api.EvalScope{GoroutineID: -1}, locs[0].PC, api.IntelFlavour) assertNoError(err, t, "DisassemblePC()") if len(d1) < 2 { t.Fatalf("wrong size of disassembly: %d", len(d1)) @@ -876,7 +876,7 @@ func Test1Disasm(t *testing.T) { pcstart := d1[0].Loc.PC pcend := d1[len(d1)-1].Loc.PC + uint64(len(d1[len(d1)-1].Bytes)) - d2, err := c.DisassembleRange(api.EvalScope{-1, 0, 0}, pcstart, pcend, api.IntelFlavour) + d2, err := c.DisassembleRange(api.EvalScope{GoroutineID: -1}, pcstart, pcend, api.IntelFlavour) assertNoError(err, t, "DisassembleRange()") if len(d1) != len(d2) { @@ -885,7 +885,7 @@ func Test1Disasm(t *testing.T) { t.Fatal("mismatched length between disassemble pc and disassemble range") } - d3, err := c.DisassemblePC(api.EvalScope{-1, 0, 0}, state.CurrentThread.PC, api.IntelFlavour) + d3, err := c.DisassemblePC(api.EvalScope{GoroutineID: -1}, state.CurrentThread.PC, api.IntelFlavour) assertNoError(err, t, "DisassemblePC() - second call") if len(d1) != len(d3) { @@ -934,7 +934,7 @@ func Test1Disasm(t *testing.T) { state, err := c.StepInstruction() assertNoError(err, t, fmt.Sprintf("StepInstruction() %d", count)) - d3, err = c.DisassemblePC(api.EvalScope{-1, 0, 0}, state.CurrentThread.PC, api.IntelFlavour) + d3, err = c.DisassemblePC(api.EvalScope{GoroutineID: -1}, state.CurrentThread.PC, api.IntelFlavour) assertNoError(err, t, fmt.Sprintf("StepInstruction() %d", count)) curinstr := getCurinstr(d3) @@ -1000,7 +1000,7 @@ func Test1ClientServer_CondBreakpoint(t *testing.T) { state := <-c.Continue() assertNoError(state.Err, t, "Continue()") - nvar, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "n") + nvar, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "n") assertNoError(err, t, "EvalVariable()") if nvar.SinglelineString() != "7" { @@ -1054,14 +1054,14 @@ func Test1TypesCommand(t *testing.T) { func Test1Issue406(t *testing.T) { withTestClient1("issue406", t, func(c *rpc1.RPCClient) { - locs, err := c.FindLocation(api.EvalScope{-1, 0, 0}, "issue406.go:146") + locs, err := c.FindLocation(api.EvalScope{GoroutineID: -1}, "issue406.go:146") assertNoError(err, t, "FindLocation()") _, err = c.CreateBreakpoint(&api.Breakpoint{Addr: locs[0].PC}) assertNoError(err, t, "CreateBreakpoint()") ch := c.Continue() state := <-ch assertNoError(state.Err, t, "Continue()") - v, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "cfgtree") + v, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "cfgtree") assertNoError(err, t, "EvalVariable()") vs := v.MultilineString("") t.Logf("cfgtree formats to: %s\n", vs) diff --git a/service/test/integration2_test.go b/service/test/integration2_test.go index 9cf441c1..36407a9f 100644 --- a/service/test/integration2_test.go +++ b/service/test/integration2_test.go @@ -26,7 +26,14 @@ import ( "github.com/go-delve/delve/service/rpccommon" ) -var normalLoadConfig = api.LoadConfig{true, 1, 64, 64, -1} +var normalLoadConfig = api.LoadConfig{ + FollowPointers: true, + MaxVariableRecurse: 1, + MaxStringLen: 64, + MaxArrayValues: 64, + MaxStructFields: -1, +} + var testBackend, buildMode string func TestMain(m *testing.M) { @@ -304,7 +311,7 @@ func TestNextGeneral(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 7, -1, 0, 0, ""}) { + if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 7, Rev: -1}) { testcases = []nextTest{ {17, 19}, {19, 20}, @@ -488,7 +495,7 @@ func TestClientServer_infoLocals(t *testing.T) { if state.Err != nil { t.Fatalf("Unexpected error: %v, state: %#v", state.Err, state) } - locals, err := c.ListLocalVariables(api.EvalScope{-1, 0, 0}, normalLoadConfig) + locals, err := c.ListLocalVariables(api.EvalScope{GoroutineID: -1}, normalLoadConfig) if err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -532,7 +539,7 @@ func TestClientServer_infoArgs(t *testing.T) { } t.Logf("GoroutineID: -1, Frame: 1\n%s", regs.String()) - locals, err := c.ListFunctionArgs(api.EvalScope{-1, 0, 0}, normalLoadConfig) + locals, err := c.ListFunctionArgs(api.EvalScope{GoroutineID: -1}, normalLoadConfig) if err != nil { t.Fatalf("Unexpected error: %v", err) } @@ -781,7 +788,7 @@ func TestClientServer_EvalVariable(t *testing.T) { t.Fatalf("Continue(): %v\n", state.Err) } - var1, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "a1", normalLoadConfig) + var1, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "a1", normalLoadConfig) assertNoError(err, t, "EvalVariable") t.Logf("var1: %s", var1.SinglelineString()) @@ -800,9 +807,9 @@ func TestClientServer_SetVariable(t *testing.T) { t.Fatalf("Continue(): %v\n", state.Err) } - assertNoError(c.SetVariable(api.EvalScope{-1, 0, 0}, "a2", "8"), t, "SetVariable()") + assertNoError(c.SetVariable(api.EvalScope{GoroutineID: -1}, "a2", "8"), t, "SetVariable()") - a2, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "a2", normalLoadConfig) + a2, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "a2", normalLoadConfig) if err != nil { t.Fatalf("Could not evaluate variable: %v", err) } @@ -935,22 +942,22 @@ func TestIssue355(t *testing.T) { assertError(err, t, "ListThreads()") _, err = c.GetThread(tid) assertError(err, t, "GetThread()") - assertError(c.SetVariable(api.EvalScope{gid, 0, 0}, "a", "10"), t, "SetVariable()") - _, err = c.ListLocalVariables(api.EvalScope{gid, 0, 0}, normalLoadConfig) + assertError(c.SetVariable(api.EvalScope{GoroutineID: gid}, "a", "10"), t, "SetVariable()") + _, err = c.ListLocalVariables(api.EvalScope{GoroutineID: gid}, normalLoadConfig) assertError(err, t, "ListLocalVariables()") - _, err = c.ListFunctionArgs(api.EvalScope{gid, 0, 0}, normalLoadConfig) + _, err = c.ListFunctionArgs(api.EvalScope{GoroutineID: gid}, normalLoadConfig) assertError(err, t, "ListFunctionArgs()") _, err = c.ListThreadRegisters(0, false) assertError(err, t, "ListThreadRegisters()") - _, err = c.ListScopeRegisters(api.EvalScope{gid, 0, 0}, false) + _, err = c.ListScopeRegisters(api.EvalScope{GoroutineID: gid}, false) assertError(err, t, "ListScopeRegisters()") _, _, err = c.ListGoroutines(0, 0) assertError(err, t, "ListGoroutines()") _, err = c.Stacktrace(gid, 10, 0, &normalLoadConfig) assertError(err, t, "Stacktrace()") - _, err = c.FindLocation(api.EvalScope{gid, 0, 0}, "+1", false) + _, err = c.FindLocation(api.EvalScope{GoroutineID: gid}, "+1", false) assertError(err, t, "FindLocation()") - _, err = c.DisassemblePC(api.EvalScope{-1, 0, 0}, 0x40100, api.IntelFlavour) + _, err = c.DisassemblePC(api.EvalScope{GoroutineID: -1}, 0x40100, api.IntelFlavour) assertError(err, t, "DisassemblePC()") }) } @@ -965,12 +972,12 @@ func TestDisasm(t *testing.T) { state := <-ch assertNoError(state.Err, t, "Continue()") - locs, err := c.FindLocation(api.EvalScope{-1, 0, 0}, "main.main", false) + locs, err := c.FindLocation(api.EvalScope{GoroutineID: -1}, "main.main", false) assertNoError(err, t, "FindLocation()") if len(locs) != 1 { t.Fatalf("wrong number of locations for main.main: %d", len(locs)) } - d1, err := c.DisassemblePC(api.EvalScope{-1, 0, 0}, locs[0].PC, api.IntelFlavour) + d1, err := c.DisassemblePC(api.EvalScope{GoroutineID: -1}, locs[0].PC, api.IntelFlavour) assertNoError(err, t, "DisassemblePC()") if len(d1) < 2 { t.Fatalf("wrong size of disassembly: %d", len(d1)) @@ -980,10 +987,10 @@ func TestDisasm(t *testing.T) { pcend := d1[len(d1)-1].Loc.PC + uint64(len(d1[len(d1)-1].Bytes)) // start address should be less than end address - _, err = c.DisassembleRange(api.EvalScope{-1, 0, 0}, pcend, pcstart, api.IntelFlavour) + _, err = c.DisassembleRange(api.EvalScope{GoroutineID: -1}, pcend, pcstart, api.IntelFlavour) assertError(err, t, "DisassembleRange()") - d2, err := c.DisassembleRange(api.EvalScope{-1, 0, 0}, pcstart, pcend, api.IntelFlavour) + d2, err := c.DisassembleRange(api.EvalScope{GoroutineID: -1}, pcstart, pcend, api.IntelFlavour) assertNoError(err, t, "DisassembleRange()") if len(d1) != len(d2) { @@ -992,7 +999,7 @@ func TestDisasm(t *testing.T) { t.Fatal("mismatched length between disassemble pc and disassemble range") } - d3, err := c.DisassemblePC(api.EvalScope{-1, 0, 0}, state.CurrentThread.PC, api.IntelFlavour) + d3, err := c.DisassemblePC(api.EvalScope{GoroutineID: -1}, state.CurrentThread.PC, api.IntelFlavour) assertNoError(err, t, "DisassemblePC() - second call") if len(d1) != len(d3) { @@ -1041,7 +1048,7 @@ func TestDisasm(t *testing.T) { state, err := c.StepInstruction() assertNoError(err, t, fmt.Sprintf("StepInstruction() %d", count)) - d3, err = c.DisassemblePC(api.EvalScope{-1, 0, 0}, state.CurrentThread.PC, api.IntelFlavour) + d3, err = c.DisassemblePC(api.EvalScope{GoroutineID: -1}, state.CurrentThread.PC, api.IntelFlavour) assertNoError(err, t, fmt.Sprintf("StepInstruction() %d", count)) curinstr := getCurinstr(d3) @@ -1109,7 +1116,7 @@ func TestClientServer_CondBreakpoint(t *testing.T) { state := <-c.Continue() assertNoError(state.Err, t, "Continue()") - nvar, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "n", normalLoadConfig) + nvar, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "n", normalLoadConfig) assertNoError(err, t, "EvalVariable()") if nvar.SinglelineString() != "7" { @@ -1227,14 +1234,14 @@ func TestTypesCommand(t *testing.T) { func TestIssue406(t *testing.T) { protest.AllowRecording(t) withTestClient2("issue406", t, func(c service.Client) { - locs, err := c.FindLocation(api.EvalScope{-1, 0, 0}, "issue406.go:146", false) + locs, err := c.FindLocation(api.EvalScope{GoroutineID: -1}, "issue406.go:146", false) assertNoError(err, t, "FindLocation()") _, err = c.CreateBreakpoint(&api.Breakpoint{Addr: locs[0].PC}) assertNoError(err, t, "CreateBreakpoint()") ch := c.Continue() state := <-ch assertNoError(state.Err, t, "Continue()") - v, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "cfgtree", normalLoadConfig) + v, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "cfgtree", normalLoadConfig) assertNoError(err, t, "EvalVariable()") vs := v.MultilineString("") t.Logf("cfgtree formats to: %s\n", vs) @@ -1246,7 +1253,7 @@ func TestEvalExprName(t *testing.T) { state := <-c.Continue() assertNoError(state.Err, t, "Continue()") - var1, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "i1+1", normalLoadConfig) + var1, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "i1+1", normalLoadConfig) assertNoError(err, t, "EvalVariable") const name = "i1+1" @@ -1266,7 +1273,7 @@ func TestClientServer_Issue528(t *testing.T) { // f744717d1924340b8f5e5a385e99078693ad9097 ver, _ := goversion.Parse(runtime.Version()) - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 7, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 7, Rev: -1}) { t.Log("Test skipped") return } @@ -1489,7 +1496,7 @@ func TestClientServerConsistentExit(t *testing.T) { func TestClientServer_StepOutReturn(t *testing.T) { ver, _ := goversion.Parse(runtime.Version()) - if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { t.Skip("return variables aren't marked on 1.9 or earlier") } withTestClient2("stepoutret", t, func(c service.Client) { @@ -1583,7 +1590,7 @@ func TestAcceptMulticlient(t *testing.T) { } func mustHaveDebugCalls(t *testing.T, c service.Client) { - locs, err := c.FindLocation(api.EvalScope{-1, 0, 0}, "runtime.debugCallV1", false) + locs, err := c.FindLocation(api.EvalScope{GoroutineID: -1}, "runtime.debugCallV1", false) if len(locs) == 0 || err != nil { t.Skip("function calls not supported on this version of go") } @@ -1633,7 +1640,7 @@ func TestClientServerFunctionCallBadPos(t *testing.T) { } withTestClient2("fncall", t, func(c service.Client) { mustHaveDebugCalls(t, c) - loc, err := c.FindLocation(api.EvalScope{-1, 0, 0}, "fmt/print.go:649", false) + loc, err := c.FindLocation(api.EvalScope{GoroutineID: -1}, "fmt/print.go:649", false) assertNoError(err, t, "could not find location") _, err = c.CreateBreakpoint(&api.Breakpoint{File: loc[0].File, Line: loc[0].Line}) @@ -1689,7 +1696,7 @@ func TestClientServerFunctionCallStacktrace(t *testing.T) { protest.MustSupportFunctionCalls(t, testBackend) withTestClient2("fncall", t, func(c service.Client) { mustHaveDebugCalls(t, c) - c.SetReturnValuesLoadConfig(&api.LoadConfig{false, 0, 2048, 0, 0}) + c.SetReturnValuesLoadConfig(&api.LoadConfig{FollowPointers: false, MaxStringLen: 2048}) state := <-c.Continue() assertNoError(state.Err, t, "Continue()") state, err := c.Call(-1, "callstacktrace()", false) @@ -1750,7 +1757,7 @@ type brokenRPCClient struct { func (c *brokenRPCClient) Detach(kill bool) error { defer c.client.Close() out := new(rpc2.DetachOut) - return c.call("Detach", rpc2.DetachIn{kill}, out) + return c.call("Detach", rpc2.DetachIn{Kill: kill}, out) } func (c *brokenRPCClient) call(method string, args, reply interface{}) error { @@ -1760,7 +1767,7 @@ func (c *brokenRPCClient) call(method string, args, reply interface{}) error { func TestUnknownMethodCall(t *testing.T) { clientConn, _ := startServer("continuetestprog", t) client := &brokenRPCClient{jsonrpc.NewClient(clientConn)} - client.call("SetApiVersion", api.SetAPIVersionIn{2}, &api.SetAPIVersionOut{}) + client.call("SetApiVersion", api.SetAPIVersionIn{APIVersion: 2}, &api.SetAPIVersionOut{}) defer client.Detach(true) var out int err := client.call("NonexistentRPCCall", nil, &out) @@ -1798,7 +1805,7 @@ func TestRerecord(t *testing.T) { t.Fatalf("Unexpected error: %v, state: %#v", state.Err, state) } - vart, err := c.EvalVariable(api.EvalScope{-1, 0, 0}, "t", normalLoadConfig) + vart, err := c.EvalVariable(api.EvalScope{GoroutineID: -1}, "t", normalLoadConfig) assertNoError(err, t, "EvalVariable") if vart.Unreadable != "" { t.Fatalf("Could not read variable 't': %s\n", vart.Unreadable) diff --git a/service/test/variables_test.go b/service/test/variables_test.go index 418fcf3b..78cdf220 100644 --- a/service/test/variables_test.go +++ b/service/test/variables_test.go @@ -19,8 +19,18 @@ import ( protest "github.com/go-delve/delve/pkg/proc/test" ) -var pnormalLoadConfig = proc.LoadConfig{true, 1, 64, 64, -1, 0} -var pshortLoadConfig = proc.LoadConfig{false, 0, 64, 0, 3, 0} +var pnormalLoadConfig = proc.LoadConfig{ + FollowPointers: true, + MaxVariableRecurse: 1, + MaxStringLen: 64, + MaxArrayValues: 64, + MaxStructFields: -1, +} + +var pshortLoadConfig = proc.LoadConfig{ + MaxStringLen: 64, + MaxStructFields: 3, +} type varTest struct { name string @@ -496,7 +506,7 @@ func TestEmbeddedStruct(t *testing.T) { assertNoError(proc.Continue(p), t, "Continue()") ver, _ := goversion.Parse(runtime.Version()) - if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 9, -1, 0, 0, ""}) { + if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) { // on go < 1.9 embedded fields had different names for i := range testcases { if testcases[i].name == "b2" { @@ -812,7 +822,7 @@ func TestEvalExpression(t *testing.T) { } ver, _ := goversion.Parse(runtime.Version()) - if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 7, -1, 0, 0, ""}) { + if ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 7, Rev: -1}) { for i := range testcases { if testcases[i].name == "iface3" { testcases[i].value = "interface {}(*map[string]go/constant.Value) *[]" @@ -948,7 +958,7 @@ func TestIssue426(t *testing.T) { } ver, _ := goversion.Parse(runtime.Version()) - if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{1, 8, -1, 0, 0, ""}) { + if ver.Major < 0 || ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 8, Rev: -1}) { testcases[2].typ = `struct { main.val go/constant.Value }` testcases[3].typ = `func(struct { main.i int }, interface {}, struct { main.val go/constant.Value })` testcases[4].typ = `struct { main.i int; main.j int }` @@ -1085,7 +1095,7 @@ func TestConstants(t *testing.T) { {"pkg.SomeConst", false, "2", "", "int", nil}, } ver, _ := goversion.Parse(runtime.Version()) - if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{1, 10, -1, 0, 0, ""}) { + if ver.Major > 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 10, Rev: -1}) { // Not supported on 1.9 or earlier t.Skip("constants added in go 1.10") }