
We occasionally receive bug reports from users of VSCode-go and GoLand. GoLand has its own way of capturing the packet exchange between itself and delve but VSCode-go (supposedly) doesn't. So far this hasn't been a problem since all bug reports were obvious bugs on the plugin or easy to reproduce without VSCode-go, but it might be helpful in the future to have a way to log the packet exchange between dlv and a frontend. This commit adds a --log-output option to enable logging of all rpc messages and changes service/rpccommon accordingly.
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package logflags
|
|
|
|
import (
|
|
"errors"
|
|
"io/ioutil"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
var debugger = false
|
|
var gdbWire = false
|
|
var lldbServerOutput = false
|
|
var debugLineErrors = false
|
|
var rpc = 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
|
|
}
|
|
|
|
// DebugLineErrors returns true if pkg/dwarf/line should log its recoverable
|
|
// errors.
|
|
func DebugLineErrors() bool {
|
|
return debugLineErrors
|
|
}
|
|
|
|
// RPC returns true if rpc messages should be logged.
|
|
func RPC() bool {
|
|
return rpc
|
|
}
|
|
|
|
var errLogstrWithoutLog = errors.New("--log-output specified without --log")
|
|
|
|
// Setup sets debugger flags based on the contents of logstr.
|
|
func Setup(logFlag bool, logstr string) error {
|
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
if !logFlag {
|
|
log.SetOutput(ioutil.Discard)
|
|
if logstr != "" {
|
|
return errLogstrWithoutLog
|
|
}
|
|
return nil
|
|
}
|
|
if logstr == "" {
|
|
logstr = "debugger"
|
|
}
|
|
v := strings.Split(logstr, ",")
|
|
for _, logcmd := range v {
|
|
switch logcmd {
|
|
case "debugger":
|
|
debugger = true
|
|
case "gdbwire":
|
|
gdbWire = true
|
|
case "lldbout":
|
|
lldbServerOutput = true
|
|
case "debuglineerr":
|
|
debugLineErrors = true
|
|
case "rpc":
|
|
rpc = true
|
|
}
|
|
}
|
|
return nil
|
|
}
|