debugger

package
v1.0.0-alpha.22 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 6 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package debugger defines portable contracts and values for controlling and inspecting Ferret debug sessions, including events, breakpoints, frames, and values. Retained event output is detached result.Content, preserving absent versus present empty data and remaining readable without consuming another observer's output or retaining a live result.Output handle.

Index

Constants

View Source
const (
	// DefaultVariablePageSize is the number requested when Count is zero.
	DefaultVariablePageSize = 100
	// MaxVariablePageSize is the largest accepted Count for one call.
	MaxVariablePageSize = 1000
)

Variables

View Source
var ErrInvalidValueReference = errors.New("invalid debugger value reference")

ErrInvalidValueReference identifies a reference that cannot be resolved in the current paused state. Implementations may wrap it. Use errors.Is.

View Source
var ErrInvalidVariablePage = errors.New("invalid debugger variable page")

ErrInvalidVariablePage identifies an unknown filter or an invalid page range.

Functions

This section is empty.

Types

type Breakpoint

type Breakpoint struct {
	Location          source.Range          `json:"location"`
	RequestedLocation source.Location       `json:"requestedLocation"`
	ID                BreakpointID          `json:"id"`
	PointID           PointID               `json:"pointID"`
	FunctionID        FunctionID            `json:"functionID"`
	BindingMode       BreakpointBindingMode `json:"bindingMode"`
	Bound             bool                  `json:"bound"`
}

Breakpoint describes a requested source-location breakpoint and its resolved executable location, when one exists.

type BreakpointBindingMode

type BreakpointBindingMode int

BreakpointBindingMode selects how a requested source location resolves to an executable debug point.

const (
	// BreakpointBindNextExecutableInSource selects the next executable point in
	// the named source and is the zero-value default.
	BreakpointBindNextExecutableInSource BreakpointBindingMode = iota
	BreakpointBindExact
	BreakpointBindNextExecutableInFunction
)

func BreakpointBindingModeFromString

func BreakpointBindingModeFromString(s string) BreakpointBindingMode

type BreakpointID

type BreakpointID int

BreakpointID identifies a breakpoint within one debugger session.

type BreakpointOptions

type BreakpointOptions struct {
	BindingMode BreakpointBindingMode `json:"bindingMode"`
}

BreakpointOptions configures how a requested source location binds.

type BreakpointRequest

type BreakpointRequest struct {
	Position source.Position   `json:"position"`
	Options  BreakpointOptions `json:"options"`
}

BreakpointRequest specifies one position and its binding policy within a source-wide replacement. Source identity belongs to ReplaceBreakpoints.

type Event

type Event struct {
	Error error `json:"error"`

	// Output is detached encoded content, not a live consumable handle.
	// Nil means absent; a non-nil pointer means present, including empty data.
	// Retained snapshots must remain valid after debugger cleanup and must
	// not share mutable implementation buffers. Recipients coordinate any
	// mutation of shared Content themselves.
	Output           *result.Content `json:"output"`
	Reason           Reason          `json:"reason"`
	HitBreakpointIDs []BreakpointID  `json:"hitBreakpointIDs"`
	Location         source.Range    `json:"location"`
	Depth            int             `json:"depth"`
}

Event reports a debugger stop, completion, or termination. Retained data is materialized; reading an event does not consume another observer's output. Available completion content may accompany an error.

type Frame

type Frame struct {
	Name       string          `json:"name"`
	Location   source.Location `json:"location"`
	FunctionID FunctionID      `json:"functionID"`
}

Frame describes the paused top frame or one of its callers.

type FunctionID

type FunctionID int

FunctionID identifies a callable function within one compiled program.

const NoFunction FunctionID = -1

NoFunction identifies the top-level program body rather than a callable function.

type PointID

type PointID int

PointID identifies a debug point within one compiled program.

type Reason

type Reason string

Reason identifies why a debug execution stopped.

const (
	ReasonEntry        Reason = "entry"
	ReasonBreakpoint   Reason = "breakpoint"
	ReasonStep         Reason = "step"
	ReasonPause        Reason = "pause"
	ReasonRuntimeError Reason = "runtime-error"
	ReasonCompleted    Reason = "completed"
	ReasonTerminated   Reason = "terminated"
)

func ReasonFromString

func ReasonFromString(s string) Reason

type Session

type Session interface {
	io.Closer
	Start(ctx context.Context) (*Event, error)
	Continue(ctx context.Context) (*Event, error)
	StepIn(ctx context.Context) (*Event, error)
	StepOver(ctx context.Context) (*Event, error)
	StepOut(ctx context.Context) (*Event, error)
	Pause(ctx context.Context) error

	// ReplaceBreakpoints atomically replaces one source's complete requested set,
	// before execution, while paused, or while running. Empty requests clear it;
	// an empty sourceName selects the launched source. Other sources are unchanged.
	// Results follow request order. Invalid positions or binding modes fail the
	// operation without publication; valid but unresolved locations return Bound=false.
	//
	// Unchanged requests retain IDs; duplicates match in ascending ID order.
	// Removed IDs are never reused in the session.
	// A hit already decided against an older set retains its IDs and remains an
	// inspectable stop. Additions affect subsequent visits, never past instructions.
	//
	// Cancellation observed before publication leaves the previous set intact.
	// After publication the operation returns success even if cancellation follows.
	// Session terminal commitment and publication are ordered: publication first
	// succeeds; completion, termination, or Close first rejects replacement.
	// Concurrent writers are serialized in admission order. Callers requiring
	// request order must await each result before issuing the next replacement.
	ReplaceBreakpoints(ctx context.Context, sourceName string, requests []BreakpointRequest) ([]Breakpoint, error)
	SetBreakpoint(ctx context.Context, pos source.Location) (Breakpoint, error)
	SetBreakpointAt(ctx context.Context, loc source.Location, opts BreakpointOptions) (Breakpoint, error)
	DeleteBreakpoint(ctx context.Context, id BreakpointID) error

	// Breakpoints returns a detached, ID-ordered snapshot, including after Close.
	// Nil or canceled contexts return an error.
	Breakpoints(ctx context.Context) ([]Breakpoint, error)
	Frames(ctx context.Context) ([]Frame, error)

	// Locals is equivalent to FrameLocals(ctx, 0), including the references
	// returned for expandable bindings.
	Locals(ctx context.Context) ([]Variable, error)

	// FrameLocals lists a frame's visible bindings. Within one stop, repeated
	// listings reuse the reference for each unchanged expandable local or
	// bound parameter in that frame.
	FrameLocals(ctx context.Context, frame int) ([]Variable, error)

	// Variables reads one bounded page of immediate children in the current
	// paused state. Page arguments follow VariablePage.Normalize. Select the
	// child kind before applying the range. An absent kind or a start at or
	// beyond the end returns an empty page. A short successful page means the
	// selected sequence is exhausted, including when its length is unknown.
	// Recognized modes that cannot be paged safely return an error matching
	// errors.ErrUnsupported. If VariableFilterAll is unsupported, request
	// VariableFilterNamed or VariableFilterIndexed on the same reference,
	// using offsets within that kind. Invalid, unknown, or expired references
	// while paused return an error matching ErrInvalidValueReference.
	//
	// Callers may retain the page as a read-only snapshot. Its slice entries
	// and counts remain readable across later calls, resume, and Close. Only
	// the expansion references expire.
	// Repeated reads of the same position in a parent's named or indexed
	// sequence reuse the child's reference for that stop.
	//
	// The producing session checks the context during reads and before publishing
	// the complete page and its new handles together. A malformed UTF-8 key in
	// the requested page is a child-read error. Read failure, cancellation,
	// termination, or handle exhaustion before publication returns a nil page
	// and an error. Exhaustion preserves previously issued handles. If remote
	// delivery fails after publication, the caller also receives a nil page
	// and an error. Context errors preserve errors.Is identity. Canceling an
	// inspection affects only that request.
	Variables(ctx context.Context, reference ValueReference, page VariablePage) ([]Variable, error)
	Evaluate(ctx context.Context, expression string) (Value, error)
	EvaluateFrame(ctx context.Context, frame int, expression string) (Value, error)
}

Session controls one retained execution. Start establishes its lifetime; resume commands observe both that lifetime and their non-nil caller context. Execution and inspection commands are serialized. Breakpoint operations may run concurrently with execution. Pause and Close may interrupt an active command. Close terminates execution, waits for commands, and releases resources; repeated closes retain the cleanup result without requiring identical error-wrapper pointers. Inspection references expire on resume or termination. A command can return an event and an error, including available completion content when subsequent cleanup fails. Event.Output holds detached materialized Content that remains readable after cleanup; inspecting a retained event never consumes a live output handle. Context arguments must be non-nil. Inspection checks cancellation before and after command admission; cancellation need not interrupt the admission wait. A canceled Pause must not request a stop. Breakpoint mutations observe their request context through publication; canceling a request does not cancel the execution. Cancellation observed before publication aborts the mutation; cancellation after publication does not undo success.

type Value

type Value struct {
	// Type is the user-facing semantic type, including for host values.
	Type string `json:"type"`
	// Display is a cheap, bounded summary. Collection summaries can use a
	// cheaply known size without previewing elements.
	Display string `json:"display"`
	// Reference is positive when at least one paging mode is safe and bounded.
	// A named or indexed view may be available even if VariableFilterAll
	// is unsupported.
	// A known empty collection or a summary-only value has reference zero.
	Reference ValueReference `json:"reference"`

	// IndexedCount and NamedCount are optional, read-only exact counts of
	// each child kind. Nil means unknown. A present count is nonnegative
	// and can be zero. A known count alone does not grant expansion.
	IndexedCount *int64 `json:"indexedCount,omitempty"`
	NamedCount   *int64 `json:"namedCount,omitempty"`
}

Value describes a value without reading its children. Producing Type and Display takes bounded work and space. Presentation and counts are detached snapshots that remain readable after the stop.

type ValueReference

type ValueReference int

ValueReference identifies an expandable debugger value within one paused session state. Resume, termination, and Close invalidate references. An expired reference must never identify another value later in that session.

func (ValueReference) Valid

func (r ValueReference) Valid() bool

Valid reports whether the reference has a valid portable encoding. It does not check whether it belongs to the current paused state.

type Variable

type Variable struct {
	Name    string `json:"name"`
	Value   Value  `json:"value"`
	Mutable bool   `json:"mutable"`
	Param   bool   `json:"param"`
}

Variable describes a local, bind parameter, or immediate child of a debugger value. A named child's Name preserves its valid UTF-8 key exactly. An indexed child's Name is its absolute decimal index.

type VariableFilter

type VariableFilter string

VariableFilter selects the immediate children in a page.

const (
	// VariableFilterAll selects named children first, followed by indexed children.
	VariableFilterAll VariableFilter = ""
	// VariableFilterNamed selects named children in stable order for the stop.
	VariableFilterNamed VariableFilter = "named"
	// VariableFilterIndexed selects indexed children in ascending source order.
	VariableFilterIndexed VariableFilter = "indexed"
)

type VariablePage

type VariablePage struct {
	Filter VariableFilter `json:"filter,omitempty"`
	Start  int64          `json:"start,omitempty"`
	Count  int64          `json:"count,omitempty"`
}

VariablePage requests a range in the selected child sequence. Start is a zero-based offset. Count is the maximum number of children to read. The zero value requests the first bounded page across both child kinds.

func (VariablePage) Normalize

func (p VariablePage) Normalize() (VariablePage, error)

Normalize replaces a zero Count with DefaultVariablePageSize. An unknown filter, negative Start or Count, Count above MaxVariablePageSize, or an exclusive end exceeding math.MaxInt64 returns ErrInvalidVariablePage.

Jump to

Keyboard shortcuts

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