diff --git a/cmd/dlv/dlv_test.go b/cmd/dlv/dlv_test.go index 5a6acaf4..6d15794a 100644 --- a/cmd/dlv/dlv_test.go +++ b/cmd/dlv/dlv_test.go @@ -127,7 +127,7 @@ func testOutput(t *testing.T, dlvbin, output string, delveCmds []string) (stdout // Give delve some time to compile and write the binary. foundIt := false - for wait := 0; wait < 30; wait++ { + for range 30 { _, err = os.Stat(debugbin) if err == nil { foundIt = true @@ -632,7 +632,7 @@ func TestDAPCmd(t *testing.T) { func newDAPRemoteClient(t *testing.T, addr string, isDlvAttach bool, isMulti bool) *daptest.Client { c := daptest.NewClient(addr) - c.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": true}) + c.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": true}) if isDlvAttach || isMulti { c.ExpectCapabilitiesEventSupportTerminateDebuggee(t) } @@ -726,7 +726,7 @@ func TestRemoteDAPClientMulti(t *testing.T) { // Client 0 connects but with the wrong attach request dapclient0 := daptest.NewClient(listenAddr) - dapclient0.AttachRequest(map[string]interface{}{"mode": "local"}) + dapclient0.AttachRequest(map[string]any{"mode": "local"}) dapclient0.ExpectErrorResponse(t) // Client 1 connects and continues to main.main @@ -749,7 +749,7 @@ func TestRemoteDAPClientMulti(t *testing.T) { // Attach to exited processes is an error dapclient3 := daptest.NewClient(listenAddr) - dapclient3.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": true}) + dapclient3.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": true}) dapclient3.ExpectErrorResponseWith(t, dap.FailedToAttach, `Process \d+ has exited with status 0`, true) closeDAPRemoteMultiClient(t, dapclient3, "exited") diff --git a/pkg/config/config.go b/pkg/config/config.go index d461ccb1..a77a16c1 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -59,7 +59,7 @@ type Config struct { // Source list line-number color, as a terminal escape sequence. // For historic reasons, this can also be an integer color code. - SourceListLineColor interface{} `yaml:"source-list-line-color"` + SourceListLineColor any `yaml:"source-list-line-color"` // Source list arrow color, as a terminal escape sequence. SourceListArrowColor string `yaml:"source-list-arrow-color"` diff --git a/pkg/config/split.go b/pkg/config/split.go index 97d01373..36eb8b04 100644 --- a/pkg/config/split.go +++ b/pkg/config/split.go @@ -131,7 +131,7 @@ func ConfigureSetSimple(rest string, cfgname string, field reflect.Value) error return nil } -func ConfigureList(w io.Writer, config interface{}, tag string) { +func ConfigureList(w io.Writer, config any, tag string) { it := IterateConfiguration(config, tag) for it.Next() { fieldName, field := it.Field() @@ -172,7 +172,7 @@ type configureIterator struct { tag string } -func IterateConfiguration(conf interface{}, tag string) *configureIterator { +func IterateConfiguration(conf any, tag string) *configureIterator { cfgValue := reflect.ValueOf(conf).Elem() cfgType := cfgValue.Type() @@ -193,7 +193,7 @@ func (it *configureIterator) Field() (name string, field reflect.Value) { return } -func ConfigureListByName(conf interface{}, name, tag string) string { +func ConfigureListByName(conf any, name, tag string) string { if name == "" { return "" } @@ -209,7 +209,7 @@ func ConfigureListByName(conf interface{}, name, tag string) string { return "" } -func ConfigureFindFieldByName(conf interface{}, name, tag string) reflect.Value { +func ConfigureFindFieldByName(conf any, name, tag string) reflect.Value { it := IterateConfiguration(conf, tag) for it.Next() { fieldName, field := it.Field() diff --git a/pkg/dwarf/dwarfbuilder/info.go b/pkg/dwarf/dwarfbuilder/info.go index 194df632..e65a5057 100644 --- a/pkg/dwarf/dwarfbuilder/info.go +++ b/pkg/dwarf/dwarfbuilder/info.go @@ -122,7 +122,7 @@ func (b *Builder) TagClose() { } // Attr adds an attribute to the current DIE. -func (b *Builder) Attr(attr dwarf.Attr, val interface{}) dwarf.Offset { +func (b *Builder) Attr(attr dwarf.Attr, val any) dwarf.Offset { if len(b.tagStack) == 0 { panic("Attr with no open tags") } @@ -269,7 +269,7 @@ func (b *Builder) AddSubprogram(fnname string, lowpc, highpc uint64) dwarf.Offse // AddVariable adds a new variable entry to debug_info. // Will write a DW_TAG_variable, followed by a DW_AT_type and a // DW_AT_location. -func (b *Builder) AddVariable(varname string, typ dwarf.Offset, loc interface{}) dwarf.Offset { +func (b *Builder) AddVariable(varname string, typ dwarf.Offset, loc any) dwarf.Offset { r := b.TagOpen(dwarf.TagVariable, varname) b.Attr(dwarf.AttrType, typ) b.Attr(dwarf.AttrLocation, loc) diff --git a/pkg/dwarf/dwarfbuilder/loc.go b/pkg/dwarf/dwarfbuilder/loc.go index f89e6e7c..66aa451a 100644 --- a/pkg/dwarf/dwarfbuilder/loc.go +++ b/pkg/dwarf/dwarfbuilder/loc.go @@ -16,7 +16,7 @@ type LocEntry struct { // LocationBlock returns a DWARF expression corresponding to the list of // arguments. -func LocationBlock(args ...interface{}) []byte { +func LocationBlock(args ...any) []byte { var buf bytes.Buffer for _, arg := range args { switch x := arg.(type) { diff --git a/pkg/dwarf/godwarf/tree.go b/pkg/dwarf/godwarf/tree.go index 7e1e64b7..f49fb324 100644 --- a/pkg/dwarf/godwarf/tree.go +++ b/pkg/dwarf/godwarf/tree.go @@ -11,13 +11,13 @@ import ( // When calling Val, if the entry does not have the specified attribute, the // entry specified by DW_AT_abstract_origin will be searched recursively. type Entry interface { - Val(dwarf.Attr) interface{} + Val(dwarf.Attr) any AttrField(dwarf.Attr) *dwarf.Field } type compositeEntry []*dwarf.Entry -func (ce compositeEntry) Val(attr dwarf.Attr) interface{} { +func (ce compositeEntry) Val(attr dwarf.Attr) any { if f := ce.AttrField(attr); f != nil { return f.Val } diff --git a/pkg/dwarf/line/line_parser.go b/pkg/dwarf/line/line_parser.go index 16bdb8dd..80d9875c 100644 --- a/pkg/dwarf/line/line_parser.go +++ b/pkg/dwarf/line/line_parser.go @@ -32,7 +32,7 @@ type DebugLineInfo struct { Instructions []byte Lookup map[string]*FileEntry - Logf func(string, ...interface{}) + Logf func(string, ...any) // stateMachineCache[pc] is a state machine stopped at pc stateMachineCache map[uint64]*StateMachine @@ -63,7 +63,7 @@ type FileEntry struct { type DebugLines []*DebugLineInfo // ParseAll parses all debug_line segments found in data -func ParseAll(data []byte, debugLineStr []byte, logfn func(string, ...interface{}), staticBase uint64, normalizeBackslash bool, ptrSize int) DebugLines { +func ParseAll(data []byte, debugLineStr []byte, logfn func(string, ...any), staticBase uint64, normalizeBackslash bool, ptrSize int) DebugLines { var ( lines = make(DebugLines, 0) buf = bytes.NewBuffer(data) @@ -79,11 +79,11 @@ func ParseAll(data []byte, debugLineStr []byte, logfn func(string, ...interface{ // Parse parses a single debug_line segment from buf. Compdir is the // DW_AT_comp_dir attribute of the associated compile unit. -func Parse(compdir string, buf *bytes.Buffer, debugLineStr []byte, logfn func(string, ...interface{}), staticBase uint64, normalizeBackslash bool, ptrSize int) *DebugLineInfo { +func Parse(compdir string, buf *bytes.Buffer, debugLineStr []byte, logfn func(string, ...any), staticBase uint64, normalizeBackslash bool, ptrSize int) *DebugLineInfo { dbl := new(DebugLineInfo) dbl.Logf = logfn if logfn == nil { - dbl.Logf = func(string, ...interface{}) {} + dbl.Logf = func(string, ...any) {} } dbl.staticBase = staticBase dbl.ptrSize = ptrSize @@ -180,7 +180,7 @@ func parseIncludeDirs5(info *DebugLineInfo, buf *bytes.Buffer) bool { } dirCount, _ := leb128.DecodeUnsigned(buf) info.IncludeDirs = make([]string, 0, dirCount) - for i := uint64(0); i < dirCount; i++ { + for range dirCount { dirEntryFormReader.reset() for dirEntryFormReader.next(buf) { switch dirEntryFormReader.contentType { diff --git a/pkg/dwarf/line/parse_util.go b/pkg/dwarf/line/parse_util.go index b1f22e54..cc5f587f 100644 --- a/pkg/dwarf/line/parse_util.go +++ b/pkg/dwarf/line/parse_util.go @@ -44,7 +44,7 @@ const ( var ErrBufferUnderflow = errors.New("buffer underflow") type formReader struct { - logf func(string, ...interface{}) + logf func(string, ...any) contentTypes []uint64 formCodes []uint64 @@ -60,7 +60,7 @@ type formReader struct { nexti int } -func readEntryFormat(buf *bytes.Buffer, logf func(string, ...interface{})) *formReader { +func readEntryFormat(buf *bytes.Buffer, logf func(string, ...any)) *formReader { if buf.Len() < 1 { return nil } diff --git a/pkg/dwarf/op/regs.go b/pkg/dwarf/op/regs.go index bd95e792..6dd837e7 100644 --- a/pkg/dwarf/op/regs.go +++ b/pkg/dwarf/op/regs.go @@ -172,10 +172,7 @@ func (reg *DwarfRegister) FillBytes() { func (reg *DwarfRegister) Overwrite(reg2 *DwarfRegister) *DwarfRegister { reg.FillBytes() reg2.FillBytes() - width := len(reg.Bytes) - if len(reg2.Bytes) > len(reg.Bytes) { - width = len(reg2.Bytes) - } + width := max(len(reg2.Bytes), len(reg.Bytes)) b := make([]byte, width) copy(b, reg.Bytes) copy(b, reg2.Bytes) diff --git a/pkg/gobuild/gobuild.go b/pkg/gobuild/gobuild.go index 9799336d..d1dc3ea2 100644 --- a/pkg/gobuild/gobuild.go +++ b/pkg/gobuild/gobuild.go @@ -17,7 +17,7 @@ import ( // This can be used to remove the temporary binary generated for the session. func Remove(path string) { var err error - for i := 0; i < 20; i++ { + for range 20 { err = os.Remove(path) // Open files can be removed on Unix, but not on Windows, where there also appears // to be a delay in releasing the binary when the process exits. @@ -41,7 +41,7 @@ func GoBuild(debugname string, pkgs []string, buildflags string) error { // GoBuildCombinedOutput builds non-test files in 'pkgs' with the specified 'buildflags' // and writes the output at 'debugname'. -func GoBuildCombinedOutput(debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) { +func GoBuildCombinedOutput(debugname string, pkgs []string, buildflags any) (string, []byte, error) { args, err := goBuildArgs2(debugname, pkgs, buildflags, false) if err != nil { return "", nil, err @@ -58,7 +58,7 @@ func GoTestBuild(debugname string, pkgs []string, buildflags string) error { // GoTestBuildCombinedOutput builds test files 'pkgs' with the specified 'buildflags' // and writes the output at 'debugname'. -func GoTestBuildCombinedOutput(debugname string, pkgs []string, buildflags interface{}) (string, []byte, error) { +func GoTestBuildCombinedOutput(debugname string, pkgs []string, buildflags any) (string, []byte, error) { args, err := goBuildArgs2(debugname, pkgs, buildflags, true) if err != nil { return "", nil, err @@ -91,7 +91,7 @@ func goBuildArgs(debugname string, pkgs []string, buildflags string, isTest bool } // goBuildArgs2 is like goBuildArgs, but takes either string or []string. -func goBuildArgs2(debugname string, pkgs []string, buildflags interface{}, isTest bool) ([]string, error) { +func goBuildArgs2(debugname string, pkgs []string, buildflags any, isTest bool) ([]string, error) { var args []string switch buildflags := buildflags.(type) { case string: diff --git a/pkg/internal/gosym/symtab.go b/pkg/internal/gosym/symtab.go index 57737776..5162d154 100644 --- a/pkg/internal/gosym/symtab.go +++ b/pkg/internal/gosym/symtab.go @@ -64,10 +64,7 @@ func (s *Sym) PackageName() string { if s.goVersion <= ver118 && (strings.HasPrefix(name, "go.") || strings.HasPrefix(name, "type.")) { return "" } - pathend := strings.LastIndex(name, "/") - if pathend < 0 { - pathend = 0 - } + pathend := max(strings.LastIndex(name, "/"), 0) if i := strings.Index(name[pathend:], "."); i != -1 { return name[:pathend+i] } @@ -81,10 +78,7 @@ func (s *Sym) ReceiverName() string { name := s.nameWithoutInst() // If we find a slash in name, it should precede any bracketed expression // that was removed, so pathend will apply correctly to name and s.Name. - pathend := strings.LastIndex(name, "/") - if pathend < 0 { - pathend = 0 - } + pathend := max(strings.LastIndex(name, "/"), 0) // Find the first dot after pathend (or from the beginning, if there was // no slash in name). l := strings.Index(name[pathend:], ".") diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 9415cf65..11f4de06 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -287,7 +287,7 @@ func FindFileLocation(p Process, filename string, lineno int) ([]uint64, error) } } - sort.Slice(selectedPCs, func(i, j int) bool { return selectedPCs[i] < selectedPCs[j] }) + slices.Sort(selectedPCs) return selectedPCs, nil } @@ -369,7 +369,7 @@ func FindFunctionLocation(p Process, funcName string, lineOffset int) ([]uint64, return nil, &ErrFunctionNotFound{funcName} } } - sort.Slice(r, func(i, j int) bool { return r[i] < r[j] }) + slices.Sort(r) return r, nil } @@ -574,10 +574,7 @@ func (fn *Function) PackageName() string { } func packageName(name string) string { - pathend := strings.LastIndex(name, "/") - if pathend < 0 { - pathend = 0 - } + pathend := max(strings.LastIndex(name, "/"), 0) if i := strings.Index(name[pathend:], "."); i != -1 { return name[:pathend+i] @@ -590,10 +587,7 @@ func packageName(name string) string { // Borrowed from $GOROOT/debug/gosym/symtab.go func (fn *Function) ReceiverName() string { inst := fn.instRange() - pathend := strings.LastIndex(fn.Name[:inst[0]], "/") - if pathend < 0 { - pathend = 0 - } + pathend := max(strings.LastIndex(fn.Name[:inst[0]], "/"), 0) l := strings.Index(fn.Name[pathend:], ".") if l == -1 { return "" @@ -1151,7 +1145,7 @@ func (image *Image) Close() error { return err2 } -func (image *Image) setLoadError(logger logflags.Logger, fmtstr string, args ...interface{}) { +func (image *Image) setLoadError(logger logflags.Logger, fmtstr string, args ...any) { image.loadErrMu.Lock() image.loadErr = fmt.Errorf(fmtstr, args...) image.loadErrMu.Unlock() @@ -2541,7 +2535,7 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugInfoBytes, debugLineB } lineInfoOffset, hasLineInfo := entry.Val(dwarf.AttrStmtList).(int64) if hasLineInfo && lineInfoOffset >= 0 && lineInfoOffset < int64(len(debugLineBytes)) { - var logfn func(string, ...interface{}) + var logfn func(string, ...any) if logflags.DebugLineErrors() { logfn = logflags.DebugLineLogger().Debugf } @@ -2985,10 +2979,7 @@ func (bi *BinaryInfo) expandPackagesInType(expr ast.Expr) { // elements of the path except the first one) like Go does in variable and // type names. func escapePackagePath(pkg string) string { - slash := strings.Index(pkg, "/") - if slash < 0 { - slash = 0 - } + slash := max(strings.Index(pkg, "/"), 0) return pkg[:slash] + strings.ReplaceAll(pkg[slash:], ".", "%2e") } diff --git a/pkg/proc/breakpoints.go b/pkg/proc/breakpoints.go index ed7815f1..2514b5c7 100644 --- a/pkg/proc/breakpoints.go +++ b/pkg/proc/breakpoints.go @@ -1104,7 +1104,7 @@ type LogicalBreakpoint struct { // condUsesHitCounts is true when 'cond' uses breakpoint hitcounts condUsesHitCounts bool - UserData interface{} // Any additional information about the breakpoint + UserData any // Any additional information about the breakpoint // Name of root function from where tracing needs to be done RootFuncName string // depth of tracing diff --git a/pkg/proc/core/core_test.go b/pkg/proc/core/core_test.go index e2292750..58b68741 100644 --- a/pkg/proc/core/core_test.go +++ b/pkg/proc/core/core_test.go @@ -42,7 +42,7 @@ func assertNoError(err error, t testing.TB, s string) { func TestSplicedReader(t *testing.T) { data := []byte{} data2 := []byte{} - for i := 0; i < 100; i++ { + for i := range 100 { data = append(data, byte(i)) data2 = append(data2, byte(i+100)) } diff --git a/pkg/proc/core/delve_core.go b/pkg/proc/core/delve_core.go index 81edf974..a6e14957 100644 --- a/pkg/proc/core/delve_core.go +++ b/pkg/proc/core/delve_core.go @@ -65,7 +65,7 @@ func threadsFromDelveNotes(p *process, notes []*note) (proc.Thread, error) { th.regs = new(delveRegisters) var readerr error - read := func(out interface{}) { + read := func(out any) { if readerr != nil { return } diff --git a/pkg/proc/core/linux_core.go b/pkg/proc/core/linux_core.go index d0dcec24..55ef6639 100644 --- a/pkg/proc/core/linux_core.go +++ b/pkg/proc/core/linux_core.go @@ -255,7 +255,7 @@ func (t *linuxLOONG64Thread) ThreadID() int { type note struct { Type elf.NType Name string - Desc interface{} // Decoded Desc from the + Desc any // Decoded Desc from the } // readNotes reads all the notes from the notes prog in core. diff --git a/pkg/proc/core/minidump/minidump.go b/pkg/proc/core/minidump/minidump.go index 484ea909..0e1831cd 100644 --- a/pkg/proc/core/minidump/minidump.go +++ b/pkg/proc/core/minidump/minidump.go @@ -317,7 +317,7 @@ const ( ) // Open reads the minidump file at path and returns it as a Minidump structure. -func Open(path string, logfn func(fmt string, args ...interface{})) (*Minidump, error) { +func Open(path string, logfn func(fmt string, args ...any)) (*Minidump, error) { rawbuf, err := os.ReadFile(path) //TODO(aarzilli): mmap? if err != nil { return nil, err @@ -598,14 +598,14 @@ func readModuleList(mdmp *Minidump, buf *minidumpBuf) { // the description of the process memory. // See: https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/ns-minidumpapiset-minidump_memory64_list // And: https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/ns-minidumpapiset-minidump_memory_descriptor -func readMemory64List(mdmp *Minidump, buf *minidumpBuf, logfn func(fmt string, args ...interface{})) { +func readMemory64List(mdmp *Minidump, buf *minidumpBuf, logfn func(fmt string, args ...any)) { rangesNum := buf.u64() baseOff := int(buf.u64()) if buf.err != nil { return } - for i := uint64(0); i < rangesNum; i++ { + for i := range rangesNum { addr := buf.u64() sz := buf.u64() @@ -625,7 +625,7 @@ func readMemory64List(mdmp *Minidump, buf *minidumpBuf, logfn func(fmt string, a } } -func readMemoryInfoList(mdmp *Minidump, buf *minidumpBuf, logfn func(fmt string, args ...interface{})) { +func readMemoryInfoList(mdmp *Minidump, buf *minidumpBuf, logfn func(fmt string, args ...any)) { startOff := buf.off sizeOfHeader := int(buf.u32()) sizeOfEntry := int(buf.u32()) diff --git a/pkg/proc/core/windows_amd64_minidump.go b/pkg/proc/core/windows_amd64_minidump.go index 30d31fea..f69b193b 100644 --- a/pkg/proc/core/windows_amd64_minidump.go +++ b/pkg/proc/core/windows_amd64_minidump.go @@ -8,7 +8,7 @@ import ( ) func readAMD64Minidump(minidumpPath, exePath string) (*process, proc.Thread, error) { - var logfn func(string, ...interface{}) + var logfn func(string, ...any) if logflags.Minidump() { logfn = logflags.MinidumpLogger().Infof } diff --git a/pkg/proc/dump.go b/pkg/proc/dump.go index abfaf90e..e1841cfb 100644 --- a/pkg/proc/dump.go +++ b/pkg/proc/dump.go @@ -161,7 +161,7 @@ func (t *Target) Dump(out elfwriter.WriteCloserSeeker, flags DumpFlags, state *D notes = append(notes, elfwriter.Note{ Type: elfwriter.DelveHeaderNoteType, Name: "Delve Header", - Data: []byte(fmt.Sprintf("%s/%s\n%s\n%s%d\n%s%#x\n", bi.GOOS, bi.Arch.Name, version.DelveVersion.String(), elfwriter.DelveHeaderTargetPidPrefix, t.pid, elfwriter.DelveHeaderEntryPointPrefix, entryPoint)), + Data: fmt.Appendf(nil, "%s/%s\n%s\n%s%d\n%s%#x\n", bi.GOOS, bi.Arch.Name, version.DelveVersion.String(), elfwriter.DelveHeaderTargetPidPrefix, t.pid, elfwriter.DelveHeaderEntryPointPrefix, entryPoint), }) threads := t.ThreadList() @@ -388,7 +388,7 @@ func (t *Target) shouldDumpMemory(mme *MemoryMapEntry) bool { } type internalError struct { - Err interface{} + Err any Stack []internalErrorFrame } @@ -399,7 +399,7 @@ type internalErrorFrame struct { Line int } -func newInternalError(ierr interface{}, skip int) *internalError { +func newInternalError(ierr any, skip int) *internalError { r := &internalError{ierr, nil} for i := skip; ; i++ { pc, file, line, ok := runtime.Caller(i) diff --git a/pkg/proc/dwarf_expr_test.go b/pkg/proc/dwarf_expr_test.go index ad0255a7..0e3aa2a7 100644 --- a/pkg/proc/dwarf_expr_test.go +++ b/pkg/proc/dwarf_expr_test.go @@ -54,7 +54,7 @@ type fakeMemory struct { data []byte } -func newFakeMemory(base uint64, contents ...interface{}) *fakeMemory { +func newFakeMemory(base uint64, contents ...any) *fakeMemory { mem := &fakeMemory{base: base} var buf bytes.Buffer for _, x := range contents { diff --git a/pkg/proc/fncall.go b/pkg/proc/fncall.go index 10a6a4c9..55c2609f 100644 --- a/pkg/proc/fncall.go +++ b/pkg/proc/fncall.go @@ -450,7 +450,7 @@ func (err fncallPanicErr) Error() string { return "panic calling a function" } -func fncallLog(fmtstr string, args ...interface{}) { +func fncallLog(fmtstr string, args ...any) { logflags.FnCallLogger().Infof(fmtstr, args...) } diff --git a/pkg/proc/gdbserial/gdbserver.go b/pkg/proc/gdbserial/gdbserver.go index a95c8085..ac61aa4e 100644 --- a/pkg/proc/gdbserial/gdbserver.go +++ b/pkg/proc/gdbserial/gdbserver.go @@ -446,7 +446,7 @@ func getLdEnvVars() []string { var result []string environ := os.Environ() - for i := 0; i < len(environ); i++ { + for i := range environ { if strings.HasPrefix(environ[i], "LD_") || strings.HasPrefix(environ[i], "DYLD_") { result = append(result, "-e", environ[i]) diff --git a/pkg/proc/gdbserial/gdbserver_conn.go b/pkg/proc/gdbserial/gdbserver_conn.go index 7f7aabb1..2ddde57d 100644 --- a/pkg/proc/gdbserial/gdbserver_conn.go +++ b/pkg/proc/gdbserial/gdbserver_conn.go @@ -394,7 +394,7 @@ func (conn *gdbConn) readAuxv() ([]byte, error) { func (conn *gdbConn) qXfer(kind, annex string, binary bool) ([]byte, error) { out := []byte{} for { - cmd := []byte(fmt.Sprintf("$qXfer:%s:read:%s:%x,fff", kind, annex, len(out))) + cmd := fmt.Appendf(nil, "$qXfer:%s:read:%s:%x,fff", kind, annex, len(out)) err := conn.send(cmd) if err != nil { return nil, err @@ -1509,7 +1509,7 @@ func wiredecode(in, buf []byte) (newbuf, msg []byte) { } else { n := in[i+1] - 29 r := buf[len(buf)-1] - for j := uint8(0); j < n; j++ { + for range n { buf = append(buf, r) } i++ diff --git a/pkg/proc/internal/ebpf/helpers_test.go b/pkg/proc/internal/ebpf/helpers_test.go index a22b8773..e70e4639 100644 --- a/pkg/proc/internal/ebpf/helpers_test.go +++ b/pkg/proc/internal/ebpf/helpers_test.go @@ -9,7 +9,7 @@ import ( "github.com/go-delve/delve/pkg/proc/internal/ebpf/testhelper" ) -func compareStructTypes(t *testing.T, gostructVal, cstructVal interface{}) { +func compareStructTypes(t *testing.T, gostructVal, cstructVal any) { gostruct := reflect.ValueOf(gostructVal).Type() cstruct := reflect.ValueOf(cstructVal).Type() if gostruct.NumField() != cstruct.NumField() { diff --git a/pkg/proc/mem.go b/pkg/proc/mem.go index d758a9db..c309a3de 100644 --- a/pkg/proc/mem.go +++ b/pkg/proc/mem.go @@ -152,10 +152,7 @@ func newCompositeMemory(mem MemoryReadWriter, arch *Arch, regs op.DwarfRegisters case op.ImmPiece: buf := piece.Bytes if buf == nil { - sz := 8 - if piece.Size > sz { - sz = piece.Size - } + sz := max(piece.Size, 8) if piece.Size == 0 && i == len(pieces)-1 { piece.Size = arch.PtrSize() // DWARF doesn't say what this should be } diff --git a/pkg/proc/native/dump_linux_amd64.go b/pkg/proc/native/dump_linux_amd64.go index 480568f7..f802046d 100644 --- a/pkg/proc/native/dump_linux_amd64.go +++ b/pkg/proc/native/dump_linux_amd64.go @@ -29,7 +29,7 @@ type linuxPrPsInfo struct { } func (p *nativeProcess) DumpProcessNotes(notes []elfwriter.Note, threadDone func()) (threadsDone bool, out []elfwriter.Note, err error) { - tobytes := func(x interface{}) []byte { + tobytes := func(x any) []byte { out := new(bytes.Buffer) _ = binary.Write(out, binary.LittleEndian, x) return out.Bytes() diff --git a/pkg/proc/native/proc.go b/pkg/proc/native/proc.go index bbe08903..b392c99d 100644 --- a/pkg/proc/native/proc.go +++ b/pkg/proc/native/proc.go @@ -484,13 +484,13 @@ func openRedirects(stdinPath string, stdoutOR proc.OutputRedirect, stderrOR proc type ptraceThread struct { ptraceRefCnt int ptraceChan chan func() - ptraceDoneChan chan interface{} + ptraceDoneChan chan any } func newPtraceThread() *ptraceThread { pt := &ptraceThread{ ptraceChan: make(chan func()), - ptraceDoneChan: make(chan interface{}), + ptraceDoneChan: make(chan any), ptraceRefCnt: 1, } go pt.handlePtraceFuncs() diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index dca2cd75..d5ffbab4 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -307,7 +307,7 @@ func findFileLocation(p *proc.Target, t *testing.T, file string, lineno int) uin } func TestHalt(t *testing.T) { - stopChan := make(chan interface{}, 1) + stopChan := make(chan any, 1) withTestProcess("loopprog", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) { setFunctionBreakpoint(p, t, "main.loop") assertNoError(grp.Continue(), t, "Continue") @@ -2371,7 +2371,7 @@ func TestNegativeIntEvaluation(t *testing.T) { testcases := []struct { name string typ string - value interface{} + value any }{ {"ni8", "int8", int64(-5)}, {"ni16", "int16", int64(-5)}, @@ -2398,7 +2398,7 @@ func TestIssue683(t *testing.T) { withTestProcess("issue683", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) { setFunctionBreakpoint(p, t, "main.main") assertNoError(grp.Continue(), t, "First Continue()") - for i := 0; i < 20; i++ { + for range 20 { // eventually an error about the source file not being found will be // returned, the important thing is that we shouldn't panic err := grp.Step() @@ -2449,7 +2449,7 @@ func TestNextInDeferReturn(t *testing.T) { // can not step out of the runtime.deferreturn and all the way to the // point where the target program panics. setFunctionBreakpoint(p, t, "main.sampleFunction") - for i := 0; i < 20; i++ { + for i := range 20 { loc, err := proc.ThreadLocation(p.CurrentThread()) assertNoError(err, t, "CurrentThread().Location()") t.Logf("at %#x %s:%d", loc.PC, loc.File, loc.Line) @@ -4861,7 +4861,7 @@ func TestManualStopWhileStopped(t *testing.T) { repeatsFast = 5 ) - for i := 0; i < repeatsSlow; i++ { + for i := range repeatsSlow { t.Logf("Continue %d (slow)", i) done := make(chan struct{}) go asyncCont(done) @@ -4872,7 +4872,7 @@ func TestManualStopWhileStopped(t *testing.T) { time.Sleep(1 * time.Second) <-done } - for i := 0; i < repeatsFast; i++ { + for i := range repeatsFast { t.Logf("Continue %d (fast)", i) rch := make(chan struct{}) done := make(chan struct{}) diff --git a/pkg/proc/proc_unix_test.go b/pkg/proc/proc_unix_test.go index c7660d36..8b0bbbad 100644 --- a/pkg/proc/proc_unix_test.go +++ b/pkg/proc/proc_unix_test.go @@ -56,7 +56,7 @@ func TestIssue419(t *testing.T) { errChan <- grp.Continue() }) - for i := 0; i < 2; i++ { + for range 2 { err := <-errChan t.Logf("error %T %#v\n", err, err) diff --git a/pkg/proc/stepping_test.go b/pkg/proc/stepping_test.go index b2e0882e..783efdc2 100644 --- a/pkg/proc/stepping_test.go +++ b/pkg/proc/stepping_test.go @@ -35,7 +35,7 @@ const ( type seqTest struct { cf contFunc - pos interface{} + pos any } func testseq(program string, contFunc contFunc, testcases []nextTest, initialLocation string, t *testing.T) { diff --git a/pkg/proc/target_exec.go b/pkg/proc/target_exec.go index 8839279a..4c7f70f2 100644 --- a/pkg/proc/target_exec.go +++ b/pkg/proc/target_exec.go @@ -10,6 +10,7 @@ import ( "go/token" "path/filepath" "runtime" + "slices" "strings" "golang.org/x/arch/ppc64/ppc64asm" @@ -785,13 +786,7 @@ func next(dbp *Target, stepInto, inlinedStepOut bool) error { if backward { // Ensure that pcs contains firstPCAfterPrologue when reverse stepping. - found := false - for _, pc := range pcs { - if pc == firstPCAfterPrologue { - found = true - break - } - } + found := slices.Contains(pcs, firstPCAfterPrologue) if !found { pcs = append(pcs, firstPCAfterPrologue) } @@ -1331,7 +1326,7 @@ func skipAutogeneratedWrappersIn(p Process, startfn *Function, startpc uint64, a return nil, startpc } fn := startfn - for count := 0; count < maxSkipAutogeneratedWrappers; count++ { + for range maxSkipAutogeneratedWrappers { if !fn.cu.isgo { // can't exit Go return startfn, startpc diff --git a/pkg/proc/test/support.go b/pkg/proc/test/support.go index c8efea36..1de7a6f9 100644 --- a/pkg/proc/test/support.go +++ b/pkg/proc/test/support.go @@ -57,7 +57,7 @@ var PathsToRemove []string func FindFixturesDir() string { parent := ".." fixturesDir := "_fixtures" - for depth := 0; depth < 10; depth++ { + for range 10 { if _, err := os.Stat(fixturesDir); err == nil { break } diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index 0ff012c7..5f4aaa23 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -1572,10 +1572,7 @@ func readStringValue(mem MemoryReadWriter, addr uint64, strlen int64, cfg LoadCo return "", nil } - count := strlen - if count > int64(cfg.MaxStringLen) { - count = int64(cfg.MaxStringLen) - } + count := min(strlen, int64(cfg.MaxStringLen)) val := make([]byte, int(count)) _, err := mem.ReadMemory(val, addr) @@ -1600,10 +1597,7 @@ func readCStringValue(mem MemoryReadWriter, addr uint64, cfg LoadConfig) (string // divisor for all architectures. curaddr := addr + uint64(len(val)) maxsize := int(alignAddr(int64(curaddr+1), 1024) - int64(curaddr)) - size := len(buf) - if size > maxsize { - size = maxsize - } + size := min(len(buf), maxsize) _, err := mem.ReadMemory(buf[:size], curaddr) if err != nil { diff --git a/pkg/proc/variables_test.go b/pkg/proc/variables_test.go index 56b57f0e..40eb70c2 100644 --- a/pkg/proc/variables_test.go +++ b/pkg/proc/variables_test.go @@ -114,7 +114,7 @@ func TestVariableEvaluation(t *testing.T) { testcases := []struct { name string st reflect.Kind - value interface{} + value any length, cap int64 childrenlen int }{ @@ -1255,7 +1255,7 @@ func TestIssue1075(t *testing.T) { withTestProcess("clientdo", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) { setFunctionBreakpoint(p, t, "net/http.(*Client).Do") assertNoError(grp.Continue(), t, "Continue()") - for i := 0; i < 10; i++ { + for i := range 10 { scope, err := proc.GoroutineScope(p, p.CurrentThread()) assertNoError(err, t, fmt.Sprintf("GoroutineScope (%d)", i)) vars, err := scope.LocalVariables(pnormalLoadConfig) diff --git a/pkg/terminal/command.go b/pkg/terminal/command.go index 9c182206..711958c8 100644 --- a/pkg/terminal/command.go +++ b/pkg/terminal/command.go @@ -78,12 +78,7 @@ type command struct { // Returns true if the command string matches one of the aliases for this command func (c command) match(cmdstr string) bool { - for _, v := range c.aliases { - if v == cmdstr { - return true - } - } - return false + return slices.Contains(c.aliases, cmdstr) } // Commands represents the commands for Delve terminal process. @@ -770,11 +765,9 @@ func nullCommand(t *Term, ctx callContext, args string) error { func (c *Commands) help(t *Term, ctx callContext, args string) error { if args != "" { for _, cmd := range c.cmds { - for _, alias := range cmd.aliases { - if alias == args { - fmt.Fprintln(t.stdout, cmd.helpMsg) - return nil - } + if slices.Contains(cmd.aliases, args) { + fmt.Fprintln(t.stdout, cmd.helpMsg) + return nil } } return errNoCmd @@ -1351,12 +1344,9 @@ func parseOneRedirect(w []string, redirs *[3]string) ([]string, bool, error) { prefixes := []string{"<", ">", "2>"} names := []string{"stdin", "stdout", "stderr"} if len(w) >= 2 { - for _, prefix := range prefixes { - if w[len(w)-2] == prefix { - w[len(w)-2] += w[len(w)-1] - w = w[:len(w)-1] - break - } + if slices.Contains(prefixes, w[len(w)-2]) { + w[len(w)-2] += w[len(w)-1] + w = w[:len(w)-1] } } for i, prefix := range prefixes { @@ -2174,10 +2164,7 @@ loop: remsz := int(count * size) for remsz > 0 { - reqsz := rpc2.ExamineMemoryLengthLimit - if reqsz > remsz { - reqsz = remsz - } + reqsz := min(rpc2.ExamineMemoryLengthLimit, remsz) memArea, isLittleEndian, err := t.client.ExamineMemory(start, reqsz) if err != nil { return err @@ -3060,14 +3047,8 @@ func printdisass(t *Term, pc uint64) error { showHeader := true for i := range disasm { if disasm[i].AtPC { - s := i - lineCount - if s < 0 { - s = 0 - } - e := i + lineCount + 1 - if e > len(disasm) { - e = len(disasm) - } + s := max(i-lineCount, 0) + e := min(i+lineCount+1, len(disasm)) showHeader = s == 0 disasm = disasm[s:e] break diff --git a/pkg/terminal/starbind/conv.go b/pkg/terminal/starbind/conv.go index a46e101b..c5767623 100644 --- a/pkg/terminal/starbind/conv.go +++ b/pkg/terminal/starbind/conv.go @@ -17,7 +17,7 @@ var autoLoadConfig = api.LoadConfig{MaxVariableRecurse: 1, MaxStringLen: 1024, M // interfaceToStarlarkValue converts an interface{} variable (produced by // decoding JSON) into a starlark.Value. -func (env *Env) interfaceToStarlarkValue(v interface{}) starlark.Value { +func (env *Env) interfaceToStarlarkValue(v any) starlark.Value { switch v := v.(type) { case bool: return starlark.Bool(v) @@ -652,7 +652,7 @@ func (it *mapVariableAsStarlarkValueIterator) Next(p *starlark.Value) bool { // This works similarly to encoding/json.Unmarshal and similar functions, // but instead of getting its input from a byte buffer, it uses a // starlark.Value. -func unmarshalStarlarkValue(val starlark.Value, dst interface{}, path string) error { +func unmarshalStarlarkValue(val starlark.Value, dst any, path string) error { return unmarshalStarlarkValueIntl(val, reflect.ValueOf(dst), path) } diff --git a/pkg/terminal/starbind/starlark.go b/pkg/terminal/starbind/starlark.go index cd62f421..675ea82a 100644 --- a/pkg/terminal/starbind/starlark.go +++ b/pkg/terminal/starbind/starlark.go @@ -197,7 +197,7 @@ func (env *Env) printFunc() func(_ *starlark.Thread, msg string) { // Source can be either a []byte, a string or a io.Reader. If source is nil // Execute will execute the file specified by 'path'. // After the file is executed if a function named mainFnName exists it will be called, passing args to it. -func (env *Env) Execute(path string, source interface{}, mainFnName string, args []interface{}) (_ starlark.Value, _err error) { +func (env *Env) Execute(path string, source any, mainFnName string, args []any) (_ starlark.Value, _err error) { defer func() { err := recover() if err == nil { @@ -321,7 +321,7 @@ func (env *Env) createCommand(name string, val starlark.Value) error { } // callMain calls the main function in globals, if one was defined. -func (env *Env) callMain(thread *starlark.Thread, globals starlark.StringDict, mainFnName string, args []interface{}) (starlark.Value, error) { +func (env *Env) callMain(thread *starlark.Thread, globals starlark.StringDict, mainFnName string, args []any) (starlark.Value, error) { if mainFnName == "" { return starlark.None, nil } diff --git a/pkg/terminal/starlark.go b/pkg/terminal/starlark.go index 9134a276..3616015d 100644 --- a/pkg/terminal/starlark.go +++ b/pkg/terminal/starlark.go @@ -4,6 +4,7 @@ import ( "github.com/go-delve/delve/pkg/terminal/starbind" "github.com/go-delve/delve/service" "github.com/go-delve/delve/service/api" + "slices" ) type starlarkContext struct { @@ -24,13 +25,10 @@ func (ctx starlarkContext) RegisterCommand(name, helpMsg string, fn func(args st found := false for i := range ctx.term.cmds.cmds { cmd := &ctx.term.cmds.cmds[i] - for _, alias := range cmd.aliases { - if alias == name { - cmd.cmdFn = cmdfn - cmd.helpMsg = helpMsg - found = true - break - } + if slices.Contains(cmd.aliases, name) { + cmd.cmdFn = cmdfn + cmd.helpMsg = helpMsg + found = true } if found { break diff --git a/service/api/prettyprint.go b/service/api/prettyprint.go index dabae990..1aac9576 100644 --- a/service/api/prettyprint.go +++ b/service/api/prettyprint.go @@ -556,7 +556,7 @@ func byteArrayToUInt64(buf []byte, isLittleEndian bool) uint64 { n = n<<8 + uint64(buf[i]) } } else { - for i := 0; i < len(buf); i++ { + for i := range buf { n = n<<8 + uint64(buf[i]) } } diff --git a/service/api/prettyprint_test.go b/service/api/prettyprint_test.go index c4070ed1..6b048ac1 100644 --- a/service/api/prettyprint_test.go +++ b/service/api/prettyprint_test.go @@ -24,7 +24,7 @@ func TestPrettyExamineMemory(t *testing.T) { t.Fatalf("wrong lines return, expected %d but got %d", len(display), len(res)) } - for i := 0; i < len(display); i++ { + for i := range display { if display[i] != res[i] { errInfo := fmt.Sprintf("wrong display return at line %d\n", i+1) errInfo += fmt.Sprintf("expected:\n %q\n", display[i]) diff --git a/service/api/types.go b/service/api/types.go index f26b3c3b..fe859385 100644 --- a/service/api/types.go +++ b/service/api/types.go @@ -132,7 +132,7 @@ type Breakpoint struct { // Disabled flag, signifying the state of the breakpoint Disabled bool `json:"disabled"` - UserData interface{} `json:"-"` + UserData any `json:"-"` // RootFuncName is the Root function from where tracing needs to be done RootFuncName string diff --git a/service/client.go b/service/client.go index 46111aa7..e51f86e7 100644 --- a/service/client.go +++ b/service/client.go @@ -212,5 +212,5 @@ type Client interface { GuessSubstitutePath() ([][2]string, error) // CallAPI allows calling an arbitrary rpc method (used by starlark bindings) - CallAPI(method string, args, reply interface{}) error + CallAPI(method string, args, reply any) error } diff --git a/service/dap/command.go b/service/dap/command.go index 0cff856c..a76b5f9e 100644 --- a/service/dap/command.go +++ b/service/dap/command.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "slices" "sort" "strings" @@ -19,10 +20,8 @@ func (s *Session) delveCmd(goid, frame int, cmdstr string) (string, error) { args = strings.TrimSpace(vals[1]) } for _, cmd := range debugCommands(s) { - for _, alias := range cmd.aliases { - if alias == cmdname { - return cmd.cmdFn(goid, frame, args) - } + if slices.Contains(cmd.aliases, cmdname) { + return cmd.cmdFn(goid, frame, args) } } return "", errNoCmd @@ -92,10 +91,8 @@ func (s *Session) helpMessage(_, _ int, args string) (string, error) { var buf bytes.Buffer if args != "" { for _, cmd := range debugCommands(s) { - for _, alias := range cmd.aliases { - if alias == args { - return cmd.helpMsg, nil - } + if slices.Contains(cmd.aliases, args) { + return cmd.helpMsg, nil } } return "", errNoCmd diff --git a/service/dap/daptest/client.go b/service/dap/daptest/client.go index 035c48f2..f40c73f3 100644 --- a/service/dap/daptest/client.go +++ b/service/dap/daptest/client.go @@ -126,7 +126,7 @@ func (c *Client) ExpectInitializeResponseAndCapabilities(t *testing.T) *dap.Init return initResp } -func pretty(v interface{}) string { +func pretty(v any) string { s, _ := json.MarshalIndent(v, "", "\t") return string(s) } @@ -199,7 +199,7 @@ func (c *Client) ExpectOutputEventClosingClient(t *testing.T, status string) *da return c.ExpectOutputEventRegex(t, fmt.Sprintf(ClosingClient, status)) } -func (c *Client) CheckStopLocation(t *testing.T, thread int, name string, line interface{}) { +func (c *Client) CheckStopLocation(t *testing.T, thread int, name string, line any) { t.Helper() c.StackTraceRequest(thread, 0, 20) st := c.ExpectStackTraceResponse(t) @@ -251,7 +251,7 @@ func (c *Client) InitializeRequestWithArgs(args dap.InitializeRequestArguments) c.send(request) } -func toRawMessage(in interface{}) json.RawMessage { +func toRawMessage(in any) json.RawMessage { out, _ := json.Marshal(in) return out } @@ -259,7 +259,7 @@ func toRawMessage(in interface{}) json.RawMessage { // LaunchRequest sends a 'launch' request with the specified args. func (c *Client) LaunchRequest(mode, program string, stopOnEntry bool) { request := &dap.LaunchRequest{Request: *c.newRequest("launch")} - request.Arguments = toRawMessage(map[string]interface{}{ + request.Arguments = toRawMessage(map[string]any{ "request": "launch", "mode": mode, "program": program, @@ -271,7 +271,7 @@ func (c *Client) LaunchRequest(mode, program string, stopOnEntry bool) { // LaunchRequestWithArgs takes a map of untyped implementation-specific // arguments to send a 'launch' request. This version can be used to // test for values of unexpected types or unspecified values. -func (c *Client) LaunchRequestWithArgs(arguments map[string]interface{}) { +func (c *Client) LaunchRequestWithArgs(arguments map[string]any) { request := &dap.LaunchRequest{Request: *c.newRequest("launch")} request.Arguments = toRawMessage(arguments) c.send(request) @@ -279,7 +279,7 @@ func (c *Client) LaunchRequestWithArgs(arguments map[string]interface{}) { // AttachRequest sends an 'attach' request with the specified // arguments. -func (c *Client) AttachRequest(arguments map[string]interface{}) { +func (c *Client) AttachRequest(arguments map[string]any) { request := &dap.AttachRequest{Request: *c.newRequest("attach")} request.Arguments = toRawMessage(arguments) c.send(request) diff --git a/service/dap/server.go b/service/dap/server.go index a3ff5fb6..add127dc 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -1137,7 +1137,7 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) { outputRedirects [2]proc.OutputRedirect ) - for i := 0; i < 2; i++ { + for i := range 2 { readers[i], outputRedirects[i], err = proc.Redirector() if err != nil { s.sendShowUserErrorResponse(request.Request, InternalError, "Internal Error", @@ -1484,7 +1484,7 @@ func (s *Session) setBreakpoints(prefix string, totalBps int, metadataFunc func( breakpoints := make([]dap.Breakpoint, totalBps) // Amend existing breakpoints. - for i := 0; i < totalBps; i++ { + for i := range totalBps { want := metadataFunc(i) got, ok := existingBps[want.name] if got == nil || !ok { @@ -1513,7 +1513,7 @@ func (s *Session) setBreakpoints(prefix string, totalBps int, metadataFunc func( s.clearBreakpoints(existingBps, createdBps) // Add new breakpoints. - for i := 0; i < totalBps; i++ { + for i := range totalBps { want := metadataFunc(i) if _, ok := existingBps[want.name]; ok { continue @@ -2174,10 +2174,7 @@ func (s *Session) onStackTraceRequest(request *dap.StackTraceRequest) { } goroutineID := request.Arguments.ThreadId - start := request.Arguments.StartFrame - if start < 0 { - start = 0 - } + start := max(request.Arguments.StartFrame, 0) levels := s.args.StackTraceDepth if request.Arguments.Levels > 0 { levels = request.Arguments.Levels @@ -4022,7 +4019,7 @@ func (s *Session) logBreakpointMessage(bp *api.Breakpoint, goid int64) bool { } func (msg *logMessage) evaluate(s *Session, goid int64) string { - evaluated := make([]interface{}, len(msg.args)) + evaluated := make([]any, len(msg.args)) for i := range msg.args { exprVar, err := s.debugger.EvalVariableInScope(goid, 0, 0, msg.args[i], DefaultLoadConfig) if err != nil { diff --git a/service/dap/server_test.go b/service/dap/server_test.go index b2dd5259..427692d8 100644 --- a/service/dap/server_test.go +++ b/service/dap/server_test.go @@ -532,7 +532,7 @@ func TestAttachStopOnEntry(t *testing.T) { // 2 >> attach, << initialized, << attach client.AttachRequest( - map[string]interface{}{"mode": "local", "processId": cmd.Process.Pid, "stopOnEntry": true, "backend": "default"}) + map[string]any{"mode": "local", "processId": cmd.Process.Pid, "stopOnEntry": true, "backend": "default"}) client.ExpectCapabilitiesEventSupportTerminateDebuggee(t) initEvent := client.ExpectInitializedEvent(t) if initEvent.Seq != 0 { @@ -719,7 +719,7 @@ func TestPreSetBreakpoint(t *testing.T) { client.ThreadsRequest() // Since we are in async mode while running, we might receive messages in either order. - for i := 0; i < 2; i++ { + for range 2 { msg := client.ExpectMessage(t) switch m := msg.(type) { case *dap.ThreadsResponse: @@ -832,7 +832,7 @@ func TestPreSetBreakpoint(t *testing.T) { // wantFrames - number of frames returned (length of StackTraceResponse.Body.StackFrames array). // wantTotalFrames - total number of stack frames available (StackTraceResponse.Body.TotalFrames). func checkStackFramesExact(t *testing.T, got *dap.StackTraceResponse, - wantStartName string, wantStartLine interface{}, wantStartID, wantFrames, wantTotalFrames int, + wantStartName string, wantStartLine any, wantStartID, wantFrames, wantTotalFrames int, ) { t.Helper() checkStackFramesNamed("", t, got, wantStartName, wantStartLine, wantStartID, wantFrames, wantTotalFrames, true) @@ -901,7 +901,7 @@ func TestFilterGoroutines(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "stopOnEntry": !stopOnEntry, @@ -953,7 +953,7 @@ func checkStackFramesHasMore(t *testing.T, got *dap.StackTraceResponse, } func checkStackFramesNamed(testName string, t *testing.T, got *dap.StackTraceResponse, - wantStartName string, wantStartLine interface{}, wantStartID, wantFrames, wantTotalFrames int, totalExact bool, + wantStartName string, wantStartLine any, wantStartID, wantFrames, wantTotalFrames int, totalExact bool, ) { t.Helper() if totalExact && got.Body.TotalFrames != wantTotalFrames { @@ -966,7 +966,7 @@ func checkStackFramesNamed(testName string, t *testing.T, got *dap.StackTraceRes t.Errorf("%s\ngot len(StackFrames)=%d\nwant %d", testName, len(got.Body.StackFrames), wantFrames) } else { // Verify that frame ids are consecutive numbers starting at wantStartID - for i := 0; i < wantFrames; i++ { + for i := range wantFrames { if got.Body.StackFrames[i].Id != wantStartID+i { t.Errorf("%s\ngot %#v\nwant Id=%d", testName, got.Body.StackFrames[i], wantStartID+i) } @@ -1307,7 +1307,7 @@ func TestFunctionNameFormattingInStackTrace(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, }) }, @@ -1440,7 +1440,7 @@ func TestGoroutineLabels(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "hideSystemGoroutines": true, @@ -1494,7 +1494,7 @@ func TestHideSystemGoroutinesRequest(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "hideSystemGoroutines": tt.hideSystemGoroutines, @@ -1536,7 +1536,7 @@ func TestScopesAndVariablesRequests(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, "backend": "default", }) }, @@ -2057,7 +2057,7 @@ func TestScopesRequestsOptimized(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, }) }, @@ -2540,7 +2540,7 @@ func TestGlobalScopeAndVariables(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, "showRegisters": true, }) }, @@ -2615,7 +2615,7 @@ func TestRegistersScopeAndVariables(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showRegisters": true, }) }, @@ -2731,7 +2731,7 @@ func TestShadowedVariables(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, }) }, @@ -2771,7 +2771,7 @@ func TestLaunchRequestWithStackTraceDepth(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "stackTraceDepth": 1, }) }, @@ -3406,7 +3406,7 @@ func TestLogPoints(t *testing.T) { client.ContinueRequest(1) client.ExpectContinueResponse(t) - for i := 0; i < 5; i++ { + for i := range 5 { se := client.ExpectStoppedEvent(t) if se.Body.Reason != "breakpoint" || se.Body.ThreadId != 1 { t.Errorf("got stopped event = %#v, \nwant Reason=\"breakpoint\" ThreadId=1", se) @@ -3508,7 +3508,7 @@ func TestHaltPreventsAutoResume(t *testing.T) { client.SetBreakpointsRequestWithArgs(fixture.Source, bps, nil, nil, logMessages) client.ExpectSetBreakpointsResponse(t) - for i := 0; i < 5; i++ { + for range 5 { // Reset the handler to the default behavior. resumeOnceAndCheckStop = savedResumeOnce @@ -3809,7 +3809,7 @@ func TestHitConditionBreakpoints(t *testing.T) { // in the launch configuration to take care of the mapping. func TestLaunchSubstitutePath(t *testing.T) { runTest(t, "loopprog", func(client *daptest.Client, fixture protest.Fixture) { - substitutePathTestHelper(t, fixture, client, "launch", map[string]interface{}{"mode": "exec", "program": fixture.Path}) + substitutePathTestHelper(t, fixture, client, "launch", map[string]any{"mode": "exec", "program": fixture.Path}) }) } @@ -3823,11 +3823,11 @@ func TestAttachSubstitutePath(t *testing.T) { runTest(t, "loopprog", func(client *daptest.Client, fixture protest.Fixture) { cmd := execFixture(t, fixture) - substitutePathTestHelper(t, fixture, client, "attach", map[string]interface{}{"mode": "local", "processId": cmd.Process.Pid}) + substitutePathTestHelper(t, fixture, client, "attach", map[string]any{"mode": "local", "processId": cmd.Process.Pid}) }) } -func substitutePathTestHelper(t *testing.T, fixture protest.Fixture, client *daptest.Client, request string, launchAttachConfig map[string]interface{}) { +func substitutePathTestHelper(t *testing.T, fixture protest.Fixture, client *daptest.Client, request string, launchAttachConfig map[string]any) { t.Helper() nonexistentDir := filepath.Join(string(filepath.Separator), "path", "that", "does", "not", "exist") if runtime.GOOS == "windows" { @@ -3902,7 +3902,7 @@ func TestWorkingDir(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "stopOnEntry": false, @@ -5237,7 +5237,7 @@ func TestFatalThrowBreakpoint(t *testing.T) { // The details have been tested by other tests, // so this is just a sanity check. // Skips line check if line is -1. -func checkStop(t *testing.T, client *daptest.Client, thread int, fname string, line interface{}) { +func checkStop(t *testing.T, client *daptest.Client, thread int, fname string, line any) { t.Helper() client.ThreadsRequest() client.ExpectThreadsResponse(t) @@ -5277,7 +5277,7 @@ type onBreakpoint struct { // source - source file path, needed to set breakpoints, "" if none to be set. // breakpoints - list of lines, where breakpoints are to be set // onBPs - list of test sequences to execute at each of the set breakpoints. -func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cmdRequest func(), source string, breakpoints interface{}, onBPs []onBreakpoint) { +func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cmdRequest func(), source string, breakpoints any, onBPs []onBreakpoint) { client.InitializeRequest() client.ExpectInitializeResponseAndCapabilities(t) @@ -5420,14 +5420,14 @@ func TestLaunchDebugRequest(t *testing.T) { func TestLaunchRequestDefaults(t *testing.T) { runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) { runDebugSession(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "" /*"debug" by default*/, "program": fixture.Source, "output": "__mybin", }) }) }) runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) { runDebugSession(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ /*"mode":"debug" by default*/ "program": fixture.Source, "output": "__mybin", }) }) @@ -5435,7 +5435,7 @@ func TestLaunchRequestDefaults(t *testing.T) { runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) { runDebugSession(t, client, "launch", func() { // Use the temporary output binary. - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "debug", "program": fixture.Source, }) }) @@ -5452,7 +5452,7 @@ func TestLaunchRequestOutputPath(t *testing.T) { runDebugSessionWithBPs(t, client, "launch", // Launch func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "debug", "program": fixture.Source, "output": inrel, "cwd": filepath.Dir(wd), }) @@ -5503,7 +5503,7 @@ func TestExitNonZeroStatus(t *testing.T) { func TestNoDebug_GoodExitStatus(t *testing.T) { runTest(t, "increment", func(client *daptest.Client, fixture protest.Fixture) { runNoDebugSession(t, client, func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "noDebug": true, "mode": "debug", "program": fixture.Source, "output": "__mybin", }) }, 0) @@ -5513,7 +5513,7 @@ func TestNoDebug_GoodExitStatus(t *testing.T) { func TestNoDebug_BadExitStatus(t *testing.T) { runTest(t, "issue1101", func(client *daptest.Client, fixture protest.Fixture) { runNoDebugSession(t, client, func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "noDebug": true, "mode": "exec", "program": fixture.Path, }) }, 2) @@ -5542,7 +5542,7 @@ func TestNoDebug_AcceptNoRequestsButDisconnect(t *testing.T) { runTest(t, "http_server", func(client *daptest.Client, fixture protest.Fixture) { client.InitializeRequest() client.ExpectInitializeResponseAndCapabilities(t) - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "noDebug": true, "mode": "exec", "program": fixture.Path, }) client.ExpectLaunchResponse(t) @@ -5616,7 +5616,7 @@ func TestLaunchRequestWithRelativeBuildPath(t *testing.T) { // Program path will be interpreted relative to dlv's. dlvwd, _ := os.Getwd() runDebugSession(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "debug", "program": program, "cwd": filepath.Dir(dlvwd), }) }) @@ -5636,7 +5636,7 @@ func TestLaunchRequestWithRelativeExecPath(t *testing.T) { } defer os.Remove(symlink) runDebugSession(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": symlink, }) }) @@ -5653,49 +5653,49 @@ func TestLaunchTestRequest(t *testing.T) { for _, tc := range []struct { name string dlvWD string - launchArgs map[string]interface{} + launchArgs map[string]any wantWD string }{{ name: "default", - launchArgs: map[string]interface{}{ + launchArgs: map[string]any{ "mode": "test", "program": absolutePkgDir, }, wantWD: absolutePkgDir, }, { name: "output", - launchArgs: map[string]interface{}{ + launchArgs: map[string]any{ "mode": "test", "program": absolutePkgDir, "output": "test.out", }, wantWD: absolutePkgDir, }, { name: "dlvCwd", - launchArgs: map[string]interface{}{ + launchArgs: map[string]any{ "mode": "test", "program": absolutePkgDir, "dlvCwd": ".", }, wantWD: absolutePkgDir, }, { name: "dlvCwd2", - launchArgs: map[string]interface{}{ + launchArgs: map[string]any{ "mode": "test", "program": ".", "dlvCwd": absolutePkgDir, }, wantWD: absolutePkgDir, }, { name: "cwd", - launchArgs: map[string]interface{}{ + launchArgs: map[string]any{ "mode": "test", "program": absolutePkgDir, "cwd": fixtures, // fixtures is relative to the current working directory. }, wantWD: absoluteFixturesDir, }, { name: "dlv runs outside of module", dlvWD: os.TempDir(), - launchArgs: map[string]interface{}{ + launchArgs: map[string]any{ "mode": "test", "program": absolutePkgDir, "dlvCwd": absoluteFixturesDir, }, wantWD: absolutePkgDir, }, { name: "dlv builds in dlvCwd but runs in cwd", dlvWD: fixtures, - launchArgs: map[string]interface{}{ + launchArgs: map[string]any{ "mode": "test", "program": absolutePkgDir, "dlvCwd": absolutePkgDir, "cwd": "..", // relative to dlvCwd. }, wantWD: absoluteFixturesDir, @@ -5743,7 +5743,7 @@ func TestLaunchTestRequest(t *testing.T) { func TestLaunchRequestWithArgs(t *testing.T) { runTest(t, "testargs", func(client *daptest.Client, fixture protest.Fixture) { runDebugSession(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "args": []string{"test", "pass flag"}, }) @@ -5760,7 +5760,7 @@ func TestLaunchRequestWithBuildFlags(t *testing.T) { runDebugSession(t, client, "launch", func() { // We reuse the harness that builds, but ignore the built binary, // only relying on the source to be built in response to LaunchRequest. - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "debug", "program": fixture.Source, "output": "__mybin", "buildFlags": "-ldflags '-X main.Hello=World'", }) @@ -5773,7 +5773,7 @@ func TestLaunchRequestWithBuildFlags2(t *testing.T) { runDebugSession(t, client, "launch", func() { // We reuse the harness that builds, but ignore the built binary, // only relying on the source to be built in response to LaunchRequest. - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "debug", "program": fixture.Source, "output": "__mybin", "buildFlags": []string{"-ldflags", "-X main.Hello=World"}, }) @@ -5851,7 +5851,7 @@ func TestLaunchRequestWithEnv(t *testing.T) { defer client.Close() runDebugSessionWithBPs(t, client, "launch", func() { // launch - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "debug", "program": testFile, "env": tc.launchEnv, @@ -5884,7 +5884,7 @@ func TestAttachRequest(t *testing.T) { runDebugSessionWithBPs(t, client, "attach", // Attach func() { - client.AttachRequest(map[string]interface{}{ + client.AttachRequest(map[string]any{ /*"mode": "local" by default*/ "processId": cmd.Process.Pid, "stopOnEntry": false, }) client.ExpectCapabilitiesEventSupportTerminateDebuggee(t) @@ -5933,7 +5933,7 @@ func TestAttachWaitForRequest(t *testing.T) { client.InitializeRequest() client.ExpectInitializeResponseAndCapabilities(t) - client.AttachRequest(map[string]interface{}{ + client.AttachRequest(map[string]any{ "mode": "local", "waitFor": fixture.Path, "stopOnEntry": true, @@ -5954,7 +5954,7 @@ func TestAttachWaitForRequest(t *testing.T) { // in either order. func expectPauseResponseAndStoppedEvent(t *testing.T, client *daptest.Client) { t.Helper() - for i := 0; i < 2; i++ { + for range 2 { msg := client.ExpectMessage(t) switch m := msg.(type) { case *dap.StoppedEvent: @@ -6252,7 +6252,7 @@ func TestSetVariable(t *testing.T) { runTest(t, "testvariables", func(client *daptest.Client, fixture protest.Fixture) { runDebugSessionWithBPs(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, }) }, @@ -6345,7 +6345,7 @@ func TestSetVariable(t *testing.T) { runTest(t, "testvariables2", func(client *daptest.Client, fixture protest.Fixture) { runDebugSessionWithBPs(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, }) }, @@ -6425,7 +6425,7 @@ func TestSetVariableWithCall(t *testing.T) { runTest(t, "testvariables", func(client *daptest.Client, fixture protest.Fixture) { runDebugSessionWithBPs(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, }) }, @@ -6489,7 +6489,7 @@ func TestSetVariableWithCall(t *testing.T) { runTest(t, "fncall", func(client *daptest.Client, fixture protest.Fixture) { runDebugSessionWithBPs(t, client, "launch", func() { - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "mode": "exec", "program": fixture.Path, "showGlobalVariables": true, }) }, @@ -6590,15 +6590,15 @@ func TestBadLaunchRequests(t *testing.T) { "Failed to launch: The program attribute is missing in debug configuration.") // Bad "program" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": 12345}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": 12345}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number into \"program\" of type string") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": nil}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": nil}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The program attribute is missing in debug configuration.") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug"}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The program attribute is missing in debug configuration.") @@ -6611,63 +6611,63 @@ func TestBadLaunchRequests(t *testing.T) { checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - unsupported 'mode' attribute \"notamode\"") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": 12345, "program": fixture.Path}) + client.LaunchRequestWithArgs(map[string]any{"mode": 12345, "program": fixture.Path}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number into \"mode\" of type string") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": ""}) // empty mode defaults to "debug" (not an error) + client.LaunchRequestWithArgs(map[string]any{"mode": ""}) // empty mode defaults to "debug" (not an error) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The program attribute is missing in debug configuration.") - client.LaunchRequestWithArgs(map[string]interface{}{}) // missing mode defaults to "debug" (not an error) + client.LaunchRequestWithArgs(map[string]any{}) // missing mode defaults to "debug" (not an error) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The program attribute is missing in debug configuration.") // Bad "args" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "exec", "program": fixture.Path, "args": "foobar"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "exec", "program": fixture.Path, "args": "foobar"}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal string into \"args\" of type []string") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "exec", "program": fixture.Path, "args": 12345}) + client.LaunchRequestWithArgs(map[string]any{"mode": "exec", "program": fixture.Path, "args": 12345}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number into \"args\" of type []string") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "exec", "program": fixture.Path, "args": []int{1, 2}}) + client.LaunchRequestWithArgs(map[string]any{"mode": "exec", "program": fixture.Path, "args": []int{1, 2}}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number into \"args\" of type string") // Bad "buildFlags" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "buildFlags": 123}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "buildFlags": 123}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number into \"buildFlags\" of type []string or string") // Bad "backend" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "backend": 123}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "backend": 123}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number …") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "backend": "foo"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "backend": "foo"}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: could not launch process: unknown backend \"foo\"") // Bad "substitutePath" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "substitutePath": 123}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "substitutePath": 123}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number into …") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "substitutePath": []interface{}{123}}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "substitutePath": []any{123}}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot use 123 as 'substitutePath' of type {\"from\":string, \"to\":string}") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "substitutePath": []interface{}{map[string]interface{}{"to": "path2"}}}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "substitutePath": []any{map[string]any{"to": "path2"}}}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - 'substitutePath' requires both 'from' and 'to' entries") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "substitutePath": []interface{}{map[string]interface{}{"from": "path1", "to": 123}}}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "substitutePath": []any{map[string]any{"from": "path1", "to": 123}}}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot use {\"from\":\"path1\",\"to\":123} as 'substitutePath' of type {\"from\":string, \"to\":string}") // Bad "cwd" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "cwd": 123}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "cwd": 123}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal number into \"cwd\" of type string") @@ -6682,7 +6682,7 @@ func TestBadLaunchRequests(t *testing.T) { } checkFailedToLaunch(client.ExpectInvisibleErrorResponse(t)) - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "request": "launch", /* mode: debug by default*/ "program": fixture.Path + "_does_not_exist", @@ -6697,13 +6697,13 @@ func TestBadLaunchRequests(t *testing.T) { client.LaunchRequest("exec", fixture.Source, stopOnEntry) checkFailedToLaunch(client.ExpectVisibleErrorResponse(t)) // Not an executable - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "buildFlags": "-bad -flags"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "buildFlags": "-bad -flags"}) oe = client.ExpectOutputEvent(t) if !strings.HasPrefix(oe.Body.Output, "Build Error: ") || oe.Body.Category != "stderr" { t.Errorf("got %#v, want Category=\"stderr\" Output=\"Build Error: ...\"", oe) } checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), "Failed to launch: Build error: Check the debug console for details.") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "noDebug": true, "buildFlags": "-bad -flags"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "noDebug": true, "buildFlags": "-bad -flags"}) oe = client.ExpectOutputEvent(t) if !strings.HasPrefix(oe.Body.Output, "Build Error: ") || oe.Body.Category != "stderr" { t.Errorf("got %#v, want Category=\"stderr\" Output=\"Build Error: ...\"", oe) @@ -6711,40 +6711,40 @@ func TestBadLaunchRequests(t *testing.T) { checkFailedToLaunchWithMessage(client.ExpectInvisibleErrorResponse(t), "Failed to launch: Build error: Check the debug console for details.") // Bad "cwd" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "noDebug": false, "cwd": "dir/invalid"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "noDebug": false, "cwd": "dir/invalid"}) checkFailedToLaunch(client.ExpectVisibleErrorResponse(t)) // invalid directory, the error message is system-dependent. - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "noDebug": true, "cwd": "dir/invalid"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "noDebug": true, "cwd": "dir/invalid"}) checkFailedToLaunch(client.ExpectVisibleErrorResponse(t)) // invalid directory, the error message is system-dependent. // Bad "noDebug" - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "debug", "program": fixture.Source, "noDebug": "true"}) + client.LaunchRequestWithArgs(map[string]any{"mode": "debug", "program": fixture.Source, "noDebug": "true"}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: invalid debug configuration - cannot unmarshal string into \"noDebug\" of type bool") // Bad "replay" parameters // These errors come from dap layer - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "replay", "traceDirPath": ""}) + client.LaunchRequestWithArgs(map[string]any{"mode": "replay", "traceDirPath": ""}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The 'traceDirPath' attribute is missing in debug configuration.") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "replay", "program": fixture.Source, "traceDirPath": ""}) + client.LaunchRequestWithArgs(map[string]any{"mode": "replay", "program": fixture.Source, "traceDirPath": ""}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The 'traceDirPath' attribute is missing in debug configuration.") // These errors come from debugger layer if _, err := exec.LookPath("rr"); err != nil { - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "replay", "backend": "ignored", "traceDirPath": ".."}) + client.LaunchRequestWithArgs(map[string]any{"mode": "replay", "backend": "ignored", "traceDirPath": ".."}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: backend unavailable") } // Bad "core" parameters // These errors come from dap layer - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "core", "coreFilePath": ""}) + client.LaunchRequestWithArgs(map[string]any{"mode": "core", "coreFilePath": ""}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The program attribute is missing in debug configuration.") - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "core", "program": fixture.Source, "coreFilePath": ""}) + client.LaunchRequestWithArgs(map[string]any{"mode": "core", "program": fixture.Source, "coreFilePath": ""}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: The 'coreFilePath' attribute is missing in debug configuration.") // These errors come from debugger layer - client.LaunchRequestWithArgs(map[string]interface{}{"mode": "core", "backend": "ignored", "program": fixture.Source, "coreFilePath": fixture.Source}) + client.LaunchRequestWithArgs(map[string]any{"mode": "core", "backend": "ignored", "program": fixture.Source, "coreFilePath": fixture.Source}) checkFailedToLaunchWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to launch: unrecognized core format") @@ -6786,49 +6786,49 @@ func TestBadAttachRequest(t *testing.T) { } // Bad "mode" - client.AttachRequest(map[string]interface{}{"mode": "blah blah blah"}) + client.AttachRequest(map[string]any{"mode": "blah blah blah"}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: invalid debug configuration - unsupported 'mode' attribute \"blah blah blah\"") - client.AttachRequest(map[string]interface{}{"mode": 123}) + client.AttachRequest(map[string]any{"mode": 123}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: invalid debug configuration - cannot unmarshal number into \"mode\" of type string") - client.AttachRequest(map[string]interface{}{"mode": ""}) // empty mode defaults to "local" (not an error) + client.AttachRequest(map[string]any{"mode": ""}) // empty mode defaults to "local" (not an error) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: The 'processId' or 'waitFor' attribute is missing in debug configuration") - client.AttachRequest(map[string]interface{}{}) // no mode defaults to "local" (not an error) + client.AttachRequest(map[string]any{}) // no mode defaults to "local" (not an error) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: The 'processId' or 'waitFor' attribute is missing in debug configuration") // Bad "processId" - client.AttachRequest(map[string]interface{}{"mode": "local"}) + client.AttachRequest(map[string]any{"mode": "local"}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: The 'processId' or 'waitFor' attribute is missing in debug configuration") - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": nil}) + client.AttachRequest(map[string]any{"mode": "local", "processId": nil}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: The 'processId' or 'waitFor' attribute is missing in debug configuration") - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 0}) + client.AttachRequest(map[string]any{"mode": "local", "processId": 0}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: The 'processId' or 'waitFor' attribute is missing in debug configuration") - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 1, "waitFor": "loopprog"}) + client.AttachRequest(map[string]any{"mode": "local", "processId": 1, "waitFor": "loopprog"}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: 'processId' and 'waitFor' are mutually exclusive, and can't be specified at the same time") - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": "1"}) + client.AttachRequest(map[string]any{"mode": "local", "processId": "1"}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: invalid debug configuration - cannot unmarshal string into \"processId\" of type int") - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 1}) + client.AttachRequest(map[string]any{"mode": "local", "processId": 1}) // The exact message varies on different systems, so skip that check checkFailedToAttach(client.ExpectVisibleErrorResponse(t)) // could not attach to pid 1 // This will make debugger.(*Debugger) panic, which we will catch as an internal error. - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": -1}) + client.AttachRequest(map[string]any{"mode": "local", "processId": -1}) er := client.ExpectInvisibleErrorResponse(t) if er.RequestSeq != seqCnt { t.Errorf("RequestSeq got %d, want %d", seqCnt, er.RequestSeq) @@ -6845,11 +6845,11 @@ func TestBadAttachRequest(t *testing.T) { } // Bad "backend" - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 1, "backend": 123}) + client.AttachRequest(map[string]any{"mode": "local", "processId": 1, "backend": 123}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: invalid debug configuration - cannot unmarshal number into …") - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 1, "backend": "foo"}) + client.AttachRequest(map[string]any{"mode": "local", "processId": 1, "backend": "foo"}) checkFailedToAttachWithMessage(client.ExpectVisibleErrorResponse(t), "Failed to attach: could not attach to pid 1: unknown backend \"foo\"") @@ -6949,7 +6949,7 @@ func TestAttachRemoteToDlvLaunchHaltedStopOnEntry(t *testing.T) { // Halted + stop on entry _, dbg := launchDebuggerWithTargetHalted(t, "increment") runTestWithDebugger(t, dbg, func(client *daptest.Client) { - client.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": true}) + client.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": true}) client.ExpectInitializedEvent(t) client.ExpectAttachResponse(t) client.ConfigurationDoneRequest() @@ -6961,7 +6961,7 @@ func TestAttachRemoteToDlvLaunchHaltedStopOnEntry(t *testing.T) { func TestAttachRemoteToDlvAttachHaltedStopOnEntry(t *testing.T) { cmd, dbg := attachDebuggerWithTargetHalted(t, "http_server") runTestWithDebugger(t, dbg, func(client *daptest.Client) { - client.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": true}) + client.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": true}) client.ExpectCapabilitiesEventSupportTerminateDebuggee(t) client.ExpectInitializedEvent(t) client.ExpectAttachResponse(t) @@ -6980,7 +6980,7 @@ func TestAttachRemoteToHaltedTargetContinueOnEntry(t *testing.T) { // Halted + continue on entry _, dbg := launchDebuggerWithTargetHalted(t, "http_server") runTestWithDebugger(t, dbg, func(client *daptest.Client) { - client.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": false}) + client.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": false}) client.ExpectInitializedEvent(t) client.ExpectAttachResponse(t) client.ConfigurationDoneRequest() @@ -6996,7 +6996,7 @@ func TestAttachRemoteToHaltedTargetContinueOnEntry(t *testing.T) { func TestAttachRemoteToRunningTargetStopOnEntry(t *testing.T) { fixture, dbg := launchDebuggerWithTargetRunning(t, "loopprog") runTestWithDebugger(t, dbg, func(client *daptest.Client) { - client.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": true}) + client.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": true}) client.ExpectInitializedEvent(t) client.ExpectAttachResponse(t) // Target is halted here @@ -7015,7 +7015,7 @@ func TestAttachRemoteToRunningTargetStopOnEntry(t *testing.T) { func TestAttachRemoteToRunningTargetContinueOnEntry(t *testing.T) { fixture, dbg := launchDebuggerWithTargetRunning(t, "loopprog") runTestWithDebugger(t, dbg, func(client *daptest.Client) { - client.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": false}) + client.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": false}) client.ExpectInitializedEvent(t) client.ExpectAttachResponse(t) // Target is halted here @@ -7106,7 +7106,7 @@ func TestAttachRemoteMultiClientDisconnect(t *testing.T) { client.InitializeRequest() client.ExpectInitializeResponseAndCapabilities(t) - client.AttachRequest(map[string]interface{}{"mode": "remote", "stopOnEntry": true}) + client.AttachRequest(map[string]any{"mode": "remote", "stopOnEntry": true}) client.ExpectCapabilitiesEventSupportTerminateDebuggee(t) client.ExpectInitializedEvent(t) client.ExpectAttachResponse(t) @@ -7157,7 +7157,7 @@ func TestLaunchAttachErrorWhenDebugInProgress(t *testing.T) { } // Both launch and attach requests should go through for additional error checking - client.AttachRequest(map[string]interface{}{"mode": "local", "processId": 100}) + client.AttachRequest(map[string]any{"mode": "local", "processId": 100}) er := client.ExpectVisibleErrorResponse(t) msgRe := regexp.MustCompile("Failed to attach: debug session already in progress at .+ - use remote mode to connect to a server with an active debug session") if er.Body.Error == nil || er.Body.Error.Id != FailedToAttach || !msgRe.MatchString(er.Body.Error.Format) { @@ -7166,7 +7166,7 @@ func TestLaunchAttachErrorWhenDebugInProgress(t *testing.T) { tests := []string{"debug", "test", "exec", "replay", "core"} for _, mode := range tests { t.Run(mode, func(t *testing.T) { - client.LaunchRequestWithArgs(map[string]interface{}{"mode": mode}) + client.LaunchRequestWithArgs(map[string]any{"mode": mode}) er := client.ExpectVisibleErrorResponse(t) msgRe := regexp.MustCompile("Failed to launch: debug session already in progress at .+ - use remote attach mode to connect to a server with an active debug session") if er.Body.Error == nil || er.Body.Error.Id != FailedToLaunch || !msgRe.MatchString(er.Body.Error.Format) { @@ -7470,7 +7470,7 @@ func TestAlignPCs(t *testing.T) { NUM_FUNCS := 10 // Create fake functions to test align PCs. funcs := make([]proc.Function, NUM_FUNCS) - for i := 0; i < len(funcs); i++ { + for i := range funcs { funcs[i] = proc.Function{ Entry: uint64(100 + i*10), End: uint64(100 + i*10 + 5), @@ -7552,7 +7552,7 @@ func TestFindInstructions(t *testing.T) { numInstructions := 100 startPC := 0x1000 procInstructions := make([]proc.AsmInstruction, numInstructions) - for i := 0; i < len(procInstructions); i++ { + for i := range procInstructions { procInstructions[i] = proc.AsmInstruction{ Loc: proc.Location{ PC: uint64(startPC + 2*i), @@ -7755,7 +7755,7 @@ func TestRedirect(t *testing.T) { } // 2 >> launch, << process, << initialized, << launch - client.LaunchRequestWithArgs(map[string]interface{}{ + client.LaunchRequestWithArgs(map[string]any{ "request": "launch", "mode": "debug", "program": fixture.Source, diff --git a/service/dap/types.go b/service/dap/types.go index 1948599d..8ce33e80 100644 --- a/service/dap/types.go +++ b/service/dap/types.go @@ -265,7 +265,7 @@ type AttachConfig struct { // unmarshalLaunchAttachArgs wraps unmarshaling of launch/attach request's // arguments attribute. Upon unmarshal failure, it returns an error massaged // to be suitable for end-users. -func unmarshalLaunchAttachArgs(input json.RawMessage, config interface{}) error { +func unmarshalLaunchAttachArgs(input json.RawMessage, config any) error { if err := json.Unmarshal(input, config); err != nil { if uerr, ok := err.(*json.UnmarshalTypeError); ok { // Format json.UnmarshalTypeError error string in our own way. E.g., @@ -284,7 +284,7 @@ func unmarshalLaunchAttachArgs(input json.RawMessage, config interface{}) error return nil } -func prettyPrint(config interface{}) string { +func prettyPrint(config any) string { pretty, err := json.MarshalIndent(config, "", "\t") if err != nil { return fmt.Sprintf("%#v", config) @@ -294,7 +294,7 @@ func prettyPrint(config interface{}) string { // BuildFlags is either string or []string. type BuildFlags struct { - value interface{} + value any } func (s *BuildFlags) UnmarshalJSON(b []byte) error { diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 39f02378..cef67dcd 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -2562,7 +2562,7 @@ func guessSubstitutePath(args *api.GuessSubstitutePathIn, bins [][]proc.Function if slashes(dir) < elems { continue } - for i := 0; i < elems; i++ { + for range elems { dir = path.Dir(dir) } diff --git a/service/rpc2/client.go b/service/rpc2/client.go index e5f330bc..ebb2df58 100644 --- a/service/rpc2/client.go +++ b/service/rpc2/client.go @@ -693,17 +693,17 @@ func (c *RPCClient) GuessSubstitutePath() ([][2]string, error) { return out.List, err } -func (c *RPCClient) call(method string, args, reply interface{}) error { +func (c *RPCClient) call(method string, args, reply any) error { return c.client.Call("RPCServer."+method, args, reply) } -func (c *RPCClient) callWhileDrainingEvents(method string, args, reply interface{}) error { +func (c *RPCClient) callWhileDrainingEvents(method string, args, reply any) error { done := c.drainEvents() err := c.call(method, args, reply) <-done return err } -func (c *RPCClient) CallAPI(method string, args, reply interface{}) error { +func (c *RPCClient) CallAPI(method string, args, reply any) error { return c.call(method, args, reply) } diff --git a/service/rpccallback.go b/service/rpccallback.go index 9ab9f47f..8d90ac1d 100644 --- a/service/rpccallback.go +++ b/service/rpccallback.go @@ -2,7 +2,7 @@ package service // RPCCallback is used by RPC methods to return their result asynchronously. type RPCCallback interface { - Return(out interface{}, err error) + Return(out any, err error) // SetupDoneChan returns a channel that should be closed to signal that the // asynchronous method has completed setup and the server is ready to diff --git a/service/rpccommon/server.go b/service/rpccommon/server.go index 07a5f538..7901ae76 100644 --- a/service/rpccommon/server.go +++ b/service/rpccommon/server.go @@ -252,7 +252,7 @@ func (s *ServerImpl) serveJSONCodec(conn io.ReadWriteCloser) { replyv = reflect.New(mtype.ReplyType.Elem()) function := mtype.method var returnValues []reflect.Value - var errInter interface{} + var errInter any func() { defer func() { if ierr := recover(); ierr != nil { @@ -303,7 +303,7 @@ func (s *ServerImpl) serveJSONCodec(conn io.ReadWriteCloser) { // contains an error when it is used. var invalidRequest = struct{}{} -func (s *ServerImpl) sendResponse(sending *sync.Mutex, req *rpc.Request, resp *rpc.Response, reply interface{}, codec rpc.ServerCodec, errmsg string) { +func (s *ServerImpl) sendResponse(sending *sync.Mutex, req *rpc.Request, resp *rpc.Response, reply any, codec rpc.ServerCodec, errmsg string) { resp.ServiceMethod = req.ServiceMethod if errmsg != "" { resp.Error = errmsg @@ -318,7 +318,7 @@ func (s *ServerImpl) sendResponse(sending *sync.Mutex, req *rpc.Request, resp *r } } -func (cb *RPCCallback) Return(out interface{}, err error) { +func (cb *RPCCallback) Return(out any, err error) { select { case <-cb.setupDone: // already closed @@ -378,7 +378,7 @@ func (s *RPCServer) SetApiVersion(args api.SetAPIVersionIn, out *api.SetAPIVersi } type internalError struct { - Err interface{} + Err any Stack []internalErrorFrame } @@ -389,7 +389,7 @@ type internalErrorFrame struct { Line int } -func newInternalError(ierr interface{}, skip int) *internalError { +func newInternalError(ierr any, skip int) *internalError { logflags.Bug.Inc() r := &internalError{ierr, nil} for i := skip; ; i++ { diff --git a/service/test/common_test.go b/service/test/common_test.go index 9eb87615..047d0bc7 100644 --- a/service/test/common_test.go +++ b/service/test/common_test.go @@ -84,7 +84,7 @@ type locationFinder2 interface { FindLocation(api.EvalScope, string, bool, [][2]string) ([]api.Location, string, error) } -func findLocationHelper(t *testing.T, c interface{}, loc string, shouldErr bool, count int, checkAddr uint64) []uint64 { +func findLocationHelper(t *testing.T, c any, loc string, shouldErr bool, count int, checkAddr uint64) []uint64 { var locs []api.Location var err error diff --git a/service/test/integration2_test.go b/service/test/integration2_test.go index 63d5eea1..a8c07411 100644 --- a/service/test/integration2_test.go +++ b/service/test/integration2_test.go @@ -2250,7 +2250,7 @@ func (c *brokenRPCClient) Detach(kill bool) error { return c.call("Detach", rpc2.DetachIn{Kill: kill}, out) } -func (c *brokenRPCClient) call(method string, args, reply interface{}) error { +func (c *brokenRPCClient) call(method string, args, reply any) error { return c.client.Call("RPCServer."+method, args, reply) }