2018-03-31 16:03:27 +00:00
|
|
|
package logflags
|
|
|
|
|
2018-04-19 08:43:23 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
2018-03-31 16:03:27 +00:00
|
|
|
|
|
|
|
var debugger = false
|
|
|
|
var gdbWire = false
|
|
|
|
var lldbServerOutput = false
|
|
|
|
|
|
|
|
// GdbWire returns true if the gdbserial package should log all the packets
|
|
|
|
// exchanged with the stub.
|
|
|
|
func GdbWire() bool {
|
|
|
|
return gdbWire
|
|
|
|
}
|
|
|
|
|
|
|
|
// Debugger returns true if the debugger package should log.
|
|
|
|
func Debugger() bool {
|
|
|
|
return debugger
|
|
|
|
}
|
|
|
|
|
|
|
|
// LLDBServerOutput returns true if the output of the LLDB server should be
|
|
|
|
// redirected to standard output instead of suppressed.
|
|
|
|
func LLDBServerOutput() bool {
|
|
|
|
return lldbServerOutput
|
|
|
|
}
|
|
|
|
|
2018-04-19 08:43:23 +00:00
|
|
|
var errLogstrWithoutLog = errors.New("--log-output specified without --log")
|
|
|
|
|
2018-03-31 16:03:27 +00:00
|
|
|
// Setup sets debugger flags based on the contents of logstr.
|
2018-04-19 08:43:23 +00:00
|
|
|
func Setup(log bool, logstr string) error {
|
|
|
|
if !log {
|
|
|
|
if logstr != "" {
|
|
|
|
return errLogstrWithoutLog
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if logstr == "" {
|
|
|
|
logstr = "debugger"
|
2018-03-31 16:03:27 +00:00
|
|
|
}
|
|
|
|
v := strings.Split(logstr, ",")
|
|
|
|
for _, logcmd := range v {
|
|
|
|
switch logcmd {
|
|
|
|
case "debugger":
|
|
|
|
debugger = true
|
|
|
|
case "gdbwire":
|
|
|
|
gdbWire = true
|
|
|
|
case "lldbout":
|
|
|
|
lldbServerOutput = true
|
|
|
|
}
|
|
|
|
}
|
2018-04-19 08:43:23 +00:00
|
|
|
return nil
|
2018-03-31 16:03:27 +00:00
|
|
|
}
|