Systematic debugging and root cause analysis for identifying and fixing software issues. Use when: debugging errors, troubleshooting bugs, investigating crashes, analyzing stack traces, fixing broken code, or when user mentions debugging, error, bug, crash, or "not working".
You are an expert debugger who uses systematic approaches to identify and resolve software issues efficiently.
Use this skill when:
Follow this systematic approach:
1. Identify code region (start → end)
2. Check middle point
3. If bug present → search left half
4. If bug absent → search right half
5. Repeat until isolated
# At function entry
print(f"[DEBUG] function_name called with: {args}")
# At decision points
print(f"[DEBUG] Condition X is {condition_result}")
# Before/after state changes
print(f"[DEBUG] Before: {state}, After: {new_state}")
# Find which commit introduced the bug
git bisect start
git bisect bad HEAD
git bisect good <last-known-good-commit>
# Test each revision until found
i < n vs i <= n)arr[len(arr)] instead of arr[len(arr)-1])Structure debugging analysis as:
## Problem Statement
[Clear description of the issue]
## Environment
- [Relevant version/config info]
## Error Analysis
[Error message/stack trace analysis]
## Hypotheses (Priority Order)
1. **[Most Likely]**: [Reasoning]
2. **[Second Most Likely]**: [Reasoning]
3. **[Less Likely]**: [Reasoning]
## Investigation Steps
1. [What to check first]
2. [How to verify hypothesis]
3. [Next steps based on results]
## Root Cause
[Once identified, explain the underlying issue]
## Fix
[Specific code changes needed]
## Prevention
[How to avoid this in the future]
User Report: "My API returns 500 errors randomly"
Debugging Response:
API endpoint returns HTTP 500 errors intermittently. Not all requests fail - some succeed.
Need to see:
Database Connection Pool Exhausted: Intermittent nature suggests resource contention
Async Operation Not Awaited: Race condition in code
Unhandled Promise Rejection: Some error paths not caught
Add Detailed Logging
app.post('/api/endpoint', async (req, res) => {
console.log('[DEBUG] Request received:', req.body);
try {
const result = await someOperation();
console.log('[DEBUG] Operation succeeded');
res.json(result);
} catch (error) {
console.error('[ERROR] Operation failed:', error.stack);
res.status(500).json({ error: error.message });
}
});
Monitor Connection Pool
db.on('acquire', () => {
console.log(`[POOL] Connection acquired (${db.pool.size}/${db.pool.max})`);
});
Check for Unhandled Rejections
process.on('unhandledRejection', (reason, promise) => {
console.error('[FATAL] Unhandled Promise Rejection:', reason);
});
Deploy logging changes and monitor for patterns in: