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
This commit is contained in:
aarzilli 2018-04-19 10:43:23 +02:00 committed by Derek Parker
parent 7fd47749ef
commit 8ce88095c6
14 changed files with 64 additions and 33 deletions

@ -31,11 +31,12 @@ Pass flags to the program you are debugging using `--`, for example:
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -31,11 +31,12 @@ dlv attach pid [executable]
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -26,11 +26,12 @@ dlv connect addr
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -30,11 +30,12 @@ dlv core <executable> <core>
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -37,11 +37,12 @@ dlv debug [package]
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -31,11 +31,12 @@ dlv exec <path/to/binary>
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -30,11 +30,12 @@ dlv replay [trace directory]
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -26,11 +26,12 @@ dlv run
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -37,11 +37,12 @@ dlv test [package]
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -39,11 +39,12 @@ dlv trace [package] regexp
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -26,11 +26,12 @@ dlv version
--headless Run debug server only, in headless mode. --headless Run debug server only, in headless mode.
--init string Init file, executed by the terminal client. --init string Init file, executed by the terminal client.
-l, --listen string Debugging server listen address. (default "localhost:0") -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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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 ".") --wd string Working directory for running the program. (default ".")
``` ```

@ -26,7 +26,9 @@ import (
var ( var (
// Log is whether to log debug statements. // 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 is whether to run without terminal.
Headless bool Headless bool
// APIVersion is the requested API version while running headless // 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(&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 debugger Log debugger commands
gdbwire Log connection to gdbserial backend gdbwire Log connection to gdbserial backend
lldbout Copy output from debugserver/lldb to standard output 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(&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().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.") 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) { func traceCmd(cmd *cobra.Command, args []string) {
status := func() int { 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()) debugname, err := filepath.Abs(cmd.Flag("output").Value.String())
if err != nil { if err != nil {
@ -463,7 +469,10 @@ const (
) )
func execute(attachPid int, processArgs []string, conf *config.Config, coreFile string, kind executeKind) int { 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 // Make a TCP listener
listener, err := net.Listen("tcp", Addr) listener, err := net.Listen("tcp", Addr)

@ -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))) saved := slurpFile(t, os.ExpandEnv(fmt.Sprintf("$GOPATH/src/github.com/derekparker/delve/%s", filename)))
if len(saved) != len(generated) { 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 { for i := range saved {

@ -1,6 +1,9 @@
package logflags package logflags
import "strings" import (
"errors"
"strings"
)
var debugger = false var debugger = false
var gdbWire = false var gdbWire = false
@ -23,11 +26,18 @@ func LLDBServerOutput() bool {
return lldbServerOutput return lldbServerOutput
} }
var errLogstrWithoutLog = errors.New("--log-output specified without --log")
// Setup sets debugger flags based on the contents of logstr. // Setup sets debugger flags based on the contents of logstr.
func Setup(logstr string) { func Setup(log bool, logstr string) error {
if logstr == "true" || logstr == "" { if !log {
debugger = true if logstr != "" {
return return errLogstrWithoutLog
}
return nil
}
if logstr == "" {
logstr = "debugger"
} }
v := strings.Split(logstr, ",") v := strings.Split(logstr, ",")
for _, logcmd := range v { for _, logcmd := range v {
@ -40,4 +50,5 @@ func Setup(logstr string) {
lldbServerOutput = true lldbServerOutput = true
} }
} }
return nil
} }