From 8ce88095c6ea40a1d10ac2e07b7ce950f6dfaa2f Mon Sep 17 00:00:00 2001 From: aarzilli Date: Thu, 19 Apr 2018 10:43:23 +0200 Subject: [PATCH] cmd/dlv: Revert 4e177b, use new flag name for debug logging options Previously to 4e177bb99acc511897f9cdbfc6cbc50d92ae4725 it was possible to use --log without arguments to enable logging, this commit reenables that use case. The new functionality of the --log flag moved to a new flag name --logx. Fixes #1188 --- Documentation/usage/dlv.md | 5 +++-- Documentation/usage/dlv_attach.md | 5 +++-- Documentation/usage/dlv_connect.md | 5 +++-- Documentation/usage/dlv_core.md | 5 +++-- Documentation/usage/dlv_debug.md | 5 +++-- Documentation/usage/dlv_exec.md | 5 +++-- Documentation/usage/dlv_replay.md | 5 +++-- Documentation/usage/dlv_run.md | 5 +++-- Documentation/usage/dlv_test.md | 5 +++-- Documentation/usage/dlv_trace.md | 5 +++-- Documentation/usage/dlv_version.md | 5 +++-- cmd/dlv/cmds/commands.go | 19 ++++++++++++++----- cmd/dlv/dlv_test.go | 2 +- pkg/logflags/logflags.go | 21 ++++++++++++++++----- 14 files changed, 64 insertions(+), 33 deletions(-) diff --git a/Documentation/usage/dlv.md b/Documentation/usage/dlv.md index d431e1b3..c8435026 100644 --- a/Documentation/usage/dlv.md +++ b/Documentation/usage/dlv.md @@ -31,11 +31,12 @@ Pass flags to the program you are debugging using `--`, for example: --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_attach.md b/Documentation/usage/dlv_attach.md index cfaab55f..dc2a4c95 100644 --- a/Documentation/usage/dlv_attach.md +++ b/Documentation/usage/dlv_attach.md @@ -31,11 +31,12 @@ dlv attach pid [executable] --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_connect.md b/Documentation/usage/dlv_connect.md index edee2c66..2eabaf27 100644 --- a/Documentation/usage/dlv_connect.md +++ b/Documentation/usage/dlv_connect.md @@ -26,11 +26,12 @@ dlv connect addr --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_core.md b/Documentation/usage/dlv_core.md index 2b671ad6..8e0d6f48 100644 --- a/Documentation/usage/dlv_core.md +++ b/Documentation/usage/dlv_core.md @@ -30,11 +30,12 @@ dlv core --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_debug.md b/Documentation/usage/dlv_debug.md index da22c461..6c78ad4a 100644 --- a/Documentation/usage/dlv_debug.md +++ b/Documentation/usage/dlv_debug.md @@ -37,11 +37,12 @@ dlv debug [package] --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_exec.md b/Documentation/usage/dlv_exec.md index cc0c6efe..22f8fd0d 100644 --- a/Documentation/usage/dlv_exec.md +++ b/Documentation/usage/dlv_exec.md @@ -31,11 +31,12 @@ dlv exec --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_replay.md b/Documentation/usage/dlv_replay.md index a3fe5a18..8364ebe1 100644 --- a/Documentation/usage/dlv_replay.md +++ b/Documentation/usage/dlv_replay.md @@ -30,11 +30,12 @@ dlv replay [trace directory] --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_run.md b/Documentation/usage/dlv_run.md index 4abfff82..c8b3c5e5 100644 --- a/Documentation/usage/dlv_run.md +++ b/Documentation/usage/dlv_run.md @@ -26,11 +26,12 @@ dlv run --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_test.md b/Documentation/usage/dlv_test.md index 7e8ff0e4..f62d10da 100644 --- a/Documentation/usage/dlv_test.md +++ b/Documentation/usage/dlv_test.md @@ -37,11 +37,12 @@ dlv test [package] --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_trace.md b/Documentation/usage/dlv_trace.md index 5ab493e5..cfabdcf8 100644 --- a/Documentation/usage/dlv_trace.md +++ b/Documentation/usage/dlv_trace.md @@ -39,11 +39,12 @@ dlv trace [package] regexp --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/Documentation/usage/dlv_version.md b/Documentation/usage/dlv_version.md index b58fb65f..5e3eb6a8 100644 --- a/Documentation/usage/dlv_version.md +++ b/Documentation/usage/dlv_version.md @@ -26,11 +26,12 @@ dlv version --headless Run debug server only, in headless mode. --init string Init file, executed by the terminal client. -l, --listen string Debugging server listen address. (default "localhost:0") - --log string Comma separated list of components that should produce debug output, possible values: + --log Enable debugging server logging. + --log-output string Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output - (default "false") +Defaults to "debugger" when logging is enabled with --log. --wd string Working directory for running the program. (default ".") ``` diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index e44f5c30..96f4ba4c 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -26,7 +26,9 @@ import ( var ( // Log is whether to log debug statements. - Log string + Log bool + // LogOutput is a comma separated list of components that should produce debug output. + LogOutput string // Headless is whether to run without terminal. Headless bool // APIVersion is the requested API version while running headless @@ -86,11 +88,12 @@ func New(docCall bool) *cobra.Command { } RootCommand.PersistentFlags().StringVarP(&Addr, "listen", "l", "localhost:0", "Debugging server listen address.") - RootCommand.PersistentFlags().StringVarP(&Log, "log", "", "false", `Comma separated list of components that should produce debug output, possible values: + RootCommand.PersistentFlags().BoolVarP(&Log, "log", "", false, "Enable debugging server logging.") + RootCommand.PersistentFlags().StringVarP(&LogOutput, "log-output", "", "", `Comma separated list of components that should produce debug output, possible values: debugger Log debugger commands gdbwire Log connection to gdbserial backend lldbout Copy output from debugserver/lldb to standard output -`) +Defaults to "debugger" when logging is enabled with --log.`) RootCommand.PersistentFlags().BoolVarP(&Headless, "headless", "", false, "Run debug server only, in headless mode.") RootCommand.PersistentFlags().BoolVarP(&AcceptMulti, "accept-multiclient", "", false, "Allows a headless server to accept multiple client connections. Note that the server API is not reentrant and clients will have to coordinate.") RootCommand.PersistentFlags().IntVar(&APIVersion, "api-version", 1, "Selects API version when headless.") @@ -311,7 +314,10 @@ func debugCmd(cmd *cobra.Command, args []string) { func traceCmd(cmd *cobra.Command, args []string) { status := func() int { - logflags.Setup(Log) + if err := logflags.Setup(Log, LogOutput); err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + return 1 + } debugname, err := filepath.Abs(cmd.Flag("output").Value.String()) if err != nil { @@ -463,7 +469,10 @@ const ( ) func execute(attachPid int, processArgs []string, conf *config.Config, coreFile string, kind executeKind) int { - logflags.Setup(Log) + if err := logflags.Setup(Log, LogOutput); err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + return 1 + } // Make a TCP listener listener, err := net.Listen("tcp", Addr) diff --git a/cmd/dlv/dlv_test.go b/cmd/dlv/dlv_test.go index 31327b44..e9710ecc 100644 --- a/cmd/dlv/dlv_test.go +++ b/cmd/dlv/dlv_test.go @@ -210,7 +210,7 @@ func checkAutogenDoc(t *testing.T, filename, gencommand string, generated []byte saved := slurpFile(t, os.ExpandEnv(fmt.Sprintf("$GOPATH/src/github.com/derekparker/delve/%s", filename))) if len(saved) != len(generated) { - t.Fatalf("%s: needs to be regenerated run scripts/gen-cli-docs.go", filename) + t.Fatalf("%s: needs to be regenerated; run %s", filename, gencommand) } for i := range saved { diff --git a/pkg/logflags/logflags.go b/pkg/logflags/logflags.go index 79d9df1c..73afd0a7 100644 --- a/pkg/logflags/logflags.go +++ b/pkg/logflags/logflags.go @@ -1,6 +1,9 @@ package logflags -import "strings" +import ( + "errors" + "strings" +) var debugger = false var gdbWire = false @@ -23,11 +26,18 @@ func LLDBServerOutput() bool { return lldbServerOutput } +var errLogstrWithoutLog = errors.New("--log-output specified without --log") + // Setup sets debugger flags based on the contents of logstr. -func Setup(logstr string) { - if logstr == "true" || logstr == "" { - debugger = true - return +func Setup(log bool, logstr string) error { + if !log { + if logstr != "" { + return errLogstrWithoutLog + } + return nil + } + if logstr == "" { + logstr = "debugger" } v := strings.Split(logstr, ",") for _, logcmd := range v { @@ -40,4 +50,5 @@ func Setup(logstr string) { lldbServerOutput = true } } + return nil }