debugger

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 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 implements the local GDB/MI controller and byte-transparent RSP relay. It owns no terminal Channel, Session lease, or MCP endpoint.

Index

Constants

This section is empty.

Variables

View Source
var ErrDataLost = errors.New("debug stream data lost; debugging cannot continue")

ErrDataLost means the Session overwrote bytes before the relay consumed them.

Functions

func DialBridge

func DialBridge(ctx context.Context, info BridgeConnection) (net.Conn, error)

DialBridge authenticates the server certificate before transmitting the bearer token. Cancellation bounds connection/authentication; after return, the caller owns the connection and its lifetime. No RSP bytes are generated.

func DialBridgeKeepAlive

func DialBridgeKeepAlive(ctx context.Context, info BridgeConnection) (net.Conn, error)

DialBridgeKeepAlive authenticates one data socket and one control socket on the same endpoint. It returns an unchanged RSP byte stream. Closing either socket terminates the pair; ctx bounds setup, and the caller owns the returned connection. A current Host is required; legacy data-only clients can still use DialBridge with explicit management renewal.

func IsCommandError

func IsCommandError(e error) bool

IsCommandError reports a completed MI error response that leaves correlation intact.

func Quote

func Quote(s string) string

Quote quotes one MI argument without allowing newline command injection.

func Relay

func Relay(ctx context.Context, conn net.Conn, stream Stream) error

Relay forwards bytes unchanged in both directions, including binary packets, acknowledgements and interrupts. Empty reads are not EOF. Packet framing is observed for ACK evidence but never rewritten. It does not negotiate no-ack mode or generate acknowledgements. Both directions drain before it returns. A failed direction closes the socket and cancels the other Session read. Blocked Session writes must be released by Application closing the Session.

Types

type BridgeConnection

type BridgeConnection struct {
	Address     string `json:"address"`
	Fingerprint string `json:"fingerprint"`
	Token       string `json:"token"`
}

BridgeConnection is a private connection descriptor for an external RSP client. Token is a bearer capability; callers must not publish this object in events or logs. Fingerprint pins the ephemeral TLS certificate before Token is sent.

type Client

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

Client owns one GDB process and its MI reader. Commands are serialized; asynchronous records are delivered independently of command responses.

func Start

func Start(path string, onRecord func(Record)) (*Client, error)

Start launches GDB with init files, auto-loaded code, and debuginfod disabled. onRecord must return promptly and must not call Command synchronously.

func (*Client) Close

func (c *Client) Close()

Close kills only the owned GDB process, closes stdin, and reaps it. Target detach/termination must already have been handled by Application.

func (*Client) Command

func (c *Client) Command(ctx context.Context, command string) (Record, error)

Command waits for its token-correlated response. Cancellation kills GDB: once a command may have executed, retrying it without a result is unsafe. Application owns target recovery and must not release its terminal lease on this error without independently proving shell restoration.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done closes when GDB's MI stream fails or exits.

func (*Client) PID

func (c *Client) PID() int

PID returns the owned GDB process ID for local socket peer authentication.

type CommandError

type CommandError struct{ Record Record }

CommandError is an authoritative GDB rejection rather than a lost response.

func (*CommandError) Error

func (e *CommandError) Error() string

Error returns GDB's MI error message.

type Endpoint

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

Endpoint accepts one authorized TLS data connection and, for a current helper, one authenticated control connection on the same TCP listener. Rejected peers do not consume them. Close interrupts authentication and both accepted sockets; the relay owner must still join its I/O workers.

func ListenBridge

func ListenBridge(address, allowedPeer string) (*Endpoint, error)

ListenBridge binds a standalone endpoint using the default port policy. Hosts should share an EndpointAllocator across their bridge operations.

func (*Endpoint) Accept

func (e *Endpoint) Accept(ctx context.Context) (net.Conn, error)

Accept authenticates bounded, sequential handshakes until one succeeds or ctx/Close ends the wait. Authentication bytes never reach the Session. The listener remains bound until Close. A v2 helper can authenticate one separate control connection on that listener; additional data clients are rejected. Neither disconnect nor OS address reuse releases the logical reservation; the operation owner calls Close at finalization.

func (*Endpoint) ClientAlive

func (e *Endpoint) ClientAlive() bool

ClientAlive reports recent challenge/response evidence from the helper's separately authenticated control socket. Merely retaining a data socket, or receiving RSP bytes, is not liveness evidence. Legacy clients return false.

func (*Endpoint) ClientError

func (e *Endpoint) ClientError() error

ClientError returns a control failure without disclosing authentication data.

func (*Endpoint) Close

func (e *Endpoint) Close()

Close idempotently releases the listener, pending authentication, and logical port reservation. It also interrupts both accepted sockets; the relay still owns joining its I/O workers.

func (*Endpoint) Connection

func (e *Endpoint) Connection() BridgeConnection

Connection returns the secret descriptor to the authorized operation owner.

type EndpointAllocator

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

EndpointAllocator tracks addresses owned by unfinished bridge operations. The zero value rotates through ports 37100..37999. Its mutex covers the cursor, real TCP binds, and reservations, never a probe-then-bind sequence. The OS bind additionally excludes other processes; the map expresses operation ownership.

func (*EndpointAllocator) Listen

func (a *EndpointAllocator) Listen(address, allowedPeer string, strictPool bool) (*Endpoint, error)

Listen binds a specific numeric IP (default loopback port pool). Wildcard binding is forbidden. A non-loopback bind requires an exact allowed peer IP; all clients, including loopback clients, must authenticate over pinned TLS. strictPool disables dynamic fallback for an omitted address. Explicit ports, including zero, always use exactly the caller's requested bind policy.

type Record

type Record struct {
	Token   string         `json:"token,omitempty"`
	Kind    string         `json:"kind"`
	Class   string         `json:"class,omitempty"`
	Results map[string]any `json:"results,omitempty"`
	Text    string         `json:"text,omitempty"`
}

Record is one parsed MI record. Repeated result keys are retained as lists. Stream text uses Go strings as byte containers; adapters must encode invalid UTF-8 before presenting it as JSON text.

func Parse

func Parse(line string) (Record, error)

Parse parses one bounded GDB/MI line, including nested tuples and both forms of MI lists. Prompt lines return a prompt record; malformed input is an error.

type RelayResult

type RelayResult struct {
	// ExitACK confirms a checksum-valid W/X packet was acknowledged.
	ExitACK bool
	// LastACK confirms the most recent complete target packet was acknowledged.
	LastACK bool
}

RelayResult records ACK evidence after both relay directions have drained.

func RelayFinalACK

func RelayFinalACK(ctx context.Context, conn net.Conn, stream Stream) (RelayResult, error)

RelayFinalACK also reports whether GDB acknowledged a checksum-valid W/X exit packet. PTYs cannot convey socket EOF; Application uses this evidence before ending a gdbserver that is waiting for stdio EOF after the inferior exited. It observes framing only: all original bytes still pass through unchanged.

type Stream

type Stream interface {
	Read(context.Context) (data []byte, dropped bool, err error)
	Write(context.Context, []byte) error
}

Stream is the minimal cursor-based Session service used by the RSP relay. Read must return an independent bounded copy and report any overwritten bytes. Write must use the existing Application lease and Session write serialization.

Jump to

Keyboard shortcuts

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