more learning/debugging code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
cbf944b0b3
commit
973f6411f4
2
args.go
2
args.go
|
@ -4,7 +4,7 @@ package debugger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
arg "github.com/alexflint/go-arg"
|
arg "github.com/alexflint/go-arg"
|
||||||
log "go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var INFO log.LogFlag
|
var INFO log.LogFlag
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
package debugger
|
||||||
|
|
||||||
|
// channel communication to the plugins
|
||||||
|
// https://github.com/sourcegraph/conc
|
||||||
|
// https://www.reddit.com/r/golang/comments/11x1oek/hello_gophers_show_me_your_concurrent_code/
|
||||||
|
|
||||||
|
import (
|
||||||
|
// "regexp"
|
||||||
|
// "go.wit.com/gui/toolkit"
|
||||||
|
"sync"
|
||||||
|
"runtime"
|
||||||
|
"github.com/sourcegraph/conc"
|
||||||
|
"github.com/sourcegraph/conc/stream"
|
||||||
|
"github.com/sourcegraph/conc/panics"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// this should never exit
|
||||||
|
// TODO: clean up all this poorly named code
|
||||||
|
func makeConc() {
|
||||||
|
var wg conc.WaitGroup
|
||||||
|
defer wg.Wait()
|
||||||
|
|
||||||
|
startTheThing(&wg)
|
||||||
|
log.Warn("panic?")
|
||||||
|
log.Sleep(2)
|
||||||
|
log.Warn("panic? after sleep(5)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func startTheThing(wg *conc.WaitGroup) {
|
||||||
|
f := func() {
|
||||||
|
log.Warn("startTheThing() == about to panic now")
|
||||||
|
panic("test conc.WaitGroup")
|
||||||
|
}
|
||||||
|
wg.Go(func() {
|
||||||
|
ExampleCatcher(f)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleCatcher(f func()) {
|
||||||
|
var pc panics.Catcher
|
||||||
|
i := 0
|
||||||
|
pc.Try(func() { i += 1 })
|
||||||
|
pc.Try(f)
|
||||||
|
pc.Try(func() { i += 1 })
|
||||||
|
|
||||||
|
recovered := pc.Recovered()
|
||||||
|
|
||||||
|
log.Warn("panic.Recovered():", recovered.Value.(string))
|
||||||
|
frames := runtime.CallersFrames(recovered.Callers)
|
||||||
|
for {
|
||||||
|
frame, more := frames.Next()
|
||||||
|
log.Warn("\t", frame.Function)
|
||||||
|
|
||||||
|
if !more {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapStream(
|
||||||
|
in chan int,
|
||||||
|
out chan int,
|
||||||
|
f func(int) int,
|
||||||
|
) {
|
||||||
|
tasks := make(chan func())
|
||||||
|
taskResults := make(chan chan int)
|
||||||
|
|
||||||
|
// Worker goroutines
|
||||||
|
var workerWg sync.WaitGroup
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
workerWg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer workerWg.Done()
|
||||||
|
for task := range tasks {
|
||||||
|
task()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ordered reader goroutines
|
||||||
|
var readerWg sync.WaitGroup
|
||||||
|
readerWg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer readerWg.Done()
|
||||||
|
for result := range taskResults {
|
||||||
|
item := <-result
|
||||||
|
out <- item
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Feed the workers with tasks
|
||||||
|
for elem := range in {
|
||||||
|
resultCh := make(chan int, 1)
|
||||||
|
taskResults <- resultCh
|
||||||
|
tasks <- func() {
|
||||||
|
resultCh <- f(elem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We've exhausted input.
|
||||||
|
// Wait for everything to finish
|
||||||
|
close(tasks)
|
||||||
|
workerWg.Wait()
|
||||||
|
close(taskResults)
|
||||||
|
readerWg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
func mapStream2(
|
||||||
|
in chan int,
|
||||||
|
out chan int,
|
||||||
|
f func(int) int,
|
||||||
|
) {
|
||||||
|
s := stream.New().WithMaxGoroutines(10)
|
||||||
|
for elem := range in {
|
||||||
|
elem := elem
|
||||||
|
s.Go(func() stream.Callback {
|
||||||
|
res := f(elem)
|
||||||
|
return func() { out <- res }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
s.Wait()
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
module go.wit.com/gui/debugger
|
||||||
|
|
||||||
|
go 1.21.4
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/alexflint/go-arg v1.4.3
|
||||||
|
go.wit.com/gui/gui v0.9.8
|
||||||
|
go.wit.com/log v0.0.0-20240102010317-907893ba7b4b
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/alexflint/go-scalar v1.1.0 // indirect
|
||||||
|
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||||
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
|
go.uber.org/multierr v1.9.0 // indirect
|
||||||
|
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,31 @@
|
||||||
|
github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo=
|
||||||
|
github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA=
|
||||||
|
github.com/alexflint/go-scalar v1.1.0 h1:aaAouLLzI9TChcPXotr6gUhq+Scr8rl0P9P4PnltbhM=
|
||||||
|
github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||||
|
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||||
|
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
|
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||||
|
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||||
|
go.wit.com/gui/gui v0.9.8 h1:oMqM4sfucMnZxh9e2F0DKxNTuVxl2JZGXcuTRnGW+xI=
|
||||||
|
go.wit.com/gui/gui v0.9.8/go.mod h1:H2+uDT6qoQ8UkV6QUNIC1MQsgy6/aAop0zWBHnwACso=
|
||||||
|
go.wit.com/log v0.0.0-20240102010317-907893ba7b4b h1:YqDB6AChqjmt5jYN4F79UrjIDoUt58pfCgXJwp+G2wg=
|
||||||
|
go.wit.com/log v0.0.0-20240102010317-907893ba7b4b/go.mod h1:GmsggfsKrqdZdAj26fEOlcTz6qEIazbV33uyuuktvB8=
|
||||||
|
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 h1:UEX2EzLQPzLTfy/kUFQD7OXtvKn8wk/+jpDOkbl4ff4=
|
||||||
|
go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9/go.mod h1:qBpgJXThMMT15vym7/E4Ur9y8oOo2nP7t2RP52QHUNw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -21,7 +21,8 @@ type LogSettings struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ls *LogSettings) Set(b bool) {
|
func (ls *LogSettings) Set(b bool) {
|
||||||
log.Set(ls.name, b)
|
// log.Set(ls.name, b)
|
||||||
|
log.Warn("log.Set() FIXME: not working here anymore")
|
||||||
ls.checkbox.Set(b)
|
ls.checkbox.Set(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +34,10 @@ func NewLogFlag(p *gui.Node, name string) *LogSettings {
|
||||||
|
|
||||||
ls.checkbox = p.NewCheckbox(name)
|
ls.checkbox = p.NewCheckbox(name)
|
||||||
ls.label = p.NewLabel("Enable log." + name)
|
ls.label = p.NewLabel("Enable log." + name)
|
||||||
ls.checkbox.Set(log.Get(name))
|
// ls.checkbox.Set(log.Get(name))
|
||||||
ls.checkbox.Custom = func() {
|
ls.checkbox.Custom = func() {
|
||||||
log.Set(name, ls.checkbox.B)
|
// log.Set(name, ls.checkbox.B)
|
||||||
|
log.Warn("log.Set() FIXME: not working here anymore")
|
||||||
}
|
}
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
@ -89,8 +91,10 @@ func DebugFlags(n *gui.Node) {
|
||||||
g = newB.NewGroup("List")
|
g = newB.NewGroup("List")
|
||||||
g = g.NewGrid("flags grid", 2, 2)
|
g = g.NewGrid("flags grid", 2, 2)
|
||||||
|
|
||||||
|
/*
|
||||||
logGadgets["INFO"] = NewLogFlag(g, "INFO")
|
logGadgets["INFO"] = NewLogFlag(g, "INFO")
|
||||||
logGadgets["WARN"] = NewLogFlag(g, "WARN")
|
logGadgets["WARN"] = NewLogFlag(g, "WARN")
|
||||||
logGadgets["SPEW"] = NewLogFlag(g, "SPEW")
|
logGadgets["SPEW"] = NewLogFlag(g, "SPEW")
|
||||||
logGadgets["ERROR"] = NewLogFlag(g, "ERROR")
|
logGadgets["ERROR"] = NewLogFlag(g, "ERROR")
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func DebugWindow(p *gui.Node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DebugWindow2(n *gui.Node, title string) *gui.Node {
|
func DebugWindow2(n *gui.Node, title string) *gui.Node {
|
||||||
var newW, newB, gog, g1 *gui.Node
|
var newW, newB, gr *gui.Node
|
||||||
// var logSettings *gadgets.LogSettings
|
// var logSettings *gadgets.LogSettings
|
||||||
|
|
||||||
// time.Sleep(1 * time.Second)
|
// time.Sleep(1 * time.Second)
|
||||||
|
@ -32,56 +32,50 @@ func DebugWindow2(n *gui.Node, title string) *gui.Node {
|
||||||
newB = newW.NewBox("hBox", true)
|
newB = newW.NewBox("hBox", true)
|
||||||
|
|
||||||
//////////////////////// main debug things //////////////////////////////////
|
//////////////////////// main debug things //////////////////////////////////
|
||||||
gog = newB.NewGroup("Debugging Windows:")
|
gr = newB.NewGroup("Debugging Windows:")
|
||||||
|
|
||||||
gog.NewButton("logging", func () {
|
gr.NewButton("logging", func () {
|
||||||
DebugFlags(myGui)
|
DebugFlags(myGui)
|
||||||
})
|
})
|
||||||
gog.NewButton("Debug Widgets", func () {
|
gr.NewButton("Debug Widgets", func () {
|
||||||
DebugWidgetWindow(myGui)
|
DebugWidgetWindow(myGui)
|
||||||
})
|
})
|
||||||
gog.NewButton("GO Language Internals", func () {
|
|
||||||
DebugGolangWindow(bugWin)
|
|
||||||
})
|
|
||||||
gog.NewButton("GO Channels debug", func () {
|
|
||||||
DebugGoChannels(bugWin)
|
|
||||||
})
|
|
||||||
|
|
||||||
gog.NewLabel("Force Quit:")
|
gr.NewLabel("Force Quit:")
|
||||||
|
|
||||||
gog.NewButton("os.Exit()", func () {
|
gr.NewButton("os.Exit()", func () {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
//////////////////////// window debugging things //////////////////////////////////
|
//////////////////////// window debugging things //////////////////////////////////
|
||||||
g1 = newB.NewGroup("list things")
|
gr = newB.NewGroup("list things")
|
||||||
|
|
||||||
g1.NewButton("List toolkits", func () {
|
gr.NewButton("List toolkits", func () {
|
||||||
dropdownWindow(g1)
|
dropdownWindow(gr)
|
||||||
bugWin.ListToolkits()
|
bugWin.ListToolkits()
|
||||||
})
|
})
|
||||||
g1.NewButton("List Windows", func () {
|
gr.NewButton("List Windows", func () {
|
||||||
dropdownWindow(g1)
|
dropdownWindow(gr)
|
||||||
})
|
})
|
||||||
g1.NewButton("List Window Widgets", func () {
|
gr.NewButton("List Window Widgets", func () {
|
||||||
dropdownWindowWidgets(g1)
|
dropdownWindowWidgets(gr)
|
||||||
})
|
})
|
||||||
|
|
||||||
g2 := newB.NewGroup("more things")
|
gr = newB.NewGroup("more things")
|
||||||
|
|
||||||
g2.NewButton("Node.ListChildren(true)", func () {
|
gr.NewButton("Node.ListChildren(true)", func () {
|
||||||
if (activeWidget == nil) {
|
if (activeWidget == nil) {
|
||||||
activeWidget = bugWin
|
activeWidget = bugWin
|
||||||
}
|
}
|
||||||
activeWidget.ListChildren(true)
|
activeWidget.ListChildren(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
g2.NewButton("test conc", func () {
|
gr.NewButton("test conc", func () {
|
||||||
log.Log(true, "TODO: fix me")
|
log.Log(true, "TODO: fix me")
|
||||||
// makeConc()
|
// makeConc()
|
||||||
})
|
})
|
||||||
|
|
||||||
g2.NewButton("List Plugins", func () {
|
gr.NewButton("List Plugins", func () {
|
||||||
log.Log(true, "TODO: fix me")
|
log.Log(true, "TODO: fix me")
|
||||||
/*
|
/*
|
||||||
for _, aplug := range allPlugins {
|
for _, aplug := range allPlugins {
|
||||||
|
@ -90,14 +84,23 @@ func DebugWindow2(n *gui.Node, title string) *gui.Node {
|
||||||
*/
|
*/
|
||||||
})
|
})
|
||||||
|
|
||||||
g2.NewButton("load toolkit 'gocui'", func () {
|
gr.NewButton("load toolkit 'gocui'", func () {
|
||||||
bugWin.LoadToolkit("gocui")
|
bugWin.LoadToolkit("gocui")
|
||||||
})
|
})
|
||||||
|
|
||||||
g2.NewButton("load toolkit 'andlabs'", func () {
|
gr.NewButton("load toolkit 'andlabs'", func () {
|
||||||
bugWin.LoadToolkit("andlabs")
|
bugWin.LoadToolkit("andlabs")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
gr = newB.NewGroup("Learn GO")
|
||||||
|
|
||||||
|
gr.NewButton("GO Language Internals", func () {
|
||||||
|
DebugGolangWindow(myGui)
|
||||||
|
})
|
||||||
|
gr.NewButton("GO Channels debug", func () {
|
||||||
|
DebugGoChannels(myGui)
|
||||||
|
})
|
||||||
|
|
||||||
return newB
|
return newB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue