| name | interactive-debugging |
| description | Patterns for controlling interactive debuggers (pdb, ipdb, gdb, lldb, node debug) via terminalcp |
Interactive Debugging with terminalcp
This skill provides comprehensive patterns for automating interactive debugger sessions using terminalcp MCP. It enables AI agents to spawn, control, and extract information from debuggers in real-time.
Overview
terminalcp enables:
- Real-time debugger control via PTY
- Breakpoint management and inspection
- Step-by-step execution with state capture
- Variable inspection and expression evaluation
- Multi-debugger session management
The MCP server runs via npx @mariozechner/terminalcp@latest --mcp and provides full terminal emulation for debugger interaction.
Python Debugging (pdb/ipdb)
Starting a Debug Session
{
"action": "start",
"command": "python -m pdb script.py",
"name": "python-debug"
}
Or with ipdb for enhanced debugging:
{
"action": "start",
"command": "python -m ipdb script.py",
"name": "python-debug"
}
Setting Breakpoints
{
"action": "stdin",
"id": "python-debug",
"data": "b script.py:42\r"
}
Set conditional breakpoint:
{
"action": "stdin",
"id": "python-debug",
"data": "b script.py:42, x > 10\r"
}
Set breakpoint in function:
{
"action": "stdin",
"id": "python-debug",
"data": "b my_function\r"
}
Execution Control
{
"action": "stdin",
"id": "python-debug",
"data": "c\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "s\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "n\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "r\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "unt 50\r"
}
Variable Inspection
{
"action": "stdin",
"id": "python-debug",
"data": "p variable_name\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "pp complex_object\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "locals()\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "p len(my_list) + 5\r"
}
Stack Frame Navigation
{
"action": "stdin",
"id": "python-debug",
"data": "w\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "u\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "d\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "l\r"
}
Capturing Debugger Output
{
"action": "stdout",
"id": "python-debug"
}
This returns the current terminal state including all debugger output, variable values, and stack traces.
GDB/LLDB Debugging (C/C++)
Starting GDB Session
{
"action": "start",
"command": "gdb ./myprogram",
"name": "gdb-debug"
}
Starting LLDB Session
{
"action": "start",
"command": "lldb ./myprogram",
"name": "lldb-debug"
}
GDB Breakpoint Management
{
"action": "stdin",
"id": "gdb-debug",
"data": "break main.c:42\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "break my_function\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "break main.c:42 if x > 10\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "info breakpoints\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "delete 1\r"
}
LLDB Breakpoint Management
{
"action": "stdin",
"id": "lldb-debug",
"data": "breakpoint set --file main.c --line 42\r"
}
{
"action": "stdin",
"id": "lldb-debug",
"data": "breakpoint set --name my_function\r"
}
{
"action": "stdin",
"id": "lldb-debug",
"data": "breakpoint list\r"
}
GDB Execution Control
{
"action": "stdin",
"id": "gdb-debug",
"data": "run\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "run arg1 arg2\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "continue\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "step\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "next\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "finish\r"
}
GDB Variable Inspection
{
"action": "stdin",
"id": "gdb-debug",
"data": "print variable_name\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "print/x pointer\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "display my_var\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "info locals\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "x/10x $rsp\r"
}
Stack and Backtrace
{
"action": "stdin",
"id": "gdb-debug",
"data": "backtrace\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "backtrace full\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "frame 2\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "up\r"
}
{
"action": "stdin",
"id": "gdb-debug",
"data": "down\r"
}
Node.js Debugging
Starting Node Debug Session
{
"action": "start",
"command": "node inspect script.js",
"name": "node-debug"
}
Node Debugger Commands
{
"action": "stdin",
"id": "node-debug",
"data": "c\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "n\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "s\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "o\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "sb()\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "sb('script.js', 42)\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "breakpoints\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "cb('script.js', 42)\r"
}
Node Variable Inspection
{
"action": "stdin",
"id": "node-debug",
"data": "exec('myVariable')\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "repl\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "myObject.property\r"
}
{
"action": "stdin",
"id": "node-debug",
"data": "\u0003"
}
Note: \u0003 is Ctrl+C to exit REPL mode.
Advanced Patterns
Automated Bug Investigation Workflow
{
"action": "start",
"command": "python -m pdb buggy_script.py",
"name": "bug-hunt"
}
{
"action": "stdin",
"id": "bug-hunt",
"data": "b buggy_script.py:100\r"
}
{
"action": "stdin",
"id": "bug-hunt",
"data": "c\r"
}
{
"action": "stdin",
"id": "bug-hunt",
"data": "pp locals()\r"
}
{
"action": "stdout",
"id": "bug-hunt"
}
{
"action": "stdin",
"id": "bug-hunt",
"data": "n\r"
}
{
"action": "stdout",
"id": "bug-hunt"
}
Multi-Breakpoint Analysis
{
"action": "stdin",
"id": "python-debug",
"data": "b function_a\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "b function_b\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "b function_c\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "c\r"
}
{
"action": "stdout",
"id": "python-debug"
}
{
"action": "stdin",
"id": "python-debug",
"data": "c\r"
}
{
"action": "stdout",
"id": "python-debug"
}
Conditional Debugging
{
"action": "stdin",
"id": "python-debug",
"data": "b process_item, item_id == 'problematic-id'\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "c\r"
}
{
"action": "stdin",
"id": "python-debug",
"data": "pp item\r"
}
{
"action": "stdout",
"id": "python-debug"
}
Post-Mortem Debugging
try:
risky_operation()
except Exception:
import pdb; pdb.post_mortem()
{
"action": "stdout",
"id": "python-debug"
}
{
"action": "stdin",
"id": "python-debug",
"data": "pp sys.exc_info()\r"
}
Stream-Based Monitoring
For long-running debug sessions, use stream mode to capture incremental output:
{
"action": "stream",
"id": "python-debug",
"since_last": true
}
This returns only new output since last check, useful for monitoring debugger progress without blocking.
Best Practices
Effective Breakpoint Strategy
- Start broad, then narrow: Set breakpoints at function entry points first
- Use conditional breakpoints: Avoid stopping at every iteration in loops
- Combine with logging: Use
p command output to understand state progression
- Clean up: Remove unnecessary breakpoints to avoid clutter
State Capture Timing
- Capture state after stepping, not before
- Use
stdout action after each significant command
- For rapid iteration, use
stream mode with since_last: true
Managing Multiple Debug Sessions
{
"action": "start",
"command": "python -m pdb version_a.py",
"name": "debug-a"
}
{
"action": "start",
"command": "python -m pdb version_b.py",
"name": "debug-b"
}
{
"action": "list"
}
{
"action": "stdin",
"id": "debug-a",
"data": "b main\r"
}
{
"action": "stdin",
"id": "debug-b",
"data": "b main\r"
}
Cleanup
Always stop debugger sessions when done:
{
"action": "stop",
"id": "python-debug"
}
Common Debugging Workflows
Python Exception Investigation
- Run script in debugger
- Let it crash or set breakpoint before error
- Use
w to see stack trace
- Use
u/d to navigate frames
- Use
p to inspect variables at each frame
- Identify root cause
Memory Leak Detection (C/C++)
- Start GDB with program
- Set breakpoint at allocation site
- Use
info proc mappings to see memory layout
- Compare memory before/after operations
- Use
x command to examine memory regions
Race Condition Debugging
- Set breakpoints at critical sections
- Run multiple debug sessions
- Use conditional breakpoints on shared state
- Capture timing of variable changes
This skill provides the foundation for AI-driven interactive debugging using terminalcp's real-time PTY capabilities.