exec
Debug a precompiled Go binary by executing it with given arguments.
Instructions
Debug a precompiled binary
Input 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 for the 'exec' tool - starts a debugging session for a precompiled binary by calling startDebugSession with type 'exec', the binary path, and any additional args.
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 for the 'exec' tool registration - defines binary (string, required) and args (array of strings, optional) parameters.
{ 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:402-408 (registration)Routes the 'exec' tool name to handleDebugCommands via the CallToolRequestSchema handler.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; // Debug commands if (["debug", "attach", "exec", "test", "core", "dap", "replay", "trace"].includes(name)) { return handleDebugCommands(name, args); } - src/session.ts:35-64 (helper)Helper function startDebugSession used by the exec handler - spawns a delve process with type 'exec' and the binary target.
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-23 (helper)Type definition for DebugSession where 'exec' is a valid session type in the union type.
export interface DebugSession { id: string; type: string; // 'debug' | 'attach' | 'exec' | 'test' | 'core' | 'replay' | 'trace' | 'dap' target: string; process?: ChildProcess; port: number; breakpoints: Map<number, Breakpoint>; logOutput?: string[];