debugger

package
v0.1.0-rc.21 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 17 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, including SSH workspaces. The GUI never opens a local debugger for a remote project.

Go quick start

Install Delve in Settings → Debuggers (DAP) → Go or put dlv on the workspace host’s PATH. Add a Delve configuration to .pencode/debug.json using the example below. 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.

Adapter settings

Open Settings → Debuggers (DAP) on the launcher or in the workspace.

Language Adapter Workspace host setup
Go Delve Install from Settings with Go, or put dlv on PATH.
PHP Xdebug Install from Settings with Node.js and enable Xdebug in the target PHP runtime.
Python debugpy Install from Settings with Python 3 and pip, or put debugpy-adapter on PATH.
Dart CLI Dart Debug Adapter Put the Dart SDK's dart executable on PATH. The adapter runs as dart debug_adapter.
C# (.NET) NetCoreDbg Install netcoredbg and the .NET runtime on the workspace host.
JavaScript, TypeScript (browser) Firefox Debug Adapter Install the adapter from Settings with Node.js, and install Firefox on the workspace host. An existing firefox-debug-adapter on PATH or an absolute path to the extension's dist/adapter.bundle.js also works.
Bash bash-dap Run pipx install bash-dap on a Unix workspace host with Bash 4.1 or later. Put bash-dap on PATH or select its executable in Settings.
Ruby rdbg Install the Ruby debug gem on the workspace host. Start rdbg in the terminal and choose the Ruby attach launcher.
C, C++, Objective-C, Objective-C++, Rust, Zig, Swift LLDB DAP Put lldb-dap on PATH or set its executable path in Settings. For Swift, use the adapter from the matching Swift toolchain.

Expand the adapter row to set its executable path. The PHP adapter path points to phpDebug.js. A project launcher's explicit command takes priority, followed by the path in Settings, then the managed copy. With none configured, Pencode uses the registered extension launcher or detects the adapter on the workspace host. For Dart and NetCoreDbg, setting the executable path in Settings supplies the built-in adapter arguments automatically. A project that specifies its own command also supplies its args, such as ["debug_adapter"] for dart.

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. 添加启动器 lists the built-in launch and attach templates along with templates contributed 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. 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.

The Python template runs the selected file. Set configuration.python to the project interpreter if the program uses a virtual environment. For LLDB, build the executable with debug information and set configuration.program to its path on the workspace host. debugpy settings · LLDB setup

The Dart template runs the selected CLI file from the workspace root. For C#, run dotnet build -c Debug and set configuration.program to the resulting application DLL. Keep the matching PDB alongside it for source breakpoints. Dart SDK debugger · NetCoreDbg

For JavaScript and TypeScript, start your project's web server and choose JavaScript / TypeScript: Firefox 网页. Change configuration.url to the page URL and webRoot to the directory served at the site root. For breakpoints in TypeScript, serve the source maps generated by your compiler or bundler. For a workspace host without a display, add "firefoxArgs": ["-headless"] to configuration. Firefox Debug Adapter

Bash: 当前脚本 runs the active script from the workspace root and writes output to Debug Console. Set configuration.console to integratedTerminal if the script reads user input. bash-dap launch options

[
  {
    "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"]
    }
  }
]

For a locally launched adapter, Delve runs 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 accepts args for other DAP adapters.

Extensions register optional JSON templates with peb.DebugAdapter.Templates.

Extensions can also contribute named stdio adapters. Set adapter to the contributed ID 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.

Remote debugging

For Ruby, run rdbg --open --host 127.0.0.1 --port 12345 app.rb in the workspace terminal. Once it is waiting for a debugger connection, select Ruby: 附加 rdbg, set a breakpoint and press F5. If you choose a different port, update the launcher's top-level port to match. The template uses source paths on the workspace host. Ruby debugger

Choose 添加启动器 → Go: 远程附加 to attach to a Go program already running under headless Delve. For example, if Delve is listening on port 2345 on the workspace host, use this .pencode/debug.json and press F5.

[
  {
    "label": "Go: 远程附加",
    "adapter": "Delve",
    "request": "attach",
    "host": "127.0.0.1",
    "port": 2345,
    "configuration": {
      "mode": "remote"
    }
  }
]

The workspace host opens the TCP connection. In an SSH workspace, 127.0.0.1 refers to the SSH host. Set host to a hostname, IPv4 address, or unbracketed IPv6 address, or omit it to use 127.0.0.1. Set port to an integer from 1 to 65535. You can also specify a single address such as [::1]:2345 in place of both fields.

Use DAP: 远程附加 for another TCP adapter. Set adapter to its ID if it expects a specific DAP adapterID. Put the adapter's launch or attach arguments in configuration, including any source path mappings. For PHP: 监听 Xdebug, the adapter runs on the workspace host and listens for the PHP runtime on configuration.port (default template value 9003). Stopping an attach session sends disconnect with terminateDebuggee: false.

Session features

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. 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_DEBUG_JS=/path/to/phpDebug.js PENCODE_TEST_PHP_XDEBUG=/path/to/xdebug.so go test ./debugger -run TestPHPWithBuiltinXdebug
go test ./debugger -run TestBuiltinStdioDebuggers

The real-Delve tests exercise the CS boundary, breakpoints, variable values, stepping, evaluation, and cleanup. They skip when Delve is unavailable. The stdio adapter test runs debugpy, LLDB, Dart, NetCoreDbg, bash-dap and the Firefox Debug Adapter when available. The Firefox tests use a headless browser and a local HTTP server, with tsc for the TypeScript source-map check. Set PENCODE_TEST_FIREFOX_DAP to the absolute path to adapter.bundle.js to test an extracted adapter. LLDB's test uses clang and NetCoreDbg's test uses the .NET SDK. Set PENCODE_TEST_INSTALL_DEBUGPY=1 to test pip installation and launch in a temporary directory.

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

View Source
var BuiltinTemplates string

BuiltinTemplates contains the launchers for built-in debug adapters.

Functions

This section is empty.

Types

type Config

type Config struct {
	Port          *uint16         `json:"port,omitempty"`
	Label         string          `json:"label"`
	Adapter       string          `json:"adapter"`
	Command       string          `json:"command,omitempty"`
	Address       string          `json:"address,omitempty"`
	Host          string          `json:"host,omitempty"`
	Request       string          `json:"request"`
	Args          []string        `json:"args,omitempty"`
	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) AdapterCommand

func (c Config) AdapterCommand(override string) protocol.DebugAdapterCommand

AdapterCommand selects the transport on the workspace host. The DAP initialize request still identifies the adapter by its configured name.

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