| name | cpp-debugger |
|---|---|
| description | AI-powered C/C++ debugger with breakpoint management, variable inspection, and step execution. Invoke when user needs to debug C/C++ code or asks for debugging assistance. |
This skill provides AI-assisted debugging capabilities for C/C++ projects, supporting both GDB and LLDB debuggers.
- Breakpoint Management: Set, remove, enable/disable breakpoints with support for conditional breakpoints
- Execution Control: Run, step, continue, and control program execution
- Variable Inspection: View local and global variables, evaluate expressions
- Call Stack Navigation: Navigate and inspect the call stack
- Multi-Session Support: Manage multiple debugging sessions simultaneously
- Cross-Platform: Works with GDB (Linux/macOS/Windows MinGW) and LLDB (macOS/Windows)
Invoke this skill when:
- User asks to debug C/C++ code
- User mentions breakpoints, stepping through code, or inspecting variables
- User encounters a crash or segmentation fault
- User wants to understand program flow
- User asks for help with debugging
from src.debugger import AIDebugger
# Initialize debugger
debugger = AIDebugger()
# Create a debug session
result = debugger.execute_command('''{
"action": "create_session",
"params": {
"program_path": "./my_program"
}
}''')
# Set a breakpoint
debugger.execute_command('''{
"action": "set_breakpoint",
"params": {
"session_id": "SESSION_ID",
"location": "main.cpp:42"
}
}''')
# Run the program
debugger.execute_command('''{
"action": "run",
"params": {
"session_id": "SESSION_ID"
}
}''')create_session: Create a new debugging sessionclose_session: Close and cleanup a debugging sessionlist_sessions: List all active sessions
set_breakpoint: Set a breakpoint at a locationremove_breakpoint: Remove a breakpointenable_breakpoint: Enable a disabled breakpointdisable_breakpoint: Disable a breakpointlist_breakpoints: List all breakpoints
run: Start or restart program executioncontinue: Continue execution after breakpointstep: Step into function callsnext: Step over function callsfinish: Execute until function returnspause: Pause program executionterminate: Terminate the debugged program
get_variables: Get variable valuesget_backtrace: Get call stackevaluate_expression: Evaluate an expressionget_registers: Get CPU registersread_memory: Read memory at address
Breakpoints can be set using various location formats:
- File and line:
"main.cpp:42" - Function name:
"main"or"MyClass::myMethod" - File and function:
"main.cpp:main" - Address:
"*0x4005a0"
{
"action": "set_breakpoint",
"params": {
"session_id": "SESSION_ID",
"location": "main.cpp:42",
"condition": "x > 10"
}
}All commands return JSON responses:
Success:
{
"success": true,
"result": {
// Action-specific result
}
}Error:
{
"success": false,
"error": "Error description"
}- Python 3.8 or higher
- GDB 9.0+ or LLDB 12.0+
- Required Python packages:
pygdbmi,lldb(optional)
Install required dependencies:
pip install pygdbmi
pip install lldb # Optional, for LLDB supportdebugger = AIDebugger()
# Create session
session = debugger.execute_command('''{
"action": "create_session",
"params": {"program_path": "./my_program"}
}''')
session_id = session['result']['session_id']
# Run until crash
debugger.execute_command(f'''{{
"action": "run",
"params": {{"session_id": "{session_id}"}}
}}''')
# Get backtrace to find the crash location
bt = debugger.execute_command(f'''{{
"action": "get_backtrace",
"params": {{"session_id": "{session_id}"}}
}}''')# Set breakpoint
debugger.execute_command(f'''{{
"action": "set_breakpoint",
"params": {{
"session_id": "{session_id}",
"location": "main.cpp:10"
}}
}}''')
# Run to breakpoint
debugger.execute_command(f'''{{
"action": "run",
"params": {{"session_id": "{session_id}"}}
}}''')
# Step through code
for i in range(5):
debugger.execute_command(f'''{{
"action": "next",
"params": {{"session_id": "{session_id}"}}
}}''')
# Check variables
vars = debugger.execute_command(f'''{{
"action": "get_variables",
"params": {{
"session_id": "{session_id}",
"scope": "local"
}}
}}''')If GDB is not found, ensure it's installed and in your PATH:
# Linux
sudo apt-get install gdb
# macOS
brew install gdb
# Windows (MinGW)
pacman -S mingw-w64-x86_64-gdbFor LLDB support:
# macOS (comes with Xcode)
xcode-select --install
# Linux
sudo apt-get install lldb
# Windows
# Install LLVM from https://releases.llvm.org/On some systems, debugging requires elevated permissions. Run with appropriate permissions or configure ptrace scope:
# Linux temporary fix
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scopeMonitor variable changes:
debugger.execute_command(f'''{{
"action": "set_watchpoint",
"params": {{
"session_id": "{session_id}",
"variable": "my_var"
}}
}}''')Switch between threads:
# List threads
threads = debugger.execute_command(f'''{{
"action": "list_threads",
"params": {{"session_id": "{session_id}"}}
}}''')
# Switch to thread 2
debugger.execute_command(f'''{{
"action": "switch_thread",
"params": {{
"session_id": "{session_id}",
"thread_id": 2
}}
}}''')- Remote debugging is not yet supported
- Visual Studio debugger is not supported (use GDB/LLDB on Windows)
- Core dump analysis is not implemented yet
Contributions are welcome! Please see the project repository for guidelines.
MIT License