mirror of
https://github.com/go-delve/delve.git
synced 2026-05-05 12:16:12 +02:00
*: modernize codebase (#4221)
Run go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... on the codebase now that the module version has updated to 1.24.
This commit is contained in:
parent
4e4f29ce75
commit
7f42ac8564
@ -808,15 +808,15 @@ func TestTraceDirRecursion(t *testing.T) {
|
||||
// Parse output to ignore calls to morestack_noctxt for comparison
|
||||
scan := bufio.NewScanner(rdr)
|
||||
text := ""
|
||||
outputtext := ""
|
||||
var outputtext strings.Builder
|
||||
for scan.Scan() {
|
||||
text = scan.Text()
|
||||
if !strings.Contains(text, "morestack_noctxt") {
|
||||
outputtext += text
|
||||
outputtext += "\n"
|
||||
outputtext.WriteString(text)
|
||||
outputtext.WriteString("\n")
|
||||
}
|
||||
}
|
||||
output := []byte(outputtext)
|
||||
output := []byte(outputtext.String())
|
||||
|
||||
if !bytes.Contains(output, expected) {
|
||||
t.Fatalf("expected:\n%s\ngot:\n%s", string(expected), string(output))
|
||||
|
||||
@ -154,7 +154,7 @@ func BenchmarkFDEForPC(b *testing.B) {
|
||||
}
|
||||
fdes, _ := Parse(data, binary.BigEndian, 0, ptrSizeByRuntimeArch(), 0)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
// bench worst case, exhaustive search
|
||||
_, _ = fdes.FDEForPC(0x455555555)
|
||||
}
|
||||
|
||||
@ -53,8 +53,7 @@ func BenchmarkParse(b *testing.B) {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
Parse(data, binary.BigEndian, 0, ptrSizeByRuntimeArch(), 0)
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,13 +211,6 @@ func normalizeRanges(rngs [][2]uint64) [][2]uint64 {
|
||||
return out
|
||||
}
|
||||
|
||||
func max(a, b uint64) uint64 {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// fuseRanges fuses rngs2 into rngs1, it's the equivalent of
|
||||
//
|
||||
// normalizeRanges(append(rngs1, rngs2))
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-delve/delve/pkg/dwarf/op"
|
||||
)
|
||||
@ -396,19 +397,20 @@ type EnumValue struct {
|
||||
func (t *EnumType) String() string { return t.stringIntl(nil) }
|
||||
|
||||
func (t *EnumType) stringIntl(recCheck recCheck) string {
|
||||
s := "enum"
|
||||
var s strings.Builder
|
||||
s.WriteString("enum")
|
||||
if t.EnumName != "" {
|
||||
s += " " + t.EnumName
|
||||
s.WriteString(" " + t.EnumName)
|
||||
}
|
||||
s += " {"
|
||||
s.WriteString(" {")
|
||||
for i, v := range t.Val {
|
||||
if i > 0 {
|
||||
s += "; "
|
||||
s.WriteString("; ")
|
||||
}
|
||||
s += v.Name + "=" + strconv.FormatInt(v.Val, 10)
|
||||
s.WriteString(v.Name + "=" + strconv.FormatInt(v.Val, 10))
|
||||
}
|
||||
s += "}"
|
||||
return s
|
||||
s.WriteString("}")
|
||||
return s.String()
|
||||
}
|
||||
|
||||
// A FuncType represents a function type.
|
||||
@ -426,18 +428,19 @@ func (t *FuncType) stringIntl(recCheck recCheck) string {
|
||||
return cyclicalTypeStop
|
||||
}
|
||||
defer release()
|
||||
s := "func("
|
||||
var s strings.Builder
|
||||
s.WriteString("func(")
|
||||
for i, t := range t.ParamType {
|
||||
if i > 0 {
|
||||
s += ", "
|
||||
s.WriteString(", ")
|
||||
}
|
||||
s += t.stringIntl(recCheck)
|
||||
s.WriteString(t.stringIntl(recCheck))
|
||||
}
|
||||
s += ")"
|
||||
s.WriteString(")")
|
||||
if t.ReturnType != nil {
|
||||
s += " " + t.ReturnType.stringIntl(recCheck)
|
||||
s.WriteString(" " + t.ReturnType.stringIntl(recCheck))
|
||||
}
|
||||
return s
|
||||
return s.String()
|
||||
}
|
||||
|
||||
// A DotDotDotType represents the variadic ... function parameter.
|
||||
|
||||
@ -182,8 +182,7 @@ func BenchmarkLineParser(b *testing.B) {
|
||||
|
||||
data := grabDebugLineSection(p, nil)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
_ = ParseAll(data, nil, nil, 0, true, ptrSizeByRuntimeArch())
|
||||
}
|
||||
}
|
||||
@ -204,9 +203,8 @@ func loadBenchmarkData(tb testing.TB) DebugLines {
|
||||
|
||||
func BenchmarkStateMachine(b *testing.B) {
|
||||
lineInfos := loadBenchmarkData(b)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
sm := newStateMachine(lineInfos[0], lineInfos[0].Instructions, ptrSizeByRuntimeArch())
|
||||
|
||||
for {
|
||||
@ -303,8 +301,8 @@ func BenchmarkPCToLine(b *testing.B) {
|
||||
lineInfos := loadBenchmarkData(b)
|
||||
|
||||
entries, basePCs := setupTestPCToLine(b, lineInfos)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
||||
for b.Loop() {
|
||||
runTestPCToLine(b, lineInfos, entries, basePCs, false, 0x10000)
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ func TestCacheConcurrent(t *testing.T) {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for j := 0; j < 100; j++ {
|
||||
for j := range 100 {
|
||||
cache.Add(i*100+j, i)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -216,8 +216,8 @@ func Setup(logFlag bool, logstr, logDest string) error {
|
||||
logstr = "debugger"
|
||||
}
|
||||
any = true
|
||||
v := strings.Split(logstr, ",")
|
||||
for _, logcmd := range v {
|
||||
v := strings.SplitSeq(logstr, ",")
|
||||
for logcmd := range v {
|
||||
// If adding another value, do make sure to
|
||||
// update "Help about logging flags" in commands.go.
|
||||
switch logcmd {
|
||||
|
||||
@ -462,18 +462,19 @@ func (e *ErrUnsupportedArch) Error() string {
|
||||
}
|
||||
}
|
||||
|
||||
errStr := "unsupported architecture of " + e.os + "/" + e.cpuArch.String()
|
||||
errStr += " - only"
|
||||
var errStr strings.Builder
|
||||
errStr.WriteString("unsupported architecture of " + e.os + "/" + e.cpuArch.String())
|
||||
errStr.WriteString(" - only")
|
||||
for _, arch := range supportArchs {
|
||||
errStr += " " + e.os + "/" + arch.String() + " "
|
||||
errStr.WriteString(" " + e.os + "/" + arch.String() + " ")
|
||||
}
|
||||
if len(supportArchs) == 1 {
|
||||
errStr += "is supported"
|
||||
errStr.WriteString("is supported")
|
||||
} else {
|
||||
errStr += "are supported"
|
||||
errStr.WriteString("are supported")
|
||||
}
|
||||
|
||||
return errStr
|
||||
return errStr.String()
|
||||
}
|
||||
|
||||
type compileUnit struct {
|
||||
|
||||
@ -204,9 +204,9 @@ func (conn *gdbConn) qSupported(multiprocess bool) (features map[string]bool, er
|
||||
for _, stubfeature := range resp {
|
||||
if len(stubfeature) == 0 {
|
||||
continue
|
||||
} else if equal := strings.Index(stubfeature, "="); equal >= 0 {
|
||||
if stubfeature[:equal] == "PacketSize" {
|
||||
if n, err := strconv.ParseInt(stubfeature[equal+1:], 16, 64); err == nil {
|
||||
} else if before, after, ok := strings.Cut(stubfeature, "="); ok {
|
||||
if before == "PacketSize" {
|
||||
if n, err := strconv.ParseInt(after, 16, 64); err == nil {
|
||||
conn.packetSize = int(n)
|
||||
}
|
||||
}
|
||||
@ -311,10 +311,10 @@ func (conn *gdbConn) readRegisterInfo(regFound map[string]bool) (err error) {
|
||||
keyval = resp[:semicolon]
|
||||
}
|
||||
|
||||
colon := strings.Index(keyval, ":")
|
||||
if colon >= 0 {
|
||||
name := keyval[:colon]
|
||||
value := keyval[colon+1:]
|
||||
before, after, ok := strings.Cut(keyval, ":")
|
||||
if ok {
|
||||
name := before
|
||||
value := after
|
||||
|
||||
switch name {
|
||||
case "name":
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
//go:build linux && loong64
|
||||
// +build linux,loong64
|
||||
|
||||
package native
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
//go:build linux && loong64
|
||||
// +build linux,loong64
|
||||
|
||||
package native
|
||||
|
||||
|
||||
@ -2983,20 +2983,20 @@ func logStacktrace(t *testing.T, p *proc.Target, frames []proc.Stackframe) {
|
||||
topmostdefer = fmt.Sprintf("%#x %s", frames[j].TopmostDefer.DwrapPC, fnname)
|
||||
}
|
||||
|
||||
defers := ""
|
||||
var defers strings.Builder
|
||||
for deferIdx, _defer := range frames[j].Defers {
|
||||
_, _, fn := _defer.DeferredFunc(p)
|
||||
fnname := ""
|
||||
if fn != nil {
|
||||
fnname = fn.Name
|
||||
}
|
||||
defers += fmt.Sprintf("%d %#x %s |", deferIdx, _defer.DwrapPC, fnname)
|
||||
defers.WriteString(fmt.Sprintf("%d %#x %s |", deferIdx, _defer.DwrapPC, fnname))
|
||||
}
|
||||
|
||||
frame := frames[j]
|
||||
fmt.Fprintf(w, "%#x\t%#x\t%#x\t%#x\t%#x\t%s\t%s:%d\t%s\t%s\t\n",
|
||||
frame.Call.PC, frame.FrameOffset(), frame.FramePointerOffset(), frame.Current.PC, frame.Ret,
|
||||
name, filepath.Base(frame.Call.File), frame.Call.Line, topmostdefer, defers)
|
||||
name, filepath.Base(frame.Call.File), frame.Call.Line, topmostdefer, defers.String())
|
||||
}
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
@ -180,12 +180,12 @@ func (check *scopeCheck) Parse(descr string, t *testing.T) {
|
||||
decl = strings.TrimSpace(decl)
|
||||
}
|
||||
|
||||
space := strings.Index(decl, " ")
|
||||
if space < 0 {
|
||||
before, after, ok := strings.Cut(decl, " ")
|
||||
if !ok {
|
||||
t.Fatalf("could not parse scope comment %q (%q)", descr, decl)
|
||||
}
|
||||
varcheck.name = strings.TrimSpace(decl[:space])
|
||||
varcheck.typ = strings.TrimSpace(decl[space+1:])
|
||||
varcheck.name = strings.TrimSpace(before)
|
||||
varcheck.typ = strings.TrimSpace(after)
|
||||
if strings.Contains(varcheck.typ, " ") {
|
||||
t.Fatalf("could not parse scope comment %q (%q)", descr, decl)
|
||||
}
|
||||
|
||||
@ -396,7 +396,7 @@ func TestScopePrefix(t *testing.T) {
|
||||
curgid = gid
|
||||
}
|
||||
|
||||
if idx := strings.Index(line, " main.agoroutine "); idx < 0 {
|
||||
if found := strings.Contains(line, " main.agoroutine "); !found {
|
||||
nonagoroutines = append(nonagoroutines, gid)
|
||||
continue
|
||||
}
|
||||
@ -411,8 +411,8 @@ func TestScopePrefix(t *testing.T) {
|
||||
if len(agoroutines) < 10 {
|
||||
extraAgoroutines := 0
|
||||
for _, gid := range nonagoroutines {
|
||||
stackOut := strings.Split(term.MustExec(fmt.Sprintf("goroutine %d stack", gid)), "\n")
|
||||
for _, line := range stackOut {
|
||||
stackOut := strings.SplitSeq(term.MustExec(fmt.Sprintf("goroutine %d stack", gid)), "\n")
|
||||
for line := range stackOut {
|
||||
if strings.HasSuffix(line, " main.agoroutine") {
|
||||
extraAgoroutines++
|
||||
break
|
||||
@ -434,16 +434,16 @@ func TestScopePrefix(t *testing.T) {
|
||||
fid := -1
|
||||
for _, line := range stackOut {
|
||||
line = strings.TrimLeft(line, " ")
|
||||
space := strings.Index(line, " ")
|
||||
if space < 0 {
|
||||
before, _, ok := strings.Cut(line, " ")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
curfid, err := strconv.Atoi(line[:space])
|
||||
curfid, err := strconv.Atoi(before)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if idx := strings.Index(line, " main.agoroutine"); idx >= 0 {
|
||||
if found := strings.Contains(line, " main.agoroutine"); found {
|
||||
fid = curfid
|
||||
break
|
||||
}
|
||||
@ -1558,7 +1558,7 @@ func TestListPackages(t *testing.T) {
|
||||
out := term.MustExec("packages")
|
||||
t.Logf("> packages\n%s", out)
|
||||
seen := map[string]bool{}
|
||||
for _, p := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||
for p := range strings.SplitSeq(strings.TrimSpace(out), "\n") {
|
||||
seen[p] = true
|
||||
}
|
||||
if !seen["main"] || !seen["runtime"] {
|
||||
@ -1568,7 +1568,7 @@ func TestListPackages(t *testing.T) {
|
||||
out = term.MustExec("packages runtime")
|
||||
t.Logf("> packages runtime\n%s", out)
|
||||
|
||||
for _, p := range strings.Split(strings.TrimSpace(out), "\n") {
|
||||
for p := range strings.SplitSeq(strings.TrimSpace(out), "\n") {
|
||||
if !strings.Contains(p, "runtime") {
|
||||
t.Errorf("output includes unexpected %q", p)
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"os"
|
||||
|
||||
"go.starlark.net/starlark"
|
||||
@ -49,9 +50,7 @@ import (
|
||||
func (env *Env) REPL() error {
|
||||
thread := env.newThread()
|
||||
globals := starlark.StringDict{}
|
||||
for k, v := range env.env {
|
||||
globals[k] = v
|
||||
}
|
||||
maps.Copy(globals, env.env)
|
||||
|
||||
rl := liner.NewLiner()
|
||||
defer rl.Close()
|
||||
@ -144,9 +143,7 @@ func rep(rl *liner.State, thread *starlark.Thread, globals starlark.StringDict,
|
||||
// The global names from the previous call become
|
||||
// the predeclared names of this call.
|
||||
// If execution failed, some globals may be undefined.
|
||||
for k, v := range res {
|
||||
globals[k] = v
|
||||
}
|
||||
maps.Copy(globals, res)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@ -188,17 +188,17 @@ func (s *Session) targetCmd(_, _ int, argstr string) (string, error) {
|
||||
tgrp, unlock := s.debugger.LockTargetGroup()
|
||||
defer unlock()
|
||||
curpid := tgrp.Selected.Pid()
|
||||
tgtListStr := ""
|
||||
var tgtListStr strings.Builder
|
||||
for _, tgt := range tgrp.Targets() {
|
||||
if _, err := tgt.Valid(); err == nil {
|
||||
selected := ""
|
||||
if tgt.Pid() == curpid {
|
||||
selected = "*"
|
||||
}
|
||||
tgtListStr += fmt.Sprintf("%s\t%d\t%s\n", selected, tgt.Pid(), tgt.CmdLine)
|
||||
tgtListStr.WriteString(fmt.Sprintf("%s\t%d\t%s\n", selected, tgt.Pid(), tgt.CmdLine))
|
||||
}
|
||||
}
|
||||
return tgtListStr, nil
|
||||
return tgtListStr.String(), nil
|
||||
case "follow-exec":
|
||||
if len(argv) == 1 {
|
||||
if s.debugger.FollowExecEnabled() {
|
||||
|
||||
@ -3085,12 +3085,12 @@ func (s *Session) onEvaluateRequest(request *dap.EvaluateRequest) {
|
||||
// that preserves their names.
|
||||
retVarsAsVar := &proc.Variable{Children: slicePtrVarToSliceVar(retVars)}
|
||||
// As a shortcut also express the return values as a single string.
|
||||
retVarsAsStr := ""
|
||||
var retVarsAsStr strings.Builder
|
||||
for _, v := range retVars {
|
||||
retVarsAsStr += s.convertVariableToString(v) + ", "
|
||||
retVarsAsStr.WriteString(s.convertVariableToString(v) + ", ")
|
||||
}
|
||||
response.Body = dap.EvaluateResponseBody{
|
||||
Result: strings.TrimRight(retVarsAsStr, ", "),
|
||||
Result: strings.TrimRight(retVarsAsStr.String(), ", "),
|
||||
VariablesReference: s.variableHandles.create(&fullyQualifiedVariable{retVarsAsVar, "", false /*not a scope*/, 0}),
|
||||
}
|
||||
}
|
||||
|
||||
@ -661,7 +661,7 @@ func TestLaunchWithFollowExec(t *testing.T) {
|
||||
}
|
||||
|
||||
// 2 >> launch, << process, << initialized, << launch
|
||||
client.LaunchRequestWithArgs(map[string]interface{}{
|
||||
client.LaunchRequestWithArgs(map[string]any{
|
||||
"mode": "exec",
|
||||
"program": fixture.Path,
|
||||
"args": []string{"spawn2", childFixture.Path}, // call spawnchild.go
|
||||
|
||||
@ -112,7 +112,7 @@ type LaunchConfig struct {
|
||||
// or
|
||||
// "buildFlags": ["-tags=integration", "-ldflags=-X main.Hello=World"]
|
||||
// Using other types is an error.
|
||||
BuildFlags BuildFlags `json:"buildFlags,omitempty"`
|
||||
BuildFlags BuildFlags `json:"buildFlags"`
|
||||
|
||||
// Output path for the binary of the debuggee.
|
||||
// Relative path is interpreted as the path relative to
|
||||
|
||||
@ -31,7 +31,7 @@ func sameUserForHexLocalAddr(filename, localAddr, remoteAddr string) (bool, erro
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, line := range strings.Split(strings.TrimSpace(string(b)), "\n") {
|
||||
for line := range strings.SplitSeq(strings.TrimSpace(string(b)), "\n") {
|
||||
// The format contains whitespace padding (%4d, %5u), so we use
|
||||
// fmt.Sscanf instead of splitting on whitespace.
|
||||
var (
|
||||
|
||||
@ -709,7 +709,7 @@ func (c *RPCClient) DownloadLibraryDebugInfo(n int) error {
|
||||
return c.call("DownloadLibraryDebugInfo", DownloadLibraryDebugInfoIn{n}, out)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user