diff --git a/cmd/grf/cmds/commands.go b/cmd/grf/cmds/commands.go index 15dc121..88054dd 100644 --- a/cmd/grf/cmds/commands.go +++ b/cmd/grf/cmds/commands.go @@ -36,6 +36,9 @@ var ( conf *config.Config loadConfErr error outFile string + + // logFlag is whether to log debug statements. + logFlag bool ) // New returns an initialized command tree. @@ -104,6 +107,8 @@ You'll have to wait for goref until it outputs 'successfully output to ...', or versionCommand.Flags().BoolVarP(&versionVerbose, "verbose", "v", false, "print verbose version info") rootCommand.AddCommand(versionCommand) + rootCommand.PersistentFlags().BoolVarP(&logFlag, "log", "", false, "Enable goref logging.") + return rootCommand } @@ -129,6 +134,11 @@ func coreCmd(_ *cobra.Command, args []string) { } func execute(attachPid int, exeFile, coreFile, outFile string, conf *config.Config) int { + if err := logflags.Setup(logFlag, "", ""); err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + return 1 + } + defer logflags.Close() if loadConfErr != nil { logflags.DebuggerLogger().Errorf("%v", loadConfErr) } diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index 59f1253..98191ca 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -167,7 +167,7 @@ func extractVarInfoFromEntry(bi *proc.BinaryInfo, image *proc.Image, regs op.Dwa t, err = resolveParametricType(bi, mem, t, dictAddr, mds) if err != nil { // Log the error, keep going with t, which will be the shape type - logflags.DebuggerLogger().Errorf("could not resolve parametric type of %s: %v", n, err) + logflags.DebuggerLogger().Warnf("could not resolve parametric type of %s: %v", n, err) } addr, pieces, _, _ := bi.Location(entry, dwarf.AttrLocation, regs.PC(), regs, mem) diff --git a/pkg/proc/gcmask.go b/pkg/proc/gcmask.go index 04a749c..6bf30dd 100644 --- a/pkg/proc/gcmask.go +++ b/pkg/proc/gcmask.go @@ -25,7 +25,6 @@ type gcMaskBitIterator struct { maskBase Address mask []uint64 - // for iterator addr Address // iterator address } diff --git a/pkg/proc/heap.go b/pkg/proc/heap.go index 3b44183..4e7db08 100644 --- a/pkg/proc/heap.go +++ b/pkg/proc/heap.go @@ -373,7 +373,7 @@ func (s *HeapScope) readType(sp *spanInfo, typeAddr, addr, end Address) { } mask, err := readUintRaw(mem, uint64(gcDataAddr.Add(addr.Sub(elem)/64)), 8) if err != nil { - logflags.DebuggerLogger().Errorf("read gc data addr error: %v", err) + logflags.DebuggerLogger().Warnf("read gc data addr error: %v", err) break } var headBits int64 diff --git a/pkg/proc/mem.go b/pkg/proc/mem.go index 0769f6c..5ae2a80 100644 --- a/pkg/proc/mem.go +++ b/pkg/proc/mem.go @@ -19,7 +19,10 @@ import ( "github.com/go-delve/delve/pkg/proc" ) -const cacheEnabled = true +const ( + cacheEnabled = true + cacheThreshold = 1024 * 1024 * 1024 // 1GB +) type memCache struct { loaded bool @@ -68,6 +71,9 @@ func cacheMemory(mem proc.MemoryReadWriter, addr uint64, size int) proc.MemoryRe // overflow return mem } + if size > cacheThreshold { + return mem + } switch cacheMem := mem.(type) { case *memCache: if cacheMem.contains(addr, size) {