debugger

package
v0.1.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 12 Imported by: 1 module, 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.

README

Debugger

Pencode implements a DAP client in dap/, session state in debugger/, and debugger views in workbench/. Adapters and debug terminals run on the workspace machine through CS v9, including SSH workspaces. The GUI never opens a local debugger for a remote project.

Go quick start

Enable the Go extension to detect/install gopls and Delve automatically. Without the extension, install dlv in the workspace server’s PATH. Select Debug in the status bar and click 添加启动器, then choose a registered Go project or package test template. Pencode writes it to .pencode/debug.json and opens the JSON for edits. Save any changes to refresh the debug configurations automatically. Choose the configured package or its tests, set a breakpoint by clicking the left edge of the gutter or pressing F9, and press F5.

Action Shortcut
Start / continue F5
Stop / detach Shift+F5
Toggle breakpoint at caret F9
Step over F10
Step in F11 while paused
Step out Shift+F11 while paused

Use the continue button to pause a running program. Select a thread or frame to inspect its scopes. Expand variables on demand, or enter an expression in Debug Console and press Enter. Program terminals requested by an adapter appear in the existing Terminal panel; console output and adapter logs appear in Debug Console and the Debugger Output channel.

Project configuration

Launchers come from the project's .pencode/debug.json array. Without configured launchers, the selector shows 暂无启动器 and starting debug is disabled; no language-specific defaults are inserted. 添加启动器 opens a popup menu of templates registered by loaded extensions. Selecting one appends its configuration to the JSON file and opens it for editing, without starting a debug session. Existing entries and workspace placeholders are preserved; save unsaved config edits before adding another template. 手动编辑配置… opens the file directly, creating an empty [] array if needed. With no registered templates, the menu offers manual editing. Saving refreshes the launcher list; use 刷新调试配置 for changes made outside the editor. An empty array is also valid. configuration is the adapter's launch/attach payload, and ${workspaceFolder} is expanded recursively in its string values. ${file} and ${fileDirname} resolve to the selected editor file on the workspace machine when debugging starts; launchers using them require an open file.

[
  {
    "label": "Go server",
    "adapter": "Delve",
    "request": "launch",
    "configuration": {
      "mode": "debug",
      "program": "${workspaceFolder}/cmd/server",
      "cwd": "${workspaceFolder}",
      "args": ["--port", "8080"],
      "env": {"APP_MODE": "development"}
    }
  },
  {
    "label": "Go package tests",
    "adapter": "Delve",
    "request": "launch",
    "configuration": {
      "mode": "test",
      "program": "${workspaceFolder}/internal/service",
      "args": ["-test.run", "TestService"]
    }
  }
]

Delve launches dlv dap --listen=127.0.0.1:0 and reads the assigned address; command can override the dlv executable, and args adds adapter arguments. stdio requires command and optionally args for other DAP adapters. tcp requires an address such as 127.0.0.1:5678 and connects from the workspace machine to an existing adapter. request accepts launch or attach; stopping an attach session sends disconnect with terminateDebuggee: false.

Extensions register optional JSON templates with peb.DebugAdapter.Templates. The Go extension provides project and package test templates; PHP provides current-file launch and Xdebug listener templates.

Extensions can also contribute named stdio adapters. Set adapter to the contributed ID, such as Xdebug from the PHP extension, and omit command/args to use its launcher. An explicit command overrides the launcher. Missing providers and duplicate adapter IDs report an error at startup.

The first version supports one active session, source breakpoints, threads, the first 100 stack frames, lazy variable expansion, expression evaluation, and integrated terminals launched directly from argv. Breakpoints remain in the project model when a tab closes and follow edits and undo/redo. They are not yet persisted across application restarts. Source navigation currently covers files inside the session's project. The Go extension manages tool installation and contributes the Delve launcher. Watch expressions, conditional breakpoint UI, and memory/disassembly views are not included.

Validation

go test ./dap ./debugger ./terminal ./client ./server
PENCODE_TEST_DLV=/path/to/dlv go test ./debugger -run TestDelve
PENCODE_TEST_DLV=/path/to/dlv go test ./workbench -run '^TestDebug'
PENCODE_TEST_PHP_EXTENSIONS=/path/to/extensions PENCODE_TEST_PHP_XDEBUG=/path/to/xdebug.so go test ./debugger -run TestPHPWithXdebugExtension

The real-Delve tests exercise the CS boundary, breakpoints, variable values, stepping, evaluation, and cleanup. They skip when Delve is unavailable.

Documentation

Overview

Package debugger owns language-independent debug session state. Snapshots are immutable after publication and can be consumed without per-frame copies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Label         string          `json:"label"`
	Adapter       string          `json:"adapter"`
	Command       string          `json:"command,omitempty"`
	Args          []string        `json:"args,omitempty"`
	Address       string          `json:"address,omitempty"`
	Request       string          `json:"request"`
	Configuration json.RawMessage `json:"configuration"`
}

Config keeps the editor's adapter settings separate from the opaque DAP launch/attach payload. All paths are interpreted on the workspace machine.

func ParseConfigs

func ParseConfigs(data []byte, root string) ([]Config, error)

func (Config) ResolveFile

func (c Config) ResolveFile(filename string) (Config, error)

ResolveFile expands the active workspace document at launch time so cached configurations follow file selection without changing the project JSON.

type Open

type Open func(context.Context) (io.ReadWriteCloser, error)

type Session

type Session struct {
	Output *output.Channel
	// contains filtered or unexported fields
}

func Start

func Start(parent context.Context, config Config, breakpoints map[string][]dap.SourceBreakpoint, open Open, handler dap.Handler, channel *output.Channel, wake func()) *Session

func (*Session) ClearConsole

func (s *Session) ClearConsole()

func (*Session) Close

func (s *Session) Close()

func (*Session) Control

func (s *Session) Control(command string)

func (*Session) Done

func (s *Session) Done() <-chan struct{}

func (*Session) Evaluate

func (s *Session) Evaluate(expression string)

func (*Session) Expand

func (s *Session) Expand(reference int)

func (*Session) SelectFrame

func (s *Session) SelectFrame(id int)

func (*Session) SelectThread

func (s *Session) SelectThread(id int)

func (*Session) SetBreakpoints

func (s *Session) SetBreakpoints(path string, breakpoints []dap.SourceBreakpoint)

func (*Session) Snapshot

func (s *Session) Snapshot() Snapshot

func (*Session) Stop

func (s *Session) Stop()

type Snapshot

type Snapshot struct {
	Breakpoints   map[string][]dap.Breakpoint
	Variables     map[int][]dap.Variable
	Reason, Error string
	Frames        []dap.StackFrame
	Threads       []dap.Thread
	Scopes        []dap.Scope
	Evaluations   []dap.Variable
	Capabilities  dap.Capabilities
	Revision      uint64
	ThreadID      int
	FrameID       int
	Epoch         uint64
	State         State
}

type State

type State uint8
const (
	Starting State = iota
	Configuring
	Running
	Stopped
	Stopping
	Ended
	Failed
)

func (State) String

func (state State) String() string

Jump to

Keyboard shortcuts

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