xdebug

package
v2.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 25 Imported by: ? 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 xdebug proxies Xdebug (DBGp) sessions to the IDE and lets an MCP agent and the web UI read the same paused session: stack, variables, properties, eval. With no IDE (mode auto or standalone) Buggregator drives the session itself: the UI steps, continues, stops or releases it. While an IDE is attached, the IDE drives and Buggregator only reads.

Index

Constants

View Source
const (
	BPLine      = "line"
	BPException = "exception"
)

Breakpoint types.

View Source
const (
	BPResolved   = "resolved"   // Xdebug found a line to stop at (resolved_line)
	BPUnresolved = "unresolved" // set, not resolved yet (the file is not loaded)
	BPSkipped    = "skipped"    // not sent: it has a condition and eval is off
	BPDisabled   = "disabled"   // switched off
	BPPending    = "pending"    // saved while the script ran: sent at the next pause
)

Breakpoint states in a session driven here.

View Source
const (
	DriverIDE  = "ide"
	DriverHere = "here"
)

Who drives a session: the IDE (relay) or Buggregator (standalone).

View Source
const (
	ReasonIDEUnreachable = "ide_unreachable"
	ReasonIDEClosed      = "ide_closed"
	ReasonEngineClosed   = "engine_closed"
	ReasonStopped        = "stopped"
	ReasonDetached       = "detached"      // released from the UI or by an agent: the script ran on
	ReasonIdleDetached   = "idle_detached" // paused with no command for idle_timeout: released
)

Close reasons of a session (tombstone).

View Source
const (
	ModeProxy      = "proxy"      // relay to the IDE; no IDE → detach, the script runs on
	ModeAuto       = "auto"       // relay when the IDE answers, else drive here
	ModeStandalone = "standalone" // never dial the IDE; drive here
)

Modes of the proxy (xdebug.mode).

View Source
const (
	ByUI    = "ui"
	ByAgent = "agent"
)

Who sent a continuation.

View Source
const Channel = "xdebug"

Channel is the WebSocket channel of the xdebug events.

Variables

This section is empty.

Functions

func ValidMode

func ValidMode(m string) bool

ValidMode reports whether m is a known xdebug.mode.

Types

type AgentCall

type AgentCall struct {
	Seq        int       `json:"seq"`
	SessionID  string    `json:"session_id"`
	At         time.Time `json:"at"`
	Tool       string    `json:"tool"`
	Args       string    `json:"args,omitempty"`
	OK         bool      `json:"ok"`
	Result     string    `json:"result_summary"`
	DurationMS int64     `json:"duration_ms"`
}

AgentCall is one MCP tool call on a session, as shown in the UI's agent log.

type Breakpoint

type Breakpoint struct {
	ID       string `json:"id"`
	Type     string `json:"type"`
	State    string `json:"state"`
	File     string `json:"file,omitempty"`
	Line     int    `json:"line,omitempty"`
	Function string `json:"function,omitempty"`
	HitCount int    `json:"hit_count"`
}

Breakpoint is a breakpoint the IDE set; the UI shows gutter dots only.

type Broadcaster

type Broadcaster interface {
	Broadcast(channel, eventName string, payload any)
}

Broadcaster publishes an event on a WebSocket channel (the ws.Hub).

type Config

type Config struct {
	Addr      string // where Xdebug connects (xdebug.client_host:client_port)
	IDEAddr   string // where the IDE listens for debug connections
	AllowEval bool   // expose eval to MCP clients and the UI
	// AllowControl exposes the MCP control tools (step, continue, stop, wait).
	AllowControl bool

	Mode             string        // proxy, auto or standalone; empty = auto
	PauseOnFirstLine bool          // a session driven here stops at the first line
	IdleTimeout      time.Duration // release a session paused here after this long without a command; 0 = 10 min, <0 = never
}

Config of the Xdebug proxy.

type Frame

type Frame struct {
	Level int    `json:"level"`
	Where string `json:"where,omitempty"`
	File  string `json:"file"`
	Line  int    `json:"line"`
	Type  string `json:"type,omitempty"`
}

Frame is one stack frame.

type Info

type Info struct {
	ID           string     `json:"id"`
	IDEKey       string     `json:"idekey"`
	State        string     `json:"state"` // starting, break, running, stopping, stopped, detached
	Kind         string     `json:"kind,omitempty"`
	Target       string     `json:"target,omitempty"`
	EntryFile    string     `json:"entry_file"`
	Language     string     `json:"language,omitempty"`
	Engine       string     `json:"engine,omitempty"`
	IDEConnected bool       `json:"ide_connected"`
	LastFile     string     `json:"last_file,omitempty"`
	LastLine     int        `json:"last_line,omitempty"`
	StartedAt    time.Time  `json:"started_at"`
	PausedAt     *time.Time `json:"paused_at,omitempty"`
	AgentCalls   int        `json:"agent_calls"`
	ClosedReason string     `json:"closed_reason,omitempty"`
	ClosedAt     *time.Time `json:"closed_at,omitempty"`

	Driver             string     `json:"driver"`                            // ide or here
	LastContinuationBy *string    `json:"last_continuation_by"`              // ui, agent or null
	LastContinuationAg string     `json:"last_continuation_agent,omitempty"` // the agent's name
	IdleDeadline       *time.Time `json:"idle_deadline"`                     // when a paused session here is released; null otherwise
}

Info is a snapshot of a session for listing.

type Module

type Module struct {
	module.BaseModule
	// contains filtered or unexported fields
}

func New

func New(cfg Config) *Module

func (*Module) Name

func (m *Module) Name() string

func (*Module) OnInit

func (m *Module) OnInit(db *sql.DB) error

OnInit loads the saved breakpoints.

func (*Module) RegisterMCPTools

func (m *Module) RegisterMCPTools(server *sdkmcp.Server)

RegisterMCPTools adds the xdebug_* tools to the MCP server: reads, the control tools when allow_control is on, xdebug_eval when allow_eval is on.

func (*Module) RegisterMigrations

func (m *Module) RegisterMigrations(migrator *storage.Migrator) error

RegisterMigrations adds the xdebug_breakpoints table.

func (*Module) RegisterProtectedRoutes

func (m *Module) RegisterProtectedRoutes(mux *http.ServeMux, auth func(http.Handler) http.Handler)

RegisterProtectedRoutes adds the /api/xdebug routes behind the API's auth.

func (*Module) SetBroadcaster

func (m *Module) SetBroadcaster(b Broadcaster)

SetBroadcaster sends session.* and agent.* events to the WebSocket hub. Events are queued and sent from one goroutine, so a slow browser never holds up the DBGp stream; when the queue is full an event is dropped.

func (*Module) TCPServers

func (m *Module) TCPServers() []tcp.ServerConfig

func (*Module) Type

func (m *Module) Type() string

type Proxy

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

Proxy accepts Xdebug connections and relays each one to the IDE, or drives it here when there is no IDE (see Settings.Mode).

func NewProxy

func NewProxy(ideAddr string) *Proxy

func (*Proxy) AddBreakpoint

func (p *Proxy) AddBreakpoint(bp SavedBreakpoint) (SavedBreakpoint, error)

AddBreakpoint saves a breakpoint and sends it to the sessions driven here.

func (*Proxy) BreakpointsChanged

func (p *Proxy) BreakpointsChanged()

BreakpointsChanged tells the UI and sends the saved breakpoints to every live session driven here before it returns: a paused session has them before the caller can continue it; a running one gets them at its next pause. Each sync reads the current list itself.

func (*Proxy) Dismiss

func (p *Proxy) Dismiss(id string) error

Dismiss removes a tombstone. A live session is never touched.

func (*Proxy) Files

func (p *Proxy) Files(q string, limit int) []string

Files returns file URIs seen in pauses and stacks plus the files of saved breakpoints, matching q.

func (*Proxy) HandleConnection

func (p *Proxy) HandleConnection(engine net.Conn)

HandleConnection implements tcp.ConnectionHandler for one Xdebug connection.

func (*Proxy) RemoveBreakpoint

func (p *Proxy) RemoveBreakpoint(id int64) error

RemoveBreakpoint deletes a breakpoint everywhere.

func (*Proxy) Session

func (p *Proxy) Session(id string) (*Session, error)

Session finds a session by id; with an empty id, the only paused session.

func (*Proxy) Sessions

func (p *Proxy) Sessions() []*Session

Sessions lists live sessions, oldest first.

func (*Proxy) SetNotify

func (p *Proxy) SetNotify(fn func(event string, payload any))

SetNotify sets the event sink (WebSocket broadcast). Call before serving.

func (*Proxy) SetSettings

func (p *Proxy) SetSettings(st Settings) error

SetSettings replaces the settings; the mode must be valid.

func (*Proxy) Settings

func (p *Proxy) Settings() Settings

Settings returns the current settings.

type SavedBreakpoint

type SavedBreakpoint struct {
	ID        int64     `json:"id"`
	Type      string    `json:"type"`                // line or exception
	File      string    `json:"file,omitempty"`      // file:// URI as PHP sees it (line)
	Line      int       `json:"line,omitempty"`      // line
	Exception string    `json:"exception,omitempty"` // class as PHP holds it, e.g. RuntimeException or * (exception); parents match, interfaces do not
	Condition string    `json:"condition,omitempty"` // PHP expression; sent only with allow_eval
	Enabled   bool      `json:"enabled"`
	Source    string    `json:"source"` // ui or mcp
	CreatedAt time.Time `json:"created_at"`
}

SavedBreakpoint is a breakpoint set from the UI or by an agent.

type Session

type Session struct {
	ID        string
	IDEKey    string
	FileURI   string
	Language  string
	Engine    string
	StartedAt time.Time
	// contains filtered or unexported fields
}

Session is one Xdebug connection, relayed to the IDE or driven here.

func (*Session) AgentLog

func (s *Session) AgentLog() []AgentCall

AgentLog returns the session's agent calls, oldest first.

func (*Session) Closed

func (s *Session) Closed() bool

Closed reports whether the session is a tombstone.

func (*Session) Command

func (s *Session) Command(name, args string, data []byte) ([]byte, error)

Command sends one read-only command for the agent and waits for its reply. args is the part after "-i <tid>"; data is sent base64-encoded after "--".

func (*Session) Continue

func (s *Session) Continue(cmd, by, agent string) error

Continue sends a continuation (run, step_into, step_over, step_out, stop, detach) from the UI or an agent. It does not wait: DBGp answers a continuation only at the next break or at the end of the script, and the reply moves the session's status. by is ByUI or ByAgent; agent is the agent's name, if known.

func (*Session) Info

func (s *Session) Info() Info

func (*Session) Paused

func (s *Session) Paused() bool

Paused reports whether the engine is stopped at a breakpoint.

func (*Session) Read

func (s *Session) Read(name, args string) ([]byte, error)

Read runs a read-only command for the UI. Replies are cached per pause, so several open tabs asking the same thing cost one DBGp round trip.

func (*Session) SessionBreakpoints

func (s *Session) SessionBreakpoints(list []SavedBreakpoint) []SessionBreakpoint

SessionBreakpoints returns the saved breakpoints with their state in this session. While paused it reads hit counts and lines from the engine.

type SessionBreakpoint

type SessionBreakpoint struct {
	SavedBreakpoint
	State        string `json:"state"`
	ResolvedLine int    `json:"resolved_line,omitempty"`
	HitCount     int    `json:"hit_count"`
}

SessionBreakpoint is a saved breakpoint with its state in one session.

type Settings

type Settings struct {
	Mode             string `json:"mode"`                // proxy, auto or standalone
	PauseOnFirstLine bool   `json:"pause_on_first_line"` // a session driven here stops at the first line
}

Settings change at runtime (PUT /api/xdebug/settings); they apply to new sessions only.

type SourceLine

type SourceLine struct {
	Line int    `json:"line"`
	Text string `json:"text"`
}

SourceLine is one line of the code view.

type StackFrame

type StackFrame struct {
	Frame
	Vendor bool `json:"vendor"`
}

StackFrame is a frame for the UI; vendor frames can be folded.

type Var

type Var struct {
	Name        string  `json:"name"`
	FullName    string  `json:"fullname,omitempty"`
	Type        string  `json:"type"`
	Class       string  `json:"class,omitempty"`
	Facet       string  `json:"facet,omitempty"`
	Value       *string `json:"value,omitempty"`
	Size        int     `json:"size,omitempty"`
	NumChildren int     `json:"numchildren,omitempty"`
	Page        int     `json:"page,omitempty"`
	PageSize    int     `json:"pagesize,omitempty"`
	Children    []Var   `json:"children,omitempty"`
}

Var is a decoded variable, array element or object property.

Jump to

Keyboard shortcuts

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