debug.go (1319B)
1 package engine 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 8 "git.defalsify.org/vise.git/cache" 9 "git.defalsify.org/vise.git/state" 10 ) 11 12 // Debug implementations output details about the execution state on each execution halt. 13 type Debug interface { 14 // Break receives the state and cache in order to generate its output. 15 Break(*state.State, cache.Memory) 16 } 17 18 // SimpleDebug is a vanilla implementation of the Debug interface. 19 type SimpleDebug struct { 20 pfx string 21 w io.Writer 22 } 23 24 // NewSimpleDebug instantiates a new SimpleDebug object. 25 func NewSimpleDebug(w io.Writer) Debug { 26 if w == nil { 27 w = os.Stderr 28 } 29 return &SimpleDebug{ 30 w: w, 31 pfx: "DUMP>", 32 } 33 } 34 35 // Break implements the Debug interface. 36 func (dbg* SimpleDebug) Break(st *state.State, ca cache.Memory) { 37 fmt.Fprintf(dbg.w, "%s State:\n", dbg.pfx) 38 node, lvl := st.Where() 39 fmt.Fprintf(dbg.w, "%s\tPath: %s (%d)\n", dbg.pfx, node, lvl) 40 fmt.Fprintf(dbg.w, "%s\tFlags:\n", dbg.pfx) 41 for _, s := range state.FlagDebugger.AsList(st.Flags, st.BitSize - 8) { 42 fmt.Fprintf(dbg.w, "%s\t\t%s\n", dbg.pfx, s) 43 } 44 for i := uint32(0); i < ca.Levels(); i++ { 45 fmt.Fprintf(dbg.w, "%s Cache[%d]:\n", dbg.pfx, i) 46 ks := ca.Keys(i) 47 for _, k := range ks { 48 v, err := ca.Get(k) 49 if err != nil { 50 continue 51 } 52 fmt.Fprintf(dbg.w, "%s\t%s: %v\n", dbg.pfx, k, v) 53 } 54 } 55 }