diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index e6af4c6255..2cda26e0d0 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -120,7 +120,7 @@ func New(docCall bool) *cobra.Command { conf, loadConfErr = config.LoadConfig() // Delay reporting errors about configuration loading delayed until after the // server is started so that the "server listening at" message is always - // the first thing emitted. Also logflags hasn't been setup yet at this point. + // the first thing emitted. Also, logflags hasn't been set up yet at this point. buildFlagsDefault := "" if runtime.GOOS == "windows" { ver, _ := goversion.Installed() @@ -501,7 +501,7 @@ func dapCmd(cmd *cobra.Command, args []string) { } disconnectChan := make(chan struct{}) - config := &service.Config{ + cfg := &service.Config{ DisconnectChan: disconnectChan, Debugger: debugger.Config{ Backend: backend, @@ -519,7 +519,7 @@ func dapCmd(cmd *cobra.Command, args []string) { fmt.Printf("couldn't start listener: %s\n", err) return 1 } - config.Listener = listener + cfg.Listener = listener } else { // with a predetermined client. var err error conn, err = net.Dial("tcp", dapClientAddr) @@ -529,7 +529,7 @@ func dapCmd(cmd *cobra.Command, args []string) { } } - server := dap.NewServer(config) + server := dap.NewServer(cfg) defer server.Stop() if conn == nil { server.Run() @@ -838,7 +838,7 @@ func getPackageDir(pkg []string) string { return listout.Dir } -func attachCmd(cmd *cobra.Command, args []string) { +func attachCmd(_ *cobra.Command, args []string) { var pid int if len(args) > 0 { var err error @@ -852,11 +852,11 @@ func attachCmd(cmd *cobra.Command, args []string) { os.Exit(execute(pid, args, conf, "", debugger.ExecutingOther, args, buildFlags)) } -func coreCmd(cmd *cobra.Command, args []string) { +func coreCmd(_ *cobra.Command, args []string) { os.Exit(execute(0, []string{args[0]}, conf, args[1], debugger.ExecutingOther, args, buildFlags)) } -func connectCmd(cmd *cobra.Command, args []string) { +func connectCmd(_ *cobra.Command, args []string) { if err := logflags.Setup(log, logOutput, logDest); err != nil { fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) @@ -871,7 +871,7 @@ func connectCmd(cmd *cobra.Command, args []string) { logflags.Close() os.Exit(1) } - ec := connect(addr, nil, conf, debugger.ExecutingOther) + ec := connect(addr, nil, conf) logflags.Close() os.Exit(ec) } @@ -909,7 +909,7 @@ func splitArgs(cmd *cobra.Command, args []string) ([]string, []string) { return args, []string{} } -func connect(addr string, clientConn net.Conn, conf *config.Config, kind debugger.ExecuteKind) int { +func connect(addr string, clientConn net.Conn, conf *config.Config) int { // Create and start a terminal - attach to running instance var client *rpc2.RPCClient if clientConn != nil { @@ -1058,7 +1058,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile } if err := server.Run(); err != nil { - if err == api.ErrNotExecutable { + if errors.Is(err, api.ErrNotExecutable) { switch kind { case debugger.ExecutingGeneratedFile: fmt.Fprintln(os.Stderr, "Can not debug non-main package") @@ -1089,7 +1089,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile return status } - return connect(listener.Addr().String(), clientConn, conf, kind) + return connect(listener.Addr().String(), clientConn, conf) } func parseRedirects(redirects []string) ([3]string, error) { diff --git a/cmd/dlv/cmds/helphelpers/help.go b/cmd/dlv/cmds/helphelpers/help.go index aff5e9258f..609aa89674 100644 --- a/cmd/dlv/cmds/helphelpers/help.go +++ b/cmd/dlv/cmds/helphelpers/help.go @@ -6,10 +6,10 @@ import ( ) // Prepare prepares cmd flag set for the invocation of its usage function by -// hiding flags that we want cobra to parse but we don't want to show to the +// hiding flags that we want cobra to parse, but we don't want to show to the // user. // We do this because not all flags associated with the root command are -// valid for all subcommands but we don't want to move them out of the root +// valid for all subcommands, but we don't want to move them out of the root // command and into subcommands, since that would change how cobra parses // the command line. // diff --git a/cmd/dlv/dlv_test.go b/cmd/dlv/dlv_test.go index 32cc2d51c3..2fe55a9d0e 100644 --- a/cmd/dlv/dlv_test.go +++ b/cmd/dlv/dlv_test.go @@ -187,10 +187,10 @@ func testOutput(t *testing.T, dlvbin, output string, delveCmds []string) (stdout if err == nil { // Sometimes delve on Windows can't remove the built binary before // exiting and gets an "Access is denied" error when trying. - // See: https://travis-ci.com/go-delve/delve/jobs/296325131) + // See: https://travis-ci.com/go-delve/delve/jobs/296325131. // We have added a delay to gobuild.Remove, but to avoid any test // flakiness, we guard against this failure here as well. - if runtime.GOOS != "windows" || !strings.Contains(err.Error(), "Access is denied") { + if runtime.GOOS != "windows" { t.Errorf("running %q: file %v was not deleted\nstdout is %q, stderr is %q", delveCmds, debugbin, stdout, stderr) } return @@ -204,7 +204,7 @@ func testOutput(t *testing.T, dlvbin, output string, delveCmds []string) (stdout func getDlvBin(t *testing.T) string { // In case this was set in the environment - // from getDlvBinEBPF lets clear it here so + // from getDlvBinEBPF lets clear it here, so // we can ensure we don't get build errors // depending on the test ordering. t.Setenv("CGO_LDFLAGS", ldFlags) @@ -308,7 +308,7 @@ func TestRedirect(t *testing.T) { // and detach from and kill the headless instance client := rpc2.NewClient(listenAddr) - _ = client.Detach(true) + client.Detach(true) cmd.Wait() } @@ -427,7 +427,7 @@ func TestExitInInit(t *testing.T) { cmd.Dir = buildtestdir out, err := cmd.CombinedOutput() t.Logf("%q %v\n", string(out), err) - // dlv will exit anyway because stdin is not a tty but it will print the + // dlv will exit anyway because stdin is not a tty, but it will print the // prompt once if the init file didn't call exit successfully. if strings.Contains(string(out), "(dlv)") { t.Fatal("init did not cause dlv to exit") diff --git a/cmd/dlv/main.go b/cmd/dlv/main.go index 34df91db47..dcb92c457b 100644 --- a/cmd/dlv/main.go +++ b/cmd/dlv/main.go @@ -15,11 +15,13 @@ func main() { if Build != "" { version.DelveVersion.Build = Build } + const cgoCflagsEnv = "CGO_CFLAGS" if os.Getenv(cgoCflagsEnv) == "" { os.Setenv(cgoCflagsEnv, "-O0 -g") } else { logrus.WithFields(logrus.Fields{"layer": "dlv"}).Warnln("CGO_CFLAGS already set, Cgo code could be optimized.") } + cmds.New(false).Execute() }