exec
Debug precompiled Go binaries by executing them with specified arguments to analyze and troubleshoot code behavior during runtime.
Instructions
Debug a precompiled binary
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| binary | Yes | Path to the binary | |
| args | No | Arguments to pass to the binary |
Implementation Reference
- src/handlers/debug.ts:41-52 (handler)Handler function for the 'exec' tool: parses binary path and args, starts a Delve debug session, and returns session info.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}` }] }; }
- src/server.ts:99-117 (schema)Input schema definition for the 'exec' tool, specifying binary path (required) and optional arguments.{ name: "exec", description: "Debug a precompiled binary", inputSchema: { type: "object", properties: { binary: { type: "string", description: "Path to the binary" }, args: { type: "array", items: { type: "string" }, description: "Arguments to pass to the binary" } }, required: ["binary"] } },
- src/server.ts:406-408 (registration)Registers and dispatches the 'exec' tool (among debug tools) to the handleDebugCommands function in CallToolRequest handler.if (["debug", "attach", "exec", "test", "core", "dap", "replay", "trace"].includes(name)) { return handleDebugCommands(name, args); }
- src/session.ts:35-64 (helper)Core helper function that implements the execution by spawning 'dlv exec --headless ... binary args' process and manages the debug session.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:18-18 (schema)Type definition including 'exec' for debug session types.type: string; // 'debug' | 'attach' | 'exec' | 'test' | 'core' | 'replay' | 'trace' | 'dap'