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
- func ValidMode(m string) bool
- type AgentCall
- type Breakpoint
- type Broadcaster
- type Config
- type Frame
- type Info
- type Module
- func (m *Module) Name() string
- func (m *Module) OnInit(db *sql.DB) error
- func (m *Module) RegisterMCPTools(server *sdkmcp.Server)
- func (m *Module) RegisterMigrations(migrator *storage.Migrator) error
- func (m *Module) RegisterProtectedRoutes(mux *http.ServeMux, auth func(http.Handler) http.Handler)
- func (m *Module) SetBroadcaster(b Broadcaster)
- func (m *Module) TCPServers() []tcp.ServerConfig
- func (m *Module) Type() string
- type Proxy
- func (p *Proxy) AddBreakpoint(bp SavedBreakpoint) (SavedBreakpoint, error)
- func (p *Proxy) BreakpointsChanged()
- func (p *Proxy) Dismiss(id string) error
- func (p *Proxy) Files(q string, limit int) []string
- func (p *Proxy) HandleConnection(engine net.Conn)
- func (p *Proxy) RemoveBreakpoint(id int64) error
- func (p *Proxy) Session(id string) (*Session, error)
- func (p *Proxy) Sessions() []*Session
- func (p *Proxy) SetNotify(fn func(event string, payload any))
- func (p *Proxy) SetSettings(st Settings) error
- func (p *Proxy) Settings() Settings
- type SavedBreakpoint
- type Session
- func (s *Session) AgentLog() []AgentCall
- func (s *Session) Closed() bool
- func (s *Session) Command(name, args string, data []byte) ([]byte, error)
- func (s *Session) Continue(cmd, by, agent string) error
- func (s *Session) Info() Info
- func (s *Session) Paused() bool
- func (s *Session) Read(name, args string) ([]byte, error)
- func (s *Session) SessionBreakpoints(list []SavedBreakpoint) []SessionBreakpoint
- type SessionBreakpoint
- type Settings
- type SourceLine
- type StackFrame
- type Var
Constants ¶
const ( BPLine = "line" BPException = "exception" )
Breakpoint types.
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.
const ( DriverIDE = "ide" DriverHere = "here" )
Who drives a session: the IDE (relay) or Buggregator (standalone).
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).
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).
const ( ByUI = "ui" ByAgent = "agent" )
Who sent a continuation.
const Channel = "xdebug"
Channel is the WebSocket channel of the xdebug events.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 (*Module) RegisterMCPTools ¶
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 ¶
RegisterMigrations adds the xdebug_breakpoints table.
func (*Module) RegisterProtectedRoutes ¶
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
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 (*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) Files ¶
Files returns file URIs seen in pauses and stacks plus the files of saved breakpoints, matching q.
func (*Proxy) HandleConnection ¶
HandleConnection implements tcp.ConnectionHandler for one Xdebug connection.
func (*Proxy) RemoveBreakpoint ¶
RemoveBreakpoint deletes a breakpoint everywhere.
func (*Proxy) SetSettings ¶
SetSettings replaces the settings; the mode must be valid.
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) Command ¶
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 ¶
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) Read ¶
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 ¶
SourceLine is one line of the code view.
type StackFrame ¶
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.