debug

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package debug provides a breakpoint/stepping debugger engine for the Gad VM.

An Engine implements gad.DebugStepper: attach it with vm.SetDebugger(engine) and run the VM in its own goroutine. The engine pauses execution at breakpoints and step boundaries, publishing StopEvents on Stops(); a controller (a DAP server, a CLI or the web UI) consumes those events, inspects state via the engine's accessors, and resumes with Continue / StepInto / StepOver / StepOut.

The engine drives the generated debug loop (vm_loop_debug.go); the production VM loop is unaffected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Breakpoint

type Breakpoint struct {
	Line      int
	Disabled  bool
	Condition string
}

Breakpoint describes a source breakpoint. Disabled breakpoints never pause; a non-empty Condition pauses only when the expression evaluates truthy (`!value.IsFalsy()`) in the current frame's scope.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is a gad.DebugStepper implementing breakpoints and stepping.

func New

func New(stopOnEntry bool) *Engine

New creates an Engine. When stopOnEntry is true, execution pauses before the first instruction.

func (*Engine) Continue

func (e *Engine) Continue()

Continue resumes until the next breakpoint or pause.

func (*Engine) EvalInFrame

func (e *Engine) EvalInFrame(expr string, repr bool) (string, error)

EvalInFrame evaluates expr against the paused frame's locals and returns the result rendered with str() (or repr() when repr is set). It is valid only while the engine is parked at a stop; otherwise it returns an error.

func (*Engine) EvalObject

func (e *Engine) EvalObject(expr string) (gad.Object, error)

EvalObject evaluates expr against the paused frame's locals and returns the resulting object (for the tree navigator / inspection). Valid only while parked at a stop.

func (*Engine) Frames

func (e *Engine) Frames() []Frame

Frames returns the current call stack (innermost last). Valid while parked.

func (*Engine) Locals

func (e *Engine) Locals() []Variable

Locals returns the current frame's local variables. Valid while parked.

func (*Engine) Pause

func (e *Engine) Pause()

Pause requests a stop at the next instruction.

func (*Engine) SetBreakpoints

func (e *Engine) SetBreakpoints(lines []int) []int

SetBreakpoints replaces the breakpoint set with plain (enabled, unconditional) breakpoints on the given source lines and returns the accepted lines (all, here — lines are not validated against the source map).

func (*Engine) SetConditionalBreakpoints

func (e *Engine) SetConditionalBreakpoints(bps []Breakpoint)

SetConditionalBreakpoints replaces the breakpoint set with the given breakpoints (each may carry a Disabled flag and a Condition expression).

func (*Engine) Step

func (e *Engine) Step(vm *gad.VM)

Step implements gad.DebugStepper. It is called before each instruction in the debug loop and blocks while the VM is paused.

func (*Engine) StepInto

func (e *Engine) StepInto()

StepInto resumes until the next source line (entering calls).

func (*Engine) StepOut

func (e *Engine) StepOut()

StepOut resumes until control returns to a shallower frame.

func (*Engine) StepOver

func (e *Engine) StepOver()

StepOver resumes until the next source line at the current depth or shallower.

func (*Engine) Stops

func (e *Engine) Stops() <-chan StopEvent

Stops returns the channel of StopEvents. The VM is parked while an event is pending; resume it with Continue/StepInto/StepOver/StepOut.

type Frame

type Frame struct {
	FuncName string
	File     string
	Line     int
	Column   int
	// Locals holds this frame's local variables.
	Locals []Variable
}

Frame is a snapshot of a call frame for the stack view.

type StopEvent

type StopEvent struct {
	Reason StopReason
	File   string
	Line   int
	Column int
}

StopEvent is published when execution pauses.

type StopReason

type StopReason string

StopReason explains why execution paused.

const (
	StopEntry      StopReason = "entry"
	StopBreakpoint StopReason = "breakpoint"
	StopStep       StopReason = "step"
	StopPause      StopReason = "pause"
)

type Variable

type Variable struct {
	Name  string
	Type  string
	Value string
}

Variable is a named local value snapshot.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL