Debugging
Powered by Delve Debugger.
Introduction
Gont can manage Delve debugger instances attached to spawned sub-processes. These Delve instances can be used to debug or trace multiple applications in a distributed system simultaneously. Users can either use DAP-compatible IDEs like VScode to attach to those processes, or record tracepoint data generated by Delve break- & watchpoints to a PCAPng file.
Its integration with the packet capture and event tracing feature of Gont allows the user to even streaming tracepoint data interleaved with packet and other tracing data in real-time to Wireshark.
Create a debugger
import dopt "cunicu.li/gont/v2/pkt/options/debug"
t := gont.NewTracer(...)
d := gont.NewDebugger(
// ... Tracepoints are defined here
dopt.BreakOnEntry(true),
dopt.ToTracer(t),
// Listening socket for connection of external DAP client
dopt.ListenAddr("tcp:[::]:1234"))
Attach a debugger
Debug all processes started by nodes of this network:
network, _ := gont.NewNetwork("", d)
Debug all processes started by a node:
host1 := network.NewHost("host1", d)
Debug a single process:
host1.RunGo("test/main.go", d)
(Like for the event tracing)
Define tracepoints
Break-, watchpoint location
import "github.com/go-delve/delve/service/api"
import dopt "cunicu.li/gont/v2/pkg/options/debug"
d := gont.NewDebugger(
gont.NewTracepoint(
dopt.Disabled(false),
dopt.Name("tp1"),
dopt.Message("A trace message with evaluated {placeholders}"),
dopt.Location(...), // A Delve locspec
dopt.Address(0x12312321),
dopt.File("main.go"),
dopt.Line(12),
dopt.FunctionName("main.main"),
dopt.FunctionNameRegex("main\.(main|setupLogger)"),
dopt.Condition("i % 100 == 0"),
dopt.HitCondition("> 100"),
dopt.HitConditionPerGoroutine(true),
dopt.Watch("p", api.WatchRead|api.WatchWrite)),
...
)
Define tracepoints
Gathering of breakpoint information
import dopt "cunicu.li/gont/v2/pkt/options/debug"
d := gont.NewDebugger(
gont.NewTracepoint(
...
dopt.Variable("j"),
dopt.Goroutine(true),
dopt.Stacktrace(10),
dopt.LoadLocals(...),
dopt.LoadArguments(
dopt.FollowPointers(true),
dopt.MaxVariableRecurse(3),
dopt.MaxStringLen(128),
dopt.MaxArrayValues(128),
dopt.MaxStructFields(32))))
VSCode Integration
Gont generates VS Code launch compound configurations based on the active debugging sessions.
d.WriteVSCodeConfigs("", false)