trace
Monitor and analyze Go program execution by tracing specific functions using regex patterns, customizable package scope, and optional stack depth details with Delve MCP.
Instructions
Trace program execution
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ebpf | No | Use eBPF for tracing (experimental) | |
| pid | No | Pid to attach to | |
| pkg | No | Package to trace (defaults to .) | |
| regexp | Yes | Regular expression to match functions to trace | |
| stack | No | Show stack trace with given depth |
Implementation Reference
- src/handlers/debug.ts:6-93 (handler)Handler function dispatched for 'trace' tool calls. Lacks specific implementation for 'trace' and will throw 'Unknown debug command' error.export async function handleDebugCommands(name: string, args: any) { switch (name) { case "debug": { const pkg = (args?.package as string) || "."; const buildFlags = args?.buildFlags as string | undefined; const cmdArgs: string[] = []; if (buildFlags) { cmdArgs.push("--build-flags", buildFlags); } const session = await startDebugSession("debug", pkg, cmdArgs); return { content: [{ type: "text", text: `Started debug session ${session.id} for package ${pkg}` }] }; } case "attach": { const pid = Number(args?.pid); if (!pid) { throw new Error("Process ID is required"); } const session = await startDebugSession("attach", pid.toString()); return { content: [{ type: "text", text: `Attached to process ${pid} with session ${session.id}` }] }; } case "exec": { const binary = String(args?.binary); const cmdArgs = (args?.args as string[]) || []; const session = await startDebugSession("exec", binary, cmdArgs); return { content: [{ type: "text", text: `Started debug session ${session.id} for binary ${binary}` }] }; } case "test": { const pkg = (args?.package as string) || "."; const testFlags = (args?.testFlags as string[]) || []; const session = await startDebugSession("test", pkg, ["--", ...testFlags]); return { content: [{ type: "text", text: `Started test debug session ${session.id} for package ${pkg}` }] }; } case "core": { const { executable, corePath } = args; const session = await startDebugSession("core", executable, [corePath]); return { content: [{ type: "text", text: `Started core dump analysis session ${session.id} for ${executable} with core ${corePath}` }] }; } case "dap": { const { clientAddr } = args; const cmdArgs = clientAddr ? ["--client-addr", clientAddr] : []; const session = await startDebugSession("dap", "", cmdArgs); return { content: [{ type: "text", text: `Started DAP server session ${session.id}${clientAddr ? ` connecting to ${clientAddr}` : ''}` }] }; } default: throw new Error("Unknown debug command"); }
- src/server.ts:320-348 (schema)Input schema and metadata for the 'trace' tool, listed in ListTools response.name: "trace", description: "Trace program execution", inputSchema: { type: "object", properties: { regexp: { type: "string", description: "Regular expression to match functions to trace" }, pkg: { type: "string", description: "Package to trace (defaults to .)" }, ebpf: { type: "boolean", description: "Use eBPF for tracing (experimental)" }, stack: { type: "number", description: "Show stack trace with given depth" }, pid: { type: "number", description: "Pid to attach to" } }, required: ["regexp"] } },
- src/server.ts:406-407 (registration)Dispatch logic in CallToolRequestSchema handler that routes 'trace' tool calls to handleDebugCommands.if (["debug", "attach", "exec", "test", "core", "dap", "replay", "trace"].includes(name)) { return handleDebugCommands(name, args);
- src/session.ts:35-64 (helper)Utility to start Delve debug session with given type ('trace') and arguments, spawning the 'dlv trace' process.export async function startDebugSession(type: string, target: string, args: string[] = []): Promise<DebugSession> { const port = await getAvailablePort(); const id = Math.random().toString(36).substring(7); const dlvArgs = [ type, "--headless", `--listen=:${port}`, "--accept-multiclient", "--api-version=2", target, ...args ]; const process = spawn("dlv", dlvArgs, { stdio: ["pipe", "pipe", "pipe"] }); const session: DebugSession = { id, type, target, process, port, breakpoints: new Map() }; sessions.set(id, session); return session; }
- src/types.ts:16-19 (schema)TypeScript type definition including 'trace' as a valid debug session type.export interface DebugSession { id: string; type: string; // 'debug' | 'attach' | 'exec' | 'test' | 'core' | 'replay' | 'trace' | 'dap' target: string;