The Compiler Copilot includes an Autonomous Debugging feature where IBM BOB takes complete control of the debugging session. Instead of manually entering debugging commands, you simply specify your debugging goal, and BOB automatically:
- Runs appropriate debugging commands
- Analyzes the output from each command
- Decides the next debugging step based on findings
- Continues until the goal is achieved or maximum steps reached
- Generates a comprehensive summary of findings
This enables hands-off debugging where you can focus on understanding the results rather than executing individual commands.
User Input (Goal)
↓
IBM BOB Analyzes Goal
↓
┌──────────────────────────────────┐
│ Autonomous Debugging Loop │
│ │
│ 1. BOB decides next command │
│ 2. Execute command in debugger │
│ 3. BOB analyzes output │
│ 4. Check if goal achieved │
│ 5. Repeat or complete │
└──────────────────────────────────┘
↓
Generate Summary
↓
Present Findings to User
IBM BOB uses the following strategy to decide debugging commands:
- Initial Phase: Start with basic commands (run, backtrace, info registers)
- Investigation Phase: Set breakpoints, examine variables, inspect memory
- Analysis Phase: Step through code, analyze stack traces, check register values
- Completion Phase: Determine if goal is achieved or if stuck
autodebug <program> "<debugging_goal>" [--debugger gdb|lldb]copilot> autodebug ./myprogram "Find cause of segmentation fault"What BOB Does:
- Starts the program
- Runs until crash
- Gets backtrace
- Examines registers at crash point
- Inspects memory addresses
- Identifies null pointer dereference
- Provides fix suggestions
copilot> autodebug ./app "Identify memory leak" --debugger gdbWhat BOB Does:
- Sets breakpoints at malloc/free
- Runs program
- Tracks allocations
- Identifies unfreed memory
- Shows allocation stack traces
- Suggests where to add free()
copilot> autodebug ./test "Debug infinite loop"What BOB Does:
- Runs program
- Interrupts after timeout
- Gets backtrace
- Examines loop variables
- Identifies loop condition issue
- Suggests fix
copilot> autodebug ./calculator "Find why division returns wrong result"What BOB Does:
- Sets breakpoint at division function
- Runs with test input
- Steps through function
- Examines variables at each step
- Identifies integer division issue
- Suggests using float
During autonomous debugging, you'll see:
🤖 AUTONOMOUS DEBUGGING SESSION STARTED
================================================================================
Session ID: debug_1717567890
Program: ./myprogram
Goal: Find cause of segmentation fault
Debugger: GDB
Max Steps: 50
================================================================================
────────────────────────────────────────────────────────────────────────────────
🔍 Step 1/50
────────────────────────────────────────────────────────────────────────────────
💭 BOB's reasoning: Start program execution to trigger the crash
🔧 Executing: run
📤 Output:
Starting program: /path/to/myprogram
Program received signal SIGSEGV, Segmentation fault.
0x0000000000401234 in main () at program.c:15
15 *ptr = 42;
🧠 BOB's analysis: Program crashed with SIGSEGV at line 15 when dereferencing pointer 'ptr'
────────────────────────────────────────────────────────────────────────────────
🔍 Step 2/50
────────────────────────────────────────────────────────────────────────────────
💭 BOB's reasoning: Get full stack trace to understand call chain
🔧 Executing: backtrace
📤 Output:
#0 0x0000000000401234 in main () at program.c:15
🧠 BOB's analysis: Crash occurred in main function, no other functions in call stack
... (continues until goal achieved)
✅ BOB determined debugging goal is achieved
================================================================================
📊 GENERATING DEBUGGING SUMMARY
================================================================================
================================================================================
📋 AUTONOMOUS DEBUGGING SESSION SUMMARY
================================================================================
Session ID: debug_1717567890
Program: ./myprogram
Goal: Find cause of segmentation fault
Total Steps: 5
Duration: 0m 12s
## OBJECTIVE
Find the root cause of the segmentation fault in the program.
## APPROACH
1. Executed the program to trigger the crash
2. Analyzed the crash location and stack trace
3. Examined the pointer variable that caused the crash
4. Inspected memory and register values
5. Identified the null pointer dereference
## KEY FINDINGS
- Segmentation fault at line 15 in main()
- Pointer 'ptr' was NULL when dereferenced
- No initialization of 'ptr' before use
- Register analysis confirms NULL pointer (0x0)
## TECHNICAL DETAILS
- Crash address: 0x0000000000401234
- Faulting instruction: mov DWORD PTR [rax], 0x2a
- RAX register: 0x0 (NULL)
- Source line: *ptr = 42;
## CONCLUSION
The segmentation fault is caused by dereferencing an uninitialized pointer 'ptr'
at line 15. The pointer was never assigned a valid memory address before use.
## RECOMMENDATIONS
1. Initialize ptr before use: int *ptr = malloc(sizeof(int));
2. Add NULL check: if (ptr != NULL) { *ptr = 42; }
3. Free allocated memory: free(ptr);
4. Compile with warnings: gcc -Wall -Wextra program.c
================================================================================
💾 Session saved to: /path/to/sessions/autodebug_debug_1717567890.json
The complete session is saved as JSON:
{
"session_id": "debug_1717567890",
"program": "./myprogram",
"debugger_type": "gdb",
"initial_goal": "Find cause of segmentation fault",
"start_time": "2026-06-05T12:00:00",
"end_time": "2026-06-05T12:00:12",
"total_steps": 5,
"findings": [
"Segmentation fault at line 15",
"NULL pointer dereference identified",
"Pointer 'ptr' was never initialized"
],
"summary": "...",
"steps": [
{
"step_number": 1,
"command": "run",
"output": "...",
"analysis": "...",
"timestamp": "2026-06-05T12:00:01"
}
// ... more steps
]
}By default, autonomous debugging runs for a maximum of 50 steps. This prevents infinite loops. You can modify this in the code:
auto_debugger = AutonomousDebugger(
debugger_wrapper=debugger_wrapper,
llm_client=self.ibm_bob,
max_steps=100 # Increase if needed
)Choose between GDB and LLDB:
# Use GDB (default)
autodebug ./program "goal"
# Use LLDB explicitly
autodebug ./program "goal" --debugger lldb
# Use GDB explicitly
autodebug ./program "goal" --debugger gdbProvide specific, actionable goals:
✅ Good:
- "Find cause of segmentation fault"
- "Identify memory leak in function process_data"
- "Debug why loop never terminates"
- "Find why variable x has wrong value"
❌ Bad:
- "Fix my program"
- "Make it work"
- "Debug"
Always compile with -g flag:
gcc -g -O0 program.c -o programThis provides:
- Line number information
- Variable names
- Function names
- Source code mapping
Ensure the issue is reproducible:
- Use consistent input
- Set random seeds if applicable
- Document steps to trigger the issue
After autonomous debugging:
- Read the summary carefully
- Review the session JSON for details
- Understand each step BOB took
- Apply suggested fixes
- Re-run to verify
copilot> debug ./program
copilot> run
copilot> backtrace
copilot> info registers
copilot> print ptr
copilot> x/10x ptr
# ... many more commandsPros:
- Full control
- Can explore freely
- Learn debugging techniques
Cons:
- Time-consuming
- Requires debugging expertise
- Easy to miss important details
copilot> autodebug ./program "Find the bug"
# BOB handles everythingPros:
- Fast and efficient
- No debugging expertise needed
- Comprehensive analysis
- Automatic summary generation
- Consistent methodology
Cons:
- Less control
- May not explore all paths
- Limited by max steps
# Run autonomous debugging
copilot> autodebug ./program "Find segfault"
# Then analyze the code
copilot> generate ir program.c
copilot> analyze ir program.c
# Get fix suggestions
copilot> suggest fix program.c# First goal
copilot> autodebug ./program "Find memory leak"
# Second goal (after fixing first issue)
copilot> autodebug ./program "Optimize performance"All autonomous debugging sessions are logged to your session history:
# View session history
cat sessions/session_20260605_120000.md
# View specific autodebug session
cat sessions/autodebug_debug_1717567890.jsonIf BOB reports "STUCK":
- Check the reason in the output
- Review last few steps to understand what happened
- Try a more specific goal
- Manually debug the specific area BOB identified
If debugging hits max steps:
- Review the session to see progress
- Increase max_steps if needed
- Break down the goal into smaller sub-goals
- Use manual debugging for complex issues
If debugger commands fail:
- Check program is compiled with debug info
- Verify debugger is installed (gdb/lldb)
- Check program permissions
- Review error messages in session log
autodebug ./program "Find segmentation fault cause"BOB will:
- Run until crash
- Get backtrace
- Examine crash location
- Check pointer values
- Identify null/invalid pointer
autodebug ./program "Find memory leak"BOB will:
- Track allocations
- Monitor free() calls
- Identify unfreed memory
- Show allocation points
autodebug ./program "Debug infinite loop"BOB will:
- Run with timeout
- Interrupt execution
- Examine loop variables
- Check loop conditions
- Identify why loop doesn't exit
autodebug ./calculator "Find why 5/2 returns 2 instead of 2.5"BOB will:
- Set breakpoints
- Step through calculation
- Examine variable types
- Identify integer division
- Suggest float usage
You can use autonomous debugging in automated testing:
#!/bin/bash
# test_script.sh
# Run tests
./run_tests.sh
# If crash detected, auto-debug
if [ $? -ne 0 ]; then
./compiler-copilot.sh -c "autodebug ./test_program 'Find test failure cause'"
fi- Max Steps: Limited to configured maximum (default 50)
- Complex Issues: May not solve highly complex bugs
- Non-Deterministic: Results may vary between runs
- Debugger Dependent: Limited by GDB/LLDB capabilities
- AI Limitations: Subject to IBM BOB's understanding
Planned features:
- Interactive mode (pause and ask user)
- Custom debugging strategies
- Multi-threaded debugging support
- Performance profiling integration
- Automatic fix application
- Regression test generation
Autonomous debugging with IBM BOB provides a powerful, hands-off approach to finding and understanding bugs. By letting BOB handle the debugging commands and analysis, you can focus on understanding the root cause and applying fixes.
For best results:
- Provide clear, specific goals
- Compile with debug information
- Review the generated summaries
- Combine with other Compiler Copilot features
- Use manual debugging for complex cases
Happy debugging! 🐛🔍