From 29eae8f61731a77b95d61f69a782a2cde1e019bf Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 28 Sep 2021 21:07:42 +0200 Subject: [PATCH] *: clean up staticcheck problems (#2723) Fix problems that can be fixed, ignore the ones that don't make sense --- _scripts/staticcheck-out.txt | 62 ---------------------- cmd/dlv/dlv_test.go | 10 +++- pkg/dwarf/dwarfbuilder/info.go | 3 +- pkg/dwarf/godwarf/type.go | 2 +- pkg/dwarf/line/line_parser.go | 5 +- pkg/dwarf/line/state_machine.go | 5 +- pkg/dwarf/reader/reader.go | 34 ++---------- pkg/dwarf/util/buf.go | 2 + pkg/dwarf/util/util.go | 2 +- pkg/locspec/locations.go | 3 ++ pkg/proc/bininfo.go | 18 +++---- pkg/proc/breakpoints.go | 2 +- pkg/proc/core/minidump/fileflags_string.go | 2 +- pkg/proc/core/minidump/minidump.go | 2 +- pkg/proc/eval.go | 5 +- pkg/proc/linutil/regs_arm64_arch.go | 2 +- pkg/proc/native/threads_linux_amd64.go | 1 - pkg/proc/stack.go | 3 +- pkg/proc/target_exec.go | 3 +- pkg/proc/variables.go | 8 +-- pkg/terminal/command.go | 26 ++++----- pkg/terminal/starbind/conv.go | 10 ++-- pkg/terminal/terminal.go | 2 + service/api/types.go | 2 +- service/dap/daptest/client.go | 4 +- service/debugger/debugger.go | 2 +- service/debugger/debugger_linux.go | 2 + service/rpc1/client.go | 11 ++-- service/rpc2/client.go | 7 +-- service/rpc2/server.go | 2 +- service/rpccommon/server.go | 2 +- 31 files changed, 90 insertions(+), 154 deletions(-) diff --git a/_scripts/staticcheck-out.txt b/_scripts/staticcheck-out.txt index f0ee5679..e69de29b 100644 --- a/_scripts/staticcheck-out.txt +++ b/_scripts/staticcheck-out.txt @@ -1,62 +0,0 @@ -pkg/dwarf/dwarfbuilder/info.go:122:2: redundant return statement (S1023) -pkg/dwarf/dwarfbuilder/info.go:127:5: builtin function len does not return negative values (SA4024) -pkg/dwarf/line/line_parser.go:249:6: every value of type uint64 is >= 0 (SA4003) -pkg/dwarf/line/line_parser.go:286:15: should omit type int from declaration; it will be inferred from the right-hand side (ST1023) -pkg/dwarf/line/state_machine.go:151:2: redundant return statement (S1023) -pkg/dwarf/line/state_machine.go:154:5: error var NoSourceError should have name of the form ErrFoo (ST1012) -pkg/dwarf/line/state_machine.go:193:2: should merge variable declaration with assignment on next line (S1021) -pkg/dwarf/reader/reader.go:77:5: error var TypeNotFoundErr should have name of the form ErrFoo (ST1012) -pkg/goversion/compat.go:12:2: error var goTooOldErr should have name of the form errFoo (ST1012) -pkg/goversion/compat.go:12:33: error strings should not be capitalized (ST1005) -pkg/goversion/compat.go:13:2: error var dlvTooOldErr should have name of the form errFoo (ST1012) -pkg/goversion/compat.go:13:33: error strings should not be capitalized (ST1005) -pkg/locspec/locations.go:71:10: error strings should not be capitalized (ST1005) -pkg/locspec/locations.go:110:10: error strings should not be capitalized (ST1005) -pkg/locspec/locations.go:423:16: error strings should not be capitalized (ST1005) -pkg/proc/bininfo.go:249:18: unnecessary assignment to the blank identifier (S1005) -pkg/proc/bininfo.go:253:19: unnecessary assignment to the blank identifier (S1005) -pkg/proc/bininfo.go:257:19: unnecessary assignment to the blank identifier (S1005) -pkg/proc/bininfo.go:1268:2: unnecessary nil check around range (S1031) -pkg/proc/core/minidump/fileflags_string.go:62:7: every value of type uint16 is >= 0 (SA4003) -pkg/proc/core/minidump/minidump.go:424:3: should merge variable declaration with assignment on next line (S1021) -pkg/proc/eval.go:324:10: error strings should not be capitalized (ST1005) -pkg/proc/eval.go:395:10: error strings should not be capitalized (ST1005) -pkg/proc/eval.go:399:10: error strings should not be capitalized (ST1005) -pkg/proc/native/threads_linux_amd64.go:42:3: redundant return statement (S1023) -pkg/proc/stack.go:398:2: this value of err is never used (SA4006) -pkg/proc/stack.go:424:12: error strings should not be capitalized (ST1005) -pkg/proc/target_exec.go:161:6: this value of err is never used (SA4006) -pkg/proc/target_exec.go:810:3: when isexists is true, err can't be nil (S1020) -pkg/proc/variables.go:1481:21: error strings should not be capitalized (ST1005) -pkg/proc/variables.go:1569:18: error strings should not be capitalized (ST1005) -pkg/proc/variables.go:2243:44: should use !strings.Contains(typename, ".") instead (S1003) -pkg/proc/variables.go:2385:4: should replace this if statement with an unconditional strings.TrimPrefix (S1017) -pkg/proc/winutil/regs.go:167:2: should merge variable declaration with assignment on next line (S1021) -pkg/terminal/command.go:650:5: error var noCmdError should have name of the form errFoo (ST1012) -pkg/terminal/command.go:986:9: unnecessary assignment to the blank identifier (S1005) -pkg/terminal/command.go:1062:10: error strings should not be capitalized (ST1005) -pkg/terminal/command.go:1069:10: error strings should not be capitalized (ST1005) -pkg/terminal/command.go:1337:15: error strings should not be capitalized (ST1005) -pkg/terminal/command.go:1521:15: error strings should not be capitalized (ST1005) -pkg/terminal/command.go:1544:5: error var notOnFrameZeroErr should have name of the form errFoo (ST1012) -pkg/terminal/command.go:1600:10: error strings should not be capitalized (ST1005) -pkg/terminal/command.go:1915:11: error strings should not be capitalized (ST1005) -pkg/terminal/command.go:2420:25: error strings should not be capitalized (ST1005) -pkg/terminal/command.go:2479:5: error var disasmUsageError should have name of the form errFoo (ST1012) -pkg/terminal/starbind/conv.go:243:40: 'bitSize' argument is invalid, must be either 32 or 64 (SA1030) -pkg/terminal/starbind/conv.go:292:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025) -pkg/terminal/starbind/conv.go:352:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025) -pkg/terminal/starbind/conv.go:418:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025) -pkg/terminal/starbind/conv.go:497:9: the argument is already a string, there's no need to use fmt.Sprintf (S1025) -pkg/terminal/terminal.go:282:14: error strings should not be capitalized (ST1005) -pkg/terminal/terminal.go:282:14: error strings should not end with punctuation or a newline (ST1005) -service/api/prettyprint.go:156:9: should omit type bool from declaration; it will be inferred from the right-hand side (ST1023) -service/api/prettyprint.go:190:9: should omit type complex128 from declaration; it will be inferred from the right-hand side (ST1023) -service/dap/server.go:1448:11: should omit type AttachConfig from declaration; it will be inferred from the right-hand side (ST1023) -service/dap/utils.go:5:6: func min is unused (U1000) -service/debugger/debugger.go:946:5: builtin function len does not return negative values (SA4024) -service/debugger/debugger_linux.go:20:12: error strings should not be capitalized (ST1005) -service/debugger/debugger_linux.go:27:12: error strings should not be capitalized (ST1005) -service/rpc1/client.go:23:5: error var unsupportedApiError should have name of the form errFoo (ST1012) -service/rpc1/client.go:78:17: error strings should not be capitalized (ST1005) -service/rpc2/client.go:111:17: error strings should not be capitalized (ST1005) diff --git a/cmd/dlv/dlv_test.go b/cmd/dlv/dlv_test.go index a1e80caf..29ce4e7f 100644 --- a/cmd/dlv/dlv_test.go +++ b/cmd/dlv/dlv_test.go @@ -888,7 +888,15 @@ func TestStaticcheck(t *testing.T) { t.Skip("staticcheck not installed") } // default checks minus SA1019 which complains about deprecated identifiers, which change between versions of Go. - args := []string{"-tests=false", "-checks=all,-SA1019,-ST1000,-ST1003,-ST1016,-ST1020,-ST1021,-ST1022", "github.com/go-delve/delve/..."} + args := []string{"-tests=false", "-checks=all,-SA1019,-ST1000,-ST1003,-ST1016,-S1021,-ST1023", "github.com/go-delve/delve/..."} + // * SA1019 is disabled because new deprecations get added on every version + // of Go making the output of staticcheck inconsistent depending on the + // version of Go used to run it. + // * ST1000,ST1003,ST1016 are disabled in the default + // staticcheck configuration + // * S1021 "Merge variable declaration and assignment" is disabled because + // where we don't do this it is a deliberate style choice. + // * ST1023 "Redundant type in variable declaration" same as S1021. cmd := exec.Command("staticcheck", args...) cmd.Dir = projectRoot() cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64") diff --git a/pkg/dwarf/dwarfbuilder/info.go b/pkg/dwarf/dwarfbuilder/info.go index 31eb15b0..95b0f05d 100644 --- a/pkg/dwarf/dwarfbuilder/info.go +++ b/pkg/dwarf/dwarfbuilder/info.go @@ -119,12 +119,11 @@ func (b *Builder) TagClose() { b.info.WriteByte(0) } b.tagStack = b.tagStack[:len(b.tagStack)-1] - return } // Attr adds an attribute to the current DIE. func (b *Builder) Attr(attr dwarf.Attr, val interface{}) dwarf.Offset { - if len(b.tagStack) < 0 { + if len(b.tagStack) == 0 { panic("Attr with no open tags") } off := dwarf.Offset(b.info.Len()) diff --git a/pkg/dwarf/godwarf/type.go b/pkg/dwarf/godwarf/type.go index 5d2a773c..ba189115 100644 --- a/pkg/dwarf/godwarf/type.go +++ b/pkg/dwarf/godwarf/type.go @@ -529,7 +529,7 @@ func (t *UnsupportedType) stringIntl(recCheck) string { func (t *UnsupportedType) String() string { return t.stringIntl(nil) } -// Type reads the type at off in the DWARF ``info'' section. +// ReadType reads the type at off in the DWARF ``info'' section. func ReadType(d *dwarf.Data, index int, off dwarf.Offset, typeCache map[dwarf.Offset]Type) (Type, error) { typ, err := readType(d, "info", d.Reader(), off, typeCache, nil) if typ != nil { diff --git a/pkg/dwarf/line/line_parser.go b/pkg/dwarf/line/line_parser.go index e330ae4c..a9a0aed9 100644 --- a/pkg/dwarf/line/line_parser.go +++ b/pkg/dwarf/line/line_parser.go @@ -246,7 +246,7 @@ func readFileEntry(info *DebugLineInfo, buf *bytes.Buffer, exitOnEmptyPath bool) entry.LastModTime, _ = util.DecodeULEB128(buf) entry.Length, _ = util.DecodeULEB128(buf) if !pathIsAbs(entry.Path) { - if entry.DirIdx >= 0 && entry.DirIdx < uint64(len(info.IncludeDirs)) { + if entry.DirIdx < uint64(len(info.IncludeDirs)) { entry.Path = path.Join(info.IncludeDirs[entry.DirIdx], entry.Path) } } @@ -283,7 +283,8 @@ func parseFileEntries5(info *DebugLineInfo, buf *bytes.Buffer) bool { for fileEntryFormReader.next(buf) { entry := new(FileEntry) var p string - var diridx int = -1 + var diridx int + diridx = -1 switch fileEntryFormReader.contentType { case _DW_LNCT_path: diff --git a/pkg/dwarf/line/state_machine.go b/pkg/dwarf/line/state_machine.go index 04501a97..bf3029a6 100644 --- a/pkg/dwarf/line/state_machine.go +++ b/pkg/dwarf/line/state_machine.go @@ -148,16 +148,15 @@ func (lineInfo *DebugLineInfo) AllPCsForFileLines(f string, m map[int][]uint64) } } } - return } -var NoSourceError = errors.New("no source available") +var ErrNoSource = errors.New("no source available") // AllPCsBetween returns all PC addresses between begin and end (including both begin and end) // that have the is_stmt flag set and do not belong to excludeFile:excludeLine. func (lineInfo *DebugLineInfo) AllPCsBetween(begin, end uint64, excludeFile string, excludeLine int) ([]uint64, error) { if lineInfo == nil { - return nil, NoSourceError + return nil, ErrNoSource } var ( diff --git a/pkg/dwarf/reader/reader.go b/pkg/dwarf/reader/reader.go index 4094833d..d0a86911 100644 --- a/pkg/dwarf/reader/reader.go +++ b/pkg/dwarf/reader/reader.go @@ -33,7 +33,7 @@ func (reader *Reader) SeekToEntry(entry *dwarf.Entry) error { return err } -// Returns the address for the named entry. +// AddrFor returns the address for the named entry. func (reader *Reader) AddrFor(name string, staticBase uint64, ptrSize int) (uint64, error) { entry, err := reader.FindEntryNamed(name, false) if err != nil { @@ -50,31 +50,7 @@ func (reader *Reader) AddrFor(name string, staticBase uint64, ptrSize int) (uint return uint64(addr), nil } -// Returns the address for the named struct member. Expects the reader to be at the parent entry -// or one of the parents children, thus does not seek to parent by itself. -func (reader *Reader) AddrForMember(member string, initialInstructions []byte, ptrSize int) (uint64, error) { - for { - entry, err := reader.NextMemberVariable() - if err != nil { - return 0, err - } - if entry == nil { - return 0, fmt.Errorf("nil entry for member named %s", member) - } - name, ok := entry.Val(dwarf.AttrName).(string) - if !ok || name != member { - continue - } - instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte) - if !ok { - continue - } - addr, _, err := op.ExecuteStackProgram(op.DwarfRegisters{}, append(initialInstructions, instructions...), ptrSize, nil) - return uint64(addr), err - } -} - -var TypeNotFoundErr = errors.New("no type entry found, use 'types' for a list of valid types") +var ErrTypeNotFound = errors.New("no type entry found, use 'types' for a list of valid types") // SeekToType moves the reader to the type specified by the entry, // optionally resolving typedefs and pointer types. If the reader is set @@ -110,7 +86,7 @@ func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resol reader.Seek(offset) } - return nil, TypeNotFoundErr + return nil, ErrTypeNotFound } func (reader *Reader) NextType() (*dwarf.Entry, error) { @@ -148,10 +124,10 @@ func (reader *Reader) SeekToTypeNamed(name string) (*dwarf.Entry, error) { } } - return nil, TypeNotFoundErr + return nil, ErrTypeNotFound } -// Finds the entry for 'name'. +// FindEntryNamed finds the entry for 'name'. func (reader *Reader) FindEntryNamed(name string, member bool) (*dwarf.Entry, error) { depth := 1 for entry, err := reader.Next(); entry != nil; entry, err = reader.Next() { diff --git a/pkg/dwarf/util/buf.go b/pkg/dwarf/util/buf.go index d7b1ea31..12899f8a 100644 --- a/pkg/dwarf/util/buf.go +++ b/pkg/dwarf/util/buf.go @@ -4,6 +4,8 @@ // Buffered reading and decoding of DWARF data streams. +//lint:file-ignore ST1021 imported file + package util import ( diff --git a/pkg/dwarf/util/util.go b/pkg/dwarf/util/util.go index a0720af9..4e199cb2 100644 --- a/pkg/dwarf/util/util.go +++ b/pkg/dwarf/util/util.go @@ -173,7 +173,7 @@ func WriteUint(writer io.Writer, order binary.ByteOrder, ptrSize int, data uint6 return fmt.Errorf("pointer size %d not supported", ptrSize) } -// ReadDwarfLength reads a DWARF length field followed by a version field +// ReadDwarfLengthVersion reads a DWARF length field followed by a version field func ReadDwarfLengthVersion(data []byte) (length uint64, dwarf64 bool, version uint8, byteOrder binary.ByteOrder) { if len(data) < 4 { return 0, false, 0, binary.LittleEndian diff --git a/pkg/locspec/locations.go b/pkg/locspec/locations.go index 16fdaf07..2bc1a8fe 100644 --- a/pkg/locspec/locations.go +++ b/pkg/locspec/locations.go @@ -68,6 +68,7 @@ func Parse(locStr string) (LocationSpec, error) { rest := locStr malformed := func(reason string) error { + //lint:ignore ST1005 backwards compatibility return fmt.Errorf("Malformed breakpoint location \"%s\" at %d: %s", locStr, len(locStr)-len(rest), reason) } @@ -107,6 +108,7 @@ func Parse(locStr string) (LocationSpec, error) { func parseLocationSpecDefault(locStr, rest string) (LocationSpec, error) { malformed := func(reason string) error { + //lint:ignore ST1005 backwards compatibility return fmt.Errorf("Malformed breakpoint location \"%s\" at %d: %s", locStr, len(locStr)-len(rest), reason) } @@ -420,6 +422,7 @@ func (loc *NormalLocationSpec) Find(t *proc.Target, processArgs []string, scope var err error if len(candidateFiles) == 1 { if loc.LineOffset < 0 { + //lint:ignore ST1005 backwards compatibility return nil, fmt.Errorf("Malformed breakpoint location, no line offset specified") } addrs, err = proc.FindFileLocation(t, candidateFiles[0], loc.LineOffset) diff --git a/pkg/proc/bininfo.go b/pkg/proc/bininfo.go index 75deff77..fc4f7d81 100644 --- a/pkg/proc/bininfo.go +++ b/pkg/proc/bininfo.go @@ -246,15 +246,15 @@ func (e *ErrUnsupportedArch) Error() string { var supportArchs []cpuArch switch e.os { case "linux": - for linuxArch, _ := range supportedLinuxArch { + for linuxArch := range supportedLinuxArch { supportArchs = append(supportArchs, linuxArch) } case "windows": - for windowArch, _ := range supportedWindowsArch { + for windowArch := range supportedWindowsArch { supportArchs = append(supportArchs, windowArch) } case "darwin": - for darwinArch, _ := range supportedDarwinArch { + for darwinArch := range supportedDarwinArch { supportArchs = append(supportArchs, darwinArch) } } @@ -1265,12 +1265,10 @@ func (bi *BinaryInfo) loadSymbolName(image *Image, file *elf.File, wg *sync.Wait bi.SymNames = make(map[uint64]*elf.Symbol) } symSecs, _ := file.Symbols() - if symSecs != nil { - for _, symSec := range symSecs { - if symSec.Info == _STT_FUNC { // TODO(chainhelen), need to parse others types. - s := symSec - bi.SymNames[symSec.Value+image.StaticBase] = &s - } + for _, symSec := range symSecs { + if symSec.Info == _STT_FUNC { // TODO(chainhelen), need to parse others types. + s := symSec + bi.SymNames[symSec.Value+image.StaticBase] = &s } } } @@ -1599,7 +1597,7 @@ func (bi *BinaryInfo) macOSDebugFrameBugWorkaround() { func (bi *BinaryInfo) findType(name string) (godwarf.Type, error) { ref, found := bi.types[name] if !found { - return nil, reader.TypeNotFoundErr + return nil, reader.ErrTypeNotFound } image := bi.Images[ref.imageIndex] return godwarf.ReadType(image.dwarf, ref.imageIndex, ref.offset, image.typeCache) diff --git a/pkg/proc/breakpoints.go b/pkg/proc/breakpoints.go index e8913403..929ea086 100644 --- a/pkg/proc/breakpoints.go +++ b/pkg/proc/breakpoints.go @@ -724,7 +724,7 @@ func (t *Target) ClearBreakpoint(addr uint64) (*Breakpoint, error) { return bp, nil } -// ClearInternalBreakpoints removes all stepping breakpoints from the map, +// ClearSteppingBreakpoints removes all stepping breakpoints from the map, // calling clearBreakpoint on each one. func (t *Target) ClearSteppingBreakpoints() error { bpmap := t.Breakpoints() diff --git a/pkg/proc/core/minidump/fileflags_string.go b/pkg/proc/core/minidump/fileflags_string.go index b69969e4..2c67cce6 100644 --- a/pkg/proc/core/minidump/fileflags_string.go +++ b/pkg/proc/core/minidump/fileflags_string.go @@ -59,7 +59,7 @@ var ( func (i Arch) String() string { switch { - case 0 <= i && i <= 10: + case i <= 10: return _Arch_name_0[_Arch_index_0[i]:_Arch_index_0[i+1]] case i == 12: return _Arch_name_1 diff --git a/pkg/proc/core/minidump/minidump.go b/pkg/proc/core/minidump/minidump.go index 65e86a18..c9d5852e 100644 --- a/pkg/proc/core/minidump/minidump.go +++ b/pkg/proc/core/minidump/minidump.go @@ -155,7 +155,7 @@ type Module struct { MiscRecord []byte } -// VSFixedFileInfo: Visual Studio Fixed File Info. +// VSFixedFileInfo Visual Studio Fixed File Info. // See: https://docs.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo type VSFixedFileInfo struct { Signature uint32 diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index dd935a04..9e968777 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -321,6 +321,7 @@ func (scope *EvalScope) setValue(dstv, srcv *Variable, srcExpr string) error { } if srcv.Unreadable != nil { + //lint:ignore ST1005 backwards compatibility return fmt.Errorf("Expression \"%s\" is unreadable: %v", srcExpr, srcv.Unreadable) } @@ -392,10 +393,12 @@ func (scope *EvalScope) SetVariable(name, value string) error { } if xv.Addr == 0 { + //lint:ignore ST1005 backwards compatibility return fmt.Errorf("Can not assign to \"%s\"", name) } if xv.Unreadable != nil { + //lint:ignore ST1005 backwards compatibility return fmt.Errorf("Expression \"%s\" is unreadable: %v", name, xv.Unreadable) } @@ -701,7 +704,7 @@ func (scope *EvalScope) evalAST(t ast.Expr) (*Variable, error) { case *ast.CallExpr: if len(node.Args) == 1 { v, err := scope.evalTypeCast(node) - if err == nil || err != reader.TypeNotFoundErr { + if err == nil || err != reader.ErrTypeNotFound { return v, err } } diff --git a/pkg/proc/linutil/regs_arm64_arch.go b/pkg/proc/linutil/regs_arm64_arch.go index acb2d497..8bdae132 100644 --- a/pkg/proc/linutil/regs_arm64_arch.go +++ b/pkg/proc/linutil/regs_arm64_arch.go @@ -6,7 +6,7 @@ import ( "github.com/go-delve/delve/pkg/proc" ) -// Regs is a wrapper for sys.PtraceRegs. +// ARM64Registers is a wrapper for sys.PtraceRegs. type ARM64Registers struct { Regs *ARM64PtraceRegs //general-purpose registers iscgo bool diff --git a/pkg/proc/native/threads_linux_amd64.go b/pkg/proc/native/threads_linux_amd64.go index c53f6c81..95147e47 100644 --- a/pkg/proc/native/threads_linux_amd64.go +++ b/pkg/proc/native/threads_linux_amd64.go @@ -39,7 +39,6 @@ func (t *nativeThread) restoreRegisters(savedRegs proc.Registers) error { } _, _, restoreRegistersErr = syscall.Syscall6(syscall.SYS_PTRACE, sys.PTRACE_SETFPREGS, uintptr(t.ID), uintptr(0), uintptr(unsafe.Pointer(&sr.Fpregset.AMD64PtraceFpRegs)), 0, 0) - return }) if restoreRegistersErr == syscall.Errno(0) { restoreRegistersErr = nil diff --git a/pkg/proc/stack.go b/pkg/proc/stack.go index 28a7b0db..bcc2fe51 100644 --- a/pkg/proc/stack.go +++ b/pkg/proc/stack.go @@ -397,7 +397,7 @@ func (it *stackIterator) advanceRegs() (callFrameRegs op.DwarfRegisters, ret uin cfareg, err := it.executeFrameRegRule(0, framectx.CFA, 0) if cfareg == nil { - it.err = fmt.Errorf("CFA becomes undefined at PC %#x", it.pc) + it.err = fmt.Errorf("CFA becomes undefined at PC %#x: %v", it.pc, err) return op.DwarfRegisters{}, 0, 0 } it.regs.CFA = int64(cfareg.Uint64Val) @@ -421,6 +421,7 @@ func (it *stackIterator) advanceRegs() (callFrameRegs op.DwarfRegisters, ret uin if i == framectx.RetAddrReg { if reg == nil { if err == nil { + //lint:ignore ST1005 backwards compatibility err = fmt.Errorf("Undefined return address at %#x", it.pc) } it.err = err diff --git a/pkg/proc/target_exec.go b/pkg/proc/target_exec.go index 6161d454..b9dae997 100644 --- a/pkg/proc/target_exec.go +++ b/pkg/proc/target_exec.go @@ -158,7 +158,7 @@ func (dbp *Target) Continue() error { if !arch.BreakInstrMovesPC() { bpsize := arch.BreakpointSize() bp := make([]byte, bpsize) - _, err = dbp.Memory().ReadMemory(bp, loc.PC) + dbp.Memory().ReadMemory(bp, loc.PC) if bytes.Equal(bp, arch.BreakpointInstruction()) { setPC(curthread, loc.PC+uint64(bpsize)) } @@ -807,6 +807,7 @@ func setStepIntoBreakpoint(dbp *Target, curfn *Function, text []AsmInstruction, func allowDuplicateBreakpoint(bp *Breakpoint, err error) (*Breakpoint, error) { if err != nil { + //lint:ignore S1020 this is clearer if _, isexists := err.(BreakpointExistsError); isexists { return bp, nil } diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index 2bb0a069..30ad20ff 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -1478,6 +1478,7 @@ func (v *Variable) loadSliceInfo(t *godwarf.SliceType) { // Dereference array type to get value type ptrType, ok := f.Type.(*godwarf.PtrType) if !ok { + //lint:ignore ST1005 backwards compatibility v.Unreadable = fmt.Errorf("Invalid type %s in slice array", f.Type) return } @@ -1566,6 +1567,7 @@ func (v *Variable) loadArrayValues(recurseLevel int, cfg LoadConfig) { return } if v.Len < 0 { + //lint:ignore ST1005 backwards compatibility v.Unreadable = errors.New("Negative array length") return } @@ -2240,7 +2242,7 @@ func (v *Variable) ConstDescr() string { if ctyp == nil { return "" } - if typename := v.DwarfType.Common().Name; strings.Index(typename, ".") < 0 || strings.HasPrefix(typename, "C.") { + if typename := v.DwarfType.Common().Name; !strings.Contains(typename, ".") || strings.HasPrefix(typename, "C.") { // only attempt to use constants for user defined type, otherwise every // int variable with value 1 will be described with os.SEEK_CUR and other // similar problems. @@ -2382,9 +2384,7 @@ func (cm constantsMap) Get(typ godwarf.Type) *constantType { ctyp.initialized = true sort.Sort(constantValuesByValue(ctyp.values)) for i := range ctyp.values { - if strings.HasPrefix(ctyp.values[i].name, typepkg) { - ctyp.values[i].name = ctyp.values[i].name[len(typepkg):] - } + ctyp.values[i].name = strings.TrimPrefix(ctyp.values[i].name, typepkg) if popcnt(uint64(ctyp.values[i].value)) == 1 { ctyp.values[i].singleBit = true } diff --git a/pkg/terminal/command.go b/pkg/terminal/command.go index ddc9fef0..cd230d70 100644 --- a/pkg/terminal/command.go +++ b/pkg/terminal/command.go @@ -2,6 +2,8 @@ // input and dispatching to appropriate backend commands. package terminal +//lint:file-ignore ST1005 errors here can be capitalized + import ( "bufio" "bytes" @@ -647,10 +649,10 @@ func (c *Commands) Merge(allAliases map[string][]string) { } } -var noCmdError = errors.New("command not available") +var errNoCmd = errors.New("command not available") func noCmdAvailable(t *Term, ctx callContext, args string) error { - return noCmdError + return errNoCmd } func nullCommand(t *Term, ctx callContext, args string) error { @@ -667,7 +669,7 @@ func (c *Commands) help(t *Term, ctx callContext, args string) error { } } } - return noCmdError + return errNoCmd } fmt.Println("The following commands are available:") @@ -983,7 +985,7 @@ func selectedGID(state *api.DebuggerState) int { func split2PartsBySpace(s string) []string { v := strings.SplitN(s, " ", 2) - for i, _ := range v { + for i := range v { v[i] = strings.TrimSpace(v[i]) } return v @@ -1541,14 +1543,14 @@ func (c *Commands) step(t *Term, ctx callContext, args string) error { return continueUntilCompleteNext(t, state, "step", true) } -var notOnFrameZeroErr = errors.New("not on topmost frame") +var errNotOnFrameZero = errors.New("not on topmost frame") func (c *Commands) stepInstruction(t *Term, ctx callContext, args string) error { if err := scopePrefixSwitch(t, ctx); err != nil { return err } if c.frame != 0 { - return notOnFrameZeroErr + return errNotOnFrameZero } defer t.onStop() @@ -1584,7 +1586,7 @@ func (c *Commands) next(t *Term, ctx callContext, args string) error { return err } if c.frame != 0 { - return notOnFrameZeroErr + return errNotOnFrameZero } nextfn := t.client.Next @@ -1622,7 +1624,7 @@ func (c *Commands) stepout(t *Term, ctx callContext, args string) error { return err } if c.frame != 0 { - return notOnFrameZeroErr + return errNotOnFrameZero } stepoutfn := t.client.StepOut @@ -2476,7 +2478,7 @@ func (c *Commands) sourceCommand(t *Term, ctx callContext, args string) error { return c.executeFile(t, args) } -var disasmUsageError = errors.New("wrong number of arguments: disassemble [-a ] [-l ]") +var errDisasmUsage = errors.New("wrong number of arguments: disassemble [-a ] [-l ]") func disassCommand(t *Term, ctx callContext, args string) error { var cmd, rest string @@ -2484,7 +2486,7 @@ func disassCommand(t *Term, ctx callContext, args string) error { if args != "" { argv := split2PartsBySpace(args) if len(argv) != 2 { - return disasmUsageError + return errDisasmUsage } cmd = argv[0] rest = argv[1] @@ -2515,7 +2517,7 @@ func disassCommand(t *Term, ctx callContext, args string) error { case "-a": v := split2PartsBySpace(rest) if len(v) != 2 { - return disasmUsageError + return errDisasmUsage } startpc, err := strconv.ParseInt(v[0], 0, 64) if err != nil { @@ -2536,7 +2538,7 @@ func disassCommand(t *Term, ctx callContext, args string) error { } disasm, disasmErr = t.client.DisassemblePC(ctx.Scope, locs[0].PC, flavor) default: - return disasmUsageError + return errDisasmUsage } if disasmErr != nil { diff --git a/pkg/terminal/starbind/conv.go b/pkg/terminal/starbind/conv.go index a102300e..49b29b31 100644 --- a/pkg/terminal/starbind/conv.go +++ b/pkg/terminal/starbind/conv.go @@ -240,7 +240,7 @@ func (env *Env) variableValueToStarlarkValue(v *api.Variable, top bool) (starlar case "NaN": return starlark.Float(math.NaN()), nil default: - n, _ := strconv.ParseFloat(v.Value, 0) + n, _ := strconv.ParseFloat(v.Value, 64) return starlark.Float(n), nil } case reflect.Ptr, reflect.Interface: @@ -289,7 +289,7 @@ func (v structVariableAsStarlarkValue) Hash() (uint32, error) { } func (v structVariableAsStarlarkValue) String() string { - return fmt.Sprintf("%s", v.v.SinglelineString()) + return v.v.SinglelineString() } func (v structVariableAsStarlarkValue) Truth() starlark.Bool { @@ -349,7 +349,7 @@ func (v sliceVariableAsStarlarkValue) Hash() (uint32, error) { } func (v sliceVariableAsStarlarkValue) String() string { - return fmt.Sprintf("%s", v.v.SinglelineString()) + return v.v.SinglelineString() } func (v sliceVariableAsStarlarkValue) Truth() starlark.Bool { @@ -415,7 +415,7 @@ func (v ptrVariableAsStarlarkValue) Hash() (uint32, error) { } func (v ptrVariableAsStarlarkValue) String() string { - return fmt.Sprintf("%s", v.v.SinglelineString()) + return v.v.SinglelineString() } func (v ptrVariableAsStarlarkValue) Truth() starlark.Bool { @@ -494,7 +494,7 @@ func (v mapVariableAsStarlarkValue) Hash() (uint32, error) { } func (v mapVariableAsStarlarkValue) String() string { - return fmt.Sprintf("%s", v.v.SinglelineString()) + return v.v.SinglelineString() } func (v mapVariableAsStarlarkValue) Truth() starlark.Bool { diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index 62bd6344..39a0b679 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -1,5 +1,7 @@ package terminal +//lint:file-ignore ST1005 errors here can be capitalized + import ( "fmt" "io" diff --git a/service/api/types.go b/service/api/types.go index 02e2cc10..276d66fc 100644 --- a/service/api/types.go +++ b/service/api/types.go @@ -593,7 +593,7 @@ const ( StacktraceG ) -// ImportPathToDirectoryPath maps an import path to a directory path. +// PackageBuildInfo maps an import path to a directory path. type PackageBuildInfo struct { ImportPath string DirectoryPath string diff --git a/service/dap/daptest/client.go b/service/dap/daptest/client.go index ed0daaec..198ca935 100644 --- a/service/dap/daptest/client.go +++ b/service/dap/daptest/client.go @@ -225,7 +225,7 @@ func (c *Client) DisconnectRequest() { c.send(request) } -// DisconnectRequest sends a 'disconnect' request with an option to specify +// DisconnectRequestWithKillOption sends a 'disconnect' request with an option to specify // `terminateDebuggee`. func (c *Client) DisconnectRequestWithKillOption(kill bool) { request := &dap.DisconnectRequest{Request: *c.newRequest("disconnect")} @@ -358,7 +358,7 @@ func (c *Client) NamedVariablesRequest(variablesReference int) { c.send(request) } -// TeriminateRequest sends a 'terminate' request. +// TerminateRequest sends a 'terminate' request. func (c *Client) TerminateRequest() { c.send(&dap.TerminateRequest{Request: *c.newRequest("terminate")}) } diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 400fdcdd..678fad13 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -941,7 +941,7 @@ func (d *Debugger) clearBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoint } clearedBp := api.ConvertBreakpoints(bps) - if len(clearedBp) < 0 { + if len(clearedBp) == 0 { return nil, nil } d.log.Infof("cleared breakpoint: %#v", clearedBp) diff --git a/service/debugger/debugger_linux.go b/service/debugger/debugger_linux.go index 8550185c..0f65c83e 100644 --- a/service/debugger/debugger_linux.go +++ b/service/debugger/debugger_linux.go @@ -9,6 +9,8 @@ import ( sys "golang.org/x/sys/unix" ) +//lint:file-ignore ST1005 errors here can be capitalized + func attachErrorMessage(pid int, err error) error { fallbackerr := fmt.Errorf("could not attach to pid %d: %s", pid, err) if serr, ok := err.(syscall.Errno); ok { diff --git a/service/rpc1/client.go b/service/rpc1/client.go index 410f60ec..9c24e7eb 100644 --- a/service/rpc1/client.go +++ b/service/rpc1/client.go @@ -12,7 +12,7 @@ import ( "github.com/go-delve/delve/service/api" ) -// Client is a RPC service.Client. +// RPCClient is a RPC service.Client. type RPCClient struct { addr string client *rpc.Client @@ -20,7 +20,7 @@ type RPCClient struct { haltReq bool } -var unsupportedApiError = errors.New("unsupported") +var errAPIUnsupported = errors.New("unsupported") // NewClient creates a new RPCClient. func NewClient(addr string) *RPCClient { @@ -75,6 +75,7 @@ func (c *RPCClient) Continue() <-chan *api.DebuggerState { } if state.Exited { // Error types apparently cannot be marshalled by Go correctly. Must reset error here. + //lint:ignore ST1005 backwards compatibility state.Err = fmt.Errorf("Process %d has exited with status %d", c.ProcessPid(), state.ExitStatus) } ch <- state @@ -202,7 +203,7 @@ func (c *RPCClient) AmendBreakpoint(bp *api.Breakpoint) error { } func (c *RPCClient) CancelNext() error { - return unsupportedApiError + return errAPIUnsupported } func (c *RPCClient) ListThreads() ([]*api.Thread, error) { @@ -300,14 +301,14 @@ func (c *RPCClient) FindLocation(scope api.EvalScope, loc string) ([]api.Locatio return answer, err } -// Disassemble code between startPC and endPC +// DisassembleRange disassembles code between startPC and endPC func (c *RPCClient) DisassembleRange(scope api.EvalScope, startPC, endPC uint64, flavour api.AssemblyFlavour) (api.AsmInstructions, error) { var r api.AsmInstructions err := c.call("Disassemble", DisassembleRequest{scope, startPC, endPC, flavour}, &r) return r, err } -// Disassemble function containing pc +// DisassemblePC disassembles function containing pc func (c *RPCClient) DisassemblePC(scope api.EvalScope, pc uint64, flavour api.AssemblyFlavour) (api.AsmInstructions, error) { var r api.AsmInstructions err := c.call("Disassemble", DisassembleRequest{scope, pc, 0, flavour}, &r) diff --git a/service/rpc2/client.go b/service/rpc2/client.go index d8e9db56..0e348970 100644 --- a/service/rpc2/client.go +++ b/service/rpc2/client.go @@ -12,7 +12,7 @@ import ( "github.com/go-delve/delve/service/api" ) -// Client is a RPC service.Client. +// RPCClient is a RPC service.Client. type RPCClient struct { client *rpc.Client @@ -108,6 +108,7 @@ func (c *RPCClient) continueDir(cmd string) <-chan *api.DebuggerState { } if state.Exited { // Error types apparently cannot be marshalled by Go correctly. Must reset error here. + //lint:ignore ST1005 backwards compatibility state.Err = fmt.Errorf("Process %d has exited with status %d", c.ProcessPid(), state.ExitStatus) } ch <- &state @@ -404,14 +405,14 @@ func (c *RPCClient) FindLocation(scope api.EvalScope, loc string, findInstructio return out.Locations, err } -// Disassemble code between startPC and endPC +// DisassembleRange disassembles code between startPC and endPC func (c *RPCClient) DisassembleRange(scope api.EvalScope, startPC, endPC uint64, flavour api.AssemblyFlavour) (api.AsmInstructions, error) { var out DisassembleOut err := c.call("Disassemble", DisassembleIn{scope, startPC, endPC, flavour}, &out) return out.Disassemble, err } -// Disassemble function containing pc +// DisassemblePC disassembles function containing pc func (c *RPCClient) DisassemblePC(scope api.EvalScope, pc uint64, flavour api.AssemblyFlavour) (api.AsmInstructions, error) { var out DisassembleOut err := c.call("Disassemble", DisassembleIn{scope, pc, 0, flavour}, &out) diff --git a/service/rpc2/server.go b/service/rpc2/server.go index 25c2fb98..afcc164a 100644 --- a/service/rpc2/server.go +++ b/service/rpc2/server.go @@ -521,7 +521,7 @@ type EvalOut struct { Variable *api.Variable } -// EvalVariable returns a variable in the specified context. +// Eval returns a variable in the specified context. // // See https://github.com/go-delve/delve/blob/master/Documentation/cli/expr.md // for a description of acceptable values of arg.Expr. diff --git a/service/rpccommon/server.go b/service/rpccommon/server.go index ff96cfe4..18953f80 100644 --- a/service/rpccommon/server.go +++ b/service/rpccommon/server.go @@ -404,7 +404,7 @@ func (s *RPCServer) GetVersion(args api.GetVersionIn, out *api.GetVersionOut) er return s.s.debugger.GetVersion(out) } -// Changes version of the API being served. +// SetApiVersion changes version of the API being served. func (s *RPCServer) SetApiVersion(args api.SetAPIVersionIn, out *api.SetAPIVersionOut) error { if args.APIVersion < 2 { args.APIVersion = 1